Symbolic Algebra in Pure Perl: terms.
A term represents a product of: variables, coefficents, divisors, square roots,
exponentials, and logs.
PhilipRBrenan@yahoo.com, 2004, Perl License. PhilipRBrenan@gmail.com, 2016, Perl
License. www.appaapps.com
new
Constructor
Finalization
Sign and lock terms
constants
Useful constants
newFromString
New from String
n
Short name for "newFromString"
newFromStrings
New from Strings
gcd
Greatest Common Divisor.
lcm
Least common multiple.
isTerm
Confirm type
intCheck
Integer check
c
Coefficient
d
Divisor
timesInt
Multiply term by integer
divideInt
Divide term by integer
negate
Negate term
isZero
Zero?
notZero
Not Zero?
isOne
One?
notOne
Not One?
isMinusOne
Minus One?
notMinusOne
Not Minus One?
i
Get/Set i - sqrt(-1)
iby
i by power: multiply a term by a power of i
Divide
Get/Set divide by.
removeDivide
Remove divide
Sqrt
Get/Set square root.
removeSqrt
Remove square root.
Exp
Get/Set exp
Log
# Get/Set log
vp
Get/Set variable power.
On get: returns the power of a variable, or zero if the variable is not present
in the term.
On set: Sets the power of a variable. If the power is zero, removes the variable
from the term. =cut
v
Get all variables mentioned in the term. Variables to power zero should have
been removed by "vp".
clone
Clone a term. The existing term must be finalized, see "z": the new
term will not be finalized, allowing modifications to be made to it.
split
Split a term into its components
signature
Sign the term. Used to optimize addition. Fix the problem of adding different
logs
getSignature
Get the signature of a term
add
Add two finalized terms, return result in new term or undef.
subtract
Subtract two finalized terms, return result in new term or undef.
multiply
Multiply two finalized terms, return the result in a new term or undef
divide2
Divide two finalized terms, return the result in a new term or undef
invert
Invert a term
power
Take power of term
sqrt2
Square root of a term
exp2
Exponential of a term
sin2
Sine of a term
cos2
Cosine of a term
log2
Log of a term
id
Get Id of a term
zz
# Check term finalized
z
Finalize creation of the term. Once a term has been finalized, it becomes
readonly, which allows optimization to be performed.
print
Print
Export "newFromStrings" to calling package with a name specifed by the
caller, or as
term() by default. =cut
Operator Overloads
Operator Overloads
add3
Add operator.
negate3
Negate operator.
multiply3
Multiply operator.
divide3
Divide operator.
power3
Power operator.
equals3
Equals operator.
print3
Print operator.
sqrt3
Square root operator.
exp3
Exponential operator.
sin3
Sine operator.
cos3
Cosine operator.
log3
Log operator.
Tests