line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 Symbols
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Symbolic Algebra in Pure Perl.
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
See user manual L.
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
PhilipRBrenan@yahoo.com, 2004, Perl License.
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head2 Synopsis
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
This package delivers the public components of package B.
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Math::Algebra::Symbols;
|
18
|
|
|
|
|
|
|
$VERSION=1.21;
|
19
|
45
|
|
|
45
|
|
172134
|
use Math::Algebra::Symbols::Sum;
|
|
45
|
|
|
|
|
174
|
|
|
45
|
|
|
|
|
473
|
|
20
|
45
|
|
|
45
|
|
511
|
use Carp;
|
|
45
|
|
|
|
|
102
|
|
|
45
|
|
|
|
|
46149
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 import
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Export components as requested by caller.
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Math::Algebra::Symbols symbols=>'s' trig=>1 hyper=>1 complex=>0;
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Valid options are:
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=over
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item symbols=>'s'
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Create a function with name B in the callers namespace to create
|
42
|
|
|
|
|
|
|
new symbols. The default is B.
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
item trig=>0
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
The default, no trigonometric functions are exported.
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
item trig=>1
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Export trigonometric functions: tan, sec, csc, cot. sin, cos are created
|
51
|
|
|
|
|
|
|
by default by overloading the existing Perl sin and cos operators.
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item hyper=>0
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
The default, no hyperbolic functions
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item hyper=>1
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Export hyperbolic functions: sinh, cosh, tanh, sech, csch, coth.
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item complex=>0
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The default, no complex functions
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item complex=>1
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Export complex functions: conjugate, cross, dot, im, modulus, re, unit.
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Trigonometric can be used instead of trig.
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Hyperbolic can be used instead of hyper.
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub import
|
95
|
45
|
|
|
45
|
|
530
|
{my %P = (program=>@_);
|
96
|
45
|
|
|
|
|
102
|
my %p; $p{lc()} = $P{$_} for(keys(%P));
|
|
45
|
|
|
|
|
426
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#_ Symbols _____________________________________________________________
|
99
|
|
|
|
|
|
|
# New symbols term constructor - export to calling package.
|
100
|
|
|
|
|
|
|
#_______________________________________________________________________
|
101
|
|
|
|
|
|
|
|
102
|
45
|
|
|
|
|
126
|
my $s = "package XXXX;\n". <<'END';
|
103
|
|
|
|
|
|
|
no warnings 'redefine';
|
104
|
|
|
|
|
|
|
sub NNNN
|
105
|
|
|
|
|
|
|
{return SSSSsum(@_);
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
END
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#_ Symbols _____________________________________________________________
|
110
|
|
|
|
|
|
|
# Complex functions: re, im, dot, cross, conjugate, modulus
|
111
|
|
|
|
|
|
|
#_______________________________________________________________________
|
112
|
|
|
|
|
|
|
|
113
|
45
|
50
|
|
|
|
202
|
if (exists($p{complex}))
|
|
0
|
|
|
|
|
0
|
|
114
|
|
|
|
|
|
|
{$s .= <<'END';
|
115
|
|
|
|
|
|
|
sub conjugate($) {$_[0]->conjugate()}
|
116
|
|
|
|
|
|
|
sub cross ($$) {$_[0]->cross ($_[1])}
|
117
|
|
|
|
|
|
|
sub dot ($$) {$_[0]->dot ($_[1])}
|
118
|
|
|
|
|
|
|
sub im ($) {$_[0]->im ()}
|
119
|
|
|
|
|
|
|
sub modulus ($) {$_[0]->modulus ()}
|
120
|
|
|
|
|
|
|
sub re ($) {$_[0]->re ()}
|
121
|
|
|
|
|
|
|
sub unit ($) {$_[0]->unit ()}
|
122
|
|
|
|
|
|
|
END
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#_ Symbols _____________________________________________________________
|
126
|
|
|
|
|
|
|
# Trigonometric functions: tan, sec, csc, cot
|
127
|
|
|
|
|
|
|
#_______________________________________________________________________
|
128
|
|
|
|
|
|
|
|
129
|
45
|
100
|
66
|
|
|
385
|
if (exists($p{trig}) or exists($p{trigonometric}))
|
|
2
|
|
|
|
|
6
|
|
130
|
|
|
|
|
|
|
{$s .= <<'END';
|
131
|
|
|
|
|
|
|
sub tan($) {$_[0]->tan()}
|
132
|
|
|
|
|
|
|
sub sec($) {$_[0]->sec()}
|
133
|
|
|
|
|
|
|
sub csc($) {$_[0]->csc()}
|
134
|
|
|
|
|
|
|
sub cot($) {$_[0]->cot()}
|
135
|
|
|
|
|
|
|
END
|
136
|
|
|
|
|
|
|
}
|
137
|
45
|
50
|
66
|
|
|
637
|
if (exists($p{trig}) and exists($p{trigonometric}))
|
|
0
|
|
|
|
|
0
|
|
138
|
|
|
|
|
|
|
{croak 'Please use specify just one of trig or trigonometric';
|
139
|
|
|
|
|
|
|
}
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#_ Symbols _____________________________________________________________
|
142
|
|
|
|
|
|
|
# Hyperbolic functions: sinh, cosh, tanh, sech, csch, coth
|
143
|
|
|
|
|
|
|
#_______________________________________________________________________
|
144
|
|
|
|
|
|
|
|
145
|
45
|
100
|
66
|
|
|
454
|
if (exists($p{hyper}) or exists($p{hyperbolic}))
|
|
3
|
|
|
|
|
8
|
|
146
|
|
|
|
|
|
|
{$s .= <<'END';
|
147
|
|
|
|
|
|
|
sub sinh($) {$_[0]->sinh()}
|
148
|
|
|
|
|
|
|
sub cosh($) {$_[0]->cosh()}
|
149
|
|
|
|
|
|
|
sub tanh($) {$_[0]->tanh()}
|
150
|
|
|
|
|
|
|
sub sech($) {$_[0]->sech()}
|
151
|
|
|
|
|
|
|
sub csch($) {$_[0]->csch()}
|
152
|
|
|
|
|
|
|
sub coth($) {$_[0]->coth()}
|
153
|
|
|
|
|
|
|
END
|
154
|
|
|
|
|
|
|
}
|
155
|
45
|
50
|
66
|
|
|
224
|
if (exists($p{hyper}) and exists($p{hyperbolic}))
|
|
0
|
|
|
|
|
0
|
|
156
|
|
|
|
|
|
|
{croak 'Please specify just one of hyper or hyperbolic';
|
157
|
|
|
|
|
|
|
}
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
#_ Symbols _____________________________________________________________
|
160
|
|
|
|
|
|
|
# Export to calling package.
|
161
|
|
|
|
|
|
|
#_______________________________________________________________________
|
162
|
|
|
|
|
|
|
|
163
|
45
|
|
|
|
|
110
|
$s .= <<'END';
|
164
|
|
|
|
|
|
|
use warnings 'redefine';
|
165
|
|
|
|
|
|
|
END
|
166
|
|
|
|
|
|
|
|
167
|
45
|
|
|
|
|
98
|
my $name = 'symbols';
|
168
|
45
|
100
|
|
|
|
388
|
$name = $p{symbols} if exists($p{symbols});
|
169
|
45
|
|
|
|
|
171
|
my ($main) = caller();
|
170
|
45
|
|
|
|
|
123
|
my $pack = __PACKAGE__. '::';
|
171
|
|
|
|
|
|
|
|
172
|
45
|
|
|
|
|
261
|
$s=~ s/XXXX/$main/g;
|
173
|
45
|
|
|
|
|
317
|
$s=~ s/NNNN/$name/g;
|
174
|
45
|
|
|
|
|
198
|
$s=~ s/SSSS/$pack/g;
|
175
|
45
|
|
|
45
|
|
273
|
eval($s);
|
|
45
|
|
|
45
|
|
280
|
|
|
45
|
|
|
59
|
|
4781
|
|
|
45
|
|
|
40
|
|
234
|
|
|
45
|
|
|
25
|
|
84
|
|
|
45
|
|
|
4
|
|
1060
|
|
|
45
|
|
|
11
|
|
9760
|
|
|
59
|
|
|
4
|
|
6236
|
|
|
40
|
|
|
11
|
|
361
|
|
|
25
|
|
|
4
|
|
145
|
|
|
4
|
|
|
12
|
|
30
|
|
|
11
|
|
|
|
|
57
|
|
|
4
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
85
|
|
|
4
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
63
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
#_ Symbols _____________________________________________________________
|
178
|
|
|
|
|
|
|
# Check options supplied by user
|
179
|
|
|
|
|
|
|
#_______________________________________________________________________
|
180
|
|
|
|
|
|
|
|
181
|
45
|
|
|
|
|
209
|
delete @p{qw(
|
182
|
|
|
|
|
|
|
symbols program trig trigonometric hyper hyperbolic complex
|
183
|
|
|
|
|
|
|
)};
|
184
|
|
|
|
|
|
|
|
185
|
45
|
50
|
|
|
|
4997
|
croak "Unknown option(s): ". join(' ', keys(%p))."\n\n". <<'END' if keys(%p);
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Valid options are:
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
symbols=>'symbols' Create a routine with this name in the callers
|
190
|
|
|
|
|
|
|
namespace to create new symbols. The default is
|
191
|
|
|
|
|
|
|
'symbols'.
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
trig =>0 The default, no trigonometric functions
|
195
|
|
|
|
|
|
|
trig =>1 Export trigonometric functions: tan, sec, csc, cot.
|
196
|
|
|
|
|
|
|
sin, cos are created by default by overloading
|
197
|
|
|
|
|
|
|
the existing Perl sin and cos operators.
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
trigonometric can be used instead of trig.
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
hyper =>0 The default, no hyperbolic functions
|
203
|
|
|
|
|
|
|
hyper =>1 Export hyperbolic functions:
|
204
|
|
|
|
|
|
|
sinh, cosh, tanh, sech, csch, coth.
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
hyperbolic can be used instead of hyper.
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
complex=>0 The default, no complex functions
|
210
|
|
|
|
|
|
|
complex=>1 Export complex functions:
|
211
|
|
|
|
|
|
|
conjugate, cross, dot, im, modulus, re, unit
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
END
|
214
|
|
|
|
|
|
|
}
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
#_ Symbols _____________________________________________________________
|
217
|
|
|
|
|
|
|
# Package installed successfully
|
218
|
|
|
|
|
|
|
#_______________________________________________________________________
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1;
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
__DATA__
|