Standard CAS

The Standard CAS (Computer Algebra System) only imports packages and modules available from python itself. Essentially it only usee only standard python with no third party packages or modules required. For example, all Number objects contain only standard python objects. Integers and reals are represented by python int and float objects. Fraction are iare represented by Fraction objects from the fractions module. The stdcas complex numbers are represented by the python complex class.

Import as shown below to get the standard CAS (Computer Algebra System).

In [1]: from truealgebra import std as cas
   ...: cas.setup_func()
   ...: fe = cas.create_frontend(
   ...:     prerule=JustOneBU(cas.evalnum, cas.predicate_rule),
   ...:     postrule=RulesBU(cas.simplify),
   ...: )
   ...: Ex = fe.history
   ...: 

Frontend

The primary means of interacting with truealgebra is the FrontEnd object called the frontend.

In [2]: fe(' height := 25.0; width := 30.0; depth := 2.0 ')
Ex(0):    height := 25.0; width := 30.0; depth := 2.0

In [3]: fe(' volume := height * width * depth ')
Ex(1):    volume := 1500.0

In [4]: fe.assigndict
Out[4]: {height: 25.0, width: 30.0, depth: 2.0, volume: 1500.0}

For the Standard CAS (truealgebra.std package) frontend, follow the documentation in the frontend documentation of the tasympy section.

Numbers

In the std CAS, TrueAlgebra Number objects are wrappers around python number objects. There are four python classes of numbers used.

Float Numbers

Digits with a decimal point are parsed as python float objects. If a - character is in front of a digit it is parserd as a negative number. Stings with an exponential foramt are also parsed as python float obejcts.

In [5]: fe(' 2.375 ')
Ex(2):    2.375

In [6]: type(Ex[-1].value)
Out[6]: float

In [7]: fe(' -19.6 ')
Ex(3):    -19.6

In [8]: type(Ex[-1].value)
Out[8]: float

In [9]: fe(' 4.5e-2 ')
Ex(4):    0.045

In [10]: type(Ex[-1].value)
Out[10]: float

Integer Numbers

digits without a decimal point are parsed as Number objects with python int integers. If a - character is in front of a digit it is parserd as a negative number.

In [11]: fe(' 57 ')
Ex(5):    57

In [12]: type(Ex[-1].value)
Out[12]: int

In [13]: fe(' -107 ')
Ex(6):    -107

In [14]: type(Ex[-1].value)
Out[14]: int

Fraction Numbers

Python fractions.Fraction objects represents fractions. Unlike python division between integers becomes a fraction or fractions.Fraction object. fractions are automatically simplified. Fractions with 1 as a denominator become an integer. Divison by 0, creates a error message and an output on null.

In [15]: fe(' 2/3 ')
Ex(7):    2/3

In [16]: type(Ex[-1].value)
Out[16]: fractions.Fraction

In [17]: fe(' 6/2; 23/46; -4/5 ')
Ex(8):    3; 1/2; -4/5

In [18]: fe(' 4/0 ')
TRUEALGEBRA ERROR!
Numerical Evaluation Error
Division by zero.
Ex(9):    <NULL>

Division by 0 will generate an error message by the python logging module. The output in this case will be a TrueAlgebra Null object.

Complex Numbers

Python complex objects are used for complex numbers. Complex numbers are created from the symbol j as the square root of negative one.

In [19]: fe(' j ')
Ex(10):    1j

In [20]: type(Ex[-1].value)
Out[20]: complex

In [21]: fe(' 37.5 + 3.0 * j ')
Ex(11):    37.5+3j

In [22]: type(Ex[-1].value)
Out[22]: complex

In [23]: fe(' 27.5 + 0.0 * j ')
Ex(12):    27.5

Numerical Evaluation

The rules evalnum and evalnumbu from truealgebra.std.evalnum, evaluates numerical expression. The frontend action fe.prerule applies evalnum bottomup.

Fundamental Math Operators

the rule evalnum deals with the common mathematical operations listed below. All evaluations are by the equivalent python operator. The word “operator” here is used as a programming term. An infix operator takes two arguments, one on each side. A prefix operator takes one argument, to its right.

  • multiplication with infix operator symbol *

  • addition with infix operator symbol +

  • division with infix operator symbol /

  • subtraction with infix operator, symbol -

  • minus (unary) with prefix operator symbol -

  • power with infix operator symbol **

The following example demonstrates evaluation of the fundamental mathematical operations.

In [24]: fe(' 2.3 * 2; 2 ** 1.4; 7 / 1.5; - j; 2 - 2/3; 4/5 + 6/5')
Ex(13):    4.6; 2.6390158215457884; 4.666666666666667; -1j; 4/3; 2

Trigonometric Functions

Trigonometric functions are numerically evaluated. The python cmath module is used for thr evaluations. The csc, sec, and cot evaluations were calculated with formulas using other cmath functions.

In [25]: fe('  cos(0.1) + sin(0.2) + tan(0.3 * j)  ')
Ex(14):    1.193673496073087+0.2913126124515909j

In [26]: fe('  sec(0.1) + csc(0.2) + cot(0.3)  ')
Ex(15):    9.271238609838626

Inverse Trigonometric Functions

Inverse trigonometric functions are numerically evaluated as well. The acsc, asec, and acot evaluations were calculated with formulas using other cmath functions.

In [27]: fe('  acos(0.1) + asin(0.2) + atan(0.3 * j)  ')
Ex(16):    1.6719868264236677+0.3095196042031117j

In [28]: fe('  asec(0.1) + acsc(0.2) + acot(0.3)  ')
Ex(17):    2.8501358591119264-0.7007911765652031j

Exponential and logarithm Functions

The rule evalnum evaluates the exponential function exp, the natural log function log, and log base 10 function log10.

In [29]: fe('  exp(3.7); log(2.0 + 4.1*j); log10(2.5 *j)  ')
Ex(18):    40.4473043600674; 1.5177168202027715+1.1169523252733864j; 0.3979400086720376+0.6821881769209206j