line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# FormulaDB.pm - A db of formulas and there properties |
4
|
|
|
|
|
|
|
# (c) Copyright 1998 Hakan Ardo |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
7
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
8
|
|
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or |
9
|
|
|
|
|
|
|
# any later version. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
12
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
|
|
|
|
# GNU General Public License for more details. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
17
|
|
|
|
|
|
|
# along with this program; if not, write to the Free Software |
18
|
|
|
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Math::Expr::FormulaDB - A db of formulas and there properties |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
require Math::Expr::FormulaDB; |
27
|
|
|
|
|
|
|
$db=new Math::Expr::FormulaDB($file); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package Math::Expr::FormulaDB; |
32
|
1
|
|
|
1
|
|
507
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
33
|
1
|
|
|
1
|
|
5
|
use Math::Expr; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1349
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
require Math::Expr::Rule; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
0
|
|
|
0
|
0
|
|
my $self = bless {}, shift; |
39
|
0
|
|
|
|
|
|
$self->Load(shift); |
40
|
0
|
|
|
|
|
|
my $db; |
41
|
0
|
|
|
|
|
|
my ($vl, $hl); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
foreach ($self->Keys) { |
44
|
0
|
|
|
|
|
|
$db=$self->Get($_); |
45
|
0
|
|
|
|
|
|
$vl=Parse($db->{'vl'}); $vl=$vl->Simplify; |
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$hl=Parse($db->{'hl'}); $hl=$hl->Simplify; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$db->{'for'}= new Math::Expr::Rule($vl, $hl); |
49
|
0
|
|
|
|
|
|
$db->{'back'}= new Math::Expr::Rule($hl, $vl); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub Load { |
56
|
0
|
|
|
0
|
0
|
|
my ($self, $file) = @_; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if (-f $file) {$self->LoadFile($file);} |
|
0
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if (-d $file) {$self->LoadDir($file);} |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
sub LoadFile { |
62
|
0
|
|
|
0
|
0
|
|
my ($self, $file) = @_; |
63
|
0
|
|
|
|
|
|
my %t; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
open (F, "<$file"); |
66
|
0
|
|
|
|
|
|
while () { |
67
|
0
|
0
|
|
|
|
|
if (/^([^:]+)\s*:\s*(.*)$/) { |
68
|
0
|
|
|
|
|
|
my $a=lc($1); |
69
|
0
|
0
|
|
|
|
|
if (defined $t{$a}) {$t{$a}.="\n$2";} else {$t{$a}=$2;} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
0
|
|
|
|
if (/^\s*$/ || eof F) { |
72
|
0
|
0
|
|
|
|
|
if ($t{'name'}) { |
73
|
0
|
|
|
|
|
|
my $t=$t{'name'}; |
74
|
0
|
|
|
|
|
|
delete $t{'name'}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
foreach (keys %t) { |
77
|
0
|
|
|
|
|
|
$self->{'opps'}{$t}{$_}=$t{$_}; |
78
|
0
|
|
|
|
|
|
delete $t{$_}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub LoadDir { |
86
|
0
|
|
|
0
|
0
|
|
my ($self, $dir) = @_; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
foreach (split(/\n/s, `find $dir -type f`)) { |
89
|
0
|
0
|
|
|
|
|
next if (/~$/); |
90
|
0
|
|
|
|
|
|
$self->LoadFile($_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub Keys { |
95
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
keys %{$self->{'opps'}}; |
|
0
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub Get { |
101
|
0
|
|
|
0
|
0
|
|
my ($self, $a) = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$self->{'opps'}{$a}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub Find { |
107
|
0
|
|
|
0
|
0
|
|
my ($self, $e, $t) = @_; |
108
|
0
|
|
|
|
|
|
my $db; |
109
|
0
|
|
|
|
|
|
my ($n, $d, $i); |
110
|
0
|
|
|
|
|
|
my (@res, $id); |
111
|
0
|
|
|
|
|
|
my $r; |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
if (!defined $t) {$t=0;} |
|
0
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
foreach $n ($self->Keys) { |
116
|
0
|
|
|
|
|
|
$db=$self->Get($n); |
117
|
0
|
|
|
|
|
|
foreach $d ("for", "back") { |
118
|
0
|
0
|
0
|
|
|
|
if (!$t || !$db->{'triv'.$d}) { |
119
|
0
|
|
|
|
|
|
@res=$db->{$d}->Apply($e); |
120
|
0
|
|
|
|
|
|
$id=$db->{$d}->GetId; |
121
|
0
|
|
|
|
|
|
for ($i=0; $i<=$#res; $i++) { |
122
|
0
|
|
|
|
|
|
$r->{"$n-$d-".$id->[$i]}=$res[$i]; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
$r; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub ApplyProof { |
131
|
0
|
|
|
0
|
0
|
|
my ($self, $key) = @_; |
132
|
0
|
|
|
|
|
|
my %vars; |
133
|
0
|
|
|
|
|
|
my $db=$self->Get($key); |
134
|
0
|
|
|
|
|
|
my $res=""; |
135
|
0
|
|
|
|
|
|
my $prev=""; |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
if (defined $db->{'b'}) { |
138
|
0
|
|
|
|
|
|
$vars{'vl'}=Parse($db->{'vl'}); |
139
|
0
|
|
|
|
|
|
$vars{'hl'}=Parse($db->{'hl'}); |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$res.=$vars{'hl'}->toText; |
142
|
0
|
|
|
|
|
|
$vars{'hl'}->Simplify; |
143
|
0
|
|
|
|
|
|
$res.=" <=> ".$vars{'hl'}->toText."\n"; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$res.=$vars{'vl'}->toText; |
146
|
0
|
|
|
|
|
|
$vars{'vl'}->Simplify; |
147
|
0
|
|
|
|
|
|
$res.=" <=> " . $vars{'vl'}->toText; |
148
|
0
|
|
|
|
|
|
$prev="vl"; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
foreach (split(/\n/s, $db->{'b'})) { |
151
|
0
|
0
|
|
|
|
|
if (/^\s*\$([^\s=]+)\s*=\s*([^\'\s]*)\s*(\'[^\']+\')?$/) { |
152
|
0
|
|
|
|
|
|
my $var=$1; my $rule=$2; my $pre=$3; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
153
|
0
|
0
|
0
|
|
|
|
if (defined $pre && $pre=~/^\s*\'\s*([^=\s]+)\s*=\s*([^\']+)\'\s*$/) { |
154
|
0
|
|
|
|
|
|
my $a=$1; my $b=$2; |
|
0
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
print "Pre: $a<=>$b\n"; |
156
|
0
|
|
|
|
|
|
$pre=new Math::Expr::VarSet; |
157
|
0
|
|
|
|
|
|
$pre->Set($a, Parse($b)); |
158
|
|
|
|
|
|
|
} else { |
159
|
0
|
|
|
|
|
|
$pre=undef; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
if ($prev ne $var) {$res.="\n".$vars{$var}->toText;} |
|
0
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
$vars{$var}=$self->ApplyAt($vars{$var},$rule,$pre); |
164
|
0
|
|
|
|
|
|
$res.=" <=> " . $vars{$var}->toText; |
165
|
0
|
|
|
|
|
|
$prev=$var; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
0
|
|
|
|
|
|
$res."\n"; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub ApplyAt { |
173
|
0
|
|
|
0
|
0
|
|
my ($self, $e, $r,$pre) = @_; |
174
|
0
|
|
|
|
|
|
my ($rule, $dir, $pos) = split (/-/, $r); |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
$self->Get($rule)->{$dir}->ApplyAt($e,$pos,$pre); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |