blib/lib/Math/Symbolic/MaximaSimple.pm

filter: Statementstmt 28.0% 25 / 89 Branchbran 6.6% 2 / 30 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 46.1% 6 / 13 Podpod 100% 5 / 5 totaltotal 27.1% 38 / 140 CC 16 SCAR 23.1
CC
16
Cov
22%
startmaxima
20.0
maxima_tex1
12.0
maxima_tex2
12.0
CRAP 10.0
↑ Summary
1 package Math::Symbolic::MaximaSimple;
2  
3 2 ▶use parent qw{Exporter};
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 our %EXPORT_TAGS=(
5 tex => [ qw{ &maxima_tex &maxima_tex1 &maxima_tex2 } ],
6 maxima => [ qw{ &maxima &startmaxima } ],
7 );
8  
9 2 ▶our @EXPORT_OK= map {ref($_) ? (@$_):()} values %EXPORT_TAGS ;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 4 0 4
10  
11 2 $EXPORT_TAGS{all}= \@EXPORT_OK;
12  
13 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 our $VERSION = '0.02';
16 2 our $state="stoped";
17  
18 2 our $N=333333333333;
19 2 ▶use IPC::Open2;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 my $pid;
22 my $R;
23 2 my $W;
24  
25 #INIT {
26 # startmaxima();
27 #}
28  
29 0 ▶sub startmaxima{
Subroutine startmaxima: not called CC=4 SCAR=30.0
Pod documented
30 0 ▶ return if $state eq "started";
Branch: 1 branch
BranchTrueFalseTotal
if $Math::Symbolic::MaximaSimple::state eq "started" 0 0 0
31 0 $state = "started";
32 0 $SIG{"INT" }=\&_K;
33 0 ▶ $pid = open2($R,$W,"maxima ---very-quiet") || die("can open2 maxima\n");
Condition0%0/2
open2($R, $W, 'maxima ---very-quiet') || die("can open2 maxima\n")
l!l
00
MC/DC0%0/1
open2($R, $W, 'maxima ---very-quiet') || die("can open2 maxima\n")
open2($R, $W, 'maxima ---very-quiet')
Truth table0%0/2
A
A= open2($R, $W, 'maxima ---very-quiet')
Aresult
11
00
34 0 print $W 'display2d:false$';
35 0 print $W "\n$N;\n";
36 0 my $a=<$R>;
37 0 ▶ while($a !~ /^\(\%o\d+\)\s*$N/){ $a = <$R>;}
Branch: 1 branch
BranchTrueFalseTotal
if (not $a =~ /^\(\%o\d+\)\s*$Math::Symbolic::MaximaSimple::N/) 0 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 0 ▶sub maxima_tex1{
Subroutine maxima_tex1: not called CC=3 SCAR=24.8
Pod documented
50 0 ▶ startmaxima() unless $state eq "started";
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Symbolic::MaximaSimple::state eq "started" 0 0 0
51 0 my $exp=shift;
52 0 print $W "tex1($exp);\n$N;\n";
53 0 my $a=<$R>;
54 0 my $b="";
55 0 ▶ while($a !~ /^\(\%o\d+\)\s*$N/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($a =~ /^\(\%o\d+\)\s*$Math::Symbolic::MaximaSimple::N/) 0 0 0
56 0 $b .= $a;
57 0 $a = <$R>;}
58 0 _clean($b);
59 }
60  
61 0 ▶sub maxima_tex2{
Subroutine maxima_tex2: not called CC=3 SCAR=24.8
Pod documented
62 0 ▶ startmaxima() unless $state eq "started";
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Symbolic::MaximaSimple::state eq "started" 0 0 0
63 0 my $exp=shift;
64 0 print $W "tex($exp);\n$N;\n";
65 #print $W "tex($exp)\$;\n$N;\n";
66 0 my $a=<$R>;
67 0 my $b="";
68 0 ▶ while($a !~ /^\(\%o\d+\)\s*$N/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($a =~ /^\(\%o\d+\)\s*$Math::Symbolic::MaximaSimple::N/) 0 0 0
69 0 $b .= $a;
70 0 $a = <$R>;}
71 0 _clean2($b,nomathenv=>1);
72 }
73  
74 0 ▶sub maxima_tex{
Subroutine maxima_tex: not called CC=3 SCAR=24.8
Pod documented
75 0 ▶ startmaxima() unless $state eq "started";
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Symbolic::MaximaSimple::state eq "started" 0 0 0
76 0 my $exp=shift;
77 0 print $W "tex($exp);\n$N;\n";
78 #print $W "tex($exp)\$;\n$N;\n";
79 0 my $a=<$R>;
80 0 my $b="";
81 0 ▶ while($a !~ /^\(\%o\d+\)\s*$N/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($a =~ /^\(\%o\d+\)\s*$Math::Symbolic::MaximaSimple::N/) 0 0 0
82 0 $b .= $a;
83 0 $a = <$R>;}
84 0 _clean2($b);
85 }
86  
87 0 ▶sub maxima{
Subroutine maxima: not called CC=3 SCAR=24.8
Pod documented
88 0 ▶ startmaxima() unless $state eq "started";
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Symbolic::MaximaSimple::state eq "started" 0 0 0
89 0 my $exp=shift;
90 0 print $W "$exp;\n$N;\n";
91 0 my $a=<$R>;
92 0 my $b="";
93 0 ▶ while($a !~ /^\(\%o\d+\)\s*$N/){ $b .= $a;
Branch: 1 branch
BranchTrueFalseTotal
unless ($a =~ /^\(\%o\d+\)\s*$Math::Symbolic::MaximaSimple::N/) 0 0 0
94 0 $a = <$R>;}
95 0 _clean($b);
96 }
97  
98 0 ▶sub _clean2{my ($b,%a)=@_;
Subroutine _clean2: not called CC=3 SCAR=24.8
99 0 $b =~ s/\(%i\d+\)\s*//g;
100 0 $b =~ s/\s*$//;
101 0 ▶ if($b =~ s/\s*\(\%o\d+\)\s*false\s*//){
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ s/\s*\(\%o\d+\)\s*false\s*//) { } 0 0 0
102 0 $b =~ s/\%e\b/e/g;
103 0 $b =~ s/\%pi\b/\\pi/g;
104 0 ▶ if($a{nomathenv}){ $b =~ s/^\$\$(.*)\$\$$/$1/s;
Branch: 1 branch
BranchTrueFalseTotal
if ($a{'nomathenv'}) { } 0 0 0
105 0 $b }
106 0 else{ $b }
107 }
108 0 else { [$b]}
109 }
110  
111 0 ▶sub _clean{my $b=shift;
Subroutine _clean: not called CC=2 SCAR=17.9
112 0 $b =~ s/\(%i\d+\)\s*//g;
113 0 $b =~ s/\s*$//;
114 0 $b =~ s/\%e\b/e/g;
115 0 $b =~ s/\%pi\b/\\pi/g;
116 0 ▶ if($b =~ s/\(\%o\d+\)\s*//){ $b }
Branch: 1 branch
BranchTrueFalseTotal
if ($b =~ s/\(\%o\d+\)\s*//) { } 0 0 0
117 0 else { [$b]}
118 }
119  
120 2 ▶sub _K { ## print STDERR "END (--$state--)\n\n";
Subroutine _K: called CC=2 SCAR=7.2
121 2 ▶ kill(9,$pid) if $state eq "started" ;
Branch: 1 branch
BranchTrueFalseTotal
if $Math::Symbolic::MaximaSimple::state eq "started" 0 2 2
122 2 exit 0;
123 }
124  
125 1 ▶END{ _K();}
Subroutine END: called CC=1 SCAR=0.0
126  
127 2 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<< <jj at di.uminho.pt> >>
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  
↑ Summary