| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Acme::HaltingProblem; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25358
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
37
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
218
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = "1.00"; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
|
9
|
3
|
|
|
3
|
1
|
17
|
my $class = shift; |
|
10
|
3
|
50
|
|
|
|
13
|
my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; |
|
|
0
|
|
|
|
|
0
|
|
|
11
|
3
|
50
|
|
|
|
8
|
die "No code provided for analysis" unless $self->{Machine}; |
|
12
|
3
|
100
|
|
|
|
8
|
$self->{Input} = [ ] unless ref($self->{Input}) eq 'ARRAY'; |
|
13
|
3
|
|
|
|
|
10
|
return bless $self, $class; |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub analyse { |
|
17
|
3
|
|
|
3
|
1
|
1173
|
my $self = shift; |
|
18
|
3
|
|
|
|
|
3
|
eval { $self->{Machine}->(@{ $self->{Input} }); }; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
13
|
|
|
19
|
3
|
|
|
|
|
13
|
return 1; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Acme::HaltingProblem - A program to decide whether a given program halts |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Acme::HaltingProblem; |
|
29
|
|
|
|
|
|
|
my $problem = new Acme::HaltingProblem( |
|
30
|
|
|
|
|
|
|
Machine => sub { ... }, |
|
31
|
|
|
|
|
|
|
Input => [ ... ], |
|
32
|
|
|
|
|
|
|
); |
|
33
|
|
|
|
|
|
|
my $solution = $problem->solve(); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The Halting Problem is one of the hardest problems in computing. The |
|
38
|
|
|
|
|
|
|
problem, approximately stated, is thus: |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Given an arbitrary Turing Machine T and input for that turing |
|
41
|
|
|
|
|
|
|
machine D, decide whether the computation T(D) will terminate. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item new Acme::HaltingProblem(...) |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Construct a new instance of the halting problem where the Machine is |
|
48
|
|
|
|
|
|
|
given as an arbitrary subref, and the Input is a reference to a list |
|
49
|
|
|
|
|
|
|
of arguments. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item $problem->analyse() |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Analyse the instance of the halting problem. If it halts, the method |
|
54
|
|
|
|
|
|
|
will return 1. Otherwise, it will not return 1. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 BUGS |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This code does not correctly deal with the case where the machine |
|
59
|
|
|
|
|
|
|
does not halt. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 TODO |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
It would be nice if this module accepted instances of Acme::Turing. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SUPPORT |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Mail the author at |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 AUTHOR |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Shevek |
|
72
|
|
|
|
|
|
|
CPAN ID: SHEVEK |
|
73
|
|
|
|
|
|
|
cpan@anarres.org |
|
74
|
|
|
|
|
|
|
http://www.anarres.org/projects/ |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Copyright (c) 2002 Shevek. All rights reserved. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
81
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
|
84
|
|
|
|
|
|
|
__END__; |