.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05) .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Math::Algebra::Symbols::Sum 3pm" .TH Math::Algebra::Symbols::Sum 3pm "2004-06-14" "perl v5.10.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "Sums" .IX Header "Sums" Symbolic Algebra using Pure Perl: sums. .PP See user manual \*(L"\s-1NAME\s0\*(R". .PP Operations on sums of terms. .PP PhilipRBrenan@yahoo.com, 2004, Perl License. .Sh "Constructors" .IX Subsection "Constructors" \fInew\fR .IX Subsection "new" .PP Constructor .PP \fInewFromString\fR .IX Subsection "newFromString" .PP New from String .PP \fIn\fR .IX Subsection "n" .PP New from Strings .PP \fIsigma\fR .IX Subsection "sigma" .PP Create a sum from a list of terms. .PP \fImakeInt\fR .IX Subsection "makeInt" .PP Construct an integer .Sh "Methods" .IX Subsection "Methods" \fIisSum\fR .IX Subsection "isSum" .PP Confirm type .PP \fIt\fR .IX Subsection "t" .PP Get list of terms from existing sum .PP \fIcount\fR .IX Subsection "count" .PP Count terms in sum .PP \fIst\fR .IX Subsection "st" .PP Get the single term from a sum containing just one term .PP \fInegate\fR .IX Subsection "negate" .PP Multiply each term in a sum by \-1 .PP \fIadd\fR .IX Subsection "add" .PP Add two sums together to make a new sum .PP \fIsubtract\fR .IX Subsection "subtract" .PP Subtract one sum from another .PP \fIConditional Multiply\fR .IX Subsection "Conditional Multiply" .PP Multiply two sums if both sums are defined, otherwise return the defined sum. Assumes that at least one sum is defined. .PP \fImultiply\fR .IX Subsection "multiply" .PP Multiply two sums together .PP \fIdivide\fR .IX Subsection "divide" .PP Divide one sum by another .PP \fIsub\fR .IX Subsection "sub" .PP Substitute a sum for a variable. .PP \fIisEqual\fR .IX Subsection "isEqual" .PP Check whether one sum is equal to another after multiplying out all divides and divisors. .PP \fInormalizeSqrts\fR .IX Subsection "normalizeSqrts" .PP Normalize sqrts in a sum. .PP This routine needs fixing. .PP It should simplify square roots. .PP \fIisEqualSqrt\fR .IX Subsection "isEqualSqrt" .PP Check whether one sum is equal to another after multiplying out sqrts. .PP \fIisZero\fR .IX Subsection "isZero" .PP Transform a sum assuming that it is equal to zero .PP \fIpowerOfTwo\fR .IX Subsection "powerOfTwo" .PP Check that a number is a power of two .PP \fIsolve\fR .IX Subsection "solve" .PP Solve an equation known to be equal to zero for a specified variable. .PP \fIpower\fR .IX Subsection "power" .PP Raise a sum to an integer power or an integer/2 power. .PP \fId\fR .IX Subsection "d" .PP Differentiate. .PP \fIsimplify\fR .IX Subsection "simplify" .PP Simplify just before assignment. .PP There is no general simplification algorithm. So try various methods and see if any simplifications occur. This is cheating really, because the examples will represent these specific transformations as general features which they are not. On the other hand, Mathematics is full of specifics so I suppose its not entirely unacceptable. .PP Simplification cannot be done after every operation as it is inefficient, doing it as part of += ameliorates this inefficiency. .PP Note: += only works as a synonym for \fIsimplify()\fR if the left hand side is currently undefined. This can be enforced by using \fImy()\fR as in: my \f(CW$z\fR += ($x**2+5x+6)/($x+2); .PP \fIpolynomialDivide\fR .IX Subsection "polynomialDivide" .PP Polynomial divide \- divide one polynomial (a) by another (b) in variable v .PP \fIeigenValue\fR .IX Subsection "eigenValue" .PP Eigenvalue check .PP \fIpolynomialDivision\fR .IX Subsection "polynomialDivision" .PP Polynomial division. .PP \fISqrt\fR .IX Subsection "Sqrt" .PP Square root of a sum .PP \fIExp\fR .IX Subsection "Exp" .PP Exponential (\fBe\fR raised to the power) of a sum .PP \fILog\fR .IX Subsection "Log" .PP Log to base \fBe\fR of a sum .PP \fISin\fR .IX Subsection "Sin" .PP Sine of a sum .PP \fICos\fR .IX Subsection "Cos" .PP Cosine of a sum .PP \fItan, Ssc, csc, cot\fR .IX Subsection "tan, Ssc, csc, cot" .PP Tan, sec, csc, cot of a sum .PP \fIsinh\fR .IX Subsection "sinh" .PP Hyperbolic sine of a sum .PP \fIcosh\fR .IX Subsection "cosh" .PP Hyperbolic cosine of a sum .PP \fITanh, Sech, Csch, Coth\fR .IX Subsection "Tanh, Sech, Csch, Coth" .PP Tanh, Sech, Csch, Coth of a sum .PP \fIdot\fR .IX Subsection "dot" .PP Dot \- complex dot product of two complex sums .PP \fIcross\fR .IX Subsection "cross" .PP The area of the parallelogram formed by two complex sums .PP \fIunit\fR .IX Subsection "unit" .PP Intersection of a complex sum with the unit circle. .PP \fIre\fR .IX Subsection "re" .PP Real part of a complex sum .PP \fIim\fR .IX Subsection "im" .PP Imaginary part of a complex sum .PP \fImodulus\fR .IX Subsection "modulus" .PP Modulus of a complex sum .PP \fIconjugate\fR .IX Subsection "conjugate" .PP Conjugate of a complexs sum .PP \fIclone\fR .IX Subsection "clone" .PP Clone .PP \fIsignature\fR .IX Subsection "signature" .PP Signature of a sum: used to optimize \fIadd()\fR. # Fix the problem of adding different logs .PP \fIgetSignature\fR .IX Subsection "getSignature" .PP Get the signature (see \*(L"signature\*(R") of a sum .PP \fIid\fR .IX Subsection "id" .PP Get Id of sum: each sum has a unique identifying number. .PP \fIzz\fR .IX Subsection "zz" .PP Check sum finalized. See: \*(L"z\*(R". .PP \fIz\fR .IX Subsection "z" .PP Finalize creation of the sum: Once a sum has been finalized it becomes read only. .PP \fIprint\fR .IX Subsection "print" .PP Print sum .PP \fIconstants\fR .IX Subsection "constants" .PP Useful constants .PP \fIfactorize\fR .IX Subsection "factorize" .PP Factorize a number. .Sh "import" .IX Subsection "import" Export \*(L"n\*(R" with either the default name \fBsums\fR, or a name supplied by the caller of this package. .Sh "Operators" .IX Subsection "Operators" \fIOperator Overloads\fR .IX Subsection "Operator Overloads" .PP Overload Perl operators. Beware the low priority of \fB^\fR. .PP \fIadd3\fR .IX Subsection "add3" .PP Add operator. .PP \fInegate3\fR .IX Subsection "negate3" .PP Negate operator. Used in combination with the \*(L"add3\*(R" operator to perform subtraction. .PP \fImultiply3\fR .IX Subsection "multiply3" .PP Multiply operator. .PP \fIdivide3\fR .IX Subsection "divide3" .PP Divide operator. .PP \fIpower3\fR .IX Subsection "power3" .PP Power operator. .PP \fIequals3\fR .IX Subsection "equals3" .PP Equals operator. .PP \fInequal3\fR .IX Subsection "nequal3" .PP Not equal operator. .PP \fItequals\fR .IX Subsection "tequals" .PP Evaluate the expression on the left hand side, stringify it, then compare it for string equality with the string on the right hand side. This operator is useful for making examples written with Test::Simple more readable. .PP \fIsolve3\fR .IX Subsection "solve3" .PP Solve operator. .PP \fIprint3\fR .IX Subsection "print3" .PP Print operator. .PP \fIsqrt3\fR .IX Subsection "sqrt3" .PP Sqrt operator. .PP \fIexp3\fR .IX Subsection "exp3" .PP Exp operator. .PP \fIsin3\fR .IX Subsection "sin3" .PP Sine operator. .PP \fIcos3\fR .IX Subsection "cos3" .PP Cosine operator. .PP \fItan3\fR .IX Subsection "tan3" .PP Tan operator. .PP \fIlog3\fR .IX Subsection "log3" .PP Log operator. .PP \fIdot3\fR .IX Subsection "dot3" .PP Dot Product operator. .PP \fIcross3\fR .IX Subsection "cross3" .PP Cross operator. .PP \fIunit3\fR .IX Subsection "unit3" .PP Unit operator. .PP \fImodulus3\fR .IX Subsection "modulus3" .PP Modulus operator. .PP \fIconjugate3\fR .IX Subsection "conjugate3" .PP Conjugate. .SH "NAME" Math::Algebra::Symbols \- Symbolic Algebra in Pure Perl. .PP User guide. .SH "SYNOPSIS" .IX Header "SYNOPSIS" Example symbols.pl .PP .Vb 6 \& #!perl \-w \-I.. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra. \& # Perl License. \& # PhilipRBrenan@yahoo.com, 2004. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols hyper=>1; \& use Test::Simple tests=>5; \& \& ($n, $x, $y) = symbols(qw(n x y)); \& \& $a += ($x**8 \- 1)/($x\-1); \& $b += sin($x)**2 + cos($x)**2; \& $c += (sin($n*$x) + cos($n*$x))\->d\->d\->d\->d / (sin($n*$x)+cos($n*$x)); \& $d = tanh($x+$y) == (tanh($x)+tanh($y))/(1+tanh($x)*tanh($y)); \& ($e,$f) = @{($x**2 eq 5*$x\-6) > $x}; \& \& print "$a\en$b\en$c\en$d\en$e,$f\en"; \& \& ok("$a" eq \*(Aq$x+$x**2+$x**3+$x**4+$x**5+$x**6+$x**7+1\*(Aq); \& ok("$b" eq \*(Aq1\*(Aq); \& ok("$c" eq \*(Aq$n**4\*(Aq); \& ok("$d" eq \*(Aq1\*(Aq); \& ok("$e,$f" eq \*(Aq2,3\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This package supplies a set of functions and operators to manipulate operator expressions algebraically using the familiar Perl syntax. .PP These expressions are constructed from \*(L"Symbols\*(R", \*(L"Operators\*(R", and \*(L"Functions\*(R", and processed via \&\*(L"Methods\*(R". For examples, see: \*(L"Examples\*(R". .Sh "Symbols" .IX Subsection "Symbols" Symbols are created with the exported \fB\f(BIsymbols()\fB\fR constructor routine: .PP Example t/constants.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: constants. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>1; \& \& my ($x, $y, $i, $o, $pi) = symbols(qw(x y i 1 pi)); \& \& ok( "$x $y $i $o $pi" eq \*(Aq$x $y i 1 $pi\*(Aq ); .Ve .PP The \fB\f(BIsymbols()\fB\fR routine constructs references to symbolic variables and symbolic constants from a list of names and integer constants. .PP The special symbol \fBi\fR is recognized as the square root of \fB\-1\fR. .PP The special symbol \fBpi\fR is recognized as the smallest positive real that satisfies: .PP Example t/ipi.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: constants. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>2; \& \& my ($i, $pi) = symbols(qw(i pi)); \& \& ok( exp($i*$pi) == \-1 ); \& ok( exp($i*$pi) <=> \*(Aq\-1\*(Aq ); .Ve .PP \fIConstructor Routine Name\fR .IX Subsection "Constructor Routine Name" .PP If you wish to use a different name for the constructor routine, say \&\fBS\fR: .PP Example t/ipi2.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: constants. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols symbols=>\*(AqS\*(Aq; \& use Test::Simple tests=>2; \& \& my ($i, $pi) = S(qw(i pi)); \& \& ok( exp($i*$pi) == \-1 ); \& ok( exp($i*$pi) <=> \*(Aq\-1\*(Aq ); .Ve .PP \fIBig Integers\fR .IX Subsection "Big Integers" .PP Symbols automatically uses big integers if needed. .PP Example t/bigInt.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: bigInt. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>1; \& \& my $z = symbols(\*(Aq1234567890987654321/1234567890987654321\*(Aq); \& \& ok( eval $z eq \*(Aq1\*(Aq); .Ve .Sh "Operators" .IX Subsection "Operators" \&\*(L"Symbols\*(R" can be combined with \*(L"Operators\*(R" to create symbolic expressions: .PP \fIArithmetic operators\fR .IX Subsection "Arithmetic operators" .PP Arithmetic Operators: \fB+\fR \fB\-\fR \fB*\fR \fB/\fR \fB**\fR .IX Subsection "Arithmetic Operators: + - * / **" .PP Example t/x2y2.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: simplification. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my ($x, $y) = symbols(qw(x y)); \& \& ok( ($x**2\-$y**2)/($x\-$y) == $x+$y ); \& ok( ($x**2\-$y**2)/($x\-$y) != $x\-$y ); \& ok( ($x**2\-$y**2)/($x\-$y) <=> \*(Aq$x+$y\*(Aq ); .Ve .PP The operators: \fB+=\fR \fB\-=\fR \fB*=\fR \fB/=\fR are overloaded to work symbolically rather than numerically. If you need numeric results, you can always \fB\f(BIeval()\fB\fR the resulting symbolic expression. .PP Square root Operator: \fBsqrt\fR .IX Subsection "Square root Operator: sqrt" .PP Example t/ix.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: sqrt(\-1). \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>2; \& \& my ($x, $i) = symbols(qw(x i)); \& \& ok( sqrt(\-$x**2) == $i*$x ); \& ok( sqrt(\-$x**2) <=> \*(Aqi*$x\*(Aq ); .Ve .PP The square root is represented by the symbol \fBi\fR, which allows complex expressions to be processed by Math::Complex. .PP Exponential Operator: \fBexp\fR .IX Subsection "Exponential Operator: exp" .PP Example t/expd.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: exp. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>2; \& \& my ($x, $i) = symbols(qw(x i)); \& \& ok( exp($x)\->d($x) == exp($x) ); \& ok( exp($x)\->d($x) <=> \*(Aqexp($x)\*(Aq ); .Ve .PP The exponential operator. .PP Logarithm Operator: \fBlog\fR .IX Subsection "Logarithm Operator: log" .PP Example t/logExp.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: log: need better example. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>1; \& \& my ($x) = symbols(qw(x)); \& \& ok( log($x) <=> \*(Aqlog($x)\*(Aq ); .Ve .PP Logarithm to base \fBe\fR. .PP Note: the above result is only true for x > 0. \fBSymbols\fR does not include domain and range specifications of the functions it uses. .PP Sine and Cosine Operators: \fBsin\fR and \fBcos\fR .IX Subsection "Sine and Cosine Operators: sin and cos" .PP Example t/sinCos.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: simplification. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my ($x) = symbols(qw(x)); \& \& ok( sin($x)**2 + cos($x)**2 == 1 ); \& ok( sin($x)**2 + cos($x)**2 != 0 ); \& ok( sin($x)**2 + cos($x)**2 <=> \*(Aq1\*(Aq ); .Ve .PP This famous trigonometric identity is not preprogrammed into \fBSymbols\fR as it is in commercial products. .PP Instead: an expression for \fB\f(BIsin()\fB\fR is constructed using the complex exponential: \*(L"exp\*(R", said expression is algebraically multiplied out to prove the identity. The proof steps involve large intermediate expressions in each step, as yet I have not provided a means to neatly lay out these intermediate steps and thus provide a more compelling demonstration of the ability of \fBSymbols\fR to verify such statements from first principles. .PP \fIRelational operators\fR .IX Subsection "Relational operators" .PP Relational operators: \fB==\fR, \fB!=\fR .IX Subsection "Relational operators: ==, !=" .PP Example t/x2y2.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: simplification. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my ($x, $y) = symbols(qw(x y)); \& \& ok( ($x**2\-$y**2)/($x\-$y) == $x+$y ); \& ok( ($x**2\-$y**2)/($x\-$y) != $x\-$y ); \& ok( ($x**2\-$y**2)/($x\-$y) <=> \*(Aq$x+$y\*(Aq ); .Ve .PP The relational equality operator \fB==\fR compares two symbolic expressions and returns \s-1\fITRUE\s0\fR\|(1) or \s-1\fIFALSE\s0\fR\|(0) accordingly. \fB!=\fR produces the opposite result. .PP Relational operator: \fBeq\fR .IX Subsection "Relational operator: eq" .PP Example t/eq.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: solving. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my ($x, $v, $t) = symbols(qw(x v t)); \& \& ok( ($v eq $x / $t)\->solve(qw(x in terms of v t)) == $v*$t ); \& ok( ($v eq $x / $t)\->solve(qw(x in terms of v t)) != $v+$t ); \& ok( ($v eq $x / $t)\->solve(qw(x in terms of v t)) <=> \*(Aq$v*$t\*(Aq ); .Ve .PP The relational operator \fBeq\fR is a synonym for the minus \fB\-\fR operator, with the expectation that later on the \fIsolve()\fR function will be used to simplify and rearrange the equation. You may prefer to use \fBeq\fR instead of \fB\-\fR to enhance readability, there is no functional difference. .PP \fIComplex operators\fR .IX Subsection "Complex operators" .PP Complex operators: the \fBdot\fR operator: \fB^\fR .IX Subsection "Complex operators: the dot operator: ^" .PP Example t/dot.t .PP .Vb 6 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: dot operator. Note the low priority \& # of the ^ operator. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my ($a, $b, $i) = symbols(qw(a b i)); \& \& ok( (($a+$i*$b)^($a\-$i*$b)) == $a**2\-$b**2 ); \& ok( (($a+$i*$b)^($a\-$i*$b)) != $a**2+$b**2 ); \& ok( (($a+$i*$b)^($a\-$i*$b)) <=> \*(Aq$a**2\-$b**2\*(Aq ); .Ve .PP Note the use of brackets: The \fB^\fR operator has low priority. .PP The \fB^\fR operator treats its left hand and right hand arguments as complex numbers, which in turn are regarded as two dimensional vectors to which the vector dot product is applied. .PP Complex operators: the \fBcross\fR operator: \fBx\fR .IX Subsection "Complex operators: the cross operator: x" .PP Example t/cross.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: cross operator. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my ($x, $i) = symbols(qw(x i)); \& \& ok( $i*$x x $x == $x**2 ); \& ok( $i*$x x $x != $x**3 ); \& ok( $i*$x x $x <=> \*(Aq$x**2\*(Aq ); .Ve .PP The \fBx\fR operator treats its left hand and right hand arguments as complex numbers, which in turn are regarded as two dimensional vectors defining the sides of a parallelogram. The \fBx\fR operator returns the area of this parallelogram. .PP Note the space before the \fBx\fR, otherwise Perl is unable to disambiguate the expression correctly. .PP Complex operators: the \fBconjugate\fR operator: \fB~\fR .IX Subsection "Complex operators: the conjugate operator: ~" .PP Example t/conjugate.t .PP .Vb 6 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: dot operator. Note the low priority \& # of the ^ operator. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my ($x, $y, $i) = symbols(qw(x y i)); \& \& ok( ~($x+$i*$y) == $x\-$i*$y ); \& ok( ~($x\-$i*$y) == $x+$i*$y ); \& ok( (($x+$i*$y)^($x\-$i*$y)) <=> \*(Aq$x**2\-$y**2\*(Aq ); .Ve .PP The \fB~\fR operator returns the complex conjugate of its right hand side. .PP Complex operators: the \fBmodulus\fR operator: \fBabs\fR .IX Subsection "Complex operators: the modulus operator: abs" .PP Example t/abs.t .PP .Vb 6 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: dot operator. Note the low priority \& # of the ^ operator. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my ($x, $i) = symbols(qw(x i)); \& \& ok( abs($x+$i*$x) == sqrt(2*$x**2) ); \& ok( abs($x+$i*$x) != sqrt(2*$x**3) ); \& ok( abs($x+$i*$x) <=> \*(Aqsqrt(2*$x**2)\*(Aq ); .Ve .PP The \fBabs\fR operator returns the modulus (length) of its right hand side. .PP Complex operators: the \fBunit\fR operator: \fB!\fR .IX Subsection "Complex operators: the unit operator: !" .PP Example t/unit.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: unit operator. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>4; \& \& my ($i) = symbols(qw(i)); \& \& ok( !$i == $i ); \& ok( !$i <=> \*(Aqi\*(Aq ); \& ok( !($i+1) <=> \*(Aq1/(sqrt(2))+i/(sqrt(2))\*(Aq ); \& ok( !($i\-1) <=> \*(Aq\-1/(sqrt(2))+i/(sqrt(2))\*(Aq ); .Ve .PP The \fB!\fR operator returns a complex number of unit length pointing in the same direction as its right hand side. .PP \fIEquation Manipulation Operators\fR .IX Subsection "Equation Manipulation Operators" .PP Equation Manipulation Operators: \fBSimplify\fR operator: \fB+=\fR .IX Subsection "Equation Manipulation Operators: Simplify operator: +=" .PP Example t/simplify.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: simplify. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>2; \& \& my ($x) = symbols(qw(x)); \& \& ok( ($x**8 \- 1)/($x\-1) == $x+$x**2+$x**3+$x**4+$x**5+$x**6+$x**7+1 ); \& ok( ($x**8 \- 1)/($x\-1) <=> \*(Aq$x+$x**2+$x**3+$x**4+$x**5+$x**6+$x**7+1\*(Aq ); .Ve .PP The simplify operator \fB+=\fR is a synonym for the \&\fIsimplify()\fR method, if and only if, the target on the left hand side initially has a value of undef. .PP Admittedly this is very strange behavior: it arises due to the shortage of over-rideable operators in Perl: in particular it arises due to the shortage of over-rideable unary operators in Perl. Never-the-less: this operator is useful as can be seen in the Synopsis, and the desired pre-condition can always achieved by using \fBmy\fR. .PP Equation Manipulation Operators: \fBSolve\fR operator: \fB>\fR .IX Subsection "Equation Manipulation Operators: Solve operator: >" .PP Example t/solve2.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: simplify. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>2; \& \& my ($t) = symbols(qw(t)); \& \& my $rabbit = 10 + 5 * $t; \& my $fox = 7 * $t * $t; \& my ($a, $b) = @{($rabbit eq $fox) > $t}; \& \& ok( "$a" eq \*(Aq1/14*sqrt(305)+5/14\*(Aq ); \& ok( "$b" eq \*(Aq\-1/14*sqrt(305)+5/14\*(Aq ); .Ve .PP The solve operator \fB>\fR is a synonym for the \&\fIsolve()\fR method. .PP The priority of \fB>\fR is higher than that of \fBeq\fR, so the brackets around the equation to be solved are necessary until Perl provides a mechanism for adjusting operator priority (cf. Algol 68). .PP If the equation is in a single variable, the single variable may be named after the \fB>\fR operator without the use of [...]: .PP .Vb 1 \& use Math::Algebra::Symbols; \& \& my $rabbit = 10 + 5 * $t; \& my $fox = 7 * $t * $t; \& my ($a, $b) = @{($rabbit eq $fox) > $t}; \& \& print "$a\en"; \& \& # 1/14*sqrt(305)+5/14 .Ve .PP If there are multiple solutions, (as in the case of polynomials), \fB>\fR returns an array of symbolic expressions containing the solutions. .PP This example was provided by Mike Schilli m@perlmeister.com. .Sh "Functions" .IX Subsection "Functions" Perl operator overloading is very useful for producing compact representations of algebraic expressions. Unfortunately there are only a small number of operators that Perl allows to be overloaded. The following functions are used to provide capabilities not easily expressed via Perl operator overloading. .PP These functions may either be called as methods from symbols constructed by the \*(L"Symbols\*(R" construction routine, or they may be exported into the user's namespace as described in \*(L"\s-1EXPORT\s0\*(R". .PP \fITrigonometric and Hyperbolic functions\fR .IX Subsection "Trigonometric and Hyperbolic functions" .PP Trigonometric functions .IX Subsection "Trigonometric functions" .PP Example t/sinCos2.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: methods. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>1; \& \& my ($x, $y) = symbols(qw(x y)); \& \& ok( (sin($x)**2 == (1\-cos(2*$x))/2) ); .Ve .PP The trigonometric functions \fBcos\fR, \fBsin\fR, \fBtan\fR, \fBsec\fR, \fBcsc\fR, \&\fBcot\fR are available, either as exports to the caller's name space, or as methods. .PP Hyperbolic functions .IX Subsection "Hyperbolic functions" .PP Example t/tanh.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: methods. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols hyper=>1; \& use Test::Simple tests=>1; \& \& my ($x, $y) = symbols(qw(x y)); \& \& ok( tanh($x+$y)==(tanh($x)+tanh($y))/(1+tanh($x)*tanh($y))); .Ve .PP The hyperbolic functions \fBcosh\fR, \fBsinh\fR, \fBtanh\fR, \fBsech\fR, \fBcsch\fR, \&\fBcoth\fR are available, either as exports to the caller's name space, or as methods. .PP \fIComplex functions\fR .IX Subsection "Complex functions" .PP Complex functions: \fBre\fR and \fBim\fR .IX Subsection "Complex functions: re and im" .PP .Vb 1 \& use Math::Algebra::Symbols complex=>1; .Ve .PP Example t/reIm.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: methods. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>2; \& \& my ($x, $i) = symbols(qw(x i)); \& \& ok( ($i*$x)\->re <=> 0 ); \& ok( ($i*$x)\->im <=> \*(Aq$x\*(Aq ); .Ve .PP The \fBre\fR and \fBim\fR functions return an expression which represents the real and imaginary parts of the expression, assuming that symbolic variables represent real numbers. .PP Complex functions: \fBdot\fR and \fBcross\fR .IX Subsection "Complex functions: dot and cross" .PP Example t/dotCross.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: methods. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>2; \& \& my $i = symbols(qw(i)); \& \& ok( ($i+1)\->cross($i\-1) <=> 2 ); \& ok( ($i+1)\->dot ($i\-1) <=> 0 ); .Ve .PP The \fBdot\fR and \fBcross\fR operators are available as functions, either as exports to the caller's name space, or as methods. .PP Complex functions: \fBconjugate\fR, \fBmodulus\fR and \fBunit\fR .IX Subsection "Complex functions: conjugate, modulus and unit" .PP Example t/conjugate2.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: methods. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my $i = symbols(qw(i)); \& \& ok( ($i+1)\->unit <=> \*(Aq1/(sqrt(2))+i/(sqrt(2))\*(Aq ); \& ok( ($i+1)\->modulus <=> \*(Aqsqrt(2)\*(Aq ); \& ok( ($i+1)\->conjugate <=> \*(Aq1\-i\*(Aq ); .Ve .PP The \fBconjugate\fR, \fBabs\fR and \fBunit\fR operators are available as functions: \fBconjugate\fR, \fBmodulus\fR and \fBunit\fR, either as exports to the caller's name space, or as methods. The confusion over the naming of: the \fBabs\fR operator being the same as the \fBmodulus\fR complex function; arises over the limited set of Perl operator names available for overloading. .Sh "Methods" .IX Subsection "Methods" \fIMethods for manipulating Equations\fR .IX Subsection "Methods for manipulating Equations" .PP Simplifying equations: \fB\f(BIsimplify()\fB\fR .IX Subsection "Simplifying equations: simplify()" .PP Example t/simplify2.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: simplify. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>2; \& \& my ($x) = symbols(qw(x)); \& \& my $y = (($x**8 \- 1)/($x\-1))\->simplify(); # Simplify method \& my $z += ($x**8 \- 1)/($x\-1); # Simplify via += \& \& ok( "$y" eq \*(Aq$x+$x**2+$x**3+$x**4+$x**5+$x**6+$x**7+1\*(Aq ); \& ok( "$z" eq \*(Aq$x+$x**2+$x**3+$x**4+$x**5+$x**6+$x**7+1\*(Aq ); .Ve .PP \&\fB\f(BISimplify()\fB\fR attempts to simplify an expression. There is no general simplification algorithm: consequently simplifications are carried out on ad hoc basis. You may not even agree that the proposed simplification for a given expressions is indeed any simpler than the original. It is for these reasons that simplification has to be explicitly requested rather than being performed automagically. .PP At the moment, simplifications consist of polynomial division: when the expression consists, in essence, of one polynomial divided by another, an attempt is made to perform polynomial division, the result is returned if there is no remainder. .PP The \fB+=\fR operator may be used to simplify and assign an expression to a Perl variable. Perl operator overloading precludes the use of \fB=\fR in this manner. .PP Substituting into equations: \fB\f(BIsub()\fB\fR .IX Subsection "Substituting into equations: sub()" .PP Example t/sub.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: expression substitution for a variable. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>2; \& \& my ($x, $y) = symbols(qw(x y)); \& \& my $e = 1+$x+$x**2/2+$x**3/6+$x**4/24+$x**5/120; \& \& ok( $e\->sub(x=>$y**2, z=>2) <=> \*(Aq$y**2+1/2*$y**4+1/6*$y**6+1/24*$y**8+1/120*$y**10+1\*(Aq ); \& ok( $e\->sub(x=>1) <=> \*(Aq163/60\*(Aq); .Ve .PP The \fB\f(BIsub()\fB\fR function example on line \fB#1\fR demonstrates replacing variables with expressions. The replacement specified for \fBz\fR has no effect as \fBz\fR is not present in this equation. .PP Line \fB#2\fR demonstrates the resulting rational fraction that arises when all the variables have been replaced by constants. This package does not convert fractions to decimal expressions in case there is a loss of accuracy, however: .PP .Vb 2 \& my $e2 = $e\->sub(x=>1); \& $result = eval "$e2"; .Ve .PP or similar will produce approximate results. .PP At the moment only variables can be replaced by expressions. Mike Schilli, m@perlmeister.com, has proposed that substitutions for expressions should also be allowed, as in: .PP .Vb 1 \& $x/$y => $z .Ve .PP Solving equations: \fB\f(BIsolve()\fB\fR .IX Subsection "Solving equations: solve()" .PP Example t/solve1.t .PP .Vb 5 \& #!perl \-w \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: examples: simplify. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests=>3; \& \& my ($x, $v, $t) = symbols(qw(x v t)); \& \& ok( ($v eq $x / $t)\->solve(qw(x in terms of v t)) == $v*$t ); \& ok( ($v eq $x / $t)\->solve(qw(x in terms of v t)) != $v/$t ); \& ok( ($v eq $x / $t)\->solve(qw(x in terms of v t)) <=> \*(Aq$v*$t\*(Aq ); .Ve .PP \&\fB\f(BIsolve()\fB\fR assumes that the equation on the left hand side is equal to zero, applies various simplifications, then attempts to rearrange the equation to obtain an equation for the first variable in the parameter list assuming that the other terms mentioned in the parameter list are known constants. There may of course be other unknown free variables in the equation to be solved: the proposed solution is automatically tested against the original equation to check that the proposed solution removes these variables, an error is reported via \fB\f(BIdie()\fB\fR if it does not. .PP Example t/solve.t .PP .Vb 5 \& #!perl \-w \-I.. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra: quadratic equation. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::Simple tests => 2; \& \& my ($x) = symbols(qw(x)); \& \& my $p = $x**2\-5*$x+6; # Quadratic polynomial \& my ($a, $b) = @{($p > $x )}; # Solve for x \& \& print "x=$a,$b\en"; # Roots \& \& ok($a == 2); \& ok($b == 3); .Ve .PP If there are multiple solutions, (as in the case of polynomials), \fB\f(BIsolve()\fB\fR returns an array of symbolic expressions containing the solutions. .PP \fIMethods for performing Calculus\fR .IX Subsection "Methods for performing Calculus" .PP Differentiation: \fBd()\fR .IX Subsection "Differentiation: d()" .PP Example t/differentiation.t .PP .Vb 5 \& #!perl \-w \-I.. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& # Symbolic algebra. \& # PhilipRBrenan@yahoo.com, 2004, Perl License. \& #_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_\|_ \& \& use Math::Algebra::Symbols; \& use Test::More tests => 5; \& \& $x = symbols(qw(x)); \& \& ok( sin($x) == sin($x)\->d\->d\->d\->d); \& ok( cos($x) == cos($x)\->d\->d\->d\->d); \& ok( exp($x) == exp($x)\->d($x)\->d(\*(Aqx\*(Aq)\->d\->d); \& ok( (1/$x)\->d == \-1/$x**2); \& ok( exp($x)\->d\->d\->d\->d <=> \*(Aqexp($x)\*(Aq ); .Ve .PP \&\fBd()\fR differentiates the equation on the left hand side by the named variable. .PP The variable to be differentiated by may be explicitly specified, either as a string or as single symbol; or it may be heuristically guessed as follows: .PP If the equation to be differentiated refers to only one symbol, then that symbol is used. If several symbols are present in the equation, but only one of \fBt\fR, \fBx\fR, \fBy\fR, \fBz\fR is present, then that variable is used in honor of Newton, Leibnitz, Cauchy. .Sh "Example of Equation Solving: the focii of a hyperbola:" .IX Subsection "Example of Equation Solving: the focii of a hyperbola:" .Vb 1 \& use Math::Algebra::Symbols; \& \& my ($a, $b, $x, $y, $i, $o) = symbols(qw(a b x y i 1)); \& \& print \& "Hyperbola: Constant difference between distances from focii to locus of y=1/x", \& "\en Assume by symmetry the focii are on ", \& "\en the line y=x: ", $f1 = $x + $i * $x, \& "\en and equidistant from the origin: ", $f2 = \-$f1, \& "\en Choose a convenient point on y=1/x: ", $a = $o+$i, \& "\en and a general point on y=1/x: ", $b = $y+$i/$y, \& "\en Difference in distances from focii", \& "\en From convenient point: ", $A = abs($a \- $f2) \- abs($a \- $f1), \& "\en From general point: ", $B = abs($b \- $f2) + abs($b \- $f1), \& "\en\en Solving for x we get: x=", ($A \- $B) > $x, \& "\en (should be: sqrt(2))", \& "\en Which is indeed constant, as was to be demonstrated\en"; .Ve .PP This example demonstrates the power of symbolic processing by finding the focii of the curve \fBy=1/x\fR, and incidentally, demonstrating that this curve is a hyperbola. .SH "EXPORTS" .IX Header "EXPORTS" .Vb 5 \& use Math::Algebra::Symbols \& symbols=>\*(AqS\*(Aq, \& trig => 1, \& hyper => 1, \& complex=> 1; .Ve .IP "trig=>0" 4 .IX Item "trig=>0" The default, do not export trigonometric functions. .IP "trig=>1" 4 .IX Item "trig=>1" Export trigonometric functions: \fBtan\fR, \fBsec\fR, \fBcsc\fR, \fBcot\fR to the caller's namespace. \fBsin\fR, \fBcos\fR are created by default by overloading the existing Perl \fBsin\fR and \fBcos\fR operators. .IP "\fBtrigonometric\fR" 4 .IX Item "trigonometric" Alias of \fBtrig\fR .IP "hyperbolic=>0" 4 .IX Item "hyperbolic=>0" The default, do not export hyperbolic functions. .IP "hyper=>1" 4 .IX Item "hyper=>1" Export hyperbolic functions: \fBsinh\fR, \fBcosh\fR, \fBtanh\fR, \fBsech\fR, \&\fBcsch\fR, \fBcoth\fR to the caller's namespace. .IP "\fBhyperbolic\fR" 4 .IX Item "hyperbolic" Alias of \fBhyper\fR .IP "complex=>0" 4 .IX Item "complex=>0" The default, do not export complex functions .IP "complex=>1" 4 .IX Item "complex=>1" Export complex functions: \fBconjugate\fR, \fBcross\fR, \fBdot\fR, \fBim\fR, \&\fBmodulus\fR, \fBre\fR, \fBunit\fR to the caller's namespace. .SH "PACKAGES" .IX Header "PACKAGES" The \fBSymbols\fR packages manipulate a sum of products representation of an algebraic equation. The \fBSymbols\fR package is the user interface to the functionality supplied by the \fBSymbols::Sum\fR and \fBSymbols::Term\fR packages. .Sh "Math::Algebra::Symbols::Term" .IX Subsection "Math::Algebra::Symbols::Term" \&\fBSymbols::Term\fR represents a product term. A product term consists of the number \fB1\fR, optionally multiplied by: .IP "Variables" 4 .IX Item "Variables" any number of variables raised to integer powers, .IP "Coefficient" 4 .IX Item "Coefficient" An integer coefficient optionally divided by a positive integer divisor, both represented as BigInts if necessary. .IP "Sqrt" 4 .IX Item "Sqrt" The sqrt of of any symbolic expression representable by the \fBSymbols\fR package, including minus one: represented as \fBi\fR. .IP "Reciprocal" 4 .IX Item "Reciprocal" The multiplicative inverse of any symbolic expression representable by the \fBSymbols\fR package: i.e. a \fBSymbolsTerm\fR may be divided by any symbolic expression representable by the \fBSymbols\fR package. .IP "Exp" 4 .IX Item "Exp" The number \fBe\fR raised to the power of any symbolic expression representable by the \fBSymbols\fR package. .IP "Log" 4 .IX Item "Log" The logarithm to base \fBe\fR of any symbolic expression representable by the \fBSymbols\fR package. .PP Thus \fBSymbolsTerm\fR can represent expressions like: .PP .Vb 1 \& 2/3*$x**2*$y**\-3*exp($i*$pi)*sqrt($z**3) / $x .Ve .PP but not: .PP .Vb 1 \& $x + $y .Ve .PP for which package \fBSymbols::Sum\fR is required. .Sh "Math::Algebra::Symbols::Sum" .IX Subsection "Math::Algebra::Symbols::Sum" \&\fBSymbols::Sum\fR represents a sum of product terms supplied by \&\fBSymbols::Term\fR and thus behaves as a polynomial. Operations such as equation solving and differentiation are applied at this level. .PP The main benefit of programming \fBSymbols::Term\fR and \fBSymbols::Sum\fR as two separate but related packages is Object Oriented Polymorphism. I.e. both packages need to multiply items together: each package has its own \fBmultiply\fR method, with Perl method lookup selecting the appropriate one as required. .Sh "Math::Algebra::Symbols" .IX Subsection "Math::Algebra::Symbols" Packaging the user functionality alone and separately in package \&\fBSymbols\fR allows the internal functions to be conveniently hidden from user scripts. .SH "AUTHOR" .IX Header "AUTHOR" Philip R Brenan at \fBphiliprbrenan@yahoo.com\fR .Sh "Credits" .IX Subsection "Credits" \fIAuthor\fR .IX Subsection "Author" .PP philiprbrenan@yahoo.com .PP \fICopyright\fR .IX Subsection "Copyright" .PP philiprbrenan@yahoo.com, 2004 .PP \fILicense\fR .IX Subsection "License" .PP Perl License.