| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Math::Goedel; |
|
2
|
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
306281
|
use warnings; |
|
|
7
|
|
|
|
|
19
|
|
|
|
7
|
|
|
|
|
278
|
|
|
4
|
7
|
|
|
7
|
|
39
|
use strict; |
|
|
7
|
|
|
|
|
15
|
|
|
|
7
|
|
|
|
|
1514
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
75
|
use Exporter qw/import/; |
|
|
7
|
|
|
|
|
25
|
|
|
|
7
|
|
|
|
|
415
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw/goedel/; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#use Math::Prime::XS qw/is_prime/; |
|
11
|
7
|
|
|
7
|
|
21389
|
use Math::Prime::Util qw/nth_prime/; |
|
|
7
|
|
|
|
|
130391
|
|
|
|
7
|
|
|
|
|
42
|
|
|
12
|
7
|
|
|
7
|
|
19380
|
use Math::BigInt try => q/GMP,Pari/; |
|
|
7
|
|
|
|
|
414701
|
|
|
|
7
|
|
|
|
|
50
|
|
|
13
|
7
|
|
|
7
|
|
249339
|
use Carp; |
|
|
7
|
|
|
|
|
20
|
|
|
|
7
|
|
|
|
|
3879
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Math::Goedel - Fundamental Goedel number calculator |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Math::Goedel qw/goedel/; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
goedel(9); # 512 (2**9) |
|
28
|
|
|
|
|
|
|
goedel(81); # 768 (2**8 * 3**1) |
|
29
|
|
|
|
|
|
|
goedel(230);# 108 (2**2 * 3**3 * 5**0) |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Math::Goedel::enc(9); # same as goedel(9) |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
goedel(9, offset => 1); # 1024 (2**(9+1)) |
|
34
|
|
|
|
|
|
|
goedel(81, reverse => 1); # 13112 (2**1 * 3**8) |
|
35
|
|
|
|
|
|
|
goedel(4999, bigint => 1); # 24821251455656250000 as BigInt (2**1 * 3**9 * 5**9 * 7**9) |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Goedel number is calculated by following Goedel's encoding theorem |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
enc(X0X1X2...Xn) = P0**X0 * P1**X1 * P2**X2 * ..... * Pn**Xn |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
I is a I th digit (from left hand) of input number. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
I is a I th prime number. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 EXPORT |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
@EXPORT_OK => qw/goedel/ |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 goedel($n, %opts) |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
calculate goedel number for I |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head3 %opts |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head4 offset => $i |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
According to fundamental theorem, goedel numbers are not unique. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
goedel(23) == goedel(230); # 2**2 * 3**3 ( * 5**0 ) == 108 |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
To make it unique, you can specify I for I |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
enc(X0X1X2...Xn) = P0**(X0 +i) * P1**(X1 +i) * P2**(X2 +i) * ..... * Pn**(Xn +i) |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
so, |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
goedel(23, offset => 1); # 2**(2+1) * 3**(3+1) == 648 |
|
72
|
|
|
|
|
|
|
goedel(230, offset => 1); # 2**(2+1) * 3**(3+1) * 5**(0+1) == 3240 |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head4 reverse => 0|1 |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This option is for same purpose as offset option. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
If reverse is set to 1, apply I in reverse order, |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
enc(X0X1X2...Xn) = P0**Xn * P1**Xn-1 * P2**Xn-2 * ..... * Pn**X0 |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
so, |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
goedel(23, reverse => 1); # 2**3 * 3**2 == 72 |
|
85
|
|
|
|
|
|
|
goedel(230, reverse => 1); # 2**0 * 3**3 * 5**2 == 675 |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head4 bigint => 0|1 |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This option is used to force result goedel numbers to be L. |
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub goedel { |
|
93
|
48
|
|
|
48
|
1
|
11851
|
my $n = shift; |
|
94
|
48
|
|
|
|
|
229
|
my %opts = ( |
|
95
|
|
|
|
|
|
|
offset => 0, |
|
96
|
|
|
|
|
|
|
reverse => 0, |
|
97
|
|
|
|
|
|
|
bigint => 0, |
|
98
|
|
|
|
|
|
|
@_ ); |
|
99
|
|
|
|
|
|
|
|
|
100
|
48
|
100
|
33
|
|
|
756
|
croak "n should be a non-negative integer" |
|
101
|
|
|
|
|
|
|
if $n eq '' || $n =~ tr/0123456789//c; |
|
102
|
|
|
|
|
|
|
|
|
103
|
45
|
|
|
|
|
166
|
my $offset = $opts{'offset'}; |
|
104
|
45
|
100
|
33
|
|
|
593
|
croak "offset should be a non-negative integer" |
|
105
|
|
|
|
|
|
|
if $offset eq '' || $offset =~ tr/0123456789//c; |
|
106
|
|
|
|
|
|
|
|
|
107
|
42
|
|
|
|
|
55
|
my $one = do { |
|
108
|
42
|
100
|
|
|
|
97
|
if ($opts{'bigint'}) { |
|
109
|
2
|
|
|
|
|
22
|
Math::BigInt->bone; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
else { |
|
112
|
40
|
|
|
|
|
95
|
$n - $n + 1; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
}; |
|
115
|
42
|
|
|
|
|
512
|
my $g = $one; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# from here, $n is treated just as string of digits |
|
118
|
|
|
|
|
|
|
#$n = "$n"; |
|
119
|
42
|
100
|
|
|
|
103
|
$n = reverse $n if $opts{'reverse'}; |
|
120
|
42
|
|
|
|
|
130
|
foreach my $i (1 .. length($n)) { |
|
121
|
127
|
|
|
|
|
4330
|
$g *= ($one * nth_prime($i)) ** (substr($n, $i-1, 1)+$offset); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
42
|
|
|
|
|
1397
|
$g; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 enc($n) |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
synonym for goedel($n). but it won't be exported. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
|
131
|
|
|
|
|
|
|
|
|
132
|
7
|
|
|
7
|
|
127
|
{ no strict q/vars/; |
|
|
7
|
|
|
|
|
15
|
|
|
|
7
|
|
|
|
|
308
|
|
|
133
|
7
|
|
|
7
|
|
45
|
no warnings; |
|
|
7
|
|
|
|
|
12
|
|
|
|
7
|
|
|
|
|
1269
|
|
|
134
|
|
|
|
|
|
|
*enc = *goedel; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 REFERENCES |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Goedel number: L |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Discussion of "how to make goedel number unique" (in Japanese): |
|
142
|
|
|
|
|
|
|
L, L |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
KATOU Akira (turugina), C<< >> |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 CONTRIBUTERS |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
DANAJ |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 BUGS |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
155
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
156
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SUPPORT |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
perldoc Math::Goedel |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
You can also look for information at: |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=over 4 |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * Search CPAN |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=back |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Copyright 2008 KATOU Akira (turugina), all rights reserved. |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
199
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
1; # End of Math::Goedel |