MathHandbook.com

Computer Algebra System with Learning

 

 

Dr. Weiguang HUANG

 

226 Anzac Pde, Kensington, Sydney, NSW 2033, Australia

Phone:  +61 (0) 413008019

E-mail: DrHuang@DrHuang.com

www.DrHuang.com

 

 

8/5/2015

 

 

Copyright (C) 1990-2015

 

 


Contents

 

PART 1  User's Guide............................................. 7

1.         Introduction..................................................... 7

1.1.         What is SymbMath......................................... 7

1.2.     Capabilities..................................................... 7

1.3.  Shareware and Advanced Versions.................... 8

1.4  A List of Files in SymbMath................................. 8

2. Calculation......................................................... 10

2.1. Exact Calculation.............................................. 10

2.2.   Discontinuity and One-sided Value.................. 11

2.3.  Undefined and Indeterminate Form................... 11

3. Simplification..................................................... 12

3.1. Assuming Domain............................................. 13

3.2. Comparing and Testing Numbers...................... 14

4.   Defining Functions, Procedures and Rules 15

4.1.    Defining Functions......................................... 15

4.1.1.  Defining Conditional Functions................................................. 16

4.1.2.  Defining Case Functions.......................................................... 16

4.1.3.  Defining Piece-wise Functions................................................. 16

4.1.4.  Defining Recursion Functions.................................................. 17

4.1.5.  Defining Multi-Value Functions................................................. 17

4.2.  Defining Procedures......................................... 17

4.3.  Defining Rules................................................. 18

5.    Limits............................................................... 18

5.1.  One-sided Limits.............................................. 18

5.2.  Numeric Limits: nlim()...................................... 20

6. Differentiation.................................................... 20

6.1.  Fractional Derivatives....................................... 21

6.2.  Defining f (x).................................................... 21

7.  Integration......................................................... 22

7.1. Indefinite Integration.......................................... 22

7.2. Definite Integration............................................ 24

7.3.  Numeric Integration.......................................... 24

8.    Solving Equations.......................................... 25

8.1. Solving Algebraic Equations.............................. 25

8.2.  Equation Solver: solve()................................... 26

8.3.  Polynomial Solver: psolve().............................. 27

8.4.  Numeric Solver: nsolve().................................. 27

8.5.  Solving Differential Equations........................... 27

8.6.  Differential Solver: dsolve().............................. 28

9.  Sums, Products, and Series........................... 28

9.1.  Partial Sum...................................................... 29

9.2.  Indefinite Sum.................................................. 29

9.3.  Series.............................................................. 29

9.4.  Polynomials..................................................... 30

10.          Lists and Arrays, Vectors and Matrices.. 31

10.1.    Lists............................................................. 31

10.1.1.  Entering Lists........................................................................ 31

10.1.2.     Accessing Lists.................................................................. 31

10.1.3.     Modifying Lists................................................................... 32

10.1.4.     Operating Lists.................................................................. 32

10.2.    Arrays.......................................................... 34

10.2.1.  Entering Arrays..................................................................... 34

10.2.2.  Accessing Arrays.................................................................. 34

10.2.3.  Modifying Arrays................................................................... 34

10.2.4.  Operating Arrays.................................................................. 34

10.3.     Vectors and Matrices.................................. 35

11.    Statistics....................................................... 35

12.     Tables of Function Values......................... 35

13.   Conversion.................................................... 36

13.1.  Converting to Numbers.................................. 36

13.2.  Converting to Lists......................................... 36

13.3.  Converting to Strings...................................... 37

13.4.  Converting to Table........................................ 37

14.    Getting Parts of Expression....................... 37

14.1.  Getting Type of Data...................................... 37

14.2.  Getting Operators........................................... 37

14.3.  Getting Operands........................................... 38

14.4.  Getting Coefficients........................................ 38

15.    Database....................................................... 38

15.1.  Phone Number............................................... 39

15.2.  Atomic Weight................................................ 39

15.3.  Chemical Reaction......................................... 39

16.  Learning from User........................................ 39

16.1.  Learning Integrals from a Derivative............... 39

16.2.  Learning Complicated Integrals from a Simple Integral............................................................................... 41

16.3.  Learning Definite Integral from Indefinite Integral 42

16.4. Learning Complicated Derivatives from Simple Derivative................................................................ 42

16.5.  Learning Integration from Algebra................... 42

16.6.  Learning Complicated Algebra from Simple Algebra............................................................................... 42

16.7.  Learning vs. Programming.............................. 43

PART 2    Programmer's Guide........................... 44

17.  Programming in SymbMath.......................... 44

17.1.  Data Types.................................................... 44

17.1.1.  Numbers.............................................................................. 44

17.1.2.  Constants............................................................................. 45

17.1.3.  Variables.............................................................................. 46

17.1.4.  Patterns............................................................................... 47

17.1.5.  Functions, Procedures and Rules........................................... 47

17.1.5.1.  Standard Mathematical Functions....................................... 47

17.1.5.2.  Calculus Functions............................................................. 48

17.1.5.3.  Test Functions................................................................... 49

17.1.5.4.  Miscellaneous Functions..................................................... 51

17.1.5.5.     User-defined Functions.................................................... 52

17.1.5.6.  Procedures........................................................................ 52

17.1.5.7.  Rules................................................................................. 52

17.1.6.  Equations............................................................................. 52

17.1.7.  Inequalities........................................................................... 53

17.1.8.  Vectors or Lists..................................................................... 53

17.1.9.  Matrices or Arrays................................................................ 53

17.1.10.  Strings................................................................................ 53

17.2.   Expressions.................................................. 54

17.2.1.   Operators............................................................................ 54

17.2.1.1.  Arithmetic Operators.......................................................... 55

17.2.1.2.  Relational Operators.......................................................... 55

17.2.1.3.    Logical Operators............................................................. 55

17.2.2.  Function Calls....................................................................... 56

17.3.    Statements.................................................. 56

17.3.1.  Comment Statements........................................................... 56

17.3.2.  Evaluation Statements.......................................................... 57

17.3.3.  Assignment Statements........................................................ 57

17.3.4.  Conditional........................................................................... 58

17.3.5.  Loop.................................................................................... 58

17.3.6.  Switch.................................................................................. 59

17.3.6.1.  Output Switch.................................................................... 59

17.3.6.2.  Case Switch....................................................................... 59

17.3.6.3.  Numeric Switch.................................................................. 59

17.3.6.4.  Expand Switch................................................................... 60

17.3.6.5.  ExpandExp Switch............................................................. 60

17.3.7.  Read and Write Statements................................................... 60

17.3.8.  DOS Command.................................................................... 61

17.3.9.  Sequence Statements........................................................... 61

17.4.  Libraries and Packages.................................. 61

17.4.1.  Initial Package init.sm............................................................ 63

17.4.2.  ExpandLn Package............................................................... 63

17.4.3.  Chemical Calculation Package............................................... 63

17.5.  Interface with Other Software................................................... 64

18.   Graphics......................................................... 64

18.1.  Drawing Lines and Arcs.................................. 65

18.2.  Plotting f(x).................................................... 66

18.3.  Plotting Parametric Functions x(t) and y(t)...... 67

18.4.    Plotting f(t) in Polar Coordinates................... 67

18.5.  Plotting Data.................................................. 68

18.6.     Printing Graphics on Printer........................... 68

Part 3 Reference Guide........................................ 69

19.  SymbMath Environment: Windows and Menus................................................................................. 69

19.1.  File Menu....................................................... 69

19.1.1.  Open.................................................................................... 70

19.1.2.  New..................................................................................... 70

19.1.3.  Save Input............................................................................ 70

19.1.4.  Save Output......................................................................... 70

19.1.5.  DOS Shell............................................................................ 70

19.1.6.  Exit...................................................................................... 70

19.2.  Input Menu..................................................... 71

19.3.  Run Menu...................................................... 71

19.4.  Output Menu.................................................. 71

19.5.  Color Menu.................................................... 71

19.5.1.  Menu Line............................................................................ 71

19.5.2.  Input Window........................................................................ 71

19.5.3.  Input Border......................................................................... 72

19.5.4.  Output Window..................................................................... 72

19.5.5.  Output Border....................................................................... 72

19.5.6.  Status Line........................................................................... 72

19.6.  Help Menu..................................................... 72

19.7.  Example Menu............................................... 73

19.8.  Keyword Menu............................................... 73

19.9.  Editor and Edit Help Menu.............................. 73

19.9.1.  Edit Help Menu..................................................................... 73

19.9.1.1.  Show Help File................................................................... 74

19.9.1.2.  Cursor Movement Commands............................................ 74

19.9.1.3.  Insert and Delete Commands............................................. 74

19.9.1.4.  Search and Replace Commands......................................... 75

19.9.1.5.  Block Commands............................................................... 75

19.9.1.6.  Special Block Commands................................................... 77

19.9.1.9.  Miscellaneous Commands.................................................. 77

19.9.1.10.   Global Commands........................................................... 78

19.9.2.  Edit Commands.................................................................... 78

19.9.3. Copy and Paste..................................................................... 81

20.   Inside SymbMath........................................... 83

20.1.  Internal Structure........................................... 83

20.2.  Internal Format.............................................. 84

21. System Limits.................................................. 84

22. Keywords......................................................... 85

22.1.     Internal Functions....................................... 85

22.2.     External Functions...................................... 85

22.3.    Keywords in Alphabetical Order.................... 86

22.4.     Keywords in Topic Order............................. 87

22.5.     Glossary..................................................... 93

 


PART 1  User's Guide

 

1.   Introduction

1.1. What is SymbMath

 

            SymbMath (an abbreviation for Symbolic Mathematics) is a symbolic calculator that can solve symbolic math problems.

            SymbMath is a computer algebra system that can perform exact, numeric, symbolic and graphic computation. It manipulates complicated formulas and returns answers in terms of symbols, formulas, exact numbers, tables and graph.

            SymbMath is an expert system that is able to learn from user's input. If the user only input one formula without writing any code, it will automatically learn many problems related to this formula (e.g. it learns many integrals involving an unknown function f(x) from one derivative f’).

           SymbMath is a symbolic, numeric and graphics computing environment where you can set up, run and document your calculation, draw your graph.

SymbMath uses external functions as if standard functions since the external functions in library are auto-loaded.

            SymbMath is a programming language in which you can define conditional, case, piecewise, recursive, multi-value functions and procedures, derivatives, integrals and rules.

            SymbMath is database where you can search your data.

            It runs on IBM PCs (8086) with 400 KB free memory under MS-DOS.

 

 

1.2.     Capabilities

 

            It can provide analytical and numeric answers for:

            *  Differentiation: regular or higher order, partial or total, mixed and implicit differentiation, one-sided derivatives.

            *  Integration: indefinite or definite integration, multiple integration, infinity as a bound, parametric or iterated implicit integration.

            *  Solution of equations: roots of a polynomial, systems of algebraic or differential equations.

            *  Manipulation of expressions: simplification, factoring or expansion, substitution, evaluation.

            *  Calculation: exact and floating-point numeric computation of integer, rational, real and complex numbers in the range from minus to plus infinity, even with different units.

            *  Limits: real, complex or one-sided limits, indeterminate forms.

            *  Complex: calculation, functions, derivatives, integration.

            *  Sum and product: partial, finite or infinite.

            *  Others: series, lists, arrays, vectors, matrices, tables, etc.

           

Also included are:

            *  External functions in library as if standard functions.

            *  Plot: functions, polar, parametric, data, and list.

            *  Draw: lines, arcs, ellipse, circles, ovals.

            * Procedural, conditional, iteration, recursive, functional, rule-based, logic, pattern-matching and graphic programming.

            *  Searching database.

 

1.3.  Shareware and Advanced Versions

 

            You should register with the author if you use SymbMath.

            Please read all * files before running SymbMath. Please copy-and-past examples in the Help window to practise. The printed documents (100+ pages) is available from author.

            If you get the SymbMath on ZIP format (e.g. sm32a.zip), you should unzip it with parameter -d by

                        pkunzip -d sm32a c:\symbmath

            If you get the SymbMath with the install file, you should install it by                                            install

            On the MS-DOS prompt to run it, type               SymbMath

            SymbMath has two versions: Shareware Version A, and Advanced Version C. The Shareware version lacks the solve(), trig (except sin(x) and cos(x)), and hyperbolic functions, (lack 10% keywords). You cannot input these lack functions in Shareware version.

 

------------------------------------------------------------------------------------------

Version             Class   Lacked functions                                  

 

Shareware        A          solve(), hyperbolic,                              

                                    trig (except sin(x), cos(x))

Advanced         C                                                                     

Libraries           * . li                                                     

Manual             printed                                     

...........................................................................................................................

Upgrade           same                                                   

...........................................................................................................................

Multiple            copies  >2                                                                   

...........................................................................................................................

Site licence       >10 copies                                                       

------------------------------------------------------------------------------------------

 

            You must provide the photocopy of your license or license number for upgrades.

            If you send the author your payment by cheque, money order or bank draft that must be drawn in Australia, you will get the latest version. If you sign the license (see the LICENSE file) and send it to the author, you will be a legal user for upgrades. If you write a paper about this software on publication, you will get a free upgrade.

            Its two versions (Shareware and Advanced) are available from the author. The Shareware version is available from my web sites.

            The Advanced version is copy-protected, so you must insert the original SymbMath disk into drive A or B before you run SymbMath. By default, it is drive B. If you use drive A, please copy (or rename) the DRIVE.A file to the SYMBMATH.DRI file, or you edit drive(2) into drive(1) in the SYMBMATH.DRI file.

 

1.4  A List of Files in SymbMath

 

---------------------------------------------------------------------------------------------------------------

In directory SymbMath:

 

SymbMath.exe              executable SymbMath system.

SymbMath.ini                initial file.

SymbMath.h*                help files, * is numbers.

SymbMath.dri               indicate which drive the original SymbMath disk is inserted into

init.sm                          initial SymbMath program file.

*.sm                             packages (user SymbMath program files).

prolog.err                     prolog error message file.

 

In directory SymbMath\BGI:

 

*.bgi                             BGI graphics drives.

*.chr                             stroked fonts.

 

 

In directory SymbMath\library:

 

*                                   the auto loaded libraries (external functions).

 

 

In directory SymbMath\keyword:

 

*.key                            the keyword files.

 

In directory SymbMath\text:

 

SymbMath                    introduction of SymbMath.

readme             the read-me file, this file should be read first.

problem                        problems that other software cannot solve, but SymbMath can do.

comment*                     comments on SymbMath.

statisti              the download statistics at FTP site of garbo.uwasa.fi.

shareware                    Shareware concept.

software                       software available from the author.

update              the latest updates in SymbMath.

------------------------------------------------------------------------

 

 


2. Calculation

 

            In the following examples, a line of "IN: " means input, which you type in the Input window, then leave the Input window by pressing <Esc>, finally run the program by the command "Run"; while a line of "OUT: " means output. You will see both input and output are displayed on two lines with beginning of "IN: " and "OUT: " in the Output window. You should not type the word "IN: ". Some outputs may be omitted on the examples.

# is a comment statement.

            You can split a line of command into multi-lines of command by the comma ,. The comma without any blank space must be the last character in the line.

            Note that you should not be suprised if some functions in the following examples are not working when their libraries are not in the default directory or missing.

 

 

2.1. Exact Calculation

 

            SymbMath gives the exact value of calculation when the switch numeric := off (default), or the approximate value of numeric calculation when the switch numeric := on or by num().

            Mathematical functions are usually not evaluated until by num() or by setting numeric := on.

            SymbMath can manipulate units as well as numbers, be used as a symbolic calculator, and do exact computation. The range of real numbers is from -infinity to +infinity, e.g. ln(-inf), exp(inf+pi*i), etc. SymbMath contains many algorithms for performing numeric calculations. e.g. ln(-9), i^i, (-2.3)^(-3.2), 2^3^4^5^6^7^8^9, etc.

            Note that SymbMath usually gives a principle value if there are multi-values, but the solve() and root() give all values.

 

            Example:

            Exact and numeric calculations of 1/2 + 1/3.

IN:  1/2+1/3                  # exact calculation

OUT: 5/6

 

IN:  num(1/2+1/3)          # numeric calculation

OUT: 0.8333333333

 

            Evaluate the value of the function f(x) at x=x0 by f(x0).

 

            Example:

            Evaluate sin(x) when x=pi, x=180 degree, x=i.

IN:  sin(pi), sin(180*degree)

OUT: 0, 0

 

IN:  sin(i), num(sin(i))

OUT: sin(i), 1.175201 i

 

            Example:

            Set the units converter from the minute to the second, then calculate numbers with different units.

IN:  minute:=60*second

IN:  v:=2*meter/second

IN:  t:=2*minute

IN:  d0:=10*meter

IN:  v*t+d0

OUT: 250 meter

 

            Evaluate the expression value by

                        subs(y, x = x0)

 

            Example:

            Evaluate z=x^2 when x=3 and y=4.

IN:  z:=x^2                    # assign x^2 to z

IN:  subs(z, x = 3)         # evaluate z when x = 3

OUT: 9

 

IN:  x:=4                       # assign 4 to x

IN:  z                            # evaluate z

OUT: 16

 

            Note that after assignment of x by x:=4, x should be cleared from assignment by clear(x) before differentiation (or integration) of the function of x. Otherwise the x values still is 4 until new values assigned. If evaluating z by the subs(), the variable x is automatically cleared after evaluation, i.e. the variable x in subs() is local variable. The operation by assignment is global while the operation by internal function is local, but operation by external function is global. This rule also applies to other operations.

            The complex numbers, complex infinity, and most math functions with the complex argument can be calculated.

 

            Example .

IN:  sign(1+i), sign(-1-i), i^2

OUT: 1, -1, -1

 

            Example:

IN:  exp(inf+pi*i)

OUT: -inf

 

IN:  ln(last)

OUT: inf + pi*i

 

            The built-in constants (e.g. inf, zero, discont, undefined) can be used as numbers in calculation of expressions or functions.

 

 

2.2.   Discontinuity and One-sided Value

 

            Some math functions are discontinuous at x=x0, and only have one-sided function value. If the function f(x0) gives the discont as its function value, you can get its one-sided function value by f(x0-zero) or f(x0+zero).

 

            Example:

IN:  f(x_) := exp(1/x)                 # define function f(x)

IN:  f(0)

OUT: discont                            # discontinuity at x=0

 

IN:  f(0-zero)                             # left-sided value at x=0-

OUT: 0

 

IN:  f(0+zero)                            # right-sided value at x=0+

OUT: inf

 

 

2.3.  Undefined and Indeterminate Form

 

            If the function value is undefined, it may be indeterminate form (e.g. 0/0, inf/inf), you can evaluate it by lim() (see Chapter  Limits).

 

 

3. Simplification

 

            SymbMath automatically simplifies the output expression. You can further simplify it by using the built-in variable last in a single line again and again until you are happy with the answer.

            Expressions can be expanded by

                        expand(x)

                        expand := on

                        expandexp := on

            Remember that the operation by assignment is global while operation by function is local. So expand(x) only expands the expression x, but the switch expand := on expands all expressions between the switch expand := on and the switch expand := off. Second difference betwen them is that the switch expand := on only expands a*(b+c) and (b+c)/p, but does not expands the power (a+b)^2. The expandexp is exp expand.

 

            Example:

IN:  expand((a+b)^2+(b+c)*p)

OUT: a^2 + 2 a b + b^2 + b p + c p

 

IN:  expand := on

IN:  (a+b)^2 + (b+c)*p

OUT: (a+b)^2 + b p + c p

 

----------------------------------------------------------------------------------------

...............         expand(x) ..........................................

(a+b)^2             to         a^2+2*a*b+b^2

(a+b)^n             to         a^n+ ...... +b^n        n is positive integer

 

............... expand(x) and expand := on ..........................

a*(b+c)             to         a*b + a*c

(b+c)/p             to         b/p + c/p

 

............... expandexp := on .....................................

e^(a+b)             to           e^a *  e^b      

-----------------------------------------------------------------------------------------------

where a+b can be many terms or a-b.

 

            Expressions can be factorised by

                        factor(x)

            e.g.

IN:  factor(a^2 + 2*a*b + b^2)

OUT: (a + b)^2

 

            Polynomials of order less than 5 can be factorised by

                        factor(y, x)

 

            Example:

IN:  factor(x^2+5*x+6, x)

OUT: (2 + x) (3 + x)

 

            Example:

            Reduce sqrt(x^2).

IN:  sqrt(x^2)

OUT: x*sign(x)

 

            This output can be further simplified if you know properties of x.

            A first way is to evaluate x*sign(x) by substituting sign(x) with 1 if x is positive.

 

IN:  sqrt(x^2)

OUT: x*sign(x)

 

IN:  subs(last, sign(x) = 1)

OUT: x

 

where a special keyword last stands for the last output, e.g. here last is x*sign(x).

 

                       

3.1. Assuming Domain

 

            A second way is to assume x>0 before evaluation. If you assume the variable x is positive or negative, the output expression is simpler than that if you do not declare it.

 

IN:  assume(x > 0, y <0)             # assume x > 0, y < 0

OUT: assumed

 

IN:  sqrt(x^2), sqrt(y^2), sqrt(z^2)

OUT: x*sign(x), y*sign(y), z*sign(z)

 

IN:  last                            # simplify last output

OUT: x, -y, z*sign(z)

 

            In this way, all of x is affected until the assume() is cleared by clear(). The first method is local simplification, but the second method is global simplification.

            By default, |x| < inf and all variables are complex, except that variables in inequalities are real, as usual only real numbers can be compared. e.g. x is complex in sin(x), but y is real in y > 1.

           

            Table 3.1       Assuming

--------------------------------------------------------------------------------------------------------

Assume                        Assignment                  Meaning               

 

assume(x>y)                x>y := 1                                    # assume x > y

assume(x>=y)              x>=y := 1                      # assume x >= y

assume(x<y)                x<y := 1                                    # assume x < y

assume(x<=y)              x<=y := 1                      # assume x <= y

assume(x==y)              x==y := 1                      # assume x == y

assume(x<>y)              x<>y := 1                      # assume x <> y

                                    iseven(b) := 1               # assume b is even

                                    isodd(b) := 1                 # assume b is odd

                                    isinteger(b) := 1                        # assume b is integer

                                    isratio(b) := 1                # assume b is ratio

                                    isreal(b) := 1                 # assume b is real

                                    iscomplex(b) := 1          # assume b is complex

                                    isnumber(b) := 1           # assume b is number

                                    islist(b) := 1                  # assume b is a list

                                    isfree(y,x) := 1              # assume y is free of x

                                    issame(a,b) := 1           # assume a is same as b

                                    sign(b) := 1                   # assume b is positive complex

                                    sign(b) := -1                 # assume b is negative complex

------------------------------------------------------------------------------------------------------------

 

            The assume() can be cleared by clear(). e.g. clear(x>y).

            You can restrict the domain of a variable by assuming the variable is even, odd, integer, real number, positive or negative.

 

            Example:

 

IN:  isreal(b) := 1          # assume b is real

IN:  sqrt(b^2)

OUT: abs(b)

 

 

            Table 3.3          Simplification in different domains

----------------------------------------------------------------------------------

expression        complex           real                  x > 0

 

sqrt(x^2)          x sign(x)           |x|                     x

x*sign(x)          x sign(x)           |x|                     x

|x|*sign(x)         |x| sign(x)         x                      x

|x|/x                  |x|/x                  1/sign(x)           1

x+inf                 x+inf                 inf

x-inf                 x-inf                 -inf

abs'(x)              |x|/x                  1/sign(x)           1

-------------------------------------------------------------------------------------

 

 

3.2. Comparing and Testing Numbers

 

            You can compare two numbers by relational operators:

                        a > b

                        a < b

                        a <= b

                        a >= b

                        a <> b

                        a == b

 

            Example:

IN:  2 > 1, 2 < 1

OUT: 1, 0

 

            You also can compare two numbers, even complex numbers z1 and z2 by

                        islarger(z1, z2)

                        isless(z1, z2)

                        issame(z1, z2)

 

            Example:

            compare 1+i and 1-i.

IN:  islarger(1+i, 1-i)         # is 1+i larger than 1-i ?

OUT: 1                             # yes, 1+i > 1-i

 

            You can compare square of a variable a^2 > 0 if you know the property of the variable.

            Example:   

IN:  assume(a > 0)

IN:  a^2 > 0, 1/a > 0

OUT: 1, 1

 

            You can test if x is even, odd, integer, real, number or list by the functions:

                        iseven(x)

                        isodd(x)

                        isinteger(x)

                        isreal(x)

                        isnumber(x)

                        islist(x)

                        isfree(y,x)

                        islarger(a,b)

                        isless(a,b)

                        issame(a,b)

 

            Example:

IN:  iseven(2)                # is 2 even ?

OUT: 1                         # yes

 

            Note that comparison by the is* functions return either 1 if it is true or 0 otherwise, but comparison by relational operators gives 1 if it is true, 0 if it is fault, or left unevaluated otherwise.

 

 

4.   Defining Functions, Procedures and Rules

 

            Anytime when you find yourself using the same expression over and over, you should turn it into a function. 

            Anytime when you find yourself using the same definition over and over, you should turn it into a library.

            You can make your defined function as if the built-in function, by saving your definition into disk file as a library with the function name plus extension  as the filename. e.g. saving the factoria function as the factoria file (see Section Libraries and Packages).

 

 

4.1.    Defining Functions

 

            You can define your own functions by

                           f(x_) := x^2

            Here are some sample function definitions:

                           f(x_) := cos(x + pi/3)

                           g(x_, y_) := x^2 - y^2

            The argument in the definition should be the pattern x_. Otherwise f() works only for a specific symbolic value, e.g. x when defining f(x):=x^2. The pattern x_ should be only on the left side of the assignment.

            Once defined, functions can be used in expressions or in other function definitions:

                        y := f(3.2)

                        z := g(4.1, -5.3)

 

            Example:

Define a new function for x^2, then evaluate it.

           

IN:  g(x) := x^2

IN:  g(2), g(a),  g(x)

OUT: g(2), g(a),  x^2                # work only for a symbolic value x

 

IN:  f(x_) := x^2

IN:  f(2), f(a)

OUT: 4, a^2                              # work for any value

 

 

4.1.1.  Defining Conditional Functions

 

            You can define a conditional function by the If() function:

                        f1(x_) := If(x>0 ,   1)

                        f2(x_) := If(x>0 ,  x^2 ,  x)

or by inequalities:

                        f3(x_) := x>0

                        f4(x_) := (x>0) * x^2 + (x<=0) * x

            On the first definition by If(), when f1() is called it gives 1 if x>0, or left unevaluated otherwise. On the second definition by the If(), when f2() is called it gives x^2 if x>0, x if x<=0, or left unevaluated otherwise. On the third definition by the inequality, when f3() is called, it gives 1 for x>0, 0 for x<=0, or x>0 for symbolic value of x. On the last definition, when f4() is called, it is evaluated for any numeric or symbolic value of x.

            You cannot differentiate nor integrate the conditional function defined by If(), but you can do the conditional functions defined by inequalities.

 

            You can define a function evaluated only for numbers by

                        f(x_) := If(isnumber(x) ,  x^2)

            This definition is different from the definition by f(x_) := x^2. On the latter, when f() is called, it gives x^2, regardless whatever x is. On the former, when f() is called, it gives x^2 if x is a number, or left unevaluated otherwise.

           

            Example:

evaluate to x^2 only if x is number, by defining a conditional function.

 

IN:  f(x_) := If(isnumber(x) ,  x^2)

IN:  f(2), f(a)

OUT: 4, f(a)

 

IN:  f(x_) := If(x>0 ,  x^2)

IN:  f(2), f(-2), f(a)

OUT: 4, f(-2), f(a)

 

IN:  f(x_) := If(x>0 ,  x^2 ,  x)

IN:  f(2), f(-2), f(a)

OUT: 4, 2, f(a)

 

 

4.1.2.  Defining Case Functions

 

            You can define the case function by different pattern name. The case function is similar to the case statement in BASIC language.

            Example:

 

IN:  f(x_) := If( x > 0 and x < 1 ,  1)

IN:  f(u_) := If( u > 1 and u < 2 ,  2)

IN:  f(v_) := If( v > 2 and v < 3 ,  3)

IN:  f(0.2), f(1.2), f(2.2)

OUT: 1, 2, 3

 

 

4.1.3.  Defining Piece-wise Functions

 

            You can define a piece-wise function.

 

            Example:

            define

 

      / x              if x < 0

f(x) =  0                        if x = 0

      \ x^2           if x > 0

 

then evaluate f(-2), f(0), f(3), f(a), f’, d(f(x), x=3).

 

IN:  f(x_) := x*(x<0)+x^2*(x>0)

IN:  f(-2), f(0), f(3), f(a)

OUT: -2, 0, 9, (a < 0) a + (a > 0) a^2

 

IN:  f’

OUT: (x < 0) + 2 x (x > 0)

 

IN:  d(f(x), x=3)

OUT: 6

 

 

4.1.4.  Defining Recursion Functions

 

            You can define a recursion function.

            Example:

IN:  factoria(1) := 1

IN:  factoria(n_) := If(n > 1, (n-1)*factoria(n-1))

 

 

4.1.5.  Defining Multi-Value Functions

 

            You can define a function with the multi function values.

            Example:

IN:  squreroot(x_) := [sqrt(x), -sqrt(x)]

IN:  squreroot(4)

OUT: [2, -2]

 

 

4.2.  Defining Procedures

 

            You can define a function as a procedure by

                        f(x_) := block(command1, command2, ..., commandN)

                        f(x_) := block(command1, command2, ..., commandN, local(a))

 

            By default, all variables within procedure are global, except for variables declared by local(). The multi-statement should be grouped by block(). The block() only outputs the result of the last statement or the second last one as its value. The multi-line must be terminated by a comma, (not by a comma and a blank space). Local() must be the last one in block().

 

            Example:

define a numeric integration procedure ninte() and calculate integral of x^2 from x=1 to x=2 by call ninte().

 

IN:  ninte(y_,x_,a_,b_) := block( numeric:=on,

            dd:=(b-a)/50,

            aa:=a+dd,

            bb:=b-dd,

            y0:=subs(y, x = a),

            yn:=subs(y, x = b),

            (sum(y,x,aa,bb,dd)+(y0+yn)/2)*dd,

            local(dd,aa,bb,y0,yn) )

 

IN:  ninte(x^2, x, 1, 2)

 

 

4.3.  Defining Rules

 

            You can define transform rules. Defining rules is similar to defining functions. In defining functions, all arguments must be simple variables, but in defining rules, the first argument can be a complicated expression.

 

            Example:

            Define log rules.

IN:  log(x_ * y_) := log(x) + log(y)

IN:  log(x_ ^ n_) := n*log(x)

IN:  log(a*b)

OUT: log(a) + log(b)

 

            Example:

IN:  sin(-x_) := -sin(x)

IN:  sin(-a)

OUT: -sin(a)

 

            Example:

            Define derivatives (see Chapter 4.5.2 Defining f’).

IN:  f'(x_) := sin(x)

IN:  f'(t)

OUT: sin(t)

 

            Example:

            Define integrals (see Chapter 4.6.1 Indefinite Integration).

IN:  integrate(f(x_),x_) := sin(x)

IN:  integrate(f(t),t)

OUT: sin(t)

 

            Example:

            Define the trig simplification rules.

IN:  simplify(sin(x_)^2, x_) := 1/2*(1-cos(x))

IN:  simplify(sin(x)^2,x)

OUT: 1/2 (1 - cos(x))

 

            Example:

            Define Laplace transform rules.

IN:  laplace(sin(t_), t_) := 1/(t^2+1)

IN:  laplace(sin(s), s)

OUT: 1/(s^2 + 1)

 

 

5.    Limits 

5.1.  One-sided Limits

 

            You can finds real or complex limits, and discontinuity or one-sided value.

            First find the expression value by subs(y, x = x0) or the function value by f(x0) when x = x0.

            If the result is the discont (i.e. discontinuity), then use the one-sided value x0+zero or x0-zero to try to find the one-sided function or expression value.

            For a function f(x), you can evaluate the left- or right-sided function value, similar to evaluate the normal function value:      

                        f(x0-zero)

                        f(x0+zero)

            For an expression y, you can evaluate its one-sided expression value by

                        subs(y, x = x0-zero)

                        subs(y, x = x0+zero)

            The discont (discontinuity) means that the expression has a discontinuity and only has the one-sided value at x=x0. You should use x0+zero or x0-zero to find the one-sided value. The value of f(x0+zero) or f(x0-zero) is the right-sided or left-sided function value as approaching x0 from positive (+inf) or negative (-inf) direction, respectively, i.e. as x = x0+ or x = x0-.

            If the result is undefined (indeterminate forms, e.g. 0/0, inf/inf, 0*inf, and 0^0), then find its limit by

                        lim(y, x = x0)

            If the limit is discont, then you can find a left- or right-sided limit when x approaches to x0 from positive (+inf) or negative (-inf) direction at discontinuity by

 

                        lim(y, x = x0+zero)

                        lim(y, x = x0-zero)

 

            Example:

            Evaluate y=exp(1/x) at x=0, if the result is discontinuity, find its left-sided and right-sided values (i.e. when x approaches 0 from positive and negative directions).

 

IN:  y:=exp(1/x)

IN:  subs(y, x = 0)

OUT: discont               # discontinuity at x=0

 

IN:  subs(y, x = 0+zero), subs(y, x = 0-zero)

OUT: inf, 0

 

            Example:

            How to handle the following one-sided values ?

 

Let f(x) = 1 when x < 1, f(x) = 1 when x > 1 (and not defined at x = 1).

Let g(x) = 1 when x < 1, g(x) = 1 when x > 1, and g(1) = 2.

Let h(x) = 1 when x < 1, h(x) = 2 when x >= 1.

Let k(x) = 1 when x < 1, k(x) = 2 when x > 1, and k(1) = 3.

 

Now ask SymbMath to compute

 

(1) the limit as x approaches 1,

(2) the limit as x approaches 1 from the left, and

(3) the limit as x approaches 1 from the right

 

for each of the above piecewise defined functions.

 

# define functions

f(x_) :=  If(x<1 or x>1, 1)

f(1+zero):=1

f(1-zero):=1

g(x_) := If( x<1 or x>1, 1)

g(1):=2

g(1+zero):=1

g(1-zero):=1

h(x_) := If( x<1, 1, 2)

h(1+zero):=2

h(1-zero):=1

k(x_) := If( x<1, 1, If( x>1, 2))

k(1):=3

k(1+zero):=2

k(1-zero):=1

 

# evaluate functions

IN:  f(1), g(1), h(1), k(1)

OUT: f(1), 2, 2, 3

 

IN:  f(1+zero), g(1+zero), h(1+zero), k(1+zero)

# right-hand side value at x=1+

OUT: 1, 1, 1, 1

 

IN:  f(1-zero), g(1-zero), h(1-zero), k(1-zero)

# left-hand side value at x=1-

OUT: 1, 1, 2, 2

 

            Example:

Find limits of types 0/0 and inf/inf.

 

IN:  p:=(x^2-4)/(2*x-4)

IN:  subs(p, x = 2)

OUT: undefined

 

IN:  lim(p, x = 2)

OUT: 2

 

IN:  subs(p, x = inf)

OUT: undefined

 

IN:  lim(p, x = inf)

OUT: inf

 

 

5.2.  Numeric Limits: nlim()

 

            If symbolic limit falls, you should try numeric limit by

                        nlim(y, x=x0)

 

            e.g. nlim(sin(x)/x, x=0)

 

 

6. Differentiation

 

            Differentiate an expression y with respect to x by 

                        d(y, x)

            Differentiate a simple function f(x) with respect to x by

                        d(f(x))

            Differentiate y in the n order by

                        d(y, x, n)

            Differentiate y at x = x0 by

                        d(y, x = x0)

            Differentiate y at x = x0 in the n order by

                        d(y, x = x0, n)

            The order can be any number, e.g. 0.5 order is fractional derivative.

                       

            Example:

            Differentiate sin(x) and x^(x^x).

IN:  d(sin(x))    # it is the same as d(sin(x), x).

OUT: cos(x)

 

IN:  d(x^(x^x), x)

OUT: x^(x^x) (x^(-1 + x) + x^x ln(x) (1 + ln(x)))

 

            If you differentiate f(x) by f’, x must be a simple variable and f(x) must be unevaluated.

            f'(x0) is the same as d(f(x0),x0), but different from d(f(x), x=x0). f'(x0) first evaluates f(x0), then differentiates the result of f(x0). But d(f(x), x=x0) first differentiates f(x), then replace x with x0. Note that sin'(x^6) gives cos(x^6) as sin'(x^6) is the same as d(sin(x^6), x^6). sin'(0) gives d(0,0) as sin(0) is evaluated to 0 before differentiation, you should use d(sin(x),x=0) which gives 1.

 

            Example:

            Differentiate the expression f=sin(x^2+y^3)+cos(2*(x^2+y^3)) with respect to x, and with respect to both x and y.

IN:  f := sin(x^2+y^3)+cos(2*(x^2+y^3))

IN:  d(f, x)

OUT: 2 x cos(x^2 + y^3) - 4 x sin(2 (x^2 + y^3))

 

IN:  d(d(f, x), y)           # mixed derivative with x and y.

OUT: -6 x y^2 sin(x^2 + y^3) - 12 x y^2 cos(2 (x^2 + y^3))

 

6.1.  Fractional Derivatives

 

            Differentiate y at fractional order by

                        d(y, x , order)

                        d(y,x , -1.5)

 

            Example:

IN:  y:=d(sin(x), x, -1.5);

IN:   d(y, x,1.5)            

 

The Davison-Essex and the Riemann-Liouville definitions are different in the following aspect: in the D-E formula, differentiation is performed first, then integration; in the R-L formula it is the other way around. The D-E definition implemented, thus, maps constants to zero, imitating integer order differentiation, while the R-L definition does not. This property of the D-E definition makes it suitable to work with initial value problems for fractional differential equations.

 

6.2.  Defining f (x)

 

            Defining derivatives is similar to defining rules. You only need to define derivatives of a simple function, as SymbMath automatically apply the chain rule to its complicated function.

 

            Example:

IN:  f(x_) := sin(x);

IN:  f(x)

OUT: sin(x)

 

IN:  f(x^6)            # the same as d(f(x^6), x^6)

OUT: sin(x^6)

 

IN:  d(f(x^6), x)

OUT: 6 x^5 sin(x^6)

 

 

 

 

7.  Integration

 

            You can find integrals of x^m*e^(x^n), x^m*e^(-x^n), e^((a*x+b)^n), e^(-(a*x+b)^n), x^m*ln(x)^n, ln(a*x+b)^n, etc., (where m and n are any real number).

            It is recommended that before you do symbolic integration, you should simplify integrand, e.g. expand the integrand by expand() and/or by setting the switch expand:=on and/or expandexp:=on.

            If symbolic integration fails, you can define a simple integral and/or derivative, (or adding integral into the int library), then do integration again (see Chapter Learning From User).

 

 

7.1. Indefinite Integration

 

            Find the indefinite integrals of expr by

                        integrate(expr, x)

            Find the double indefinite integrals by

                        integrate(integrate(expr, x), y)

            Note that the arbitrary constant is not represented.

 

            Example:

            Find integrals of 1/a, 1/b and 1/x, knowing a >0, b is real.

 

IN:  assume(a>0), isreal(b):=1

IN:  integrate(1/a, a), integrate(1/b, b), integrate(1/x, x)

OUT: ln(a), ln(|b|), ln(x*sign(x))

 

            Example:

            Find indefinite integrals.

 

IN:  integrate(sin(a*x+b), x)        # integrands involving sin(x)

OUT: -cos(b + a x)/a

 

IN:  integrate( sin(x)/x^2, x)

OUT: ci(x) - sin(x)/x

 

IN:  integrate( x*sin(x), x)

OUT: -x cos(x) + sin(x)

 

IN:  integrate(sin(x)*cos(x), x)

OUT: (1/2)*sin(x)^2

 

IN:  integrate( e^(x^6), x)              # integrands involving e^x

OUT: 1/6 ei(-5/6, x^6)

 

IN:  integrate( x^2*e^x, x)

OUT: ei(2, x)

 

IN:  integrate( x*e^(-x), x)

OUT: -e^(-x) - x e^(-x)

 

IN:  integrate( e^x/sqrt(x), x)

OUT: ei(-0.5, x)

 

IN:  integrate(x^1.5*exp(x), x)

OUT: ei(1.5, x)

 

IN:  integrate(sin(x)*e^x, x)      # integrals involving sin(x) and e^x

OUT: 1/2 * (sin(x) - cos(x)) * e^x

 

IN:  integrate( x*ln(x), x)             # integrands involving ln(x)

OUT: -1/4 x^2 + 1/2 x^2 ln(x)

 

IN:  integrate( ln(x)^6, x)

OUT: li(6, x)

 

IN:  integrate( ln(x)/sqrt(x), x)

OUT: -4 sqrt(x) + 2 sqrt(x) ln(x)

 

IN:  integrate( ln(x)/sqrt(1 + x), x)

OUT: -4 sqrt(1 + x) + 2 sqrt(1 + x) ln(x) - 2 ln((-1 + sqrt(1 + x))/(1 + sqrt(1 + x)))

 

IN:  integrate( 1/(a x + b), x)                   # integrands involving polynomials

OUT: ln((b + a x) sign(b + a x))/a

 

IN:  integrate( x/(x^2 + 5 x + 6), x)

OUT: 1/2 ln(|6 + 5 x + x^2|) - 5/2 ln(|(2 + x)/(3 + x)|)

 

IN:  integrate( (x^3 + x)/(x^4 + 2 x^2 + 1), x)

OUT: 1/4 ln((1 + 2 x^2 + x^4) sign(1 + 2 x^2 + x^4))

 

            Example:

            Find the line integral.

 

IN:  x:=2*t

IN:  y:=3*t

IN:  z:=5*t

IN:  u:=x+y

IN:  v:=x-y

IN:  w:=x+y+z

IN:  integrate(u*d(u,t)+v*d(v,t)+w*d(w,t), t)

OUT: 63 t^2

 

            Example:

            Integrate x^2*e^x, then expand it by the mean of the packages "ExpandEi.sm" (expand ei(n,x)).  The packages "ExpandGa.sm" (expand gamma(n,x)) and "ExpandLi.sm" (expand li(n,x)) are similar one.

 

IN:  integrate(x^2*e^x, x)

OUT: ei(2,x)                                         # ei()

 

IN:  readfile("ExpandEi.sm")

IN:  ExpandEi(ei(2, x))

OUT: x^2 e^x - 2 x e^x + 2 e^x             # ei() is expanded

 

 

            Defining integrals is similar to defining rules.

            Example:

 

IN:  integrate(f(x_), x_) := sin(x)

IN:  integrate(f(t), t)

OUT: sin(t)

 

 

7.2. Definite Integration

 

            Find definite integrals by external functions

                        integrate(expr, x , xmin , xmax)

                        integrate(expr, x , xmin , singularity , xmax)

 

            Example:

            Find the definite integral of y=exp(1-x) with respect to x taken from 0 to infinity.

 

IN:  integrate(exp(1-x), x , 0 , inf)

OUT: e

 

            Example:

do discontinuous integration of 1/x^2 and 1/x^3 with discontinuity at x=0.

 

IN:  integrate(1/x^2, x , -1 , 2)               # singularity at x=0

OUT: inf

 

IN:  integrate(1/x^3, x , -1 , 1)               # singularity at x=0

OUT: 0

 

IN:  integrate(sqrt((x-1)^2), x , 0 , 2)      # singularity at x=1

OUT: 1

 

            SymbMath usually detect singularity, but sometime it cannot, in this case you must provide singularity.

 

            Example:

IN:  integrate(1/(x-1)^2, x , 0 , 1 , 2)      # provide singularity at x=1

OUT: inf

 

            Example:

            complex integration.

 

IN:  integrate(1/x, x , i , 2*i)

OUT: ln(2)

 

 

7.3.  Numeric Integration

 

            The external function

                        nint(y, x , xmin , xmax)

does numeric integration.

            Example:

Compare numeric and symbolic integrals of 4/(x^2+1) with respect to x taken from 0 to 1.

 

IN:  nint(4/(x^2+1), x , 0 , 1)

OUT: 3.1415

 

IN:  num(int(4/(x^2+1), x , 0 , 1))

OUT: 3.1416

 

 

8.    Solving Equations

8.1. Solving Algebraic Equations

 

            The equations can be operated (e.g. +, -, *, /, ^, expand(), d(), integrate()). The operation is done on both sides of the equation, as by hand. You can find roots of a polynomial, algebraic equations, systems of equations, differential and integral equations.

            You can get the left side of the equation by

                        left(left_side = right_side)

or get the right side by

                        right(left_side = right_side)

            You can assign equations to variables.

 

            Example:

 

IN:  eq1:= x + y = 3

IN:  eq2:= x - y = 1

IN:  eq1+eq2

OUT: 2 x = 4

 

IN:  last/2

OUT: x = 2

 

IN:  eq1-eq2

OUT: 2 y = 2

 

IN:  last/2

OUT: y = 1

 

            Example:

            Solve an equation sqrt(x+2*k) - sqrt(x-k) = sqrt(k), then check the solution by substituting the root into the equation.

 

IN:  eq1 := sqrt(x + 2*k) - sqrt(x - k) = sqrt(k)

OUT: eq1 := sqrt(x + 2*k) - sqrt(x - k) = sqrt(k)

 

IN:  eq1^2

OUT: ((2*k + x)^0.5 - ((-k) + x)^0.5)^2 = k

 

IN:  expand(last)

OUT: 2*x + k + (-2)*(2*k + x)^0.5*((-k) + x)^0.5 = k

 

IN:  last-k-2*x

OUT: (-2)*(2*k + x)^0.5*((-k) + x)^0.5 = (-2)*x

 

IN:  last/(-2)

OUT: (2*k + x)^0.5*((-k) + x)^0.5 = x

 

IN:  last^2

OUT: (2*k + x)*((-k) + x) = x^2

 

IN:  expand(last)

OUT: (-2)*k^2 + k*x + x^2 = x^2

 

IN:  last-x^2+2*k^2

OUT: k*x = 2*k^2

 

IN:  last/k

OUT: x = 2*k

 

IN:  subs(eq1, x = right(last))

OUT: k^0.5 = k^0.5

 

            You can solve algebraic equations step by step, as above. This method is useful in teaching, e.g. showing students how to solve equations.

 

 

8.2.  Equation Solver: solve()

 

            The solve() functions

 

                        solve(expr1 = expr2, x)

                        solve([expr1 = expr2, expr3 = expr4], [x, y])

 

solve a polynomial and systems of linear equations on one step. It is recommended to set the switch expand:=on when solve the complicated equations. All of the real and complex roots of the equation will be found by solve(). The function solve() outputs a list of roots when there are multi-roots. You can get one of roots from the list, (see Chapter 4.9 Arrays, Lists, Vectors and Matrices).

 

            Example:

            Solve a+b*x+x^2 = 0 for x, save the root to x.

 

IN:  solve(a+b*x+x^2 = 0, x)      # solve or re-arrange the equation for x

OUT: x = [-b/2 + sqrt((b/2)^2 - a),  -b/2 - sqrt((b/2)^2 - a)]

 

IN:  x := right(last)                                # assign two roots to x

OUT: x := [-b/2 + sqrt((b/2)^2 - a),  -b/2 - sqrt((b/2)^2 - a)]

 

IN:  x[1]                                                # the first root

OUT: -b/2 + sqrt((b/2)^2 - a)

IN:  x[2]                                                # the second root

OUT: -b/2 - sqrt((b/2)^2 - a)

 

            Example:

            Solve x^3 + x^2 + x + 5 = 2*x + 6.

 

IN:  num(solve(x^3+x^2+x+5 = 2*x+6, x))

OUT: x = [1, -1, -1]

 

            The function solve() not only solves for a simple variable x but also solves for an unknown function, e.g. ln(x).

 

            Example:

            Solve the equation for ln(x).

 

IN:  solve(ln(x)^2+5*ln(x) = -6, ln(x))

OUT: ln(x) = [-2, -3]

 

IN:  exp(last)

OUT: x = [exp(-2), exp(-3)]

 

            Example:

            Rearrange the equations.

 

IN:  eq := [x+y = 3+a+b, x-y = 1+a-b]                # assign equations to eq

IN:  solve(eq, [x,y])                                           # rearrange eq for x and y

OUT: [x = -1/2*(-4 - 2 a), y = -1/2*(-2 - 2 b)]

 

IN:  solve(eq, [a,b])                                           # rearrange eq for a and b

OUT: [a = -1/2*(4 - 2 x), b = -1/2*(2 - 2 y)]

 

IN:  solve(eq, [a,y])                                           # rearrange eq for a and y

OUT: [b = -1/2*(2 - 2 y), x = -1/2*(-4 - 2 a)]

 

IN:  solve(eq, [x,b])                                           # rearrange eq for x and b

OUT: [a = 1/2*(-4 + 2 x), y = 1/2*(2 + 2 b)]

 

 

8.3.  Polynomial Solver: psolve()

 

            The external function

                        psolve(f(x), x)

solves f(x)=0 for x. It is similar to solve(), but it only can solve polynomial with order < 3.

 

            e.g.

IN:  psolve(x^2+5*x+6, x)

OUT: [-2, -3]

 

 

8.4.  Numeric Solver: nsolve()

 

            The external functions

                        nsolve(f(x) = x, x)

                        nsolve(f(x) = x, x,x0)

numerically solves an algebraic equation with an initial value x0. By default x0=1. nsolve() only gives one solution near x0, omitting other solutions.

 

            Example:

IN:  nsolve( cos(x) = x, x)

OUT: x = 0.73911289091

 

IN:  nsolve( sin(x) = 0, x,0)                   # similar to asin( sin(x)=0 )

OUT: x = 0                                           # only gives one solution near x0=0

 

IN:  nsolve( sin(x) = 0, x,3)

OUT: x = 3.14                                       # only gives one solution near x0=3

 

 

8.5.  Solving Differential Equations

 

            You can solve the differential equations:

                        y' = f(x)

by integrating the equation.

            y'  is the same as d(y(x),x).

           

            Example:

            solve y'=sin(x) by integration.

IN:  integrate( y' = sin(x), x)

OUT: y(x) = constant - cos(x)

 

 

8.6.  Differential Solver: dsolve()

 

            The external function

                        dsolve(y'(x) = f(x,y), y(x), x)

can solve the first order variables separable and linear differential equations

                        y'(x) = h(x)

                        y'(x) = f(y(x))

                        y'(x) = f(y(x))*x

                        y'(x) = g(x)*y(x)

                        y'(x) = g(x)*y(x)+h(x)

on one step. Notice that y'(x) must be alone on the left hand side of the equation. It is recommended to set the switch expand:=on when solving the complicated differential equations.

 

            Example:

            Solve y'(x) = sin(x) by dsolve().

IN:  dsolve( y'(x) = sin(x), y(x), x)

OUT: y(x) = constant - cos(x)

 

            Example:

            Solve differential equations by dsolve(). If the result is a polynomial, then rearrange the equation by solve().

 

IN:  dsolve(y'(x) = x/(2+y(x)), y(x), x)

OUT: 2*y(x) + 1/2*y(x)^2 = constant + x^2

 

IN:  solve(last, y(x))

OUT: y(x) = [-2 + sqrt(4 - 2*(-constant - x^2)),

                 -2 - sqrt(4 - 2*(-constant - x^2))]

 

            Example:

            Solve differential equations by dsolve().

 

IN:  dsolve(y'(x) = x*exp(y(x)), y(x), x)

OUT: -e^(-y(x)) = constant + x^2

 

IN:  dsolve(y'(x) = y(x)^2+5*y(x)+6, y(x), x)

OUT: ln((4 + 2 y(x))/(6 + 2 y(x))) = constant + x

 

IN:  dsolve(y'(x) = y(x)/x, y(x), x)

OUT: y(x) = constant x sign(x)

 

IN:  dsolve(y'(x) = x + y(x), y(x), x)

OUT: y(x) = -1 - x + constant*e^x

 

 

9.  Sums, Products, and Series

 

            You can compute partial, finite or infinite sums and products. Sums and products can be differentiated and integrated. You construct functions like Taylor polynomials or finite Fourier series. The procedure is the same for sums as products so all examples will be restricted to sums.  The general formats for these functions are:

                        sum(y,x)

                        sum(y)

                        sum(expr, x , xmin , xmax)

                        sum(expr, x , xmin , xmax , dx)

 

                        prod(expr, x , xmin , xmax)

                        prod(expr, x , xmin , xmax , dx)

            The expression expr is evaluated at xmin, xmin+dx, ...  up to the last entry in the series not greater than xmax, and the resulting values are added or multiplied.  The part "step dx" is optional and defaults to 1.  The values of xmin, xmax and dx can be any real number.

            Here are some examples:

             sum(j, j , 1 , 10,1)  

for 1 + 2 + .. + 10.

            sum(3^j, j , 0 , 10 , 2) 

for 1 + 3^2 + ... + 3^10.

            Here are some sample Taylor polynomials:

            sum(x^j/j!, j , 0 , n) 

for exp(x).

            sum((-1)^j*x^(2*j+1)/(2*j+1)!, j , 0 , n)

for sin(x) of degree 2*n+2.

            Remember, the 3 keywords (from, to and step) can be replaced by the comma ,.

 

 

9.1.  Partial Sum

 

            The function

                        sum(f(x),x, a,b)

finds the partial sum (symbolic sum).

 

            Example:

Find the sum of 1^2 + 2^2 ... + n^2.      

 

IN:  sum(x^2, x, 0,n)

OUT: 1/6 *n*(1 + n) *(1 + 2* n)

 

 

9.2.  Indefinite Sum

 

            The function

                        sum(f(x), x) 

finds the indefinite sum, i.e. inverse of the difference F(x+1)-F(x).

 

            Example:

IN:  sum(x)

OUT:  x^2/2-x/2

 

This is different from the partial sum(x,x,0,n).

9.3.  Series

 

            The external functions

                        series(f(x), x)

                        series(f(x), x, order)

to find the Taylor series at x=0. The argument (order) is optional and defaults to 5.

           

            Example:

            Find the power series expansion for cos(x) at x=0.

 

IN:  series(cos(x), x)

OUT: 1 - 1/2 x^2 + 1/24 x^4

 

            The series expansion of f(x) is useful for numeric calculation of f(x). If you can provide derivative of any function of f(x) and f(0), even though f(x) is unknown, you may be able to calculate the function value at any x, by series expansion. Accuracy of calculation depends on the order of series expansion. Higher order, more accuracy, but longer calculation time.

           

            Example:

            calculate f(1), knowing f’=-sin(x) and f(0)=1, where f(x) is unknown.

 

IN:  f'(x_) := -sin(x)

IN:  f(0) := 1

IN:  f(x_) := eval(series(f(x), x))            #  must eval()

OUT: f(x_) := 1 - 1/2 x^2 + 1/24 x^4

 

IN:  f(1)

OUT: 13/24

 

 

9.4.  Polynomials

 

            Polynomials are automatically sorted in order from low to high.

            You can pick up one of coefficient of x in polynomials by

                        coef(poly, x^n)

            e.g.

IN:  coef(x^2+5*x+6, x)

OUT: 5

 

            Note that you cannot pick up the coefficient of x^0 by coef(y,x^0).

            You can pick up one of coefficient of x in polynomials with order < 5 by

                        coef(poly, x,n)

 

            e.g.

IN:  coef(x^2+5*x+6, x,0)

OUT: 6

 

            You can pick up all of coefficients of x in polynomials with order < 5 by

                        coefall(poly, x)

 

            e.g.

IN:  coefall(x^2+5*x+6, x)

OUT: [6, 5, 1]                    # 6 + 5*x + x^2

 

IN:  coefall(a*x^2+b*x+c, x)

OUT: [c, b, a]                    # symbolic values of coefficients

 

            You can pick up the highest order of x in polynomials with order < 5 by

                        order(poly, x)

 

            e.g.

IN:  order(x^2+5*x+6, x)

OUT: 2

 

            You can factor polynomials in order < 5 with respect to x by

                        factor(poly, x)

 

            e.g.

IN:  factor(x^2+5*x+6, x)

OUT: (2 + x) (3 + x)

 

10. Lists and Arrays, Vectors and Matrices

 

            You can construct lists and arrays of arbitrary length, and the entries in the lists and arrays can be of any type of value whatsoever: constants, expressions with undefined variables, or equations.

            A vector or matrix can be represented by a list or array. In a matrix, the number of elements in each row should be the same, e.g. [[a11, a12], [a21, a22]].

 

 

10.1.    Lists

10.1.1.  Entering Lists

 

            You can define a list by putting its elements between two square brackets. e.g. [1,2,3]

            You can define lists another way, with the command:

                        [ list(f(x), x from xmin to xmax step dx) ]

            This is similar to the sum command,  but the result is a list:

                        [f(xmin), f(xmin+dx), ..., f(xmin+x*dx), ...]

which continues until the last value of xmin + x*dx  <= xmax. 

            You also can assign the list to a variable, which variable name become the list name:

 

                        a := [1,2,3]                 # define the list of a

                        b := [f(2), g(1), h(1)]      # assumes f,g,h defined

                        c := [[1,2],3,[4,5]]         # define the list of c

 

            Lists are another kind of value in SymbMath, and they can be assigned to variables just like simple values. (Since variables in SymbMath language are untyped, you can assign any value to any variable.).

            A function can have a list for its value:

                        f(x_) := [sqrt(x), -sqrt(x)]

 

            e.g.

IN:  squreroot(x_) := [sqrt(x), -sqrt(x)]

IN:  squreroot(4)

OUT: [2, -2]

 

            A function can have a list for its argument:

                        abs([-1,2])

            Try

                        a := [ list(j^2, j from 0 to 10 step 1) ]

                        f(x_) := [ list(x^j, j from 0 to 6 step 1) ]

                        b := f(-2)

 

 

10.1.2.     Accessing Lists

 

            You can find the value of the j-th member in a list by

                        member([a,b], j)

The first member of a list is always member(x, 1).

           If you have assigned a list to a variable x, you can access the j-th element by the list index x[j]. The first element of x is always  x[1].  If the x[j] itself is a list, then its j-th element is accessed by repeating the similar step.But you can not use the list index unless the list is already assigned to x.

 

            e.g.

IN:  x := [[1,2],3,[4,5]]    # define the x list

IN:  x[1], x[2]                            # take its first and 2nd element

OUT: [1, 2], 3

 

IN:  x                                        # access the entire list of x

OUT: [[1, 2], 3, [4,5]]

 

IN:  member(x, 2)                     # same as x[2]

OUT: 3

 

            An entire sub-list of a list x  can be accessed with the command x[j], which is the list:

                          [x[j], x[j+1], ... ]

 

 

10.1.3.     Modifying Lists

 

            The subs() replaces the value of the element in the list, as in the variables. e.g.

 

IN:  subs([a,b,c], a = a0)

OUT: [a0, b, c]

 

            Note that you cannot modify lists by assignment.

 

 

10.1.4.     Operating Lists

 

            Lists can be added, subtracted, multiplied, and divided by other lists or by constants.  When two lists are combined, they are combined term-by-term, and the combination stops when the shortest list is exhausted.  When a scalar is combined with a list, it is combined with each element of the list.  Try:

 

            a := [1,2,3]

            b := [4,5,6]

            a + b

            a / b

            3 * a

            b - 4

 

            Example 4.9.2.4.1.

            Two lists are added.

 

IN:  [a1,a2,a3] + [b1,b2,b3]

OUT: [a1 + b1, a2 + b2, a3 + b3]

 

IN:  last[1]

OUT: a1 + b1

 

            If L is a list, then  f(L) results in a list of the values, even though f() is the differentiation or integration function (d() or integrate()).

 

IN:  sqrt([a, b, c])

OUT: [sqrt(a), sqrt(b), sqrt(c)]

 

IN:  d([x, x^2, x^3], x)

OUT: [1, 2*x, 3*x^2]

 

            If you use a list as the value of a variable in a function, SymbMath will try to use the list in the calculation.

            You can sum all the elements in a list x by

                        listsum(x)

            Example:

 

IN:  listsum([a,b,c]^2)

OUT: a^2 + b^2 + c^2

 

            This function takes the sum of the squares of all the elements in the list x.

            You can do other statistical operations (see Section 4.10. Statistics) on the list, or plot the list of numeric data (see Section 5. Plot).

            You can find the length of a list (the number of elements in a list) with:

                        length(a)


10.2.    Arrays

10.2.1.  Entering Arrays

 

            You can define an array of a by assigning its element value into its index:

            a[1]:=1

            a[2]:=4

or you can define arrays another way, with the command:

                        do(a[x]:=f(x), x from xmin to xmax step dx)

 

            e.g.

            do(a[j] := 2*j, j from 1 to 2)

            You can define 2-dimentional array by

                        a[1,1]:=11

                        a[1,2]:=12

                        a[2,1]:=21

                        a[2,2]:=22

or

            do(do(a[j,k]:=j+k, j,jmin,jmax,dj), k,kmin,kmax,dk)

 

 

10.2.2.  Accessing Arrays

 

            After defining an array of a, you can access one of its element by its index

 

IN:  a[1]

OUT: 1

 

            You also can list out all of its elements by

                        list(a[j], j,1,2,1)

 

            e.g.

IN:  do(a[j]:=2*j, j,1,2,1)

IN:  list(a[j], j,1,2)

OUT: 1, 4

 

 

10.2.3.  Modifying Arrays

 

            You can modify an array by assigning new value into its index

 

IN:  a[1]:=2

 

 

10.2.4.  Operating Arrays

 

            e.g.

            after defining 2 arrays a and b, find their dot time, a .* b.

IN:  a[1]:=1, a[2]:=2                 # define array a

IN:  b[1]:=11, b[2]:=12               # define array b

IN:  p:=0

IN:  do(p:=p + a[j]*b[j], j,1,2,1)    # a .* b

 

 

10.3.     Vectors and Matrices

 

            You can uses arrays or lists to represent vectors, and lists of lists to represent matrices.

            Vectors and matrices can be operated by "+" and "-" with vectors and matrixes, by "*" and "/" with a scalar, and by d() and integrate(). These operations are on each element, as in lists.

            You can use lists as vectors, adding them and multiplying them by scalars. For example, the dot product of two vectors of a and b is:

                        sum(a[j]*b[j], j from 1 to jmax)

            You can even make this into a function:

                        dottime(x_, y_) := listsum(x*y)

 

            e.g.

            represent the dot product of two vectors by arrays

IN:  a[1]:=1, a[2]:=2                   # define array a

IN:  b[1]:=11, b[2]:=12               # define array b

IN:  p:=0

IN:  do(p:=p + a[j]*b[j], j,1,2,1)    # a .* b

 

            represent the dot product of two vectors by lists

IN:  dottime([1,2], [11,12])          # by lists in function dottime()

 

            How about the cross product:

cross(a,b) = [a[2]*b[3]-b[2]*a[3],a[3]*b[1]-b[3]*a[1],a[1]*b[2]-b[1]*a[2]]

 

 

11.    Statistics

 

            Some statistical functions are:

                        average(x), max(x), min(x), listsum(x), length(x)

 

            A list of numbers can be calculation on statistics.

           

            Example:

IN:  p := [1, 2, 3]

IN:  average(p), max(p), min(p), length(p)

OUT: 2, 3, 1, 3

 

            Not only a list of number but also a list of symbolic data can be operated by some statistic functions to show how to do the statistic operation.

 

IN:  p := [a, b, c]

IN:  average(p)

OUT: 1/3*(a + b + c)

 

IN:  listsum(p)

OUT: a + b + c

 

IN:  length(p)

OUT: 3

 

 

12.     Tables of Function Values

 

            If you want to look at a table of values for a formula, you can use the table command:

                        table(f(x), x)

                        table(f(x), x from xmin to xmax)

                        table(f(x), x from xmin to xmax step dx)

            It causes a table of values for f(x) to be displayed with x=xmin, xmin+dx, ..., xmax.  If xmin, xmax, and step omit, then xmin=-5, xmax=5, and dx=1 for default. You can specify a function to be in table(),

 

            Example:

Make a table of x^2.

 

IN:  table(x^2, x)

OUT:

-5,        25

-4,        16

-3,        9

-2,        4

:           :

:           :

 

            Its output can be written into a disk file for interfacing with other software (e.g. the numeric computation software).

 

 

13.   Conversion

 

            Different types of data may be converted each other.

 

 

13.1.  Converting to Numbers

 

            The complex number is converted to the real number by

                        re(z), im(z), abs(z), arg(z), sign(z)

            The real number is converted to the integer number by

                        trunc(x)

                        round(x)

            The real number is converted to the rational number by

                        ratio(x)

            The rational number is converted to the real number by

                        num(x)

                        numeric:=on

            The rational number is converted to the integer number by

                        nume(x)

                        deno(x)    

            The string is converted to the real number if possible, by

                        number("123")

 

 

13.2.  Converting to Lists

 

            You can convert sum to a list of terms by

                        term(a+b)

 

IN:  term(a+b)

OUT: [a, b]

 

            You can convert product to a list of multipliers by

                        mult(a*b)

 

IN:  mult(a*b)

OUT: [a, b]

 

            You can convert an array x to a list by

                        [ list(x[j], j,1,jmax,1) ]

 

 

13.3.  Converting to Strings

 

            You can convert numbers to strings by

                        string(123)

 

IN:  string(123)

OUT: "123"

 

 

13.4.  Converting to Table

 

            A list of real numbers can be converted to a table by

                        table()

           

            Example:

 

IN:  x := [5,4,3,2,1]

IN:  table(x[j], j from 1 to 4 step 1)

OUT:

1,      5

2,      4

3,      3

4,      2

 

 

14.    Getting Parts of Expression

14.1.  Getting Type of Data

 

            You can get type of data by

                        type(x)

 

IN:  type(2)

OUT: "integer"

 

 

14.2.  Getting Operators

 

            You also can get operators by

                        type(x)

 

IN:  type(a>b)

OUT: ">"

 

IN:  type(sin(x))

OUT: "sin()"

 

 

14.3.  Getting Operands

 

            The functions

                        left(x=a), left(a > b)

                        right(x=a), right(a > b)

pick up the left- and right- side of the equation and inequality.

 

IN:  left(a>b), right(a>b)

OUT: a, b

 

            You can get the j-th term of sum by

                        member(term(a+b), j)

 

IN:  member(term(a+b), 1)

OUT: a

 

            You can get the arguments of a function by

                        argue(f(x))

 

IN:  argue(sin(x))

OUT: x

 

 

14.4.  Getting Coefficients

 

            A coefficient of x^n in an expression can be picked up by

                        coef(p, x^n)

 

            e.g.

IN:  coef(a + b*x + c*x^2 + d*x^3, x)

OUT: b

 

            You can get a coefficient of x^n (where 0<= n < 4) in polynomials ordered up to 4 by

                        coef(poly, x,n)

(see Chapter Polynomials for detail).

 

                       

15.    Database

 

            After you create a database file as a library (external function), you can search your data by finding its function value.

 

 

15.1.  Phone Number

 

            If you have created the database file "phoneNo" as follow:

 

-------------------------------------

phoneno("huang") := "6974643"

phoneno("john")  := "12345"

--------------------------------------

 

            You can find out phone No. of someone from the phone No. database file "phoneNo" by the external function

                        phoneno("name")

 

            Example:

            find out phone No. of huang.

IN:  phoneno("huang")

OUT: 6974643

 

 

15.2.  Atomic Weight

 

            You can search atomic weight of chemical element from the database file "atom_wei".

            e.g.

            What is atomic weight of chemical element H ?

IN:  atom_wei(H)

OUT: 1

 

 

15.3.  Chemical Reaction

 

            You can predict products for chemical reactions from the database file "react".

 

            Example 4.14.2. 

            What are the products when HCl + NaOH react ?

IN:  react(HCl+NaOH)

OUT: H2O + NaCl

 

 

16.  Learning from User

 

            One of the most important feature of SymbMath is its ability to deduce and expand its knowledge. If you provide it with the necessary facts, SymbMath can solve many problems which were unable to be solved before. The followings are several ways in which SymbMath is able to learn from your input.

 

 

16.1.  Learning Integrals from a Derivative

 

            Finding derivatives is much easier than finding integrals. Therefore, you can find the integrals of a function from the derivative of that function.

            If you provide the derivative of a known or unknown function, SymbMath can deduce the indefinite and definite integrals of that function. If the function is not a simple function, you only need to provide the derivative of its simple function. For example, you want to evaluate the integral of f(a*x+b), you only need to provide f’.

 

            If you know a derivative of an function f(x) (where f(x) is a known or unknown function), SymbMath can learn the integrals of that function from its derivative.

 

            Example:

            check SymbMath whether or not it had already known integral of f(x)

IN:  integrate(f(x), x)

OUT: integrate(f(x), x)

 

IN:  integrate(f(x), x, 1, 2)

OUT: integrate(f(x), x, 1, 2)

 

            As the output displayed only what was typed in the input without any computed results, imply that SymbMath has no knowledge of the indefinite and definite integrals of the functions in question. Now you teach SymbMath the derivative of f(x) on the first line, and then run the program again.

 

IN:  f'(x_) := exp(x)/x

IN:  integrate(f(x), x)

OUT: x*f(x) - e^x

 

IN:  integrate(f(x), x, 1, 2)

OUT: e - f(1) + 2*f(2) - e^2

 

            As demonstrated, you only supplied the derivative of the function, and in exchange SymbMath logically deduced its integral.

            Another example is

 

IN:  f'(x_) := 1/sqrt(1-x^2)

IN:  integrate(f(x), x)

OUT: sqrt(1 - x^2) + x*f(x)

 

IN:  integrate(k*f(a*x+b), x)

OUT: k*(sqrt(1 - (b + a*x)^2) + (b + a*x)*f(b + a*x))/a

 

IN:  integrate(x*f(a*x^2+b), x)

OUT: sqrt(1-(a*x^2 + b)^2) + (a*x^2 + b)*f(a*x^2 + b)

 

            The derivative of the function that you supplied can be another derivative or integral.

 

            Example:

 

IN:  f'(x_) := eval(integrate(cos(x),x))

OUT: f'(x_) := sin(x)

 

IN:  integrate(f(x), x)

OUT: -sin(x)

 

IN:  integrate(f(a*x + b), x)

OUT: -sin(b + a*x)/a

 

IN:  integrate(x*f(x), x)

OUT: -cos(x) - x*sin(x)

 

IN:  integrate(x^1.5*f(x), x)

OUT: 1.5*integrate(sqrt(x)*sin(x), x) - x^1.5*sin(x)

 

IN:  integrate(x^2*f(x), x)

OUT: -2*x*cos(x) + 2*sin(x) - x^2*sin(x)

 

IN:  integrate(x*f(x^2), x)

OUT: -sin(x^2)

 

IN:  integrate(x^3*f(x^2), x)

OUT: -0.5*cos(x^2) - 0.5*x^2*sin(x^2)

 

IN:  integrate(f(x)/(x^1.5), x)

OUT: -2/sqrt(x)*f(x) + 2*integrate(sin(x)/sqrt(x), x)

 

IN:  integrate(f(x)/(x^2), x)

OUT: -f(x)/x + si(x)

 

 

16.2.  Learning Complicated Integrals from a Simple Integral

 

            You supply a simple indefinite integral, and in return, SymbMath will perform the related complicated integrals.

 

            Example:

            Check whether SymbMath has already known the following integrals or not.

 

IN:  integrate(f(x), x)

OUT: integrate(f(x), x)

 

IN:  integrate((2*f(x)+x), x)

OUT: integrate((2*f(x)+x), x)

 

IN:  integrate(integrate(f(x)+y), x), y)

OUT: integrate(integrate(f(x)+y), x), y)

 

            Supply, like in the previous examples, the information: integral of f(x) is f(x) - x; then ask the indefinite integral of 2*f(x)+x, and a double indefinite integral of 2*f(x) + x, and a double indefinite integral of respect to both x and y. Change the first line, and then run the program again.

 

IN:  integrate(f(x_), x_) := f(x) - x

IN:  integrate(2*f(x)+x, x)

OUT: 2*f(x) - 2*x + 1/2*x^2

 

IN:  integrate(integrate(f(x)+y, x), y)

OUT: f(x)*y - x*y + x*y^2

 

            You can also ask SymbMath to perform the following integrals:

integrate(integrate(f(x)+y^2, x), y),

integrate(integrate(f(x)*y, x), y),

integrate(x*f(x), x),

triple integral of f(x)-y+z, or others.

 

 

16.3.  Learning Definite Integral from Indefinite Integral

 

            You continue to ask indefinite integral.

 

IN:  integrate(integrate(f(x)+y, x from 0 to 1), y from 0 to 2)

OUT: 2 f(1)

 

 

16.4. Learning Complicated Derivatives from Simple Derivative

 

            SymbMath can learn complicated derivatives from a simple derivative, even though the function to be differentiated is an unknown function, instead of standard function.

 

            Example :

            Differentiate f(x^2)^6, where f(x) is an unknown function.

 

IN:  d(f(x^2)^6, x)

OUT: 12 x f(x^2)^5 f'(x^2)

 

            Output is only the part derivative. f'(x^2) in the output suggest that you should teach SymbMath f'(x_). e.g. the derivative of f(x) is another unknown function df(x), i.e. f'(x_) = df(x), assign f'(x_) with df(x) and run it again.

 

IN:  f'(x_) := df(x)

IN:  d(f(x^2)^6, x)

OUT: 12 x f(x^2)^5 df(x^2)

 

            This time you get the complete derivative.

 

           

16.5.  Learning Integration from Algebra

 

            If you show SymbMath algebra, SymbMath can learn integrals from that algebra.

 

            Example :

            Input f(x)^2=1/2-1/2*cos(2*x), then ask for the integral of f(x)^2.

 

IN:  f(x)^2 := 1/2-1/2*cos(2*x)

IN:  integrate(f(x)^2, x)

OUT: 1/2 x - 1/4 sin(2 x)

 

            SymbMath is very flexible. It learned to solve these problems, even though the types of problems are different, e.g. learning integrals from derivatives or algebra.

 

 

16.6.  Learning Complicated Algebra from Simple Algebra

 

            SymbMath has the ability to learn complicated algebra from simple algebra.

 

            Example:

            Transform sin(x)/cos(x) into tan(x) in an expression.

 

IN:  sin(x)/cos(x) := tan(x)

IN:  x+sin(x)/cos(x)+a

OUT: a + x + tan(x)

 

 

16.7.  Learning vs. Programming

 

            The difference between learning and programming is as follows: the learning process of SymbMath is very similar to the way human beings learn, and that is accomplished by knowing certain rule that can be applied to several problems. Programming is different in the way that the programmer have to accomplish many tasks before he can begin to solve a problem. First, the programmer defines many subroutines for the individual integrands (e.g. f(x), f(x)+y^2, 2*f(x)+x, x*f(x), etc.), and for individual integrals (e.g. the indefinite integral, definite integral, the indefinite double integrals, indefinite triple integrals, definite double integrals, definite triple integrals, etc.), second, write many lines of program for the individual subroutines, (i.e. to tell the computer how to calculate these integrals), third, load these subroutines, finally, call these subroutines. That is precisely what SymbMath do not ask you to do.

            In one word, programming means that programmers must provide step-by-step procedures telling the computer how to solve each problems. By contrast, learning means that you need only supply the necessary facts (usually one f’ and/or one integral of f(x)), SymbMath will determine how to go about solutions of many problems.

            If the learning is saved as a library, then you do not need to teach SymbMath again when you run SymbMath next time.

 

 


PART 2    Programmer's Guide

 

17.  Programming in SymbMath

 

            SymbMath is an interpreter, and runs a SymbMath program in the Input window, which is written by any editor in the text (ASCII) file format.

            SymbMath language is a procedure language, which is executed from top to bottom in a program, like BASIC, FORTRAN, or PACSAL. It also is an expression-oriented language and functional language.

            The SymbMath program consists of a number of statements. The most useful statement contains expressions, the expression includes data, and the most important data is functions.

            The structure of SymbMath language is:

                        data -> expression -> statement -> program

            Note that upper and lower case letters are different in SymbMath language, (e.g. abc is different from ABC) until the switch lowercase := on.

            In the following examples, a line of "IN: " means input, which you type in the Input window, then leave the Input window by <Esc>, finally run the program by the command "Run"; while a line of "OUT:" means output. You will see both input and output are displayed on two lines with beginning of "IN: " and "OUT: " in the Output window. You should not type the word "IN: ". Some outputs may be omit on the examples.

# is a comment statement.

            You can split a line of command into multi-lines of command by the comma ,. The comma without any blank space must be the last character in the line.

 

 

17.1.  Data Types

 

            The data types in SymbMath language is the numbers, constants, variables, functions, equations, arrays, array index, lists, list index, and strings. All data can be operated. It is not necessary to declare data to be which type, as SymbMath can recognise it.

 

 

17.1.1.  Numbers

 

            The types of numbers are integer, rational, real (floating-point), and complex numbers in the range from -infinity to infinity.

            In fact, the range of the input real numbers is

-inf, -(10^300)^(10^300) to -10^(-300), 0, 10^(-300) to (10^300)^(10^300), inf.

            The range of the output real numbers is the same as input when the switch numeric := off, but when the switch numeric := on, it is

            -inf, -1.E300 to -1.E-300, 0, 1.E-300 to 1.E300, inf.

            It means that the number larger than 1.e300 is converted automatically to inf, the absolute values of the number less than 1.e-300 is converted to 0, and the number less than -1e300 is converted to -inf.

 

 

            For examples:

-------------------------------------------

Numbers          Type

 

23                    integer

2/3                   rational

0.23                  real

2.3E2               real

2+3*i                complex

2.3+i                 complex

---------------------------------------------

 

            That "a" and "b" are the same means a-b = 0, while that they are different means a-b <> 0.

            For the real numbers, the upper and lower case letters E and e in exponent are the same, e.g. 1e2 is the same as 1E2.

 

 

17.1.2.  Constants

 

            The constants are the unchangeable values. There are some built-in constants. The name of these built-in constants should be avoided in the user-defined constants.

 

------------------------------------------------------------------

Built-in Constants                     Meanings

 

pi:=3.1415926536                      the circular constant.

e:=2.7182818285                      the base of the natural logarithms.

i:=sqrt(-1)                                 the imaginary sign of complex numbers.

inf                                            infinity.

-inf                                           negative infinity.

c_inf                                         complex infinity, both real and imaginary parts

                                                of complex numbers are infinity. e.g. inf+inf*i.

constant                                   the integral constant.

discont                                     discontinuity, e.g. 1/0. (You can evaluate the one-sided value                                         by x=x0+zero or x0-zero if the value of expression is discont).

x0-zero                                     to evaluate left-sided value when x approach x0

                                                from negative (-inf) direction, as zero -> 0.

x0+zero                                    to evaluate right-sided value when x approach x0

                                                from positive (+inf) direction, as zero -> 0.

undefined                                  the undefined value, e.g. indeterminate forms:

                                                0/0, inf/inf, 0*inf, 0^0, etc.

--------------------------------------------------------------------

 

            Zero is the positive-directed 0, as the built-in constant. f(x0+zero) is the right-hand sided function value when x approaches to x0 from the positive direction, i.e. x = x0+. f(x0-zero) is the left-sided function value when x approaches to x0 from the negative direction, i.e. x = x0-. e.g. f(1+zero) is the right-hand sided function value when x approaches to 1 from the positive (+infinity) direction, i.e. x = 1+, f(1-zero) is the left-hand sided function value when x approaches to 1 from the negative (-infinity) direction, i.e. x = 1-; exp(1/(0+zero)) gives inf, exp(1/(0-zero)) gives 0.

            The inf, discont and undefined can be computed as if numbers.

 

            Example:

IN:  inf+2, discont+2, undefined+2

OUT: inf, discont, undefined

 

            Notice that the discont and undefined constants are different. If the value of an expression at x=x0 is discont, the expression only has the one-sided value at x=x0 and this one-sided value is evaluated by x=x0+zero or x=x0-zero. If the value of an expression at x=x0 is undefined, the expression may be evaluated by the function lim().

 

            Example: evaluate exp(1/x) and sin(x)/x at x=0.

 

IN:  f(x_) := exp(1/x)

OUT: f(x_) := exp(1/x)

 

IN:  f(0)

OUT: discont           # f(0) is discontinuity, only has one sided value

 

IN:  f(0+zero)          # right-sided value

OUT: inf

 

IN:  f(0-zero)          # left-sided value

OUT: 0

 

IN:  subs(sin(x)/x, x = 0)

OUT: undefined

 

IN:  lim(sin(x)/x, x = 0)              # it is evaluated by lim()

OUT: 1

 

 

17.1.3.  Variables

 

            The sequence of characters is used as the name of variables. Variable names can be up to 128 characters long. They must begin with a letter and use only letters and digits.  SymbMath knows upper and lower case distinctions in variable names, so AB, ab, Ab and aB are the different variables. They are case sensitive until the switch lowercase is set to on (i.e. lowercase := on).

            Variables can be used to store the results of calculations. Once a variable is defined, it can be used in another formula. Having defined X as above, you could define Y := ASIN(X). You can also redefine a variable by storing a new value in it.  If you do this, you will lose the original value entirely.

            Assign a result to a variable, just put

            <var-name> :=  expression

            e.g.               x := 2 + 3      # assign value to x

            Variables can be used like constants in expressions.

            For example:

                               a := 2 + 3

                               b := a*4

            If an undefined variable is used in an expression, then the expression returns a symbolic result (which may be stored in another variable).  Pick an undefined variable name, say x, and enter:

 

                        y := 3 + x          # formula results since x undefined

                        x := 4               # Now x is defined

                        y                      # y returns 7, but its value is still the formula 3 + x

                        x := 7               # revalue x

                        y                      # new value for y

 

            Note that in symbolic computation, the variable has not only a numeric value but also a symbolic value.

            Symbolic values for variables are useful mostly for viewing the definitions of functions and symbolic differentiation and integration.

            Watch out for infinite recursion here.  Defining

                        x := x+3

when x has no initial value, it will not cause an immediate problem, but any future reference to x  will result in an infinite recursion !

            A value can be assigned to the variable, by one of three methods:

            (1) the assignment :=,

            (2) the user-defined function f(),

            (3) subs(y, x = x0).

 

e.g.

y:=x^2

x:=2                             # assignment

y

f(2)                               # if f(x) has been defined, e.g. f(x_):=x^2.

subs(x^2, x = 2)                        # evaluate x^2 when x = 2.

 

            The variable named last is the built-in as the variable last is always automatically assigned the value of the last output result.

            The usual used independent variable is x.

            By default, |x| < inf and all variables are complex, except that variables in inequalities are real, as usual only real numbers can be compared. e.g. x is complex in sin(x), but y is real in y > 1.

            You can restrict the domain of a variable by assuming the variable is even, odd, integer, real number, positive or negative (see Chapter Simplification and Assumption).

 

 

17.1.4.  Patterns

 

            Patterns stand for classes of expressions.

 

_          any expression.

x_        any expression, given the name x.

 

            Patterns should appear on the left-hand side of the assignment only, not on the right-hand side of the assignment. Patterns are only used in definition of functions, procedures and rules.

            Patterns are used to define functions and rules for pattern match.

 

 

17.1.5.  Functions, Procedures and Rules

 

            These are two types of functions: internal and external. The internal function is compiled into the SymbMath system. The external function is the library written in SymbMath language, which is automatically loaded when it is needed. (See Chapter Library and Package). The usage of both types are the same. You can change the property or name of the external function by modifying its library file, or you add a new external function by creating its library file, but you cannot change the internal function.

 

 

17.1.5.1.  Standard Mathematical Functions

 

            Different versions of SymbMath have different number of standard mathematical functions. The Advanced Version C has all of them. See the following table in detail for other versions. All below standard functions, (except for random(x), n!, fac(n) and atan2(x,y)), can be differentiated and integrated symbolically.

 


             Table 17.1.5.1  Standard Mathematical Functions

-----------------------------------------------------------------------

Functions                     Meanings

 

random(x)                     generate a random number.

n!                                 factorial of n.

fac(n)                           the same as n!.

sqrt(x)                          square root, the same as x^0.5.

root(x,n)                       all n'th root of x.

exp(x)                          the same as e^x.

sign(x)                         1 when re(x) > 0, or both re(x) = 0 and im(x) > 0; 0 whenx=0;

                                    -1 otherwise.

abs(x)                          absolute value of x.

ln(x)                             natural logarithmic function of x, based on e.

log10(x)

sin(x)                           sine function of x.

cos(x)

 

...............................   above functions in Shareware Version A ...............

 

tan(x)

csc(x)

sec(x)

cot(x)

asin(x)              arc sine function of x, the inverse of sin(x).

acos(x)

atan(x)

acot(x)

asec(x)

acsc(x)

atan2(x,y)

 

............................. above functions in Student Version B .................

 

sinh(x)              hyperbolic sine function of x.

cosh(x)

tanh(x)

csch(x)

sech(x)

coth(x)

asinh(x)                        arc hyperbolic sine function of x, the inverse of sinh(x).

acosh(x)

atanh(x)

acoth(x)

asech(x)

acsch(x)

--------------------------------------------------------------------------

 

 

 

17.1.5.2.  Calculus Functions

 

            Calculus functions are for calculus calculation. The first argument of the function is for evaluation, and the second argument is a variable that is with respect to.

 

 

 

 

 

 

                        Table 17.1.5.2       Calculus Functions

--------------------------------------------------------------------------------------------------------------

Functions         Meanings

 

replace(y, x , x0)          evaluates y when x = x0.

lim(y, x = x0)    gives the limit of y when x approaches x0. Note that the correct answers                                   usually for the indeterminate forms: 0/0, inf/inf, 0*inf, 0^0, inf^0.

 

d(y, x)              differentiate y with respect to x.

d(y, x, order)    gives the n-th order derivative of y with respect to an undefined variable x.

d(y)                  implicit differentiation,  the default variable is x .

 

integrate(y, x)   find the indefinite integral of y with respect to an undefined variable x.

integrate(y,x,a,b)          find the definite integral of y with respect to an undefined variable x taken             from x=a to x=b.

integrate(y,x,a,b,c)       find the definite integral of y with respect to an undefined variable x taken             from x=a to x=b, then to x=c, where b is singularity.

integrate(y, x , a , b)     the same as integrate(y,x,a,b).

integrate(y)                   implicit integration,  the default variable is x.

 

dsolve(y'=f(x,y), y, x)    solve a differential equation.

 

sum(y,x)           indefinite sum with a variable x.

sum(y)             indefinite sum y,  the default variable is x.

sum(y, x , xmin , xmax)                        partial   sum of y from xmin to xmax .

sum(y,x,0, inf)              infinite sum.

sum(y, x , xmin , xmax , dx)                  sum of y, by step dx.

 

prod(y, x , xmin , xmax)                                    product of y step=1.

prod(y, x , xmin , xmax , dx)                 product of y.

----------------------------------------------------------------------------------------------------------------

 

            If a second argument x is omitted in the functions d(y) and integrate(y), they are implicit derivatives and integrals. If f(x) is undefined, d(f(x), x) is differentiation of f(x). These are useful in the differential and integral equations. (see later chapters).

 

            For examples:

            integrate(integrate(F,x), y) is double integral of F with respect to both variables x and y.

            d(d(y,x),t) is the mixed derivative of y with respect to x and t.

 

                        Examples:

--------------------------------------------------------------------------------

differentiation                d()                    d(x^2,x)

integration                    integrate()        integrate(x^2,x)

limit                              lim()                 lim(sin(x)/x, x = 0)

---------------------------------------------------------------------------------

 

 

17.1.5.3.  Test Functions

 

                        Table 17.1.5.3.1  The is*(x) Functions

---------------------------------------------------------------------

Function                       Meaning

 

isodd(x)                                    test if x is an odd number.

iseven(x)                      test if x is an even number.

isinteger(x)                   test if x is an integer number.

isratio(x)                       test if x is a rational number.

isreal(x)                                    test if x is a real number.

iscomplex(x)                 test if x is a complex number.

isnumber(x)                  test if x is a number.

islist(x)                         test if x is a list.

isfree(y,x)                     test if y is free of x.

issame(a,b)                  test if a is the same as b.

islarger(a,b)                  test if a is larger than b.

isless(a,b)                    test if a is less than b.

----------------------------------------------------------------------

 

            All of the is* functions give either 1 if it is true or 0 otherwise.

            The type(x) gives the type of x. Its value is a string.

 


            Table 17.1.5.3.2  The type(x) functions

--------------------------------------------------

x                      type(x)

 

1                      integer

1.1                   real

2/3                   ratio

1+i                   complex

sin(x)               sin()

[1,2]                 []

a                      symbol

"a"                    string

a+b                  +

a*b                   *

a^b                   ^

a=b                  =

a==b                ==

a>b                  >

a>=b                >=

a<b                  <

a<=b                <=

a<>b                <>

a,b                   ,

---------------------------------

 

            You also can test x, e.g. if x is type of real number, by

                        type(x)=="real"

 

 

17.1.5.4.  Miscellaneous Functions

 

                        Table 17.1.5.4.1      Algebra Functions

---------------------------------------------------------------------------------------------------

expand(F)                     expand (a+b)^2 to a^2 + 2*a*b + b^2.

factor(F)                       factorise a^2 + 2*a*b + b^2 to (a+b)^2.

solve(f(x)=0, x)             solve polynomial and systems of linear equations

---------------------------------------------------------------------------------------------------

Note: the Shareware Version has not solve().

 

            For example:

-----------------------------------------------------------------------

solving             solve()              solve(x^2+1 = 0, x)

expanding         expand()           expand((a+b)^2)        

factoring           factor()             factor(a*c+b*c)        

----------------------------------------------------------------------

 

            Conversion functions convert a type of data to another type of data.

 

                        Table 17.1.5.4.2   Conversion Functions

---------------------------------------------------------------------

listsum([a,b])                convert list to sum.

coef(expr, x^2)             gives the coefficient of x^2 in expr.

left(x^2=b)                    left hand side of an equation.

right(x^2=b)                  right hand side of an equation.

re(x)                             real part of complex numbers.

im(x)                            imaginative part of complex numbers.

num(x)                         convert x to the floating-point number.

ratio(x)                         convert x to the rational number.

round(x)                       convert x to the rounded integer.

trunc(x)                                    convert x to the truncated integer.

----------------------------------------------------------------------

 

                        Table 17.1.5.4.3     The List and Table Functions

-------------------------------------------------------------------------------------------

list(f(x), x from xmin to xmax step dx)   lists of f(x).

table(f(x), x from xmin to xmax step dx) data table of function values.

--------------------------------------------------------------------------------------------

 

            Above functions can be operated and chained, like the standard functions.

 

 

17.1.5.5.     User-defined Functions

 

            You can define the new functions, which include the standard functions, calculus functions, and algebraic operators.

            Define a new function f(x) by 

                        f(x_) := x^2

and then call f(x) as the standard functions. The function name can be any name, except for some keywords. (for the maximum number of arguments, see Chapter  System Limits).

            Clears a variable or function from assignment by

                        clear(x)            # clear x from assignment.

                        clear(f(x))         # clear f(x) from assignment.

                        clear(a>0)         # clear a>0 from assignment.

            Variables can be used in function definitions. It leads to an important difference between functions and variables.  When a variable is defined, all terms of the definition are evaluated.  When a function is defined, its terms are not evaluated; they are evaluated when the function is evaluated. That means that if a component of the function definition is changed, that change will be reflected the next time the function is evaluated.

 

 

17.1.5.6.  Procedures

 

            A procedure is similar to a function, but the right side of assignment in its definition is multi statements grouped by block(). The block(a,b,c) groups a,b,c and only returns the last argument as its value, or returns the second last argument as its value if the last argument is local(). It is used as grouper in definition of a procedure. All variables in block are local.

 

            e.g. f(x_):=block(p:=x^6,p)

            Remember that you can split a line of program into multi-lines program at comma,.

 

 

17.1.5.7.  Rules

 

            A rule is similar to a function. In definition of function, all arguments of function are simple variables, but in definition of rules, the first argument may be a complicated expression.

 

            e.g.

            f(x_,y_) := x^2+y^2                               # defining function

            f(x_,y_) := block(a:=2, a+x^2+y)                        # defining procedure

            log(x_ * y_) := log(x)+ log(y)                 # defining rule

 

 

 

17.1.6.  Equations

 

            An equation is an equality of two sides linked by an equation sign =, e.g. x^2+p = 0, where the symbol = stands for an equation. Note that the symbols "=", "==" and ":=" are different: ":=" is the assignment, "==" is the equal sign, but "=" is the equation sign.

 

            Example:

IN:  2 = 2

OUT: 2 = 2                   # unevaluated

 

IN:  2 == 2

OUT: 1                         # evaluated to 1 (true)

 

            Systems of equations are a list of equations, e.g.

[a1*x+a2*y=a3, b1*x+b2*y=b3].

 

 

17.1.7.  Inequalities

 

            e.g.

                        a < b                less than

                        a <= b              less than or equal to

                        a > b                greater than

                        a >= b              greater than or equal to

                        a == b              equal to

                        a <> b              not equals

 

 

17.1.8.  Vectors or Lists

 

            Lists are similar to lists in such language as PROLOG.

            [a, b, c] is a list.

            [a, b, [c1, c2]] is a list of lists.

            The list index is the index for n-th element in a list. e.g. b[2] indicates the second element in the list b.

            The built-in list index is last[number]. The name of last output list is last, e.g. last[1] is the first element in the last output list.

 

 

17.1.9.  Matrices or Arrays

 

            Arrays are the same as those in such language as PASCAL and FORTRAN. But you can use arrays without declaring arrays, unlike in PASCAL and FORTRAN.

 

            e.g.

a[1]:=1

a[2]:=4

 

            The array index is the index for n-th element in an array. e.g. a[2] indicates the second element in the array a.

 

 

17.1.10.  Strings

 

            A string is a sequence of characters between two quotation marks. e.g. "1234567890". Note that 1234 is number but "1234" is string. The number can be calculated and only has 11 of max digits, while string cannot be calculated and has 64000 of max characters long.

            Note that the output of strings in SymbMath is without two quotation marks. This makes text output to graph and database more readable.

            Strings can be stored in variables, concatenated, broken, lengthen, and converted to numbers if possible.

 

            e.g.

IN:  p := "abc"               # "abc" is stored in variable p

OUT: p := abc

 

IN:  concat("s","t")         # concatenate "s" and "t"

OUT: st

 

IN:  length("abc")          # count length of "abc"

OUT: 3

 

IN:  number("123")        # convert string "123" into number 123

OUT: 123      

 

IN:  type(a), type("a")

OUT: symbol, string

 

 

17.2.   Expressions

 

            The expressions (i.e. expr) are made up of operators and operands. Most operator are binary, that is, they take two operands; the rest are unitary and take only one operand. Binary operators use the usual algebraic form, e.g. a+b.

            There are two kinds of expressions: numeric and Boolean. The numeric expression is combination of data and algebraic operators while the Boolean expression is combination of data and relational operators and logic operators. These two kinds of expressions can be mixed, but the numeric expression has higher priority than Boolean operators. x*(x>0) is different from x*x>0. x*x>0 is the same as (x*x)>0.

            e.g.

a+b+3               numeric expression,

a>0                  Boolean expression

a>0 and b>0     Boolean expression

(x>0)*x             mixed numeric and Boolean expression

 

                       

17.2.1.   Operators

 

            Table 17.2.1       Operators

--------------------------------------------------------------------------------------------------

Operation                     Operators         Examples         Order

 

comma                         ,                       a:=2, b:=3         1

assignment                   :=                     p:=2+3              2

and                               and                   a>2 and a<8     2

or                                 or                     a>2 or b>2        2

equation                       =                      x^2+x+1 = 0     3

equal                            ==                    a==2                3

larger than                    >                      a>2                  3

larger and equal            >=        a>=2                3

less than                      <                      a<2                  3

less and equal              <=                    a<=2                3

unequal                                    <>                    a<>2                3

plus                              +                      a+b                  4

minus                           -                       a-b                   4

mutilation                      *                       a*b                   5

division                         /                       a/b                   5

power                           ^                      a^b                   6

factorial                                    !                       n!                     6

positive                        +                      +a                    7

negative                       -                       -a                     7

function                                    f()                     sin(x)               7

list index                       f[]                     f[1]                   7

parentheses                  ()                      (a+b)*c             7

list                                []                      [a,b]                 7

------------------------------------------------------------------------------------------------

 

            All functions have the same 7th order.

            Operations with higher order precede, otherwise operations with equal precedence are performed from left to right.  These are the usual algebraic conventions.

            a^b^c is the same as (a^b)^c.

            You can get operators by type(x).

 

 

17.2.1.1.  Arithmetic Operators

 

-------------------------------------------------------------------------------------------

plus                              +                      a+b                  4

minus                           -                       a-b                   4

mutilation                      *                       a*b                   5

division                         /                       a/b                   5

power                           ^                      a^b                   6

fractorial                       !                       a!                     6

---------------------------------------------------------------------------------------------

 

 

17.2.1.2.  Relational Operators

 

            Before you can write loops, you must be able to write statements that evaluate to 1 or 0, and before you can do that, you must be able to write useful statements with logical values. In mathematics, these are relational statements.

            SymbMath allows you to compare numbers six ways:

 

                        a < b                less than

                        a <= b              less than or equal to

                        a > b                greater than

                        a >= b              greater than or equal to

                        a == b              equal to

                        a <> b              not equals

 

            SymbMath uses the double equals sign == (like C language) for "is equal to" to distinguish this operator from the equation =.

            The result of a comparison of two real numbers is either 1 or 0. If the comparison is not both real numbers, it left unevaluated.

 

 

17.2.1.3.    Logical Operators

 

            SymbMath uses the logical operators:  AND, and OR.  You can combine comparison operators with them to any level of complexity. In contrast to Pascal, logical operators in SymbMath have a lower order or precedence than the comparisons, so a < b  and  c > d works as expected.  The result of combining logical values with

logical operators is another logical value (1 or 0).  Bit operations on integers can be performed using the same operations, but result is integers.

            SymbMath uses the "short-circuit" definition of AND and OR when the arguments are Boolean.  Here are tables that show how AND and OR are defined:

 

                        a and b

--------------------------------------------------------

                        b          1          0

            a

            1                      1          0

            0                      0          0

------------------------------------------------------

 

                        a or b

--------------------------------------------------------

                        b          1          0

            a

            1                      1          1

            0                      1          0

------------------------------------------------------

 

            Short-circuit evaluation is used because often one condition must be tested before another is meaningful.

            The result of Boolean expression with logic operators is either 1 or 0. Boolean expression like (1 < 3 or 1 > 4) return a real value 1 or 0.  Numeric expressions can replace Boolean ones, provided they evaluate to 1 or 0.  The advantage here is that you can define the step function that is 0 for x < a and 1 for x > a by entering:

 

                        step(x_, a_) := x > a

 

            To define the function:

                                    f(x) = x-1          if x < 1

                                         = x^2-x        if x >= 1

 

            enter:

            f(x_) := (x-1)*(x < 1) + (x^2-x)*(x >= 1)

 

            These functions can be differentiated and integrated symbolically.

 

 

17.2.2.  Function Calls

 

            A function call activates the function specified by the function name. The function call must have a list of actual parameters if the corresponding function declaration contains a list of formal parameters. Each parameter takes the place of the corresponding formal parameter. If the function is external, the function call will automatically load the library specified by its function name plus extension  when needed.

            Some examples of the function calls follow:

            sin(x)               # load the library sin when needed

            integrate(x^2, x)           # load the library int when needed

 

 

17.3.    Statements

17.3.1.  Comment Statements

 

            # is the comment statement sign.

            You can add comments into a line, or even produce a single line which is entirely a comment, by preceding the comment sign with #.

 

            For example:

                        # This is my program;

                        3 + 4    # My first calculation;

 

            Comments make your calculations more understandable, whether you are making a printed record of what you are doing or if you just want to jot some notes to yourself while you are working.

 

 

17.3.2.  Evaluation Statements

 

            The evaluation statement has the format:

 

                        expression

 

            SymbMath evaluates any expression which in a line and gives the value of the expression. e.g.

 

IN:  3 + 4

OUT: 7                         # the value of 3+4

 

IN:  d(x^6, x)

OUT: 6 x^5                   # the value of d(x^6, x)

 

IN:  subs(last, x = 1)     # evaluate the last output when x = 1.

OUT: 6

 

            The last output can be saved to a variable for the later use by the built-in variable "last", e.g. f :=last.

 

 

17.3.3.  Assignment Statements

 

            The assignment in SymbMath language is similar to assignment in such language as PASCAL.

            An assignment operator is   :=

            The assignment statement specifies that a new value of expr2 be assigned to expr1, and saved into memory. The form of the assignment statements is

 

                        expr1 := expr2;

 

            You can use assignment for storing result.

            You can assign the result of calculation or any formula to a variable with a command like:    X := SIN(4.2).

            The assignments are useful for long calculations.  You can save yourself a lot of recalculations by always storing the results of your calculations in your own variables instead of leaving them in the default variable last.

             You can destroy the assignment to X with the command clear(X). If X stored a large list, you could regain a considerable amount of memory by clearing X. Also, since a variable and a function can have the same name, you can clear a variable p, not a function p(x).

            The assignment operator is also used in the definition of a function or procedure.

            Variables can be used in function definitions, and that leads to an important difference between functions and variables.  When a variable is defined, all terms of the definition are evaluated.  When a function is defined, its terms are not evaluated; they are evaluated when the function is evaluated.  That means that if a component of the function definition is changed, that change will be reflected the next time the function is evaluated.

 

            e.g.

IN:  p:=2+3                   # 2+3 is evaluated at the time of assignment, p is assigned with 5.

OUT: p := 5

 

IN:  p(x):=2+3               # 2+3 is evaluated when the value of p(x) is requested, 

                                    # p(x) is assigned with 2+3.

OUT: p(x) := 2+3

 

            If the left hand side of the assignment is a variable, it is the immediate assignment (i.e. expr2 is evaluated at the time of assignment); if the left hand side is a function, it is the delayed assignment (i.e. expr2 is evaluated when the value of expr1 is requested).

            You can force all the components of a function to be evaluated when the function is defined by preceding the function with the command eval():

                        f(x_) := eval(2+3)   # f(x_) is assigned with 5

            Note that not only a variable but also any expression can be assigned. e.g. x := 2, sin(x)/cos(x) := tan(x), a>0 := 1.

            Clear a variable, function or expression from assignment by

 

                        clear(x)            # clear x from assignment.

                        clear(f(x))         # clear f(x) from assignment.

                        clear(a>0)         # clear a>0 from assume(a>0).

 

 

17.3.4.  Conditional

 

            There are two conditional functions:

                        If(test , x)

                        If(test , x , y)

 

            If(condition ,  x) gives x if condition evaluates to 1, or no output otherwise.

            If(condition ,  x ,  y) gives x if condition evaluates to 1, y if it evaluates to 0, or no output if it evaluates to neither 1 or 0. The 2 words (then and else) can be replaced by comma ,.

            It is useful in definition of the use-defined function to left the function unevaluated if the argument of the function is not number. e.g. define f(x_) := If(isnumber(x), 1), then call f(x), f(10) gives 1, and f(a) gives f(a).

 

 

17.3.5.  Loop

 

            You can use two kinds of loops in SymbMath, fixed length loops controlled by do() and variable-length loops controlled by repeat(). The do() loop is similar to the FOR loop in BASIC language.

            The control variable in the do() loops is not limited to integer values. You can say:

 

                        do(f:=f+1, x from xmin to xmax step dx)

 

            It is similar to

                        FOR x := xmin TO xmax STEP dx

                        f:=f+1

                        NEXT x

where xmin, xmax, and dx are real values.  If STEP dx is omitted, it defaults to 1.

 

            e.g.

IN:  x:=0

OUT: x := 0

IN:  do(x:=x+1, j from 1 to 5 step 1)

OUT: x := 5

 

              The conditional loops are probably more useful than the do() loops if a number of iteration is unknown. It is

                        repeat(y until test)

                        repeat(y, test)

            The word (until) can be replaced by comma ,. The repeat() repeats to evaluate f until the test is true (i.e. the result of the test is 1).

 

            Example:

IN:  x:=1

OUT: x := 1

 

IN:  repeat(x:=x+1 until x>5)

OUT: x := 6

 

 

17.3.6.  Switch

 

            The switch sets or changes the switch status. The switch status is unchanged in memory until the switch is assigned by the new value.

 

---------------------------------------------------------------------------------------------------------

Switch                          Action

 

output := math              output form is math symbol notation, this is default.

output := basic              output form is BASIC format.

output := fortran                        output form is FORTRAN format.

output := prolog            output form is PROLOG format (internal form).

output := off                  not display output.

output := on                  the same as output := basic

 

lowercase := on                        convert letters into the lower-case letters.

lowercase := off                        not convert letters into the lower-case letters, this is default.

numeric := on               convert numbers to floating-point numbers.

numeric := off               not convert numbers to floating-point numbers, this is default.

 

expand := on                 expansion. e.g. c*(a+b) to c*a+c*b.

expand := off                disable expansion, this is default.

 

expandexp := on           expand exponent. e.g. c^(a+b) to c^a*c^b.

expandexp := off           disable exponent expansion, this is default.

------------------------------------------------------------------------------------------------------------------

 

 

17.3.6.1.  Output Switch

 

            When the switch output := math, the output displays the math symbol notation.

            When the switch output := basic, the output form is the BASIC language format.

            When the switch output := fortran, the output form is the FORTRAN language format.

            The default switch is output := math.

            The output switch only changes the output format, neither affects the internal format nor the calculation.

 

 

17.3.6.2.  Case Switch

 

            When the switch lowercase := on, all letters are converted into the lower-case letters so the upper- and lower- case letters are the same, e.g. EXP(x) is the same as exp(x).

 

 

17.3.6.3.  Numeric Switch

 

            Example:

IN:  1/2

OUT: ½

 

IN:  numeric := on

IN:  1/2

OUT: 0.5

 

 

17.3.6.4.  Expand Switch

 

            Example:

IN:  a*(b+c)

OUT: a (b + c)

 

IN:  expand := on

IN:  a*(b+c)

OUT: a* b + a* c

 

 

17.3.6.5.  ExpandExp Switch

 

            Example:

IN:  exp(a+b)

OUT: e^(a + b)

 

IN:  expandexp := on

IN:  exp(a+b)

OUT: e^a* e^b

 

17.3.7.  Read and Write Statements

 

            The format of the readfile statement is

                        readfile("filename")

            The filename is any MS-DOS file name. If the file is not in the current directory, the filename should include the directory. e.g.

                        readfile("directory\filename")

            e.g. read a file named "int.sm":

                        readfile("int.sm")

            It seems to copy the file into the user program.

            After a file is read, you can call any part of this package from a second package, as it seems the part of the first program has already been in the second program. you can read many files into the SymbMath program at a time. However, all names of the variables are public and name conflicts must be avoided.

            Write a file to disk by

                        openfile("file")

                        do something

                        closefile("file")

                       

            Table 17.3.7.         Reading and Writing Statements

---------------------------------------------------------------------

readchar                       read a character from  keyboard.

readline                                    read a line of strings from keyboard.

readfile("file")                read (run or include) the file named "file".

 

......................................................................

openfile("file")               open the disk file "file" for writing.

closedfile("file")             closed the file "file".

writes(s)                       write s on screen, only on graphics mode.

newline                         write next text on a new line.

null                               not write.

block(a,b)                     write the value of the last argument, b.

---------------------------------------------------------------------

where the filename is any MS-DOS filename.

 

            Note that the file must be closed by the closefile() command when writing a file with the openfile() command, but the file is automatically closed after reading the file. There must be the end statement at the end of file for reading.

            SymbMath can read expressions from a disk file, then manipulate the expression, and finally write the result into another disk file.

            Example: an expression y:=x^6 is already in the file "y.in",

            The contents of the file "y.in":

---------------------------------------------------------------------

y:=x^6

-----------------------------------------------------------------------

 

            Run this SymbMath program

----------------------------------------------------------------------------

readfile("y.in")               # read the expression y:=x^6 from the file "y.in"

openfile("y.out")                        # open a disk file "y.out" for writing

d(y,x)                           # differentiate y and write the result to the file

closefile("y.out")           # close the file and return output to SymbMath

----------------------------------------------------------------------------

 

            The contents of the file "y.out":

---------------------------------------------------------------------

6*x^5

---------------------------------------------------------------------

 

            In this way you can interface to other software (see 3.7. Interface with Other Software).

            These outputs in the disk file can be edited in the Edit window or the Aux Edit window.

            It is recommended to use the BASIC output format by setting the switch output := basic when you write the output into the disk file. The default switch is output := math.

 

 

17.3.8.  DOS Command

 

            You can executes a DOS command in SymbMath language by

                        system("dir")

 

 

17.3.9.  Sequence Statements

 

            The all above statements are simple statements. The sequence statement specifies that its component statements are to be executed in the same sequence as they are written. They are separated by the separators (comma ","). e.g.

                        a+b, 2+3

 

 

17.4.  Libraries and Packages

 

            A library is a file of an external function, which filename is its function name within 8 letters plus extension . e.g. the library named sin is a file of the sin(x) function definition.

            The library (the * file) is similar to the MS-DOS *.BAT file. You do not need to load or read the library by any command. SymbMath automatically load the library when it is needed. For example, when you use the sin(x) function first time, the library sin will be auto-loaded. The library must be in the default directory, otherwise the library is not loaded and the function is not working. Only the assignments in the library can be loaded, and others in the library will be omitted, but all of these assignments will be not evaluated when they are loaded. You can clear the library sin from memory by clear(sin(x)).

            You can have libraries (external functions) as many as your disk space available. You should use the "one function per file" convenience.

            Note that all names of the variables in libraries and packages are public (global) except for those declared by local() and name conflicts must be avoided.

 

            A package is the SymbMath program file which filename has not  extension . It is recommended that its filename has the extension .SM.

            A package is similar to a library, but the package must be read by a command

                        readfile("filename")

            The filename can be any MS-DOS filename. It is recommended that the filename is same function name used in your program, plus the extension .sm. e.g. int.sm is the filename of the integral package as the name of integral function is integrate(). If the file is not in the current directory, the filename should include the directory. e.g.

                         readfile("directory\filename")

            After reading the package, you can call the commands in the package from your program.

            The readfile() command must be in a single line anywhere.

            Many packages can be read at a time.

            You can convert a package of f.sm into a library by renaming f.sm to f for auto loading, or a library f to a package by renaming f to f.sm for not auto loading.

            You can get help for all libraries by the library Index command in the Help menu. You first open the library index window by this command, then open a library by selecting its library name in the library index window.

            There are many libraries and packages. The following are some of them.

 

 

                        Table 17.4.1      Libraries

------------------------------------------------------------------------

File Name                     Function

 

plot                               plotting functions.

d                                  derivatives.

int                                integrals.

sin                                sin(x) function.

cos                               cos(x) function.

fac                               n!.

sign                              sign(x) function.

abs                               abs(x) function.

arg                               arg(x) function.

sum                              sum function.

NInte                            numeric integration.

NSolve             numeric solver of equation.

DSolve             differential equation solver.

gamma             gamma function.

ei                                 exponential integral function.

series                           Taylor series.

partSum                       partial sum.

infSum              infinite sum.

sinh                              sinh(x) function.

cosh                             cosh(x) function.

average                        average([x]) function.

listSum             sum of list of data.

react                            chemical reactions database.

phoneNo                       phone No. database.

------------------------------------------------------------------------

 

 

                        Table 17.4.2     Packages

------------------------------------------------------------------------

init.sm                          initial package when running the program in

                                    the Input window. It contains switches on the default status.

 

chemical.sm                 the atomic weight of chemical elements.

ExpandTr.sm                expansion of trig functions.

expandLn.sm                expand ln(x*y).

ExpandGa.sm               expand gamma(n,x).

ExpandEi.sm                expand ei(n,x).

units.sm                       an units conversion.

listPlot.sm                    plotting a list of data.

plotData.sm                  interfacing software PlotData.

-----------------------------------------------------------------------

 

 

17.4.1.  Initial Package init.sm

 

            When a program is run in the Input window, SymbMath first automatically reads (or runs) the initial package "init.sm". The commands in the "init.sm" package seems to be the SymbMath system commands. You can read other packages (e.g. f.sm) in the initial package "init.sm", so the commands in the package "f.sm" seems to be in SymbMath system. You do this by adding the readfile("f.sm") into the init.sm file:

                        readfile("f.sm")

 

 

17.4.2.  ExpandLn Package

 

            The lnexpand.sm package does the logarithmic expansion. e.g. ln(a*b) is expanded into ln(a)+ ln(b).

 

                                   

17.4.3.  Chemical Calculation Package

 

            SymbMath recognises 100 symbols of chemical elements and converts them into their atomic weights after the chemical package of "Chemical.sm" is read.

 

            Example:

            Calculate the weight percentage of the element C in the molecule CH4.

 

IN:  readfile("chemical.sm")

IN:  numeric := on

IN:  C/(C+H*4)*100*%

OUT: 74.868 %

 

            Example:

            Calculate the molar concentration of CuO when 3 gram of CuO is in 0.5 litre of a solution.

 

IN:  readfile("chemical.sm")

IN:  numeric := on

IN:  g:=1/(Cu+O)*mol

IN:  3*g/(0.5*l)

OUT: 0.07543 mol/l

 

 

17.5.  Interface with Other Software

 

            You can run SymbMath from another software as a engine. Anthoer software sends a text file to SymbMath, then run SymbMath in background, get result back from SymbMath.

Interface with other software, (e.g. CurFit, Lotus 123) is similar to interface with the software PlotData in the plotdata package "plotdata.sm".

            After load the file "plotdata.sm", the functions

                        plotdata(y, x)

                        plotdata(y, x from xmin to xmax)

                        plotdata(y, x from xmin to xmax step dx)

plot a function of y by mean of the software PlotData. The plotdata() first opens a file "SymbMath.Out" for writing, then write the data table of the y function into the file "SymbMath.Out", then close the file, and finally call the software PlotData to plot. These are done automatically by plotdata(). After it exits from PlotData, it automatically return to SymbMath.

            When SymbMath is interfaced with the software PlotData, SymbMath produces the data table of functions, and PlotData plots from the table. So SymbMath seems to plot the function. This interface can be used to solve equations graphically.

           

            Example:

plot x^2 by interfacing software PlotData.

 

IN:  readfile("plotdata.sm")

IN:  plotdata(x^2, x)

 

in the software PlotData, you just select the option to read the file "SymbMath.Out" and to plot. PlotData reads the data in the SymbMath format without any modification (and in many data format).

            In PlotData,

in the main menu:

1 <Enter>

in the read menu:

2 <Enter>

<Enter>

in the main menu:

2 <Enter>

in the graph menu:

1 <Enter>

 

where <Enter> is the <Enter> key. Refer to PlotData for detail.

 

18.   Graphics

 

            SymbMath includes extensive facilities for graphing. It supports BGI graphics, which graphics commands are the same as those in Borland Turbo Pascal and Turbo C, except for:

 

            different graphics commands

---------------------------------------------------------------

SymbMath                    Turbo Pascal or C

 

graph                           initgraph(drive,mode,path)

text                              closegraph

writes(x)                       outtext(x)

-----------------------------------------------------------------

 

            Note that if your monitor is Hercules, you must load the MSHERC.COM program as a TRS program before you run PlotData. Otherwise you will get Error when you plot.                                     

            Before graphing (drawing or plotting), you must initialize the graphics system and puts the computer hardware into graphics mode by the command:

                        graph

 

 

18.1.  Drawing Lines and Arcs

 

then you can draw a line by

                        line(x1,y1,x2,y2)

                        lineto(x2,y2)

                        linerel(dx,dy)

 

draw a circular arc by               

                        arc(x,y,angle1,angle2,radius)

 

draw an elliptical arc by               

                        ellipse(x,y,angle1,angle2,XRadius,YRadius)

 

put a pixel by                

                        putpixel(x,y,color)

            you can move a pointer by

                        moveto(x,y)

                        moverel(dx,dy)

            A upper left corner on your graphics screen coordinates is (0,0).

            The style of the line can be set by

 

                        setlinestyle()

 

            You can set screen colors. If you are using a color system, you can set the color of the next line or graph or text with the command:

                        setcolor(color)

where color is color number (i.e. an integer in the range 0..15), or one  of the colorno(x) function value.

            You can set the background color for your graphs with the command

                        setbkcolor(color)

where color is color number (i.e. an integer in the range 0..15), or one  of the colorno(x) function value.

 

        Table 18.1     ColorNo(x) function in the colorno library

--------------------------------------------------------------------------------------

x                                  value

 

black                            0

blue                              1

green                           2

cyan                             3

red                               4

magenta                       5

brown                           6

lightgray                       7

gray                             8

lightblue                       9

lightgreen                     10

lightcyan                      11

lightred                         12

lightmagenta                 13

yellow                           14

white                            15

-----------------------------------------------------------------------

 

            You can set line styles.

            On both monochrome and color systems, you can draw lines and graphs with different line styles.  (Since the line segments used to draw graphs are usually very short, different line styles may not be distinguished in graphs, but they will be distinguished on long lines.)  Linestyles are indicated by integers in the range 0..3, and are set by the command:

                        setlinestyle(style,u,thickness)

where style, u and thickness are integers.

            You can set the text style by

                        settextstyle(font,direction,size)

where font, direction and size are integers.

            You can add labels to your graphs by

                        writes(s)

            You can put alphanumeric labels anywhere on your graphic screens. They can be horizontal or vertical, and they can be printed in various sizes. To print a string  s  horizontally on the screen with the lower-left corner at the screen coordinates (x,y), use two commands:

                        moveto(x,y), writes(s)

To write vertically bottom to top, use two commands:

                        settextstyle(1,2,2), writes(s)

             

            If SymbMath attempts to graph a point (x,y) which is outside the the screen coordinate, it ignores the point and continues.  No error message is generated, and even functions which are undefined on part of the graphing domain can be graphed.

            You can get the max x and max y on your graphics screen

coordinates by

                        getmaxx

                        getmaxy

            You can get the current point(x, y) on your graphics screen coordinates by

                        getx

                        gety

            You can get the background color and foregroud color on your graphics screen by

                        getbkcolor

                        getcolor

            You can read a character from the keyboard or pause by the command:

                        readchar

            You can clear graph by

                        cleardevice

 

            SymbMath auto goes back the text mode at the end of run. You can force it goes back the text mode by the command:

                        text

 

            Example:     

#          drawing a group of circles and ovals.

#          Circles are 9 planets around sun.

 

graph                                       # graph mode

do(circle(getmaxx*0.5+2.5*x,getmaxy*0.5,5), x,0,90,10)

do(oval(getmaxx*0.5,getmaxy*0.5,2.5*x,x), x,10,90,10)

readchar                                   # pause graph by read a char

text                                          # back text mode

 

 

18.2.  Plotting f(x)

 

            You can plot a function of y = f(x) on the xy-plane by external function:

 

                        plot(f(x),x)

                        plot(f(x),x,xmin,xmax)

                        plot(f(x),x,xmin,xmax,ymin,ymax)

                        plot(f(x),x,xmin,xmax,ymin,ymax,color)

 

f(x) can be either a function  with bound variable x or an expression involving x.  For example, you could graph the parabola with the command plot(x^2,x). 

            The xmin and xmax are range of x-axis, the ymin and ymax are range of y-axis. The default values are xmin=-5, xmax=5, ymin=-5, and ymax=5. The values of xmin, xmax, ymin, ymax are real numbers, such that  xmin < xmax  and  ymin < ymax.  Thses values tell SymbMath that the visible screen corresponds to a portion of the xy-plane with  xmin <= x <= xmax  and  ymin <= y <= ymax.

            The operator plot() plots one point (x,f(x)) for each pixel on the x-axis, and connects successive points.  To omit the connections and just plot the points, use the command:

                                    dotplot(f(x),x)

            To plot only every 20th point, which is useful for rapidly graphing complicated functions, use

                                    sketch(f(x),x)

            If you want your circles and squares to look correct --that is, if you want one vertical unit to be really the same distance as one horizontal unit--you should select window parameters so that the horizontal axis is 1.4 times as long as the vertical axis.

 

            Example 5.2:               

            plot x^3 and sin(x).

IN:  graph

IN:  plot(x^3,x)               

IN:  plot(sin(x),x)

 

                

18.3.  Plotting Parametric Functions x(t) and y(t)

 

            You can plot the parametric functions of x=x(t) and y=y(t) by

 

                        paraplot(x(t),y(t),t)

                        paraplot(x(t),y(t),t,tmin,tmax)

                        paraplot(x(t),y(t),t,tmin,tmax,ymin,ymax)

 

            Example:

IN:  graph

IN:  paraplot(sin(t),sin(2*t),t)

 

 

18.4.    Plotting f(t) in Polar Coordinates

 

            You can graph the portion of a polar curve  r = f(t) that lies in the window with external function:

 

                       polaplot(f(t),t)

                       polaplot(r, t,tmin,tmax)

                       polaplot(r, t,tmin,tmax,rmin,rmax)

 

f(t) can be a function with bound variable t or an expression involving t.

 

            Example:

            Plot a circle  r = 1 in polar coordinates.

IN:  graph

IN:  polaplot(1,t)

 

The variable t covers the domain (0, 2*pi); you can change this default by specifying a range for t:

                       polaplot(1, t,0,pi)

 

           

18.5.  Plotting Data

 

            You can plot data by

 

                        dataplot([x1,x2,...], [y1,y2,...])

                        dataplot([x1,x2,...], [y1,y2,...], xmin,max)

                        dataplot([x1,x2,...], [y1,y2,...], xmin,xmax,ymin,ymax)

                        dataplot([x1,x2,...], [y1,y2,...], xmin,xmax,ymin,ymax,link)

 

            Example:

IN:  graph

IN:  dataplot([1,2,3], [1,4,9])

 

        You can plot a list of data by

               listplot([y1,y2,...])

for x1=1, x2=2, x3=3, ....

 

            Example:

IN:  graph

IN:  listplot([1,4,9])

 

            You can fit a set of data into a function x^2

            Example 5.7.

IN:  graph

IN:  dataplot([1,2,3,4],[1,4,9,16],0,5,0,20)

IN:  plot(x^2,x,0,5,0,20)

 

 

 

18.6.     Printing Graphics on Printer

 

1. Load the Graphics.EXE file into memory in the DOS prompt by

            c:\DOS\graphics

2. Run SymbMath, then display a graph on screen.

3. Print Screen by pressing the <Print Screen> key on keyboard.

 

Note that you must load the Graphics.EXE file before you run SymbMath.

 

 


Part 3 Reference Guide

 

19.  SymbMath Environment: Windows and Menus

 

            SymbMath is a multi-windowed editor in which you can copy-and-paste anywhere in a file and between files, even from the Help window.

            When you start SymbMath, the computer screen looks like:

 

-----------------------------------------------------------------------------------------

| File  Input  Run  Output  Color                 Help  Example Keyword  |

---------------------------------- Input -----------------------------------------------

|                                                                                                       |

|                                                                                                       |

|                                                                                                       |

-----------------------------------------------------------------------------------------

---------------------------------- Output ---------------------------------------------

|                                                                                                       |

|                                                                                                       |

|                                                                                                       |

|                                                                                                       |

-----------------------------------------------------------------------------------------

SymbMath  | Arrow keys and <Enter>, Highlight or first capital letter

------------------------------------------------------------------------------------------

 

            The screen is divided into four areas: a menu line, an input window, an output window, and a status line.

            The menu line is the main menu and locates in the top of the screen.

            The input window is a multi-windowed text editor for input.

            The output window is a multi-windowed text editor for output.

            The status line indicates the current status or which key to be active. It places in the bottom of the screen. The content of the status line will be changed according to which active window.

            In the menu line, the File, Color, and Help commands have its pull-down menus.

            Select the menu by the arrow keys and <Enter>, or the first capital letter. The <Esc> key always escape from the current window and return to the previous window.

            A pop-up menu is the Edit Help menu.

 

 

19.1.  File Menu

 

            The File menu has 5 choices in the pull-down menu:

 

----------------------

| Open              |

| New                |

| Save               |

| DOS shell       |

| Exit                |

----------------------

 

 

19.1.1.  Open

 

            The Open command opens a file for edit in the Input window. This command first opens a Directory window to choose a file for edit. In the Directory window, the following commands are available.

 

 

 

 

            Table 2.1          Commands in the Directory Window

---------------------------------------------------------------------------------------

Action                           Keystrokes

 

file mask                      <F4>, *.sm                   e.g. *.sm

zoom window                <F5>

zoom back                    <F5>

resize window               <Shift><F10>, then the -><- keys, <F10>

select                           the arrow keys

page up                        <Pg Up>

page down                    <Pg Dn>

accept                          <Enter>

abort                            <Esc>

go to the x filename      x                      (where x is any single letter.)

-------------------------------------------------------------------------------------------

 

            You select a file from the Directory window to open for edit in the Input window.

 

 

19.1.2.  New

 

            The New command creates a new file and clears the Input window.

 

 

19.1.3.  Save Input

 

            The "Save Input" command saves the file in the Input window into disk under a different name or in a different directory.

 

 

19.1.4.  Save Output

 

            The "Save Output" command saves the file in the Output window into disk under a different name or in a different directory.

 

 

19.1.5.  DOS Shell

 

            The "DOS shell" command executes a DOS command and automatically returns to the SymbMath system if you provide a DOS command on the command window, otherwise it goes to the DOS shell, the control must be returned to the resident SymbMath system with the EXIT command on the DOS shell.

 

 

19.1.6.  Exit

 

            The Exit command exits from SymbMath.

 

 

19.2.  Input Menu

 

            The Input menu lets the control goes into the Input window. To enter text (e.g. math expressions), type as though you were using a typewriter.

 

 

19.3.  Run Menu

 

            The Run menu executes the user program in the Input window, outputs the results in the Output window, and saves the output into the file named "output".

            Notice that it clears memory and executes the initial package "init.sm" before it interprets the users program in the Input window.

 

 

19.4.  Output Menu

 

            The Output command goes into the Output window.

            The Output window is similar to the Input window, where you can edit any text. You can copy the output into your document by the block copy command in the editor.

            In the Output window, the line with beginning of IN: is content of input, and the line with beginning of OUT: is the output.

            The output in the Output window is always saved into the "output" file

 

 

19.5.  Color Menu

 

            The Color menu has 6 choices:

 

----------------------------------

| Menu line                    |

I Input window               |

| input Border                |

| output Window            |

| Output border              |

| Status line                  |

---------------------------------

 

            When you choose one of them, a color pattern will come up. There are 126 colours in the color pattern. Select your favour color by the arrow keys and <Enter>.

 

 

19.5.1.  Menu Line

 

            It is to change the menu line's color.

 

 

19.5.2.  Input Window

 

            It is to change the input window's color.

 

 

19.5.3.  Input Border

 

            It is to change the input window border's color.

 

 

19.5.4.  Output Window

 

            It is to change the output window's color.

 

 

 

19.5.5.  Output Border

 

            It is to change the output window border's color.

 

19.5.6.  Status Line

 

            It is to change the status line's color.

 

 

19.6.  Help Menu

 

            The Help menu displays the syntax of SymbMath language.

            In the Help menu, Each command has its own Help window and help file. The on-line help files are text (ASCII) files.

            In the Help window, to search for a special word, you first press <Ctrl><F3>, then type the word you want to search, finally press <Ctrl><F3> again. e.g. if you want to search for the word "help", you first press <Ctrl><F3>, then type "help", finally press <Ctrl><F3> again. The cursor will go to the word "help". You press <Shift><F3> to repeat the last find.

            The commands in the Help window are the same as that in the Edit window, except that text is unable to be changed, (see Chapter 2.9 Editor).

 

 

            Table 19.6        Commands in the Help window

-------------------------------------------------------------------

Action                                                   Keystrokes

 

move the cursor                                    the arrow keys

zoom in window                                    <F5>

zoom out window                                  <F5>

exit from the window                             <Esc> or <F10>

go to the beginning of the line                <Home>

go to the end of the line                         <End>

page up                                                <Pg Up>

page down                                            <Pg Dn>

go to the beginning of window               <Ctrl><Home>

go to the end of the window                   <Ctrl><End>

go to the beginning of the file                <Ctrl><Pg Up>

go to the end of the file                          <Ctrl><Pg Dn>

go to nth line                                         <Crtl><F2>, No., <Crtl><F2>

find the special word                             <Ctrl><F3>, "word", <Ctrl><F3>

repeat last find                                      <Shift><F3>

re-size window                                      <Shift><F10>, the arrow keys, <F10>

go to x                                                  x

(where x is the first letter of filename)

-----------------------------------------------------------------------------------------------------------

 

            In the Input, Output and Aux Edit windows, press <F1> to pop-up the Edit Help menu.

 

19.7.  Example Menu

 

            The Example menu shows examples in the SymbMath language.

 

19.8.  Keyword Menu

 

            The Keyword menu shows keyword in the SymbMath language.

            The Topic command opens a help window for the keywords in topic order.

            The Alphabetical order command opens a help window for the keywords in alphabetical order.

            The Index command opens an index window, where you can select a keyword (file *.key) to open a help window for its file. e.g. if you want to help for the keyword d, you press d and <Enter> to open the help file d.key.  If the keyword is longer than 8 letters, its filename is the first 8 letters plus extension .key.

            The Library index command is similar to the Index command, but it opens a library index window for library (external function file *).

 

 

19.9.  Editor and Edit Help Menu

 

            SymbMath includes a multi-windowed text editor for creating and modifying program files. Usage of the editor is similar to WordStar in non document mode, to Borland's SideKick, or to Borland's C compiler.

            You can execute the edit commands either by selecting the edit commands in the Edit Help menu or by keystrokes.

 

 

19.9.1.  Edit Help Menu

 

            Open the Edit Help menu by pressing <F1> within the Input window, the Aux Edit window, or the Help window.

            This menu has 11 choices:

 

------------------------------------

| Show help file             |

| Cursor movement       |

| Insert & Delete            |

| Searching                   |

| Block functions           |

| Special block functions            |

| File functions              |

| Application keys          |

| Miscellaneous             |

| Global functions          |

| Hot keys                     |

------------------------------------

 

            Except for the first choice of the "Show help file", others have their own sub-menu. You can select the edit command in the sub-menu by the up or down key and <Enter>.

 

 

19.9.1.1.  Show Help File

 

            This command opens a help window to show a help file.

 

 

19.9.1.2.  Cursor Movement Commands

 

            This command opens a menu for the cursor movement commands.The functionality of most of the cursor-movement commands is straight forward. In this section, only the "non-obvious" commands will be explained.

                        Scroll Up

            The text scrolls one line up. The cursor will be at same physical line on the computer-screen

                        Scroll Down

            The text scrolls one line down. The cursor will be at the same physical line on the computer-screen.

                        Previous Position

            Moves the cursor to its position just prior to the last command. For instance, if you inadvertently press Goto Text start, moving your cursor to the top of the file, you can press Previous Position to get back to where you were.

                        Goto Line

            Moves the cursor to the line number you specify.

                        Goto Position

            The position is the number of characters from the text start. New lines and tabs are both counted as one character.

                        Goto Blockstart

            Moves the cursor to the block-begin marker that you already have set with Mark blockstart. The command works even if the block is not displayed (see "Hide/display block" under "Block Commands"), or if the block-end marker is not set.

                        Goto Blockend

            Moves the cursor to the block-end marker that you have already set with Mark Blockend. The command works even if the block is not displayed (see "Hide/display block") or the block-begin marker is not set.

 

 

19.9.1.3.  Insert and Delete Commands

 

            To write a program, you need to know more than just how to move the cursor around. You also need to be able to insert and delete text. The following commands insert and delete characters, words, and lines.You can also insert blocks of text from other files - refer to "The Auxiliary Editor" later in this chapter.

                        Insert Line

            Inserts a line break at the cursor position.

                        Delete character left of cursor

            Moves one character to the left and deletes the character positioned there by backspace. Any characters to the right of the cursor move one position to the left. You can use this command to remove line breaks.

                        Delete character under cursor

            Deletes the character under the cursor and moves any characters to the right of cursor one position to the left. This command works across line breaks, and can be used to remove them.

                        Delete word right of cursor

            Deletes the word to the right of the cursor. A word is defined as a sequence of characters delimited by one of the following characters:

            space < > , ; . ( ) [ ] ^  ' * + - / $

This command does not work across line breaks.  Press Paste to undo a deleted word.

                        Delete from cursor to start of line

            Seletes all text from the cursor position to the beginning of the line. To undo this command press Paste.

                        Delete from cursor to end of line

            Selects all text from the cursor position to the end of the line. To undo this command press Paste.

                        Delete line

            Deletes the line containing the cursor and moves any lines below one line up. To undo a line delete, use Paste.

 

 

19.9.1.4.  Search and Replace Commands

 

            The editor supports search and replace commands that let you search for strings in the text and replace them with other strings. Replacement can optionally be prompted (ask yes/no at each replacement).

                        Search

            Lets you search for a string of up to 45 characters. When you enter this command, the status line is cleared, and the prompt

            search text, text:

appears at the bottom of the Edit window. Enter the string you are looking for and then press Search again. The search string can contain any characters, including control characters. To quit the search operation, use the abort command <Esc>.

                        Search again

            Moves the cursor to the next occurrence of the last used search-string.

                        Replace

            This operation works identically to the Find command, except that you can replace the "found" string with any other string of up to 45characters. First, enter the search string and press Replace, the editor prompts you for the string that will replace the search string. Enter up to 45 characters, press Replace again.

            The next prompt (prompt before replacing (y/n)) can be answered Yes or No: y means you decide whether an occurrence of the string will be replaced, while n means the editor will replace it automatically.

            When the editor finds the items--and of the N option is not specified-it then positions the cursor at the start of the item, and asks

                        Replace Yes/No/Rest (y/n/r) ?

            in the prompt line. You can abort the Find/Replace operation at this point with the Abort command <Esc>. Press the Y-key and the word at the cursor will be replaced with the replace-string, and the cursor moves to the next occurrence of the search string. Press the R-key and this and all subsequent of the search-string on replaced automatically.

                        Replace Again

            Finds the next occurrence of the last used search string and prompts for replacement with the last used replace-string.

                        Wordstar Search and Replace commends

            These four commands is almost identical to the four described above. The only difference is that the user input is terminated with <Enter> and not the commandkeystroke. This means that it's not possible to search for new lines.

 

 

19.9.1.5.  Block Commands

 

            A block of text is any amount of text, from a single character to hundreds of lines, that has been surrounded with special block-marker characters. You can only mark one block in a source text at a time.

            Three different kinds of block-marking commands can be used in the editor, and the commands are: WordStar-like block commands, MultiMate-like block commands and Sprint-like block commands. The overall concept for each of the three command-categories can be summarised as follows:

                        Sprint like commands

            Place the cursor at the beginning at the block - press Block select. Now move the cursor to the blockend (the block will be highlighted as you go). When at the blockend, select a function to be performed of the block.  The block can be either moved or copied to the paste buffer. Later the content of the paste buffer can be pasted into the text with the Paste command.

                        WordStar like commands

            You mark a block by placing a block-begin marker before the first character and a block-end marker after the last character of the desired portion of text. Once the block is marked, you can copy, move, or delete it, or write it to a file.

                        MultiMate like commands

            These commands works on the principle that you use the same key to begin and end a given operation. To abort any block command before it's completed (when it's waiting for input), just press Esc. For instance, to copy a block using the block commands, you press MultiMate copy to start the process (mark the block begin), use the arrow keys to highlight the block, then press MultiMate copy again to mark the block end. After that, you move the cursor to the position where the copy. If you want to insert multiple copies of the marked block, you simply move the cursor with arrowkeys to the new location(s), then press Paste.

                        Block select

            When pressing the Block select command, you enter block marking mode. The block will be highlighted as you move (ahead or back from the starting position). In block marking mode, no characters can be inserted. Pressing a character key causes the cursor to move to the next occurrence of that character, Quit block marking mode by pressing <Esc> of Block select again.

                        Copy block to paste buffer

            The currently marked block is copied to the paste buffer. The command terminates block marking mode, and the previous content of the paste buffer are overwritten.

                        Move block to paste buffer

            The currently marked block is deleted from the text and moved to the paste buffer. the command terminate block marking mode, and the previous contents of the paste buffer are overwritten.

                        Paste

            The contents of the paste buffer are inserted in the text at the current cursor position. The paste buffer itself is not affected by the command.

                        Mark Blockstart

            Marks the beginning of a block. The marker itself is not visible, and the block itself only becomes visible when the block-end marker is set. The marked text (a block) is displayed with a different attribute than theunmarked text (you can choose the attribute for unmarked text with the menu item.

                        Mark Blockend

            Marks the end of a block. The marker itself is invisible, and the block itself becomes visible only when the block-begin marker is also set. Pressing Mark Blockend in block marking mode exit this mode. The block isstill highlighted.

                        WordStar show/hide block

            Causes the visual marking of a block to be alternately switched off and on. The block manipulation commands copy, move, delete, and write to a file work only when the block is displayed. Block-related cursor movements jump to beginning/end of block works both when the block is hidden and displayed.

                        WordStar copy block

            Copies the currently marked block to the paste buffer and thenpastes the contents of the paste buffer at the current cursor position.

                        MultiMate copy block

            Press MultiMate copy block to start the process mark the block begin, use the arrow keys to highlight the block, then press MultiMatecopy block again to mark the block end. After that, you move the cursor tothe position where the copy is to be inserted,then press MultiMate copy block once more to insert the copy. If you want toinsert multiple copies of the marked block, you simply move the cursor with arrow keys to the new locations, then press Paste.

                        MultiMate move block

            Press MultiMate move block to start the process mark the block beginning, use the arrow keys to highlight the block, then press MultiMate move block again to mark the block end. After that, you press MultiMate move block once more to move the block.

                        MultiMate delete block

            Press MultiMate delete block to start the process mark the block beginning, use the arrow keys to highlight the block, then press MultiMate delete block again to delete the block.

 

 

19.9.1.6.  Special Block Commands

 

                        Copy block to printer

            Writes previously marked block to the printer. The block is left unchanged in the current file, and the markers remain in place. If no block is marked, nothing happens.

                        Copy block to file

             Writes a previously marked block to a file. the block is left unchanged in the current file, and the markers remain in place. If no block is marked, nothing happens.

            When you issue this command, the editor prompts you for the mane of the file. To select an existing file to overwrite, use DOS wildcards. A directory appears in a small window on screen, and you can select a file name from this directory. If you type the file name yourself and the file specified already exists, the editor issues a warning and prompts for verification before overwriting the existing file. If you don't give an extension for the file name, the system automatically appends the extension for the current file mask. To specify a file name with no extension, follow the name with a dot.

                        Change case for a block

            Changes case for the currently marked block. Three selections is offered:

            Upper/Lower or Reverse case (u/l/r):

Type u for Upper (all letters in the block is changed to upper case), l for Lower (all letters changed to lower case) or r for Reverse (all letters shift case from lower to upper or from upper to lower).

                        Copy block from file

            Invokes the auxiliary editor in Xcopy mode and pops up the Pick list (a list of the files most recently loaded into the editor, up to seven files). You can select the file to read from this list, or choose..load file.. which will pop up the File name input box.

            You can type in an explicit file name, or use DOS wildcards to form a file mask. If you type in a name, you can specify any legal file name. If you specify no file extension (.PRO, , .BAK, etc.) the editor assumes you want the extension for the current file mask. To read a file that lacks an extension, append a period to the file name.

 

 

19.9.1.9.  Miscellaneous Commands

 

                        Aux edit

            You are asked to enter a filename. This done in the same way as described under Load file. An auxiliary editor pops up a new window with the selected file. After editing the file, press Esc or F10 to return to the original editor. If the file is changed you are asked for a filename (Just press return to save with the same filename) or asked "Are you sure"

(if Esc was pressed).

                        Pop-up help menu

            Shows the key-sequences for all commands. A command can be activated from the help menu simply by pressing return with the cursor on the command. The first entry in the help menu is show help file. If this entry is selected the help file is displayed.

                        Show Help file

            Displays the help file (if a help file is present) in a separate window.

                        Auto indentation

            Provides automatic indentation of successive lines.  When auto indentation is active, the cursor does not return to column one when you press Enter. Instead, it returns to the starting column of the line you just left.

            When auto indentation is On, the message indent shows up on the status line; when it's Off, the message disappears. Auto indent is On by default.

                        Insert mode

            When entering text, you can choose between two basic entry modes: Insert and Overwrite. You can switch between these modes with the Insert mode toggle, (Ctrl-V or Ins). The current mode is displayed in the status line at the top of the screen.

            Insert mode is the editor's default; this lets you insert new characters into old text. Text to the right of the cursor simply moves to the right as you enter new text.

            Use Overwrite mode to replace old text with new. Any characters entered will replace existing characters under the cursor.

                        Text mode

            Use this command to toggle word wrapping between on and off.

                        Lower/Upper/Reverse case word

            Use these three commands to change case for a single word.

                        Exit editor

            The command that exits the editor.

 

 

19.9.1.10.   Global Commands

 

                        Resize window

            Move the window to a new position by holding down the <Shift> key and pressing the appropriate arrow key in the numeric keypad without Caps Lock.

            Change the size of a window by the arrow keys.

                        Zoom window

            The window is zoomed out to the screen-size. Press Zoom window again to return to original size.

                        Previous line

            When the editor prompts for a string (as in Search), pressing Previous line causes the most recently entered string to be shown.

                        File mask

            Press this command when the filename browser in the file-name input box is active. You can then enter the file-mask (e.g. *.sm).

                        Terminate input

            The key to use to terminate user input.

 

 

19.9.2.  Edit Commands

 

                        The Edit Window Status line

            The status line in the top bar of the Edit window gives you information about the source text you are editing, where in the text the cursor is located, and which editing modes are activated:

 

            Line      Col       X:FILENAME.TYP         Insert   Indent   Text mode

 

---------------------------------------------------------------------------

Status              Description

---------------------------------------------------------------------------

Line                  Shows which line number contains the cursor.

Col                   Shows which column number contains the cursor.

X:FILENAME.TYP         Indicates the drive (x:), name (FILENAME), and extension

                                    (.TYP) of the text you are editing.

Insert               Tells you that the editor is in Insert mode: Characters entered on the                              keyboard are inserted at the cursor position, and text in front of the cursor                     moves to the right.

 

                        Use the Ins key or Ctrl-V to toggle the editor between insert mode and                           Overwrite mode.

 

                        In Overwrite mode, text entered at the keyboard overwrites characters under                 the cursor, instead of inserting them before existing text.

 

Indent               Indicates that the auto indent feature is set to On. You toggle it on and off                      with the command Auto indentation.

 

Text mode        Indicates whether text mode (word-wrap mode) is on. You toggle it on and off                 with the command Text mode.

---------------------------------------------------------------------------

 

            Within the Input window, press <F8> to open another window, called the Aux Edit window. In the Aux Edit window, press <F8> again to open another Aux Edit window. So you can open many the Aux Edit windows to edit many files.

            Text in the Input window always be saved after exit by pressing <Esc>. The Aux Edit window is closed with saving by pressing <F10>, or without saving by pressing <Esc>.

            In the Input window or the Aux Edit window, press <F1> to pop-up the Edit Help menu (see 19.9.1 Edit Help Menu), or <Shift><F1> to see the manual, and <F7> to copy block from the an Aux Edit window into the main editor or into the last Aux Edit window.

            Move the cursor around in the editor with the arrow keys, <Page Up>, <Page Down>, and some other keys listed below.  The editor has two typing modes: Insert and Overwrite.  In Insert mode, anything you type is inserted at the cursor position. In Overwrite mode, pressing a key replaces the current character at the cursor position with the new typed character. Initially, the editor operates in Insert mode, to switch modes, press the <Insert> key or <Ctrl>V.  (<Ctrl>V means to hold down the <Ctrl> key on your keyboard while you press V.  The V need not be in upper case.)

            Unlike a more standard word processing program, the editor does not have word-wrap. You must press <Enter> at the end of each line.

            The editor has an auto indent feature that allows subsequent lines to automatically indent.  If you leave several spaces at the start of a line, use <Ctrl>OI to indent subsequent lines the same amount.  The command sequence is a toggle, so you need only press <Ctrl>OI again to stop indenting.

            Sometimes you may want to see more than the area covered by the current window.  You can zoom the window, expanding it to the size of the entire screen, by pressing <F5>.  To return the window to its usual size, press <F5> again.  For other window commands, such as moving and resizing a window, see the window command table, below.

            The editor uses approximately 70 commands, which can be grouped into 6 main categories:

            1. cursor movement commands

            2. insert and delete commands

            3. search and replace commands

            4. file commands

            5. block commands

            6. miscellaneous commands

 

 


              Table 19.9.1  Editor commands.

---------------------------------------------------------------

  Cursor Movement Commands (move cursor to):

.............................................................................

  Line up                                   <Ctrl>E  or Up arrow

  Line down                               <Ctrl>X  or Down arrow

  Character left                          <Ctrl>S  or Left arrow <-

  Character right                                   <Ctrl>D  or Right arrow  ->

  Word left                                <Ctrl>A  or <Ctrl> <-

  Word right                              <Ctrl>F  or <Ctrl> ->

  Beginning of line                     <Ctrl>QS or <Home>

  End of line                              <Ctrl>QD or <End>

  Page up                                  <Ctrl>R  or <Pg Up>

  Page down                             <Ctrl>C  or <Pg Dn>

  Scroll up                                 <Ctrl>W

  Scroll down                             <Ctrl>Z

  Top of screen                         <Ctrl>QE or <Ctrl><Home>

  Bottom of screen                    <Ctrl>QX or <Ctrl><End>

  Top of file                               <Ctrl>QR or <Ctrl><Pg Up>

  Bottom of file                          <Ctrl>QC or <Ctrl><Pg Dn>

  Beginning of block                  <Ctrl>QB

  End of block                           <Ctrl>QK

  Previous point                         <Ctrl>QP

  Goto line                                 <Ctrl>F2

  Goto position                          <Shiift>F2

 

...........................................................

 

  Insert & Delete Commands:

...........................................................

  Insert mode on/off                   <Ctrl>V or <Ins>

  Insert line                               <Ctrl>N

  Delete line                              <Ctrl>Y

  Delete to end of line                <Ctrl>QY

  Delete left character                <Ctrl>H or <Backspace>

  Delete character under cursor <Ctrl>G or <Del>

  Delete right word                    <Ctrl>T

 

...........................................................

 

  Block commands:

............................................................

  Block select                            <Ctrl>KM

  Copy block to paste buffer       <Ctrl>KI

  Move block to paste buffer      <Ctrl>KY

  Paste                                     <Ctrl>U or <Ctrl><F7>

  Mark block begin                    <Ctrl>KB

  Mark block end                       <Ctrl>KK

  Mark word                              <Ctrl>KT

  WordStar show/hide block       <Ctrl>KH

  WordStar copy block               <Ctrl>KC or <Ctrl><F5>

  Repeat the last copy               <Shift><F5>

  WordStar move block              <Ctrl>KV or <Alt><F6>

  MultiMate copy block              <Ctrl><F5>

  MultiMate move block             <Alt><F6>

  MultiMate delete block            <Alt><F7>

  Delete block                           <Ctrl>KY

  Read block                             <Ctrl>KR or <F7>

 

.....................................................................

 

  Special Block functions

....................................................................

  Copy block to printer               <Ctrl>KP or <Alt><F8>

  Copy block to file                    <Ctrl>KW or <Alt><F5>

  Copy block from file                <Ctrl>KR or <F7>

  Change case for block                        <Ctrl>KE or <Ctrl><F6>

 

.....................................................................

 

  Miscellaneous Commands:

.....................................................................

  Quit edit                                 <Esc>, <F10>, <Ctrl>KD, or <Ctrl>KQ

  Call the auxiliary editor                        <F8>

  Tab                                        <Ctrl>I  or <Tab>

  Tab mode toggle                     <Ctrl>OT

  Auto indent on/off                    <Ctrl>OI

  Restore line                            <Ctrl>QL

  Find                                        <Ctrl>QF or <Ctrl><F3>

  Repeat last find                       <Ctrl>L  or <Shift><F3>

  Find & replace                        <Ctrl>QA or <Ctrl><F4>

  Repeat last find & replace       <Ctrl>L  or <Shift><F4>

  Control key prefix                   <Ctrl>P

  Abort operation                       <Ctrl>U

  Restore error message           <Ctrl>QW

 

...................................................................

 

  Global Commands

...................................................................

  Resize window                        <Shift><F10>

  Zoom window                          <F5>

  Previous line                           <F8>

  File mask                               <F4>

  Terminate input                                   <F10>

------------------------------------------------------------------

 

 

 

 

            Table 19.9.2   Edit window commands

---------------------------------------------------------------------

Action                                       Keystrokes

 

help                                          <F1>

zoom in window                        <F5>

zoom out window                      <F5>

resize window                           <Shift><F10>, the arrow keys, <F10>

move window                            <Shift><F10>, <Shift> and the arrow key in numeric

                                                keypad without Caps Lock

open an Aux Edit window                                   <F8>

close the Aux Edit window with saving               <F10>

close the Aux Edit window without saving          <Esc>

copy block from an Aux Edit window                  <F7>

-----------------------------------------------------------------------------------------------------------------

 

 

19.9.3. Copy and Paste

 

            You can copy-and-paste text anywhere in a file and between files, even from the Help window. In this way you do not need to remember syntax of the SymbMath commands.

            You move the cursor to the beginning of text you want to copy, press <F1>, select the Block Function menu and press <Enter>, select the Block Select command and press <Enter>, move the cursor to the end of text you want to copy, press <F1>, select the Copy Block To Paste buffer command and press <Enter>, press <Esc>, go into the Input window, move the cursor to a place where you want to paste, press <F1>, select the Paste command and <Enter>.

 

 


20.   Inside SymbMath

20.1.  Internal Structure

 

            As an expert system, SymbMath consists of three major components: a knowledge base, an inference engine, and a global database. The knowledge base is a set of rules, the inference engine is a rule interpreter for utilising the knowledge base in the solution of the problem, and the global data base is a working memory for keeping track of the problem status, the data from the data file for the particular problem, and the solution of sub-problems. In addition, it contains a natural language interface for input and output natural languages (e.g. mathematical formulas, chemical reactions).

 

 

                        User    Library         disk

                         /|\       |                              /|\

                          |        |                    |

                         \|/      \|/                  \|/

                        ---------------------------------------

                        | Natural Language Interface |

                        --------------------------------------

                                           /|\

                                            |

                                           \|/

                        ------------------------------

            ------->|    Inference Engine     |<----------

            |           ------------------------------            |

           \|/                                                      \|/

-------------------------                           --------------------------

| Knowledge Base |                          | Global Data Base |

-------------------------                           --------------------------

                                                                   /|\

                                                                    |

                                                            --------------------

                                                            |    Data File     |

                                                            --------------------

 

            Figure 20.1      Structure of SymbMath

 

 


 

            Table 20.1      Characteristics of SymbMath

--------------------------------------------------------------------

Function:                                  Symbolic computation.

Domain:                                    Mathematics, chemistry.

Search direction:                       Forward chaining.

Control mechanism:                  Guessing and test, pattern match.

Search space transformations:  Break into sub-problems.

Knowledge base representation: Rules.

Developer interface:                  Learning, programming, library.

User interface:                          Pull-down menu, pop-up menu, multi-windowed editor, help,                                           windows.

System interface:                      numeric computation software, graphic software, etc.

Input format:                             Math formulas, numbers, BASIC or FORTRAN codes,                                                   chemical symbols and reactions.

Output format:                          Math notation, BASIC or FORTRAN codes,

                                                chemical reaction equations.

Input from:                                Keyboard, disk.

Output to:                                 Screen, disk, printer.

Tool language:                          PROLOG.

Computer:                                IBM PC.

Memory:                                   400 KBytes.

Operating system:                    MS-DOS.

---------------------------------------------------------------------

 

 

 

20.2.  Internal Format

 

            You can peep at the internal format in the SymbMath system by setting output := prolog. This is useful for understanding SymbMath.

            Example:

IN:  output := prolog

IN:  a+b

OUT: plus(var("a"),var("b"))

 

 

21. System Limits

 

            1. The maximum character of a symbol is 64000.

            2. The maximum character of an expression is 64000.

            3. The range of the input real numbers is

-inf, -(10^300)^(10^300) to -10^(-300), 0, 10^(-300) to (10^300)^(10^300), inf.

            4. The range of the output real numbers is the same as input when the switch numeric:=off, but when the switch numeric:=on, it is

            -inf, -1.E300 to -1.E-300, 0, 1.E-300 to 1.E300, inf.

            5. The maximum digit of the input numbers is 64000.

            6. The maximum digit of the stored numbers is 16.

            7. The maximum digit of the output numbers is 11.

            8. The maximum digit of the rational numbers is 16.

            9. The maximum arguments of the user-defined function with pattern is 7.

 

 

           

22. Keywords

 

            SymbMath has two versions: Shareware Version A, and Advanced Version C. The Shareware version lacks the solve(), trig (except sin(x) and cos(x)), and hyperbolic functions, (lack 10% keywords). You cannot input these lack functions in Shareware or student version.

            Upper-case and lower-case letters are different. All keywords are lower-case letters except the If keyword.

            There are two types of the functions: internal and external. The internal functions have been compiled into the SymbMath system, so you cannot change them. The external functions are the function file name, so you can change their name. Usages of both types are the same.

            The keywords include the internal and external function name, the constant name and operators. You can define your own keyword and add your defined function. If they do not work, you should check whether or not the function name is the exact same as in the default function library directory because the name is case sensitive.

 

22.1.     Internal Functions

See its developer document.

 

 

22.2.     External Functions

 

            The external function can be used as standard functions by its file name without extension, e.g. abs(x), not abs.txt. You can add your own file to the library.

-------------------------------------------------------------------------------------------------------------------------

abs

acot             acoth            acsc

acsch            asec             asech

assume           atan             binomial

cis              combination      cos

d                def              define

definition       diff             digamma

dsolve           dt               ei

erfc             erfi             exp

expand           factor           factorial2

factorialpower   for              gamma

im               infsum           int

integrate        integrates       inverse

isatom           iseven           isinteger

isnumber         isodd            laplace

lg               li               lim

limit            ln               log

log10            max              min

n                nint             nlim

not              nsolve           plot

polygamma        prime            prod

product          psi              psolve

re               series           sgn

si               simplify         sin

sinc             sinh             solve

sum              tangent          taylor

theta            value            zeta

 --------------------------------------------------------------------

 

22.3.    Keywords in Alphabetical Order

The keywords include the system keywords, internal and external function name. You can add your own file to the library to become keywords.

---------------------------------------------------------------------------------------------------

acosh                           acot                  acoth                acsc                 acsch  

and                   arc                   arg                   argue              asec   

asech              asin                  asinh                assume            assumed

atan                  atan2                atanh                                        average

base                 basic                block                ci                     circle 

clear                 cleared                         closefile            coef                  coefall

colorno                         concat                          constant           cos                   cosh   

cot                   coth                  csc                   csch                 c_inf  

d                      dataplot                        degree              deno                 diff   

discont            div                    do                    done                 dotplot

dottime                         dsolve             e                      ei                     ellipse

else                  erf                    eval                  exp                   expand 

expandall          expandde          expandexp        f(x)                   fac    

factor               fortran              frac                  from                 gamma  

                        getbkcol           getcolor                        getmaxx           getmaxy

getx                 gety                 graph              grid                  i      

If                      im                    inf                    infsum                          int    

int                    iscomplex         iseven             isfree                isinteger

islarger             isless               islist                 isnumber          isodd  

isratio               isreal                issame             laplace             last   

left                   length               li                      lim                    line   

linerel               lineto                list                    listplot              listsum

ln                     log                   log10                lowercase         math   

max                  member            min                   mod                  moverel

moveto             mult                  newline             nint                   nlim   

not                   nsolve              null                   num                  number 

nume                numeric            off                    on                    openfile

or                     order                output               oval                  paraplot

partsum            pi                     plot                   power                           prod   

prolog               psolve             putpixel             random             ratio  

re                     readchar           readfile             readline                        repeat 

reverse             right                 root                  round                sec    

sech                 sequence         series               setbkcolor        setcolor

setlinestyle       settextjustify     settextstyle       setviewpoint     si     

sign                  sin                    sinh                  solve                sqrt   

step                  string               subs                 sum                  system 

table                 tan                   tanh                  term                 text   

                                                trunc                type                  undefined

                        writes               zero

 

+                      -                       *                       /                       ^

*                       ()                      []                      =                      :=

==                    >                      >=                    <                      <=

<>                    !                       #                      ,                       |x|

"x"                    '                       ;

--------------------------------------------------------------------------------------------------

 


 

22.4.     Keywords in Topic Order

---------------------------------------------------------------------

Arithmetic operators:

     +, -, *, /        plus, minus, times, division

     ^                  power

     ()

 

Relational operators:

     ==               equals

     >                 greater than

     >=               greater than or equal

     <                 less than

     <=               less than or equal

     <>               not equal

 

Assignments:

     :=               

 

Equation:

     =

     solve(x^2=1,x)                     solve x^2=1 for x                     

     nsolve(cos(x)=x,x)               numerically solve f(x)=0 for x with initial x0=1

     nsolve(f(x)=0,x,x0)               numerically solve f(x)=0 for x with initial x0

     dsolve(y'=f(x,y), y,x)                        solve differential equation y’=f(x,y) for y(x)

 

Comment:

     #

 

Built-in constants:

     i, e, pi, inf, zero, constant, discont, c_inf, undefined, NaN.

 

Built-in variables:

     last

 

Logic operators:

     and, or, not(x)

 

Algebraic functions:

     -x                            minus x

     sqrt(x)                     sqare root of x

     n!                            factorial of n

     fac(n)                      faction of n

     mod(x,y)                  reminder on division of x by y

     div(x,y),                   integer divide x by y

     random                    random number 0<= x<1

     random(x)                random number <= x

     expand(x)                expand x

     factor(x)                  factor x

     factor(y,x)

     root(x,n)                  all n-th roots of x

 

Complex to real:

     re(x)                                    real part of the complex number x

     im(x)                       imaginative part of the complex number x

     abs(x)                      absolute value of x

     |x|                            absolute value of x

     arg(x)                      argument of complex number x

     sign(x)                     sign of complex number of x

 

Exponential functions:

     exp(x)                      natual expoential of x, exp(x)=e^x

     ln(x)                        natual logarithm of x

     log10(x)                   log of x to base 10

 

Trig functions:

     sin(x)                       sine of x

     cos(x)                      cosine of x

     tan(x)                      tangent of x

     csc(x)                      cosecant of x

     sec(x)                      secant of x

     cot(x)                      cotangent of x

 

Inverse trig functions:

     asin(x)                     angle whose sine is x

     acos(x)                    angle whose cosine is x

     atan(x)                     angle whose tangent is x

     acot(x)                     angle whose cotangent is x

     asec(x)                    angle whose secant is x

     acsc(x)                    angle whose cosecant is x

     atan2(x,y)                angle whose tangent is x/y

 

Hyperbolic functions:

     sinh(x)                     hyperbolic sine of x

     cosh(x)                    hyperbolic cosine of x

     tanh(x)                     hyperbolic tangent of x

     csch(x)                    hyperbolic cosecant of x

     sech(x)                    hyperbolic secant of x

     coth(x)                     hyperbolic cotangent of x

 

Inverse hyperbolic functions:

     asinh(x)

     acosh(x)

     atanh(x)

     acoth(x)

     acsch(x)

     asech(x)

 

Special math integral functions:

     ei(x)                        expoential integral function

     ei(n,x)                      incomplete exponential integral function integrate(t^n*e^t, t,-inf,x)

     gamma(n)                gamma function integrate(t^(n-1)*e(-t), t,0,inf)=(n-1)!

     gamma(n,x)             incomplete gamma function integrate(t^n*e(-t), t,0,x)

     erf(x)                       error function 2/sqrt(pi)*integrate(e^(-t^2),t,0,x)

     si(x)                        sine integral function integrate(sin(x)/x)

     ci(x)                        cosine integral function integrate(cos(x)/x)

     li(x)                         log integral function integrate(1/ln(t), t,0,x)

     li(n,x)                       incomplete log integral function integrate(ln(t)^n, t,0,x)

 

Defining functions:

     f(x_) := x^2;

     f(x_) := If(x>0 , x^2);

 

Defining procedures:

     f(x_) := block(p:=x^2,p);

 

Defining rules:

     log(x_ * y_) := log(x)+log(y);

     d(f(x_),x_) := sin(x);

 

Clear:

     clear(x)                    clear variable x

     clear(f(x))                clear function f(x)

     clear(a>0)                clear unequal a>0

 

Calculus functions:

Differentiating:

     d(y,x)                      differentiate y with respect to x

     d(y,x,n)                    differentiate y with respect to x in the n-th order

     d(y,x=x0)                 differentiate y with respect to x at x0

     d(y,x=x0,n) differentiate y with respect to x at x0 in the n-th order

 

Integrating:     

     integrate(y,x)                       integrate y with respect to x

     integrate(y,x,xmin,xmax)      integrate y with respect to x from xmin to xmax

     nintegrate(y,x,xmin,xmax) numerically integrate y w.r.t. x from xmin to xmax

 

Substituting:

     subs(y,x=x0)                       substitute x by x0 in y

 

Limit:   

     lim(y,x=x0)              limit of y as x  -> x0

     lim(y,x=x0+zero)      limit of y as x  -> x0 from right

     lim(y,x=x0-zero)       limit of y as x  -> x0 from left

     nlim(y, x=x0)           numeric limit of y as x  -> x0

 

     laplace(y,x)              Laplace transform

 

     sum(y, x,xmin,xmax,dx)       sum of y with x from xmin to xmax step dx

     sum(y,x,a,b)                                    partial sum of y

     sum(y,x)                              indefinite sum of y

 

     prod(y, x,xmin,xmax,dx)       product of y w.r.t x from xmin to xmax step dx

 

     series(y,x)               series of y at x=0 to order of 5

     series(y,x,order)      series of y at x=0 to order

 

Conversion functions:

     ratio(x)                    convert real number to ratio

     round(x)                   convert x to the rounded integer closet to x

     trunc(x)                   convert x to the truncated integer closet to x

     nume(a/b)                numerator of a/b

     deno(a/b)                 denominator of a/b

     number(x)                convert a string to a number

     string(x)                  convert a number to a string

     term(a+b)                a list of terms

     multi(a*b)                 a list of multipliers

     type(x)                     type of x

     gcd(a,b)                   the greatest common divider of a and b

 

Table:

     table(x)                    produce a table of the function values from x=-5 to 5 with step 1

     table(x,xmin,xmax)  produce a table of the function values from x=xmin to xmax on step 1

     table(x,xmin,xmax,dx)          produce a table of the function values from x=xmin to xmax                                           with step dx

 

Numeric computation:

     num(x)                                 numeric value of x

     nsolve(cos(x)=x,x)               numerically solve cos(x)=x w.r.t. x with initial x0=1

     nsolve(cos(x)=x,x,x0)          numerically solve cos(x)=x w.r.t. x with initial x0

     ninte(y,x,xmin,xmax)                        numerically integrate y w.r.t. x from xmin to xmax

     nlim(y,x=x0)                        numerica limit of y w.r.t. x at x0

     numeric:=on                         numeric switch on

 

Test functions:

     isodd(x)                   test if x is odd

     iseven(x)                 test if x is even

     isinteger(x)              test if x is integer

     isratio(x)                  test if x is rational number

     isreal(x)                   test if x is real

     iscomplex(x)                        test if x is complex

     isnumber(x)             test if x is a number

     islist(x)                    test if x is a list

     isfree(y,x)                test if y is free of x

     issame(x,y)             test if x is same as y

     islarger(a,b)             test if a is larger than b

     isless(a,b)               test if a is less than b

     type(x)=="real"         test if x is real

 

Vector or list:

     [a,b]                         vector or list

     [list(y,x,xmin,xmax)]

     member([a],j)           the j-th member of a list [a]

     last[1]                      the first member of the last list

     reverse([x])              reverse a list x

     a[1]                          list index, the first member of a list a

     dottime(a,b)             dot product of vectors a and b

    

Matrix or array:

     [[a11,a12],[a21,a22]]             matrix or array

     a[a[1]]

 

Statistics:

     average([a,b])          avergae of a list of [a,b]

     max([a,b])                max of a list of [a,b]

     min([a,b])                 min of a list of [a,b]

     listsum([a,b])           convert a list of [a,b] to sum a+b

     length([a,b])             length of a list of [a,b]

 

Comma:

     ,

    

 

Assume:

     assume(a>0)           assume a > 0

     isreal(x):=1              assume x is real

 

Conditional:

     If(x>0 , x)                if x > 0 then x

     If(x>0 , x , -x)          if x > 0 then x else -x

 

Loop:

     repeat(expr , x>5)    repeat expr unti x>5

     do(expr, x,xmin,xmax,dx)     do expr w.r.t. x from xmin to xmax with step dx, last output

     list(y,x,xmin,xmax)              do expr w.r.t. x from xmin to xmax with step dx, all output

 

 

String:

     "123"                       string

     concat("a","b")         concate “a” and “b”

     break("ab",1)            break “ab” from the first member

     length("a")               length of “a”

     string(1)                  convert a number to a string

 

Getting parts:

     type(x)                     type of x

     left(a=b)                   left side of a=b

     right(a=b)                right side of a=b

     term(a+b)               

     multi(a*b)

     coef(y,x)                  coefficeint of x in y

     coef(y,x,n)               coefficeint of x with the n-th order in y

     coefall(y,x)              a list of all coefficients of x in y from low to high, order <5.

     power(x^n)               powe, give n

     base(x^n)                base, give x

     argue(x)                  argument of function, argue(f(x)) gives x

     sequence(x)

     re(x)                                    real part

     im(x)                       imaginative part

     int(x)                       integer part

     frac(x)                     fractional part

 

Database:

     phoneno(x)              phone number

     colorno(x)                color number

     atom_wei(x)             atomic weight

 

Graph:

     graph                       graph mode

     text                          text mode

     cleardevice              clear graph screen

 

     line(x1,y1,x2,y2)      draw a line from point (x1,y1) to (x2,y2)

     lineto(x,y)                draw a line from current point to (x,y)

     linerel(dx,dy)                        draw a line from current point by (dx,dy)

     arc(x,y,r,t1,t2)          draw arc at (x,y) with radia r from angle t1 to t2

     ellipse(x,y,angle1,angle2,xRadius,yRadius)

                                    draw an ellipse arc from angle1 to angle 2 with xRadius and yRadius                             as the horizontal and vertical axes at point (x,y)

     circle(x,y,r)              draw a circle at (x,y) with radia r

     oval(x,y,xr,yr)          draw an oval at (x,y) with x radia xr and y radia yr

     putpixel(x,y,color)    put pixel at (x,y) with color       

 

     moveto(x,y)             move current pointer to (x,y)

     moverel(dx,dy)         move current pointer by (dx,dy)

 

     setviewport(x1,y1,x2,y2,clip)                        set view port from (x1,y2) to (x2,y2)

     setlinestyle(style,dir,thick)                set line style

     settextstyle(font,dir,size)                  set text style

     settextjustify(hor,ver)

     setcolor(colorno)                              set color

     setbkcolor(colorno)                          set background color

 

     getbkcolor               get background color

     getcolor                   get color

     getx                         get x of current pointer

     gety                         get y of current pointer

     getmaxx                  get max x of screen

     getmaxy                  get max y of screen

 

     plot(y,x)                   plot y w.r.t. x from x=-5 to 5, from y=-5 to 5

     plot(y,x,xmin,xmax) plot y w.r.t. x from x=xmin to xmax, from y=-5 to 5

     plot(y,x,xmin,xmax,ymin,ymax)       

                                    plot y w.r.t. x from x=xmin to xmax, from y=ymin to ymax

     dotplot(x^3,x)

     dotplot(y,x,xmin,xmax)

     dotplot(y,x,xmin,xmax,ymin,ymax)

 

     paraplot(x(t),y(t),t)               parametric plot x(t) and y(t) w.r.t. t from t=0 to 2*pi

     paraplot(x(t),y(t),t,tmin,tmax)            parametric plot x(t) and y(t) w.r.t. t from t=tmin to tmax

 

     polaplot(r(t),t)                       polar plot r(t) w.r.t. t from t=0 to 2*pi

     polaplot(r(t),t,tmin,tmax)       polar plot x(t) and y(t) w.r.t. t from t=tmin to tmax

 

     dataplot([x1,x2],[y1,y2])        plot a set of data

     dataplot([x1,x2],[y1,y2],xmin,xmax,ymin,ymax)                    

                                                plot a set of data from xmin to xmax, from ymin to ymax

 

     listplot([y1,y2])                     plot a list of data

----------------------------------------------------------------------------------------------------------------

 


 

22.5.     Glossary

 

            The keywords that mark as internal are the internal system functions or constants, otherwise they are external.

 

----------------------------------------------------------------------------------------------------------------------------

* abs                                                                             internal + external

abs(x) is the absolute value function of x. x can be complex numbers. abs(x) = sqrt(re(x)^2+im(x)^2). The results are in the range 0 to inf. abs(x) = |x|.

See also: abs, arg, sign, re, im, |x|.

e.g.

IN:  abs(-1), abs(-i)

OUT: 1, 1

 

* acos

acos(x) is the arc cosine function of x. The inverse function of cos(x). The result is given in radians.

See also: acos, cos.

 

* acosh

acosh(x) is the inverse hyperbolic cosine function of x. The inverse function of cosh(x).

See also: acosh, cosh.

 

* acot

acot(x) is the arc cotangent function of x. The inverse function of cot(x). The result is given in radians. acot(x)=pi/2-atan(x).

See also: acot, cot.

 

* acoth

acoth(x) is the inverse hyperbolic cotangent function of x. The inverse function of coth(x). acoth(x)=atanh(1/x).

See also: acoth, coth.

 

* acsc

acsc(x) is the arc cosecant function of x. The inverse function of csc(x). The result is in radians. acsc(x)=pi/2-asin(x).

See also: acsc, csc.

 

* acsch

acsch(x) is the inverse hyperbolic cosecant function of x. The inverse function of csch(x). acsch(x)=asinh(1/x).

See also: acsch, csch.

 

* and                                                                                        internal

logic operator. It is bitwise and. The result is 1, 0 or unevaluated.

See also: and, or.

e.g.

IN:  1 and 1, 1 and 0

OUT: 1, 0

 

* arc                                                                                          internal

arc(x,y,angle1,angle2,radius) draws a circular arc from angle1 to angle2 with radius at point(x,y). The angles are counter-clockwise with 0 degrees at o'clock, 90 degrees at 12 o'clock, and so on. It only works on graphics mode.

See also: arc, ellipse, line, lineto, linerel, putpixel.

e.g.

IN:  graph, arc(100,100,0,180,100), readchar, text

 

* arg

arg(x) gives the argument (phase angle) of x in radians. It only gives the principle value (P.V.): -pi < arg(x) <= pi. arg(x) = atan2(re(x),im(x)). x can be complex number. For positive real x, arg(x)=0.

See also: abs, arg, sign, atan2.

e.g. num(arg(i)) gives 1.5..

 

* argue                                                                                     internal

argue(f(x)) gives the argument of the function f(x). type(f(x)) gives the function name.

See also: type.

e.g. argue(sin(x)) give x, type(sin(x)) gives "sin()".

 

* asec

asec(x) is the arc secant function of x. The inverse function of sec(x). The result is given in radians.

See also: asec, sec.

 

* asech

asech(x) is the inverse hyperbolic secant function of x. The inverse function of sech(x). asech(x)=acosh(1/x).

See also: asech, sech.

 

* asin

asin(x) is the arc sine function of x. The inverse function of sin(x). The result is given in radians.

See also: asin, sin.

 

* asinh

asinh(x) is the inverse hyperbolic sine function of x. The inverse function of sinh(x).

See also: asinh, sinh.

 

* assume

assume(x > 1) assumes the variable x > 1 in real domain.

            By default, |x| < inf and all variables are complex, except that variables in inequalities are real, as usual only real numbers can be compared. e.g. x is complex in sin(x), but y is real in y > 1.

            You can restrict the domain of a variable by assuming the variable is even, odd, integer, real number, positive or negative. The assume() can be cleared by clear().

See also: sign, isodd, iseven, isinteger, isreal, isnumber, clear.

e.g. assume(x>0), assume(x>0, y<0), iseven(x):=1

 

* assumed

assumed points out that the variable has been assumed.

See also: assume, clear.

 

* atan                                                                            internal + external

atan(x) is the arc tangent function of x. The inverse function of tan(x). The result is given in radians.

See also: atan, tan.

 

* atan2                                                                                     internal

atan2(x,y) returns the radian angle of (x,y).

   atan2(x,y)      = sign(y)*pi/2  if x=0

                        = atan(y/x)     if x>0

                        = atan(y/x)+pi  if x<0, y>=0

                        = atan(y/x)-pi  if x<0, y<0 .

Thus atan2(x,y) takes its value of -pi < atan2(x,y) <= pi.

See also: atan, arg.

 

* atanh

atanh(x) is the inverse hyperbolic tangent function of x. The inverse function of tanh(x).

See also: tanh.

 

* average

average(x) gives average of a list of data.

See also: max, min, length, listsum.

e.g.

IN:  average([1,2,3]

OUT: 2

 

* base                                                                                       internal

base(x^n) gives the base of x^n.

See also: base, power, type.

e.g. base(x^n) gives x, type(x^n) gives "^", power(x^n) gives n.

 

* basic                                                                                      internal

basic is a value of the switch output. It sets output in BASIC format.

See also: output, on, off, fortran, prolog, math.

e.g. output := basic.

 

* block                                                                                      internal

block(a,b,c) groups a,b,c and only returns the last argument as its value, or returns the second last argument as its value if the last argument is local(). It is used as grouper in definition of a procedure. All variables in block are global, except for variables declared by local().

See also: local.

e.g. f(x_):=block(p:=x^6,p, local(p))

 

* break                                                                                                          internal

break("ab",n) breaks a string into two strings in position of the n-th characters.

e.g. break("ab",1) gives [a,b].

 

* ci

ci(x) is cos integral, ci(x) = integrate(cos(x)/x, x).

See also: si, ei, gamma, erf.

 

* circle

circle(x,y,radius) draws a circle at point(x,y) with radius.

See also: graph, arc, oval.

e.g. graph, circle(200,200,100), readchar, text

 

* clear                                                                                      internal

clear(y) clears values and definitions for the variable, function or expression y from memory.

See also: assume, :=.

e.g. clear(p), clear(f(x)), clear(a>0)

 

* cleared                                                                                  internal

It says that the variable, function or expression has been cleared from assignment.

See also: clear, assume, :=.

 

* closefile                                                                                internal

closefile("filename") closes the file "filename" and return the output to screen. The filename is any MS-DOS file name.

See also: openfile, readfile.

 

* coef                                                                           internal + external

coef(y,form) gives the coefficient of form in the polynomial y. It picks only terms that contain the particular form specified. x is not considered part of x^6.

See also: coefall.

e.g.

IN:  coef(2*x^6+x+4, x^6), coef(2*x^6+x+4, x)

OUT: 2, 1

 

coef(y, x, order) gives the coefficient of x with order in the polynomial

y.  order < 5.

e.g.

IN:  coef(x^2+x+6, x, 0)

OUT: 6

 

* coefall                                                                                   internal

coefall(y, x) gives a list of all coefficients of x in the polynomial y. order < 5.  The polynomial is in order from low to high.

See also: coef.

e.g.

IN:  coefall(6+5*x+x^2, x)

OUT: [6, 5, 1]

 

* concat                                                                                   internal

concat("a","b") concatenates 2 string into one string.

See also: remove, string.

e.g. concat("a","b") gives "ab".

 

* constant                                                                     internal+external

The indefinite integral constant. It only appear on solving differential equation, be omitted on indefinite integral.

See also: dslove, pi, e.

 

* cos                                                                             internal + external

cos(x) is the cosine function of x. The angle x is measured in radians (multiply by degree to convert from degrees). x can be complex numbers.

See also: acos, sec.

 

* cosh

cosh(x) is the hyperbolic cosine function of x. cosh(x)=(exp(x)+exp(-x))/2. x can be complex numbers.

See also: acosh.

 

* cot

cot(x) is the cotangent function of x. The angle x is measured in radians. (multiply by degree to convert from degrees). cot(x)=1/tan(x).

See also: acot, tan.

 

* coth

coth(x) is the hyperbolic cotangent function of x. coth(x)=1/tanh(x).

See also: acoth, tanh.

 

* csc

csc (x) is the cosecant function of x. The angle x is measured in radians (multiply by degree to convert from degrees). csc(x)=1/sin(x) x can be complex numbers.

See also: acsc, sin.

 

* csch

csch(x) is the hyperbolic cosecant function of x. csch(x)=1/sinh(x). x can be complex numbers.

See also: acsch, sinh.

 

* c_inf                                                                                      internal

The complex infinite, both real and imaginary parts of complex numbers are infinity, as the built-in constant. complex_inf=inf+inf*i, inf-inf*i, -inf+inf*i, or -inf-inf*i.

See also: inf, zero.

 

* d                                                                                 internal + external

d() gives the partial derivative.                    

 

d(y,x)                                                                                       internal

It differentiate y with respect to x.

e.g. d(x^2,x) gives 2*x.

d(f(x),x) is the same as f’ .

e.g. d(sin(x),x) gives cos(x).

 

d(y, x, n)

It gives the n-th order derivative of y with respect to an undefined variable x. It can be any fractional order, e.g. 0.5 order.

e.g. d(sin(x),x,2) gives -sin(x).

 

d(y,x,=x0, n)

It gives the n-th order derivative of y at x=x0.

 

See also: diff, f’, lim, int, nint.

 

* degree

degree gives the number of radians in one degree. degree=pi/180. You can multiply by degree to convert from degree to radians.

See also: pi.

e.g. 45*degree, sin(45*degree).

 

* deno                                                                                       internal

deno(x) gives denominator of x. It only works for rational number.

See also: nume.

e.g. deno(2/3) gives 3.

 

* diff

diff(y,x) hold differentiation of y with  x.

See also: d, int, lim.

 

* div                                                                                         internal

div(a,b) divides a by b in integer.

See also: mod.

e.g. div(5,2) gives 2, mod(5,2) gives 1.

 

* discont                                                                                  internal

The discontinuity. If f(x0) gives discont, the function has a discontinuity and only has the one-sided value at x=x0. You should evaluate its left-sided or right-sided value by f(x0-zero) or f(x0+zero).

See also: zero, inf.

e.g.

IN:  f(x_) := 1/x+1

IN:  f(0)

OUT: discont

IN:  f(0+zero)

OUT: inf

 

* do                                                                                          internal

do(expr, x,xmin,xmax,dx) evaluates expr with the x looping from xmin to xmax on step dx.

See also: repeat, list.

e.g.

IN:  x:=0, do(x:=x+1, j,1,5,1)

OUT: x := 5

 

* done                                                                                       internal

It indicates that the command has been done. See also: assumed, cleared.

 

* dotplot

dotplot(y, x) plots y with dots.

dotplot(y, x,xmin,xmax)

dotplot(y, x,xmin,xmax,ymin,ymax)

See also: plot, polaplot, paraplot.

e.g. dotplot(x^3, x)

 

* dsolve

dsolve(y'=f(x,y), y, x) solves the first order variables separable and linear differential equations. The y' must be alone on the left hand side of the equations.

See also: solve, nsolve.

e.g. dsolve(y' = sin(x), y, x)

 

* E                                                                                           internal

E is the exponential part of a floating point number.

See also: e, exp.

e.g. 1.1E2 is the same as 1.1*10^2.

 

* e                                                                                 internal + external

(1) e is the exponential constant (base of natural logarithms), e=2.718..., the built-in constant, e is converted to 2.718... when the switch numeric:=on. e^x is the same as exp(x).

e.g. e^2, e^x.

(2) e is the exponential part of a floating point number, the same as E.

e.g. 1.1e2 is the same as 1.1E2.

See also: E, exp.

 

* ei

ei(x) is the exponential integral function Ei(x), ei(x) = integrate(e^t/t, t,-inf,x), ei'(x) = e^x/x.

 

ei(n,x) is the incomplete exponential integral function, ei(n,x) = integrate(t^n*e^t, t,-inf,x), d(ei(n,x),x) = x^n*e^x, ei(-1, x) = ei(x), ei(0,x) = e^x.

See also: gamma, erf, ci, si, li.

 

* ellipse                                                                                   internal

ellipse(x,y,angle1,angle2,XRadius,YRadius) draws an elliptical arc from angle1 to angle2 with XRadius and YRadius as the horizontal and vertical axes at point(x,y). The angles are counter-clockwise with 0 degrees at o'clock, 90 degrees at 12 o'clock, and so on. it only works on graphics mode.

See also: arc, ellipse, line, lineto, linerel, putpixel.

e.g.

IN:  graph, ellipse(100,100,0,180,200,100), readchar, text

 

* else

comma. The same as comma ,. The 6 keywords: from, to, step, then, else, until are the same as comma ,.

See also: from, to, step, then, until, ,.

 

* eval                                                                           internal

eval(y) evaluates y. It is only used in definition of a function.

e.g.

IN:  f(x_):= eval(sin'(x))

OUT: f(x_) := cos(x).

 

* erf

erf(x) is the error function of x. It is the probability integral  function or the integral of the Gaussian distribution. erf(x) = 2/sqrt(pi)*integrate(exp(-t^2),t,0,x), d(erf(x),x) = 2/sqrt(pi)*e^(-x^2).

See also: ei, gamma, ci, si.

 

* exp                                                                            internal

exp(x) is the exponential function of x (base of e). The same as e^x, e=2.718... It is the inverse to ln(x). x can be complex numbers.

See also: e, E.

 

* expand                                                                       internal

(1) expand(y)  expands out products and positive powers in y. expand() works only on positive integer powers.

See also: factor.

e.g. expand((a+b)^2) gives a^2 + 2*a*b + b^2.

 

(2) the switch of expansion.

expand:=on       e.g. c*(a+b) to c*a+c*b.

expand:=off      disable expansion, this is default.

See also: expandexp.

 

* expandexp                                                                              internal

The switch of exponential expansion.

expandexp:=on       e.g. c^(a+b) to c^a*c^b.

expandexp:=off      disable exponential expansion, this is default.

See also: expand.

 

* f’

f’ differentiates f(x) with respect to x. f’=d(f(x),x). f'(x0) is different from d(f(x), x=x0): f'(x0) first evaluates f(x0), then differentiates the value of f(x0); d(f(x), x=x0) first differentiates f(x), then replace x = x0.

See also: d.

 

* fac

fac(n) is the factorial function of n. The same as n!.

See also: n!.

e.g. fac(3) gives 6.

 

* factor                                                                        internal + external

factor(y)                                                                       internal

It factorises y.

See also: expand, expandexp.

e.g.

IN:  factor(a^2 + 2*a*b + b^2)

OUT: (a+b)^2

 

factor(y, x)

It factorises y for x. y must be polynomial with order < 5.

e.g.

IN:  factor(x^2+5*x+6, x)

OUT: (2+x) (3+x)

 

* fortran                                                                                   internal

fortran is the value of the switch output. It forces the output in FORTRAN format.

See also: output, basic, math, prolog, on, off.

e.g. output:=fortran.

 

* frac

frac(x) gives the fractional part of number x. frac(x)=x-trunc(x).

See also: int, trunc.

e.g. frac(2.4) gives 0.4.

 

 

* gamma

gamma(n) is the gamma function _(n), gamma(n) = integrate(t^(n-1)*e^(-t), t,0,inf), gamma(n) = (n-1)!.

 

gamma(n,x) is the incomplete gamma function, gamma(n,x) = integrate(t^n*e^(-t), t,0,x),  d(gamma(n,x),x) = x^n*e^(-x) gamma(n,0) = 0, gamma(n,inf) = gamma(n+1) = n!.

gamma(n,x) is similar to gamma(n), but its power term is t^n, instead of t^(n-1).

See also: ei, erf, ci, si, li.

 

* gcd

gcd(a,b) gives the greatest common divider of a and b.

e.g. gcd(2,4) gives 2.

 

* getbkcolor                                                                                          internal

getbkcolor gets background color on the graph screen. It must be on the graph mode.

See also: getbkcolor, getcolor, setbkcolor, setcolor.

 

* getcolor                                                                                 internal

getbkcolor gets foreground color on the graph screen. It must be on the graph mode.

See also: getbkcolor, getcolor, setbkcolor, setcolor.

 

* getmaxx                                                                                            internal

getmaxx gets the max x of the graphics screen (number of column of pixel). For EGA video, getmaxx gives 640. It must be in graph mode.

See also: getmaxx, getmaxy, getx, gety.

 

* getmaxy                                                                                             internal           

getmaxy gets the max y of the graphics screen (number of rows of pixel). For EGA video, getmaxy gives 350. It must be in graph mode.

See also: getmaxx, getmaxy, getx, gety.

 

* getx                                                                                                    internal           

getx gets the x of the current point(x,y) on the graphics screen (number of column of pixel). For EGA video, 0 <= getx < 640. It must be in graph mode.

See also: getmaxx, getmaxy, getx, gety.

 

* gety                                                                                                    internal           

gety gets the y of the current point(x,y) on the graphics screen (number of rows of pixel). For EGA video, 0 <= gety < 350. It must be in graph mode.

See also: getmaxx, getmaxy, getx, gety.

 

* graph                                                                                                 internal

graph is the graph mode. It initialises the graphics system and sets the screen to graphics mode. You can close graphics mode and go back the text mode by the text command. It is useful to freeze the graphics by the command readchar before back to the text mode.

See also: text.

e.g. graph, line(100,100,300,300), readchar, text

 

* i                                                                                             internal

i represents the imaginative unit of the complex numbers, i=sqrt(-1), as the built-in constant.

See also: re, im, sign, arg.

e.g. 1+2*i.

 

* If                                                                                           internal

Notice: The first letter is upper case.

If(condition, x)  gives x if condition evaluates to 1, or left unevaluated otherwise.

 

If(condition, x,y)

gives x if condition evaluates to 1, y if it evaluates to 0, or left unevaluated if the condition is neither 1 nor 0.

It is useful in definition of the use-defined function to left the function unevaluated if the argument of the function is not number.

See also: isnumber.

e.g.

IN:  f(x_) := If(isnumber(x), 1)

IN:  f(x), f(10)

OUT: f(x), 1

 

* im                                                                                           internal

im(x) gives the imaginative part of the complex number x.

See also: re, abs, sign, arg.

e.g. im(1+2*i) gives 2.

 

* inf                                                                                         internal

inf is a positive infinity, as the built-in constant.

See also: c_inf, zero.

e.g. inf+2*inf gives inf, 1/inf gives 0.

 

* infsum

infsum(y,x) is infinite sum.

See also: partsum, sum.

 

* int

The same as integrate.

 

* integrate                                                                               internal + external

integrate() is the integral function.

 

integrate(y,x)                                                                                        internal

It finds the indefinite integral of y with respect to an undefined variable x.

 

integrate(y,x,xmin,xmax)

It finds the definite integral of y with respect to the variable x taken from x=xmni to x=xmax.

 

integrate(y,x,xmin,x1,xmax)

It finds the definite integral of y from x=xmin to x=x1, then from x=x1 to x=xmax. x1 is singularity.

See also: ninte.

 

* iscomplex                                                                                         internal

iscomplex(x) tests if x is complex. It gives 1 if x is complex, or 0 otherwise.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. iscomplex(i) gives 1.

 

* iseven                                                                                   internal

iseven(x) gives 1 if x is an even integer, or 0 otherwise. You can assume x is even by iseven(x) := 1.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. iseven(2) gives 1, iseven(3) gives 0.

 

* isfree                                                                                      internal

isfree(y,x) gives 1 if y is free of x, or 0 otherwise. You can assume y is free of x by iseven(y,x) := 1.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. isfree(a*b,x) gives 1, isfree(x*y,x) gives 0.

 

* isinteger                                                                                 internal

isinteger(x) gives 1 if x is an integer, or 0 otherwise. You can assume x is integer by isinteger(x) := 1.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. isinteger(2) gives 1, isinteger(3.2) gives 0.

 

* islarger

islarger(a,b) gives 1 if a is larger than b, or 0 otherwise. It is extent of operator >. It can compare 2 complex number, but the operator > cannot.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber. isless.

e.g.

IN:  islarger(1+i, 1-i)         # is 1+i larger than 1-i ?

OUT: 1                             # yes

 

* isless

isless(a,b) gives 1 if a is less than b, or 0 otherwise. It is extent of operator <. It can compare 2 complex number, but the operator < cannot.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g.

IN:  isless(1+i, 1-i)           # is 1+i less than 1-i ?

OUT: 0                          # no

 

* islist                                                                                       internal

islist(x) gives 1 if x is a list, or 0 otherwise. You can assume x is a list by islist(x) := 1.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. islist([a]) gives 1, islist(3.2) gives 0.

 

* isodd                                                                                      internal

isodd(x) gives 1 if x is an odd integer, or 0 otherwise. You can assume x is odd by isodd(x) := 1.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. isodd(3) gives 1, isodd(2) gives 0.

 

* isratio                                                                                    internal

isratio(x) gives 1 if x is ratio, or 0 otherwise. You can assume x is ratio by isodd(x) := 1.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. isratio(2/3) gives 1, isratio(2) gives 0.

 

* isreal                                                                                     internal

isreal(x) gives 1 if x is real, or 0 otherwise. You can assume x is real by isreal(x) := 1.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. isreal(2.2) gives 1, isreal(a) gives 0.

 

* issame                                                                                   internal

issame(a,b) gives 1 if a is the same as b, or 0 otherwise. You can assume a is the same as b by issame(a,b) := 1. It is similar to a==b, but a == b left unevaluated if a <> b.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. issame(3,3) gives 1, issame(3,2) gives 0.

 

* isnumber                                                                                            internal

isnumber(x) gives 1 if x is a number, or 0 otherwise. You can assume x is a number by isnumber(x) := 1.

See also: iscomplex, iseven, isfree, isinteger, islarger, isless, islist, isodd, isreal, isratio, issame, isnumber.

e.g. isnumber(2.2) gives 1, isnumber(a) gives 0.

 

* laplace

laplace(y,x) gives Laplace transform of y.

e.g. laplace(sin(t),t) gives 1/(1+t^2).

 

* last                                                                                         internal

last        represents the last output, as the built-in variable.

last[1]     the first element of the last output list.

 

* left                                                                                        internal

left(x=a) gives the left-hand side of an equation and inequality.

See also: right.

e.g. left(x+y=2) gives x+y, left(a>b) gives a.

 

* length                                                                                     internal

length([a]) gives the length of a list and string (the number of member in the list and string).

See also: list, string.

e.g. length([a,b]) gives 2, length("abc") gives 3.

 

* li

li(x) is the ln integral function, li(x) = integrate(1/ln(t), t,0,x) = ei(ln(x)), li'(x)=1/ln(x).

 

li(n,x) is the incomplete ln integral function, li(n,x) = integrate(ln(t)^n, t,0,x) = ei(n,ln(x)), d(li(n,x),x) = ln(x)^n. li(n,0) = 0.

See also: ei, gamma, erf, ci, si, li.

 

* lim

lim(y, x = x0) finds the limiting value of y when x = x0.

 

lim(y, x = x0+zero) finds the right-sided limit as x approaches to x0 from the positive (+inf) direction (x = x0+).

 

lim(y, x = x0-zero) finds the left-sided limit as x approaches to x0 from the negative (-inf) direction (x = x0-).

 

            Note that the correct answers are usually for the indeterminate forms: 0/0, inf/inf, 0*inf, 0^0, inf^0.

See also: zero, replace.

e.g. lim(sin(x)/x, x = 0) gives 1.

 

* line                                                                                         internal

line(x1,y1,x2,y2) draws a line from point (x1,y1) to (x2,y2). line() is graphics function so it only works on graphics mode.

See also: arc, lineto, linerel, putpixel.

e.g. graph, line(100,100,200,200), readchar, text

 

* lineto                                                                                      internal

lineto(x2,y2) draws a line from the current point (x,y) to (x2,y2). lineto() is graphics function so it only works on graphics mode.

See also: arc, line, linerel, putpixel.

e.g. graph, moveto(100,100), lineto(200,200), readchar, text

 

* linerel                                                                                     internal

linerel(dx,dy) draws a line from the current point (x,y) to (x+dx,y+dy). linerel() is graphics function so it only works on graphics mode.

See also: arc, line, lineto, putpixel.

e.g. graph, moveto(100,100), linerel(100,100), readchar, text

 

* list                                                                                         internal

list(y,x,xmin,xmax,dx)  lists every y when x runs from xmin to xmax on step dx. list() is similar to do(), but list() outputs every result at every step dx, and cannot accept assignment as y.

See also: do, repeat, table.

e.g. [ list(x^2, x,1,3,1) ] gives [1,4,9].

 

* listsum

listsum(x) converts a list into sum.

See also: average, max, min.

e.g. listsum([a,b] gives a+b.

 

* ln   

The same as log.

 

* log                                                                             internal+external

log(x) is the natural logarithmic function of x. Its base is e. It is the inverse to exp(x). Note that if it has multi-values, the ln(x) only gives a principle value (P.V.) and other values are P.V.+2*k*pi*i (where k=0, 1, 2,..., -1, -2, ...). If x is complex number (x=A+B*i) then ln(x)=ln(abs(x))+i*atan2(A,B).

See also: exp.

e.g. ln(e) gives 1.

 

* local                                                                                       internal

local(a,b) declares the variables a and b are local variables in block(). local() must be the last argument within block().

See also: block

e.g. f(x_) := block(p:=x^2,p,local(p))

 

* log10

log10(x) is log with base of 10. log10(x) = ln(x)/ln(10).

See also: ln.

e.g. log10(10) gives 1.

 

* lowercase                                                                                          internal

The switch of the case conversion.

lowercase := on

It converts the letters to lower-case letters.

e.g. SIN(x) is converted to sin(x).

 

lowercase := off

It disables the case conversion, this is default. It only effects the input.

 

* math                                                                                      internal

math is a value of the switch output. It forces output in math symbolic notation.

See also: output, off, on, basic, fortran, prolog.

e.g. output:=math.

 

* max

max(x,y) gives maximum.                           

See also: min, average, listsum, length.

e.g. max(1,3) gives 3.

 

* member                                                                                              internal

member(list,n) gives n-th member of list.

See also: length, last.

e.g. member([a,b,c], 2) gives b.

 

* min

min(x,y) gives minimum.                           

See also: max, average, listsum, length.

e.g. min(1,3) gives 1.

 

* mod                                                                                       internal

mod(m,n) gives the remainder on division of m by n.

See also: div.

e.g. mod(4,3) gives 1.

 

* moveto                                                                                              internal

moveto(x2,y2) moves from the current x,y to x2,y2. it is graphics function so it only works on graphics mode.

See also: arc, line, linerel, putpixel.

e.g. graph, moveto(100,100), lineto(200,200), readchar, text

 

* moverel                                                                                             internal

moverel(dx,dy) moves from the current x,y to x+dx,y+dy. it is graphics function so it only works on graphics mode.

See also: arc, line, lineto, putpixel.

e.g. graph, moverel(10,10), linerel(100,100), readchar, text.

 

* mult                                                                           internal+external

mult(x)                                                                                     internal

It gives a list of multipliers of x. It converts product into a list of multipliers.

e.g. mult(a*b) gives [a,b].

 

mult(x, n)

It gives the n-th multiplier of x if possible. multi(x_,n_) := member(multi(x), n).

e.g. multi(a*b*c, 1) gives a.

See also: multi, term, type.

 

* n                                                                                             internal

n(x) gives the numeric value of x. It converts all numbers to the real number.

See also: numeric.

e.g. n(pi) gives 3.1416.

 

* newline                                                                                             internal

newline writes a new line. The output following the command newline will be written on next line.

 

* nint

nint(y, x , xmin , xmax) numerically integrates y.

See also: int.

e.g. nint(x^2, x , 0 , 1) gives

 

* nlim

nlim(y, x=x0) numerically limits y when x=x0.

See also: lim.

e.g. nlim(sin(x)/x, x=0) gives 1.

 

* not

not(x) is logic not. It gives 1 if x=0, or 0 if x=1.

See also: and, not.

e.g. not(1) gives 0, not(0) gives 1.

 

* nsolve

nsolve(cos(x)=x,x,x0,n)                        numerically solves the equation with initial x0 and iteration n, using Newston's method. By default n=5, you can increase the n value if you want more close to exact solution. It only gives one root near x0 if equation has multi roots.

 

nsolve(cos(x)=x, x)       numerically solves equation with default initial x0=1 and n=5.

nsolve(cos(x)=x, x,x0)  numerically solves the equation with initial x0 and n=5.

See also: solve, dsolve.

e.g. nsolve(sin(x)=0, x,3) gives 3.14.

 

* null                                                                                         internal

null is a symbol used to indicate the absence of an expression or a result. When it appears as an output expression, no output is printed.

See also: block, output.

e.g. block(output:=on, null).

 

 

* number                                                                                             internal

number("1") converts string "1" into number 1.

See also: string.

 

* nume                                                                                     internal

nume(x) gives numerator of x. It only works for rational number.

See also: deno.

e.g. nume(2/3) gives 2.

 

* numeric                                                                                  internal

The switch of numeric calculation.

 

numeric:=on       numeric computation.

numeric:=off      disable numeric computation, this is default.

 

See also: num.

 

* off                                                                                          internal

When the switch is set to off, it is inactive.       

e.g. numeric:=off, output:=off, expand:=off

 

* on                                                                                          internal

When the switch is set to on, it is active.

See also: off, output.

e.g. numeric:=on, expand:=on, expandexp:=on, lowercase:=on, output:=on

 

* openfile                                                                                 internal

openfile("filename") opens the disk file "filename" for writing. The filename is any MS-DOS file name. After doing something, the file must be closed by closefile("filename").

See also: closefile, readfile.

 

* or                                                                                          internal

The logic operator. The result is 1, 0 or unevaluated.

See also: and.

e.g. 1 or 0 gives 1.

 

* order

order(y, x) gives the highest order of x in y. y must be polynomial with order < 5.

See also: coef, coefall.

e.g.

IN:  order(x^2+5*x+6, x)

OUT: 2

 

* output                                                                       internal

The switch of the output format.

See also: math, basic, fortran, on, off.

e.g. output:=basic, output:=fortran, output:=math, output:=on, output:=off.

 

* oval

oval(x,y, xRadius,yRadius) draws an oval at point(x,y) with x-radius and y-radius. It must be in graphics mode.

See also: ellipse.

e.g. graph, oval(200,200,200,100), readchar, text

 

* paraplot

plot the parametric functions of x=x(t) and y=y(t) by

                        paraplot(x(t),y(t),t)

                        paraplot(x(t),y(t),t,tmin,tmax)

                        paraplot(x(t),y(t),t,tmin,tmax,ymin,ymax)

See also: plot,polaplot.

e.g. graph, paraplot(sin(t),sin(2*t),t)

 

* partsum

partsum(y,x) gives partial sum of y (symbolic sum).

See also: infsum, sum.

e.g. partsum(n^2, n) gives 1/6 n (1 + n) (1 + 2 n)

 

* pi

pi=3.1416..., as the built-in constant, pi is converted to 3.1416... when the switch numeric:=on.

See also: e.

 

* plot

plot(y,x) plots a function y=f(x) in xy plane with the default values x from -5 to 5, and y from -5 to 5.

 

plot(y,x,xmin,xmax)

plot(y,x,xmin,xmax,ymin,ymax)

 

See also: dotplot, polar.

e.g. graph, plot(x^3,x)

 

* polaplot

polaplot(r,t) plots a function r=f(t) in polar coordinates with the default values t from 0 to 2 pi, and r from 0 to 5.

 

polaplot(r,t,tmin,tmax)

polaplot(r,t,tmin,tmax,rmin,rmax)

 

See also: dotplot, paraplot, polaplot.

e.g. graph, polaplot(1,t)

 

* power                                                                                    internal

power(x^n) gives the power n.

See also: base, power, type.

e.g. base(x^n) gives x, type(x^n) gives "^", power(x^n) gives n.

 

* prod

prod(f,x,xmin,xmax)                  with the default step dx = 1.

prod(f,x,xmin,xmax,dx)             evaluates the product of f when x runs from

                                                xmin to xmax with step dx.

See also: sum, list, table.

 

* prolog                                                                                   internal

prolog is the value of the switch output. It forces the output in the Prolog format, i.e. internal form.

See also: output, basic, fortran.

e.g.

IN:  outout:=prolog

IN:  a+b

OUT: plus(var("a"),var("b"))

 

* psolve

psolve(f(x), x) solves polynomial f(x)=0 for x. The order of polynomial < 3.

See also: solve, nsolve, dsolve.

e.g. psolve(x^2+5*x+6, x) gives [-2,-3].

 

* putpixel                                                                                             internal

putpixel(x,y,color) puts pixel on the point (x,y) with color. It only works on the graphics mode.

See also: line, lineto, linerel.

e.g. graph, putpixel(100,100,1), readchar, text

 

* random                                                                                             internal

random gives a uniformly distributed pseudo random real in

                        the range 0 to 1.

 

random(n)         gives a uniformly distributed pseudo random integer

                        in the range 0 to n. (n < 36000).

e.g. random gives 0.11111, random(5) gives 2.

 

* ratio                                                                                      internal

ratio(x) converts x to a rational number.

See also: num.

e.g. ratio(0.5) gives 1/2.

 

* re                                                                                           internal

re(x) gives the real part of the complex number x.

See also: im, abs, sign.

e.g. re(1+2*i) gives 1.

 

* readchar                                                                                            internal

readchar reads a character from the keyboard. It is useful to freeze the graphics by readchar. This is similar to pause, but it returns the character from the keyboard as its value.

See also: readchar, readfile, readln, writes.

e.g. graph, line(100,100,300,300), readchar, text

 

* readfile                                                                                  internal

readfile("file") reads (or runs) the file named "file". The filename is any MS-DOS file name.

See also: readchar, readfile, readline, writes.

 

* readline                                                                                  internal

readline reads a line of strings from the keyboard into the readline.

See also: readchar, readfile, readline, writes.

 

* repeat                                                                                     internal

repeat(expr until test) repeats expr until test gives 1.

See also: do, list.

e.g.

IN:  x:=1, repeat(x:=x+1, x>5)

OUT: x := 6

 

* reverse

reverse(f(x)) reverses a function f(x).

See also: solve.

e.g. reverse(sin(x)) gives  asin(x)

 

* right                                                                                      internal

right(x=a) gives the right hand side of an equation.

See also: left, solve.

e.g. right(x+y = 3) gives 3.

 

* root

root(x,n) gives a  n-th root. It is the same as x^(1/n).

e.g. root(4,2)  gives  2

 

* round                                                                                    internal

round(x) converts x to the rounded integer closest to x.

See also: trunc.

e.g. round(2.4) gives 2, round(2.5) gives 3.

 

* sec

sec(x) is the secant function of x. The angle x is measured in radians (multiply by degree to convert from degrees). sec(x)=1/cos(x).

See also: asec, cos.

 

* sech

sech(x) is the hyperbolic secant function of x. sech(x)=1/cosh(x).

See also: asech, cosh.

 

* series

series(y, x)  gives series expansion of y at x=0 to order of 5.

series(y, x, order)  gives series expansion of y at x=0 to order.

See also: sum.

e.g. series(sin(x),x) gives x - 1/6*x^3 + 1/120*x^5.

 

* sequence                                                                                           internal

sequence(x) gives a sequence. It only work on a list.

See also: type, argue.

e.g. sequence( [a,b] ) gives a,b

 

* setbkcolor                                                                                         internal

setbkcolor(x) sets the background color, where the argument value is 0 to 15, or the color word. The default background color is 0 (black). It only works on graphics mode.

e.g. graph, setbkcolor(1), line(100,100,200,200), readchar, text.

See also: setcolor.

 

* setcolor                                                                                 internal

setcolor(x) sets the foreground color, where the argument value is 0 to 15, or the color word. The default foreground color is 7 (white). It only works on graphics mode.

e.g. graph, setcolor(1), line(100,100,200,200), readchar, text.

See also: setbkcolor.

 

* setlinestyle                                                                                       internal

setlinestyle(style, direction, thickness) sets the line style, where style is the style name, direction is the line direction, thickness is the thickness of the line.

it only works on the graphics mode.

See also: setlinestyle, settextstyle.

e.g. graph, setlinestyle(2,1,2), line(100,100,300,300), readchar, text

 

* settextjustify                                                                                     internal

settextjusttify(hor,vert) sets text justification values used by writes(). Text written by writes() after the settextjustify() will be justified around the current pointer in the manner specified.

See also: settextstyle, writes.

 

* settextstyle                                                                                       internal

settextstyle(font, direction, size) sets the text style, font, and character magnification factor, where font is the font name, direction is the text direction, size is the character size. it only works on the graphics mode.

e.g. graph, textstyle(2,1,2), writes("abc"), readchar, text.

See also: setlinestyle.

 

* setviewport                                                                                       internal

setviewport(x1,y1,x2,y2,clip) sets the view port from (x1,y1) to (x2,y2) on the graphics screen. Everything is invisible if it out of the (x1,y1) to (x2,y2). It only works on the graphics mode.

e.g. graph, line(100,100,300,300), setviewport(200,200,300,300,1), line(100,200,100,200), readchar, text

See also: graph, text.

 

* si

si(x) is the sin integral, si(x) = integrate(sin(x)/x, x).

See also: ci, ei, gamma, erf.

 

* sign                                                                                       internal

sign(x) is the sign function of x. Its value is 1, 0 or -1.

 

            /  1     if re(x) > 0; or both re(x) = 0 and im(x) > 0.

sign(x) =  0     if x=0.

            \ -1     otherwise.

 

the same as the definition by arg(x):

 

            / 1      if -pi/2 < arg(x) <= pi/2.

sign(x) =  0     if x=0.

            \ -1     otherwise.

 

            You can assume x is positive or negative by sign(x) := 1 or sign(x) := -1.

e.g. sign(2) gives 1, sign(1+i) gives 1.

See also: abs, arg, re, im, >, <.

 

* sin                                                                             internal + external

sin(x) is the sine function of x. The angle x is measured in radians. (multiply by degree to convert from degrees).

See also: asin, csc.

 

* sinh

sinh(x) is the hyperbolic sine function of x. sinh(x) = (exp(x)-exp(-x))/2.

See also: asinh, acsch.

 

* solve                                                                                     internal

solve(x^2=0, x) solves an equation. It gives symbolic solutions.

See also: nsolve.

 

* sqrt                                                                                       internal

sqrt(x) is the square root function of x. It is the same as x^0.5. It only gives the principal value (P.V.) (sign(sqrt(x)) >= 0). root(x,2) gives all branch of square root.

See also: root, ^.

e.g. sqrt(4) gives 2, num(sqrt(2*i)) gives 1+i.

 

* subs                                                                                      internal

subs(y, x=x0) substitutes x in y with x0.

e.g. subs(x^6, x=x0) gives x0^6.

 

* sum                                                                           external + internal

sum(y,x)

The indefinite sum with the variable x.

 

sum(x)

The indefinite sum with the variable x.

 

sum(f, x,xmin,xmax)

The partial sum, symbolic sum. It evaluates the sum of f when x runs from xmin to xmax

 

sum(f, x,xmin,xmax,dx)                                                            internal

It evaluates the sum of f when x runs from xmin to xmax with step dx.

 

See also: prod, list, table, infsum, partsum.

e.g. sum(2^n,n,1,5,1.1), sum(x^n,n,1,5).

 

 

* string                                                                                    internal

string(x) converts a number x to a string "x".

See also: number.

e.g. string(123) gives "123".

 

* system                                                                                              internal

system("DOS") executes the operating system (DOS) command "DOS".

e.g. system("dir").

 

* table                                                                          external + internal

table(f,x)

It produces a table of the function values from x=-5 to x=5 with step 1.

 

table(f,x,xmin,xmax)

It produces a table of the function values from x=-5 to x=5 with the default step dx = 1.

 

table(f,x,xmin,xmax,dx)                                                             internal

It produces a table of the function values when x runs from xmin to xmax with step dx.

 

table(y[x],x,xmin,xmax,dx)                                                        internal

It transforms a list y into a table.

See also: list, plot.

e.g. table(x^2,x,1,4,1).

 

* tan                                                                             internal + external

tan(x) is the tangent function of x. The angle x is measured in radians (multiply by degree to convert from degrees).

See also: atan, cot.

 

* tanh

tanh(x) is the hyperbolic tangent function of x.

See also: atanh, coth.

 

* term                                                                          internal+external

term(x)                                                                                     internal

It gives a list of terms of x. It converts sum into a list of terms.

e.g. term(a+b) gives [a,b].

 

term(x, n)

It gives the n-th term of x if possible. term(x_,n_) := member(term(x),n).

See also: multi, term, type.

e.g. term(a+b, 1) gives a, term(a+b, 2) gives b, type(a+b) gives "+".

 

* text                                                                                                    internal

text is the text mode.

See also: graph.

e.g.

IN:  graph, line(100,100,200,200), readchar, text

 

 

* trunc                                                                                     internal

trunc(x) converts x to the truncated integer.

See also: round.

e.g. trunc(2.9) gives 2.

 

* type                                                                                       internal

type(x) gives the type of x. Its value is a string. Note that the output of strings in SymbMath is without two quotation marks.

e.g.

-------------------------------

x                      type(x)

-------------------------------

1                      integer

1.1                   real

2/3                   ratio

1+I                   complex

f(x)                   f()

[1,2]                 []

a                      symbol

"a"                    string

a+b                  +

a*b                   *

a^b                   ^

a=b                  =

a==b                ==

a>b                  >

a>=b                >=

a<b                  <

a<=b                <=

a<>b                <>

a,b                   ,

---------------------------------

 

            You also can test x, e.g. if x is type of real number, by type(x)=="real".

 

* undefined                                                                                          internal

The built-in constant. It indicates that the value of the expression is undefined, and may be the indeterminate form: 0/0, inf/inf, 0*inf, 0^0. You should try again by lim(y, x=x0).

See also: lim.

e.g.

IN:  f(x_) := sin(x)/x;

IN:  f(0)

OUT: undefined

IN:  lim(f(x), x=0)

OUT: 1

 

* writes                                                                                    internal

writes(x) writes x on the graphics screen.

It only works on the graphics mode.

See also: graph, readchar.

 

* zero                                                                                       internal

zero is the positive-directed 0, as the built-in constant. f(x0+zero) is the right-hand sided function value when x approaches to x0 from the positive direction, i.e. x = x0+. f(x0-zero) is the left-sided function value when x approaches to x0 from the negative direction, i.e. x = x0-.

e.g. f(1+zero) is the right-hand sided function value when x approaches to 1 from the positive (+infinity) direction, f(1-zero) is the left-hand sided function value when x approaches to 1 from the negative (-infinity) direction.

See also: lim.

e.g.

IN:  exp(1/(0+zero)), exp(1/(0-zero))

OUT: inf, 0

 

 

+          add or positive sign, e.g. a+b.

-           subtract or negative sign, e.g. a-b, -1.

*           multiply, e.g. a*b.

/           divide, e.g. a/b.

^          power in BASIC, the same as ** in FORTRAN, e.g. 2^3 gives 8.

!           factorial, the same as fac(x), e.g. 3! or fac(3) gives 6.

 

<          less than.

<=        less than or equal to.

>          greater than.

>=        greater than or equal to.

 

<>        unequal

a <> b gives 1 if a is not equal to b, 0 if a is equal to b, or left unevaluated otherwise. It only test two real numbers.

e.g. 2 <> 3 gives 1, 2 <> 2 gives 0.

 

==        equal

a==b gives 1 if a is equal to b, 0 if a is not equal to b, or left unevaluated otherwise. It can test two complex numbers or expressions. It gives 1 if a and b are the same expression or left unevaluated otherwise.

e.g. 2==2 gives 1, a==a gives 1.

 

=          equation sign, e.g. x^6+1 = 0

 

:=         assignment.

 

,           comma

;           semi-comma, for the end of the statement.

 

|x|        the same as abs(x).

'           f’ is the same as d(f(x),x).

 

#          comment statement, with the end of semi-comma ;  e.g. # this is demo;

 

 ()

-------------------------------------------------------------------------