line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Symbolic::MaximaSimple; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17286
|
use parent qw{Exporter}; |
|
1
|
|
|
|
|
287
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
our %EXPORT_TAGS=( |
5
|
|
|
|
|
|
|
tex => [ qw{ &maxima_tex &maxima_tex1 &maxima_tex2 } ], |
6
|
|
|
|
|
|
|
maxima => [ qw{ &maxima &startmaxima } ], |
7
|
|
|
|
|
|
|
); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK= map {ref($_) ? (@$_):()} values %EXPORT_TAGS ; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$EXPORT_TAGS{all}= \@EXPORT_OK; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
112
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
14
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
51
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.01_4'; |
16
|
|
|
|
|
|
|
our $state="stoped"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $N=333333333333; |
19
|
1
|
|
|
1
|
|
557
|
use IPC::Open2; |
|
1
|
|
|
|
|
4810
|
|
|
1
|
|
|
|
|
762
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $pid; |
22
|
|
|
|
|
|
|
my $R; |
23
|
|
|
|
|
|
|
my $W; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#INIT { |
26
|
|
|
|
|
|
|
# startmaxima(); |
27
|
|
|
|
|
|
|
#} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub startmaxima{ |
30
|
0
|
0
|
|
0
|
1
|
0
|
return if $state eq "started"; |
31
|
0
|
|
|
|
|
0
|
$state = "started"; |
32
|
0
|
|
|
|
|
0
|
$SIG{"INT" }=\&_K; |
33
|
0
|
|
0
|
|
|
0
|
$pid = open2($R,$W,"maxima ---very-quiet") || die("can open2 maxima\n"); |
34
|
0
|
|
|
|
|
0
|
print $W 'display2d:false$'; |
35
|
0
|
|
|
|
|
0
|
print $W "\n$N;\n"; |
36
|
0
|
|
|
|
|
0
|
my $a=<$R>; |
37
|
0
|
|
|
|
|
0
|
while($a !~ /^\(\%o\d+\)\s*$N/){ $a = <$R>;} |
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#while(<>) { |
41
|
|
|
|
|
|
|
# chomp; |
42
|
|
|
|
|
|
|
# next unless /\S/; |
43
|
|
|
|
|
|
|
# print "maxima-- ",maxima($_), "\n"; |
44
|
|
|
|
|
|
|
# print "maxima tex-- ",maxima_tex($_), "\n"; |
45
|
|
|
|
|
|
|
# print "maxima tex1-- ",maxima_tex1($_), "\n"; |
46
|
|
|
|
|
|
|
# print "maxima tex2-- ",maxima_tex2($_), "\n"; |
47
|
|
|
|
|
|
|
#} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub maxima_tex1{ |
50
|
0
|
0
|
|
0
|
1
|
0
|
startmaxima() unless $state eq "started"; |
51
|
0
|
|
|
|
|
0
|
my $exp=shift; |
52
|
0
|
|
|
|
|
0
|
print $W "tex1($exp);\n$N;\n"; |
53
|
0
|
|
|
|
|
0
|
my $a=<$R>; |
54
|
0
|
|
|
|
|
0
|
my $b=""; |
55
|
0
|
|
|
|
|
0
|
while($a !~ /^\(\%o\d+\)\s*$N/){ |
56
|
0
|
|
|
|
|
0
|
$b .= $a; |
57
|
0
|
|
|
|
|
0
|
$a = <$R>;} |
58
|
0
|
|
|
|
|
0
|
_clean($b); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub maxima_tex2{ |
62
|
0
|
0
|
|
0
|
1
|
0
|
startmaxima() unless $state eq "started"; |
63
|
0
|
|
|
|
|
0
|
my $exp=shift; |
64
|
0
|
|
|
|
|
0
|
print $W "tex($exp);\n$N;\n"; |
65
|
|
|
|
|
|
|
#print $W "tex($exp)\$;\n$N;\n"; |
66
|
0
|
|
|
|
|
0
|
my $a=<$R>; |
67
|
0
|
|
|
|
|
0
|
my $b=""; |
68
|
0
|
|
|
|
|
0
|
while($a !~ /^\(\%o\d+\)\s*$N/){ |
69
|
0
|
|
|
|
|
0
|
$b .= $a; |
70
|
0
|
|
|
|
|
0
|
$a = <$R>;} |
71
|
0
|
|
|
|
|
0
|
_clean2($b,nomathenv=>1); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub maxima_tex{ |
75
|
0
|
0
|
|
0
|
1
|
0
|
startmaxima() unless $state eq "started"; |
76
|
0
|
|
|
|
|
0
|
my $exp=shift; |
77
|
0
|
|
|
|
|
0
|
print $W "tex($exp);\n$N;\n"; |
78
|
|
|
|
|
|
|
#print $W "tex($exp)\$;\n$N;\n"; |
79
|
0
|
|
|
|
|
0
|
my $a=<$R>; |
80
|
0
|
|
|
|
|
0
|
my $b=""; |
81
|
0
|
|
|
|
|
0
|
while($a !~ /^\(\%o\d+\)\s*$N/){ |
82
|
0
|
|
|
|
|
0
|
$b .= $a; |
83
|
0
|
|
|
|
|
0
|
$a = <$R>;} |
84
|
0
|
|
|
|
|
0
|
_clean2($b); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub maxima{ |
88
|
0
|
0
|
|
0
|
1
|
0
|
startmaxima() unless $state eq "started"; |
89
|
0
|
|
|
|
|
0
|
my $exp=shift; |
90
|
0
|
|
|
|
|
0
|
print $W "$exp;\n$N;\n"; |
91
|
0
|
|
|
|
|
0
|
my $a=<$R>; |
92
|
0
|
|
|
|
|
0
|
my $b=""; |
93
|
0
|
|
|
|
|
0
|
while($a !~ /^\(\%o\d+\)\s*$N/){ $b .= $a; |
|
0
|
|
|
|
|
0
|
|
94
|
0
|
|
|
|
|
0
|
$a = <$R>;} |
95
|
0
|
|
|
|
|
0
|
_clean($b); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
0
|
|
0
|
sub _clean2{my ($b,%a)=@_; |
99
|
0
|
|
|
|
|
0
|
$b =~ s/\(%i\d+\)\s*//g; |
100
|
0
|
|
|
|
|
0
|
$b =~ s/\s*$//; |
101
|
0
|
0
|
|
|
|
0
|
if($b =~ s/\s*\(\%o\d+\)\s*false\s*//){ |
102
|
0
|
0
|
|
|
|
0
|
if($a{nomathenv}){ $b =~ s/^\$\$(.*)\$\$$/$1/; |
|
0
|
|
|
|
|
0
|
|
103
|
0
|
|
|
|
|
0
|
$b } |
104
|
0
|
|
|
|
|
0
|
else{ $b } |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
0
|
else { [$b]} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
0
|
|
0
|
sub _clean{my $b=shift; |
110
|
0
|
|
|
|
|
0
|
$b =~ s/\(%i\d+\)\s*//g; |
111
|
0
|
|
|
|
|
0
|
$b =~ s/\s*$//; |
112
|
0
|
0
|
|
|
|
0
|
if($b =~ s/\(\%o\d+\)\s*//){ $b } |
|
0
|
|
|
|
|
0
|
|
113
|
0
|
|
|
|
|
0
|
else { [$b]} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _K { ## print STDERR "END (--$state--)\n\n"; |
117
|
1
|
50
|
|
1
|
|
3
|
kill(9,$pid) if $state eq "started" ; |
118
|
1
|
|
|
|
|
5
|
exit 0; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
1
|
|
190
|
END{ _K();} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; # End of Math::Symbolic::MaximaSimple |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 NAME |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Math::Symbolic::MaximaSimple - open2 interface with maxima math system |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 VERSION |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Version 0.01_4 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SYNOPSIS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
use Math::Symbolic::MaximaSimple qw(:all); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$e = "x+x+x+x+x**2-4+8" |
138
|
|
|
|
|
|
|
maxima_tex($e) ## $$x^2+4\,x+4$$ |
139
|
|
|
|
|
|
|
maxima_tex1$e) ## "x^2+4\\,x+4" |
140
|
|
|
|
|
|
|
maxima_tex2($e) ## x^2+4\,x+4 |
141
|
|
|
|
|
|
|
maxima_tex2("diff($e,x)") ## 2\,x+4 |
142
|
|
|
|
|
|
|
maxima("diff($e,x)") ## 2*x+4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 EXPORT |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 startmaxima |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
star maxima process in beckgrown with Open2. |
151
|
|
|
|
|
|
|
Not necessary; the other functions call startmaxima if state="stoped"; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 maxima_tex |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 maxima_tex1 |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 maxima_tex2 |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 maxima |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 AUTHOR |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
J.Joao Almeida, C<< >> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Copyright 2011 J.Joao Almeida. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
172
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
173
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
176
|
|
|
|
|
|
|
|