Sums

Symbolic Algebra using Pure Perl: sums.

Operations on sums of terms.

PhilipRBrenan@yahoo.com, 2004, Perl License. PhilipRBrenan@gmail.com, 2016, Perl License. www.appaapps.com

Constructors

new

Constructor

constants

Variables used to sign and lock each sum that have to be declared early on

constants

Useful constants

newFromString

New from String

n

New from Strings

sigma

Create a sum from a list of terms.

makeInt

Construct an integer

Methods

isSum

Confirm type

t

Get list of terms from existing sum

count

Count terms in sum

st

Get the single term from a sum containing just one term

negate

Multiply each term in a sum by -1

add

Add two sums together to make a new sum

subtract

Subtract one sum from another

Conditional Multiply

Multiply two sums if both sums are defined, otherwise return the defined sum. Assumes that at least one sum is defined.

multiply

Multiply two sums together

divide

Divide one sum by another

sub

Substitute a sum for a variable.

isEqual

Check whether one sum is equal to another after multiplying out all divides and divisors.

normalizeSqrts

Normalize sqrts in a sum.

This routine needs fixing.

It should simplify square roots.

isEqualSqrt

Check whether one sum is equal to another after multiplying out sqrts.

isZero

Transform a sum assuming that it is equal to zero

powerOfTwo

Check that a number is a power of two

solve

Solve an equation known to be equal to zero for a specified variable.

power

Raise a sum to an integer power or an integer/2 power.

d

Differentiate.

simplify

Simplify just before assignment.

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.

Simplification cannot be done after every operation as it is inefficient, doing it as part of += ameliorates this inefficiency.

Note: += only works as a synonym for simplify() if the left hand side is currently undefined. This can be enforced by using my() as in: my $z += ($x**2+5x+6)/($x+2);

polynomialDivide

Polynomial divide - divide one polynomial (a) by another (b) in variable v

eigenValue

Eigenvalue check

polynomialDivision

Polynomial division.

Sqrt

Square root of a sum

Exp

Exponential (e raised to the power) of a sum

Log

Log to base e of a sum

Sin

Sine of a sum

Cos

Cosine of a sum

tan, Ssc, csc, cot

Tan, sec, csc, cot of a sum

sinh

Hyperbolic sine of a sum

cosh

Hyperbolic cosine of a sum

Tanh, Sech, Csch, Coth

Tanh, Sech, Csch, Coth of a sum

dot

Dot - complex dot product of two complex sums

cross

The area of the parallelogram formed by two complex sums

unit

Intersection of a complex sum with the unit circle.

re

Real part of a complex sum

im

Imaginary part of a complex sum

modulus

Modulus of a complex sum

conjugate

Conjugate of a complexs sum

clone

Clone

signature

Signature of a sum: used to optimize add(). # Fix the problem of adding different logs

getSignature

Get the signature (see "signature") of a sum

id

Get Id of sum: each sum has a unique identifying number.

zz

Check sum finalized. See: "z".

z

Finalize creation of the sum: Once a sum has been finalized it becomes read only.

print

Print sum

factorize

Factorize a number.

import

Export "n" with either the default name sums, or a name supplied by the caller of this package.

Operators

Operator Overloads

Overload Perl operators. Beware the low priority of ^.

add3

Add operator.

negate3

Negate operator. Used in combination with the "add3" operator to perform subtraction.

multiply3

Multiply operator.

divide3

Divide operator.

power3

Power operator.

equals3

Equals operator.

nequal3

Not equal operator.

tequals

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.

solve3

Solve operator.

print3

Print operator.

sqrt3

Sqrt operator.

exp3

Exp operator.

sin3

Sine operator.

cos3

Cosine operator.

tan3

Tan operator.

log3

Log operator.

dot3

Dot Product operator.

cross3

Cross operator.

unit3

Unit operator.

modulus3

Modulus operator.

conjugate3

Conjugate.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 616:

=pod directives shouldn't be over one line long! Ignoring all 6 lines of content

Around line 617:

Non-ASCII character seen before =encoding in '𝗮+𝗯'. Assuming UTF-8