line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Symbolic::MaximaSimple; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24827
|
use parent qw{Exporter}; |
|
1
|
|
|
|
|
360
|
|
|
1
|
|
|
|
|
6
|
|
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
|
|
132
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
14
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
70
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
16
|
|
|
|
|
|
|
our $state="stoped"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $N=333333333333; |
19
|
1
|
|
|
1
|
|
956
|
use IPC::Open2; |
|
1
|
|
|
|
|
6170
|
|
|
1
|
|
|
|
|
1089
|
|
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
|
$b =~ s/\%e\b/e/g; |
103
|
0
|
|
|
|
|
0
|
$b =~ s/\%pi\b/\\pi/g; |
104
|
0
|
0
|
|
|
|
0
|
if($a{nomathenv}){ $b =~ s/^\$\$(.*)\$\$$/$1/s; |
|
0
|
|
|
|
|
0
|
|
105
|
0
|
|
|
|
|
0
|
$b } |
106
|
0
|
|
|
|
|
0
|
else{ $b } |
107
|
|
|
|
|
|
|
} |
108
|
0
|
|
|
|
|
0
|
else { [$b]} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
0
|
|
0
|
sub _clean{my $b=shift; |
112
|
0
|
|
|
|
|
0
|
$b =~ s/\(%i\d+\)\s*//g; |
113
|
0
|
|
|
|
|
0
|
$b =~ s/\s*$//; |
114
|
0
|
|
|
|
|
0
|
$b =~ s/\%e\b/e/g; |
115
|
0
|
|
|
|
|
0
|
$b =~ s/\%pi\b/\\pi/g; |
116
|
0
|
0
|
|
|
|
0
|
if($b =~ s/\(\%o\d+\)\s*//){ $b } |
|
0
|
|
|
|
|
0
|
|
117
|
0
|
|
|
|
|
0
|
else { [$b]} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _K { ## print STDERR "END (--$state--)\n\n"; |
121
|
1
|
50
|
|
1
|
|
5
|
kill(9,$pid) if $state eq "started" ; |
122
|
1
|
|
|
|
|
8
|
exit 0; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
1
|
|
|
1
|
|
326
|
END{ _K();} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; # End of Math::Symbolic::MaximaSimple |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 NAME |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Math::Symbolic::MaximaSimple - open2 interface with maxima math system |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 VERSION |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Version 0.01_4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SYNOPSIS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
use Math::Symbolic::MaximaSimple qw(:all); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$e = "x+x+x+x+x**2-4+8" |
142
|
|
|
|
|
|
|
maxima_tex($e) ## $$x^2+4\,x+4$$ |
143
|
|
|
|
|
|
|
maxima_tex1$e) ## "x^2+4\\,x+4" |
144
|
|
|
|
|
|
|
maxima_tex2($e) ## x^2+4\,x+4 |
145
|
|
|
|
|
|
|
maxima_tex2("diff($e,x)") ## 2\,x+4 |
146
|
|
|
|
|
|
|
maxima("diff($e,x)") ## 2*x+4 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 EXPORT |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 startmaxima |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
star maxima process in beckgrown with Open2. |
155
|
|
|
|
|
|
|
Not necessary; the other functions call startmaxima if state="stoped"; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 maxima_tex |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 maxima_tex1 |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 maxima_tex2 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 maxima |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
J.Joao Almeida, C<< >> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Copyright 2011-2012 Project Natura. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This library is free software; you can redistribute it |
176
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
179
|
|
|
|
|
|
|
|