home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
utility
/
sm22a.zip
/
SYMBMATH.DOC
< prev
next >
Wrap
Text File
|
1993-04-23
|
54KB
|
1,476 lines
SymbMath 2.2: A Symbolic Calculator with Learning
(Version 2.2)
by Dr. Weiguang HUANG
Dept. Analytical Chemsitry, University of New South Wales,
Kensington, Sydney, NSW 2033, Australia
Phone: 61-2-697-4643
Fax: 61-2-662-2835
E-mail: w.huang@unsw.edu.au
Copyright (C) 1990-1993
April 15, 1993
This is Part One of SymbMath manual. The SymbMath manual has
three parts in the files SymbMath.DOC, SymbMath.DO2 and SymbMath.DO3.
If you have any problem or advice, please feel free to write
to the author.
Contents
1. Introduction
2. Capabilities
3. Shareware, Student and Advanced Versions
4. A List of Files in SymbMath
5. Pull-down Menu and Pop-up Menu
5.1 File Menu
5.2 Edit Menu
5.2.1 Edit Help Menu
5.3 Run Menu
5.4 Window Menu
5.5 Color Menu
5.6 Help Menu
5.7 Print Menu
6. Programming in SymbMath
6.1. Data Types
6.1.1 Numbers
6.1.2 Constants
6.1.3 Variables
6.1.4 Patterns
6.1.5 Functions
6.1.5.1 Built-in Standard Functions
6.1.5.2 Calculus and Transformation Functions
6.1.5.3 User-defined Functions
6.1.6 Equations
6.1.7 Lists, Arrays, Vectors and Matrices
6.1.8 List Index
6.2. Operators
6.2.1 Assignment Operators
6.2.2 Arithmetic Operators
6.2.3 Relational Operators
6.2.4 Logical Operators
6.3. Expressions
6.3.1 Numerical Exprssions
6.3.2 Boolean Expressions
6.4. Statements
6.4.1 Comment Statement
6.4.2 Evaluation Statement
6.4.3 Assignment Statement
6.4.4 Conditional Statement
6.4.5 Loop Statement
6.4.6 Switch Statement
6.4.7 Command Statement
6.4.8 Compound Statement
6.4.9 Include Statement
6.4.10 End Statement
6.5 Output Form
6.6 Input and Output
7. Examples
7.1 Simplification and Assumption
7.2 Calculation
7.3 Defining Your Own Functions, Procedures and Rules
7.4 Limits
7.5 Differentiation
7.6 Integration
7.6.1 Indefinite Integration
7.6.2 Definte Integration
7.7 Equations
7.7.1 Algebraic Equations
7.7.2 Differential Equations
7.8 Sums and Products
7.9 Lists, Arrays, Vectors and Matrices
7.9.1 Entering Lists
7.9.2 Accessing Lists
7.9.3 Modifying Lists
7.9.4 List Operations
7.9.5 Vector Operations
7.10 Complex Analysis
7.11 Tables of Function Values
7.12 Transformation and Pieces of Expressions
7.13 Learning from Users
7.13.1 Learning indefinite and definite integrals
from derivatives
7.13.2 Learning complicated indefinite integrals
from a simple indefinite integral
7.13.3 Learning definite integral from indefinite integral
7.13.4 Learning integrals from algebra
7.13.5 Learning complicated derivatives from a simple
derivative
7.13.6 Learning complicated algebra from simple algebra
8. Packages
8.1 Initial Package
8.2 Derivative Package
8.3 Total Derivative Package
8.4 Integral Package
8.5 Numeric Integration Package
8.6 Numeric Solving Package
8.7 Seriers Package
8.8 Infinite Sum Package
8.9 Chemical Calculation Package
8.10 Chemical Reaction Package
8.11 Plot Function Package
8.12 Plot Data Package
10. Interface with Other Software
11. Inside SymbMath
12. System Limits
13. Keywords
13.1 Keywords in Functional Order
13.2 Keywords in Alphabetical Order
13.3 Glossary
14. References
1. Introduction
SymbMath (an abbreviation for Symbolic Mathematics) is a
symbolic calculator that can solve symbolical math problems. SymbMath
also perform exact numeric computation. It can manipulate complicated
formulas and return answers in terms of symbols, formulas and exact
numbers.
SymbMath is an expert system that is able to learn from users.
If users only input one formula without writing any code, it will
automatically learn many problems related to this formula (e.g. it
learns the integrals of an unknown function from a derivative of that
unknown function).
SymbMath is a programming language in which you can write
programs, functions and procedures.
SymbMath is a computing environment where you can set up,
run and document your calculation.
SymbMath is a text editor in which you can edit many documents
in many windows.
It runs on small IBM PCs (8086) with 420 KB free memory under
MS-DOS.
2. Capabilities
Its capabilities include facilities to provide analytical and
numerical answers for:
o Differentiation: regular or higher order, partial or total,
mixed and implicit differentiation, one-sided derivatives.
o Integration: indefinite or definite integration, multiple
integration, infinity as a bound, parametric or iterated
integration, line or surface integrals, discontinuous or
implicit integration.
o Solution of equations: roots of a polynomial, systems of
algebraic or differential equations.
o Manipulation of expressions: simplification, factoring or
expansion, substitution, evaluation, built-in standard or
user-defined functions.
o Calculation: exact and floating-point numerical computation
of integer, rational, real and complex numbers in the range
from minus to plus infinity, even with different units.
o Limits: real or complex limits, one-sided limits,
indeterminate forms.
o Complex: calculation, functions, derivatives, integration.
o Sum and product: finite or infinite, partial.
o Others: series, lists, arrays, vectors, matrices, tables, etc.
Also included are:
o Pull-down and pop-up menus, resizable and colourable windows.
o Multi-windowed text editor with syntax check.
o Programming in integrated edit-interpret-debug environment.
o Reading and generating BASIC and FORTRAN codes.
o Displaying two-dimensional math notation.
o On-line help, and on-line manual.
o Procedural, conditional, iterational, recursive, functional,
rule-based, logic, and pattern-matching programming.
o Editable library in "formula format" or SymbMath language.
o Learning from user.
o Plotting functions and data.
3. Shareware, Student and Advanced Versions
Please read two document files SymbMath.DOC and SymbMath.DO*
and all *.TXT files before running SymbMath. You should print them out
if you need the printed documents. Please follow examples in the
document to practise.
Type SymbMath on the MS-DOS prompt to run.
SymbMath has three versions: Shareware Version A, Student
Version B and Advanced Version C. You cannot input the lacked
functions in shareware or student version, but all versions can
output all of these functions.
----------------------------------------------------------------------
Version Class Lacked Functions on Input Price
Shareware A solve(), dsolve(), US$20 or AU$25
trig (except sin(x)),
hyerbolic,
Student B hyerbolic, dsolve() US$50 or AU$65
Advanced C US$99 or AU$130
Packages *.sm US$20 or AU$25
----------------------------------------------------------------------
Upgrade same 50%
----------------------------------------------------------------------
Multiple copies discount is less 20%.
----------------------------------------------------------------------
Other foreign money is accepted at the current exchange rate.
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.TXT file)
and send it to the author, you will be legal users for upgrades.
If you write a paper about this software on publication, you will get
a free upgrade.
It has three versions: Shareware, Student, and Advanced. The
shareware version is available from SIMTEL20 archives on anonymous FTP
sites (wsmr-simtel20.army.mil as /calculator/sm22a.zip, rana.cc.deakin.
oz.au as /huang/sm22a.zip, etc) or by e-mail from listserv@vm1.nodak.edu,
listserv@ndsuvm1.bitnet.
4. A List of Files in SymbMath
-------------------------------------------------------------------------
SymbMath.exe executable SymbMath system.
SymbMath.ini initial file.
SymbMath.h* help files, * is numbers.
SymbMath.txt introduction of SymbMath.
SymbMath.doc part one of document file or manual file.
SymbMath.do2 part two of document file or manual file.
SymbMath.do3 part three of document file or manual file.
readme the read-me file, this file should be read first.
readme.2 the read-me file, for PlotData.
init.sm initial SymbMath program file.
*.sm user SymbMath program files or packages.
problem.txt problems that other software cannot solve, but
SymbMath can do.
comment*.txt comments on SymbMath.
statisti.txt the download statistics at FTP site of garbo.uwasa.fi.
prolog.err error messages.
shareware.txt shareware concept.
software.txt software available from the author Dr. W. Huang.
update.txt the latest updates in SymbMath.
PlotData.exe program of plotting data.
PlotData.ini initial file of PlotData.
PlotData.doc PlotData manual file.
PlotData.hlp PlotData help file.
PlotData.txt introduction of PlotData.
------------------------------------------------------------------------
5. Pull-down Menu and Pop-up Menu
The screen is divided into four areas: a menu line, an edit
window, an output window, and a status line.
The menu line is the main menu and locates in the top of the
screen.
The edit window is a multi-windowed text editor.
The output window displays the 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.
The menu line has 6 choices:
------------------------------------------------------
| File Edit Run Window Color Help |
------------------------------------------------------
When the menu line or the pull-down menus is active, the
content of the status line is
--------------------------------------------------------------------------
SymbMath 2.2 | Arrow keys and <Enter>, First capital letter, <Alt>P Print
--------------------------------------------------------------------------
Select the menu by the arrow keys and <Enter>, the first capital
letter, or pop up the Print menu by <Alt>P. The <Esc> key always
escape from the current window and return to the previous window.
Two pop-up menus are the Print menu and the Edit Help menu.
5.1 File Menu
The File menu has 5 choices in the pull-down menu:
-----------
|Load |
|New file |
|Save |
|OS shell |
|Quit |
-----------
The "Load" command loads a file from a disk into the Edit
window. This command pops up a Directory window and changes the
content of the status line to
---------------------------------------------------------------------
<F4> File mask, <F5> Zoom, <Pg Dn> More, -><- Select, <Enter> Accept
---------------------------------------------------------------------
In the Directory window, the following commands are available.
Table 5.1 Commands in the Directory Window
-------------------------------------------------------
key action
<F4> file mask, e.g. *.sm.
<F5> zoom the window, zoom back by <F5> again.
<Shift><F10> resize the window with the -><- keys
-><- select
<Pg Up> page up
<Pg Dn> page down
<Enter> accept
<Esc> abort
--------------------------------------------------------
The "New file" command creates a new file, clears the Edit
window, and changes the content of the status line to
----------------------------------------------------------------------------
Input filename | <F8> Last filename, -><- Edit, <Enter> Accept, <Esc> Abort
----------------------------------------------------------------------------
The "Save" command saves the program in the Edit window into a
disk for a new filename.
The "OS shell" command executes a DOS command and automatically
returns to the SymbMath system if users provide a special 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.
The "Quit" command exit from SymbMath.
5.2 Edit Menu
SymbMath includes multi-windowed text editors for creating
and modifying program files. Usage of the editors is similar to
WordStar in nondocument mode, to Borland's SideKick, or to Borland's C
compiler.
Within the Edit window, press <F8> to open an Aux Edit window
with an auxiliary editor. In the Auxi Edit window, press <F8> again to
open another Aux Edit window. So the user can open many Aux Edit
windows to edit many files.
Text in the Edit 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 Edit window or the Aux Edit window, press <F1> to pop-
up the Edit Help menu (see 5.8 Edit Help Menu), or <Shift><F1> to call
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 autoindent 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.
Table 5.2 window command
---------------------------------------------------------------------
Key Action
<F5> zoom window, zoom back by <F5> again.
<Shift><F10> resize window with the -><- keys.
<F8> open an Aux Edit window.
<F10> close the Aux Edit window with saving.
<Esc> close the Aux Edit window without saving.
<F7> block copy from an Aux Edit window into the last window.
---------------------------------------------------------------------
The content of the status line is
--------------------------------------------------------------------------
<F1> Help, <Shi><F1> Manual, <F3> Load, <F5> Zoom, <F7> XCopy, <F8> XEdit
--------------------------------------------------------------------------
Table 5.2 Summary of the editing commands.
---------------------------------------------------------------
Cursor Movement Commands (move cursor to):
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> ->
Line up <Ctrl>E or Up arrow
Line down <Ctrl>X or Down arrow
Scroll up <Ctrl>W
Scroll down <Ctrl>Z
Page up <Ctrl>R or <Pg Up>
Page down <Ctrl>C or <Pg Dn>
Beginning of line <Ctrl>QS or <Home>
End of line <Ctrl>QD or <End>
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
Marker 0 <Ctrl>Q0
Marker 1 <Ctrl>Q1
Marker 2 <Ctrl>Q2
Marker 3 <Ctrl>Q3
Set marker 0 <Ctrl>K0
Set marker 1 <Ctrl>K1
Set marker 2 <Ctrl>K2
Set marker 3 <Ctrl>K3
...........................................................
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:
Mark block begin <Ctrl>KB
Mark block end <Ctrl>KK
Mark word <Ctrl>KT
Hide block <Ctrl>KH
Copy block <Ctrl>KC or <Ctrl><F5>
Repeat the last copy <Shift><F5>
Move block <Ctrl>KV or <Alt><F6>
Delete block <Ctrl>KY
Read block <Ctrl>KR or <F7>
Write block <Ctrl>KW
Print block <Ctrl>KP
.....................................................................
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
Search Options:
L Local search
G Global search
N Replace without asking
Y Replace with asking
------------------------------------------------------------------
Pop-up the Edit Help menu by <F1>, select the editing commands
from its sub-menus by the arrow keys and <Enter>.
5.2.1 Edit Help Menu
Users pop-up the Edit Help menu by pressing <F1> within the
Edit window or the Aux Edit window.
This menu has 7 choices:
------------------
|Show help file |
|Cursor movement |
|Insert & Delete |
|Block functions |
|Wordstar-like |
|Miscellaneous |
|Global functions|
------------------
Except for the first choice of the "Show help file", others have their
own sub-menu. Users can select the edit command in the sub-menu by
the up or down key and <Enter>.
5.3 Run Menu
The Run menu executes the user program in the Edit window, and
outputs the results in the Output window.
Notice that it clears memory and executes the initial package
init.sm before it inteprets the users programm in the Edit window.
You can run the user program from the disk (see Chapter 11 Packages).
5.4 Window Menu
The Window menu has 2 choices:
--------
|Clear |
|Resize|
--------
The "Clear" command clears the Output window.
The "Resize" command changes the Output window size
(see Table 5.2 window command).
5.5 Color Menu
The Color menu has 4 choices in the pull-down menu:
---------------
|Menu line |
|Edit window |
|Output window|
|Status line |
---------------
When users choose one of them, a color pattern will come up.
There are 125 colors in the color pattern. Users select their favour
color by the arrow keys and <Enter>.
5.6 Help Menu
The Help menu has 18 choices in the pull-down menu:
---------------
|How to help |
|Brief |
|Simplify |
|Calculate |
|Function |
|Limit |
|Differentiate|
|Integrate |
|Equation |
|sUm |
|Vector |
|Table |
|leArn |
|Package |
|plOt |
|sWitch |
|Keyword |
|Glossary |
---------------
Each command has its own Help window and help file. The on-
line help files are text (ASCII) files.
While the Help window is open, the status line is changed to
-----------------------------------------------------------------------------
<Ctrl><F3> Find, <Shift><F3> Find again, <F5> Zoom, <Pg Dn> more, <Esc> Abort
-----------------------------------------------------------------------------
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.
Table 5.6 Commands in the Help window
-------------------------------------------------------------------
Keys Action
-><- move the cursor.
<F5> zoom the window, <F5> again to zoom out.
<Esc> exit from the window.
<F10> exit from the window, the same as <Esc>.
<Pg Up> page up.
<Pg Dn> page down.
<Crtl><F2> go to nth line, end by <crtl><F2> instead of <Enter>.
<Ctrl><F3> find the special word, end by <Ctrl><F3>
instead of <Enter>.
<Shift><F3> repeat last find.
<Shift><F10> re-size window by arrow keys.
----------------------------------------------------------------------
There are other two help windows in the Edit window, press
<F1> to pop-up the Edit Help menu, or <Shift><F1> to open the manual
window.
5.7 Print Menu
Users pop up the Print Menu by <Alt>P, and set "Printer On" in
the Print window to toggles echoing to a printer, or/and set "Log File
On" to toggles echoing to the log file "Prolog.Log".
Another way to print, by using MS-DOS screen print command
<Print Screen>, everything on screen is printed out.
6. Programming in SymbMath
SymbMath is an interpreter, and runs a SymbMath program in
the Edit window, which is written by any editor in the text (ASCII)
file format.
SymbMath language is 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 funtional 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.
6.1. Data Types
The data types in SymbMath language is the numbers, constants,
variables, functions, equations, lists, arrays, vectors, matrixes,
and list index. All data can be operated. It is not necessary to declare
data to be which type, as SymbMath can recognize it.
6.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^307)^(10^307) to -(10^-307)^(10^-307), 0, (10^-307)^(10^-307)
to (10^307)^(10^307), inf.
The range of the output real numbers is the same as input
when the switch numerical=off, but when the switch numerical=on, it is
-inf, -1.E307 to -1.E-307, 0, 1.E-307 to 1.E307, inf.
It means that the number larger than 1.e307 is converted
automatically to inf, the absolute values of the number less than
1.e-307 is converted to 0, and the number less than -1e307 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.
6.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.
complex_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 expr is discont).
x0-zero approach x0 from negative (-inf) direction,
limit as zero ->0.
x0+zero approach x0 from positive (+inf) direction,
limit as zero ->0.
undefined the undefined value, e.g. indeterminate forms:
0/0, inf/inf, 0*inf, 0^0, etc.
--------------------------------------------------------------------
Notice that the constants discont and undefined 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 6.1.1. evaluate 1/sgn(x) and sin(x)/x at x=0.
Input:
f(x_) = 1/sgn(x)
f(0)
f(0+zero)
end
Output:
f(x_) = 1/sgn(x)
discont
1
Input:
f2=sin(x)/x
subs(f2, x=0)
lim(f2, x=0)
end
Output:
f2 = sin(x)/x
undefined
1
6.1.3. Variables
The sequence of characters is used as the name of variables.
Variables are used to store the results of calculations.
Variable names must start with a letter and use only letters and
numbers. They can be up to 124 characters long. They are
case sensitive until the switch lowercase is set to on
(lowercase=on). To assign a result to a variable, just put
<var-name> = before the expression to be evaluated:
a = 2 + 3 # assign value to a
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 program, 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
a = a+3
when a has no initial value will not cause an immediate
problem, but any future reference to a will result in an
infinite recursion !
The usual used independent variable is "x". A value can be assigned
to the variable, by
(1) the assignment = or :=,
(2) the user-defined function f(),
(3) the function subs().
e.g.
x=2, p:=3
f(2) # if f(x)=x^2 has been defined,
subs(x^2, x=2)
The built-in variable is "last". The variable "last" is
always automatically assigned the value of the last output result.
6.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.
6.1.5. Functions
6.1.5.1 Built-in Standard Mathematical Functions
Different versions of SymbMath have different built-in
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 n!, fac(n) and atan2(x,y), can be differentiated
and integrated symbolically.
Table 6.1.5.1 Built-in Standard Mathematical Functions
-----------------------------------------------------------------------
Functions Meanings
n! factorial of n.
fac(n) the same as n!.
sqrt(x) square root, the same as x^0.5.
exp(x) the same as e^x.
sgn(x) 1 when Re(x) > 0, or Re(x) = 0 and Im(x) > 0; 0 when
x=0; -1 otherwise.
abs(x) absolute value of x.
ln(x) natural logarithmic function of x, based on e.
sin(x) sine function of x.
............... above functions in Shareware Version A ...............
cos(x)
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) the radian angle of (x,y).
............... above functions in Student Version B .................
sinh(x) hyerbolic sine function of x.
cosh(x)
tanh(x)
csch(x)
sech(x)
coth(x)
asinh(x) arc hyerbolic sine function of x, the inverse of sinh(x).
acosh(x)
atanh(x)
acoth(x)
asech(x)
acsch(x)
--------------------------------------------------------------------------
6.1.5.2 Calculus and Transformation Functions
Calculus functions are for calculus calculation while trans-
formations functions are to move or take a piece of expression. The
first argument of the function is for evaluation.
Table 6.1.5.2 Calculus Functions
----------------------------------------------------------------------
Functions Meanings
subs(y, x=x0) substitutes x in y by x0.
lim(y, x=x0) gives the limit of y when x approaches x0. Note that
the correct answers only 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 nth order derivative of y with respect to an
undefined variable x.
d(y, x=x0) gives the derivative of y with respect to an undefined
variable x at x=x0.
d(y, x=x0, n) gives the nth order derivative of y with respect to an
undefined variable x at x=x0.
d(y) implicit differentiation, used in differential
equations, e.g. x*d(x)+y*d(y) === 0.
inte(y, x) find the indefinite integral of y with respect to an
undefined variable x.
inte(y,x,a,b) find the definite integral of y with respect to an
undefined variable x taken from x=a to x=b.
inte(y, x from a to b) the same as inte(y,x,a,b).
inte(y) implicit integration, used to integrate the
differential equations.
dsolve(d(y)/d(x)===f(x,y), y) solve differential equations.
sum(y, x from xmin to xmax step dx) sum of y.
sum(y, x from xmin to xmax) sum of y step=1.
prod(y, x from xmin to xmax step dx) product of y.
prod(y, x from xmin to xmax) product of y step=1.
---------------------------------------------------------------------
Note: the Shareware and Studen Versions have not dsolve().
Table 6.1.5.3 Transformation Functions
---------------------------------------------------------------------
expand(F) expand F, e.g. expand((a+b)^2) gives a^2 + 2*a*b + b^2.
factor(F) factorise from F, e.g. factor(a^2 + 2*a*b + b^2) gives
(a+b)^2.
solve(f(x)===0, x) solve polynomial and systems of linear
equations, or rearrange the equation.
list(a+b) transform sum to list.
sum([a,b]) transform list to sum.
coef(expr, x^n) gives the coefficient of x^n in expr.
assume(x>0) assume x>0.
assume(x<0) assume x<0.
isreal(x)=1 assume x is real.
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.
float(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.
----------------------------------------------------------------------
Note: the Shareware Version has not solve().
Table 6.1.5.4 Test Function
---------------------------------------------------------------------
Function Meaning
isodd(x) test if x if an odd number.
iseven(x) test if x is an even number.
isinteger(x) test if x is an integer number.
isreal(x) test if x is a real number.
isnumber(x) test if x is a number.
isfree(y,x) test if y is free of x.
----------------------------------------------------------------------
Table 6.1.5.5 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.
----------------------------------------------------------------------
For example:
-----------------------------------------------------------
differentiation d() d(x^2,x)
integration inte() inte(x^2,x)
limit lim() lim(sin(x)/x, x=0)
solving solve() solve(x^2+1===0, x)
expanding expand() expand((a+b)^2)
factoring factor() factor(a*c+b*c)
-----------------------------------------------------------
where "x" is an undefined variable.
Above functions can be operated and chained, like the standard
functions.
If a second argument x is omitted in the functions d(y)
and inte(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:
inte(inte(F,x), y) is double integral of F with respect
to both variables x and y.
d(y, x=x0, 2) is the second order derivative of y with
respect to x at x=x0.
d(d(y,x),t) is the mixed derivative of y with respect
to x and t.
The keywords "from" "to" "step" "," are the same as separators
in multi-arguement functions. e.g. inte(f(x), x, 0, 1) are the same as
inte(f(x), x from 0 to 1).
6.1.5.3 Users-defined Functions
Users can define the new functions, which include the
standard functions, calculus functions, and algebraic operators.
Users 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 the keywords. The maximum number of arguments
in the users-defined functions on this version is 5, but that in the
users-defined rules on this version is 2.
Alternately, users assign x^2 to a variable f by f=x^2, and
then call the variable f by subs(f, x=x0). f=x^2 seems a function.
To clears a variable or function from memory by
clear(x) clear x from memory.
clear(f(x)) clear f(x) from memory.
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.
6.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, and "===" is the
equation sign.
Systems of equations are a list of equations, e.g.
[a1*x+a2*y===a3, b1*x+b2*y===b3].
6.1.7 Lists, Array, Vectors and Matrices
A list is [a, b, c].
An array is a list of lists. e.g. [a, b, [c1, c2]].
A vector and matrix are similar a list and array, but in a
matrix, the number of elements in each row should be the same, e.g.
[[a11, a12], [a21, a22]].
6.1.8 List Index
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.
6.2 Operators
Table 6.2.1 Operators
-----------------------------------------------------------------
Operation Operators Examples Order
comma , a=2, b=3 1
immedate assignment = p=2+b 2
delayed assignment := p:=2+3 2
and and a>-2 and a<2 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
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 are
performed left to right. These are the usual algebraic conventions.
a^b^c is the same as (a^b)^c.
6.2.1 Assigment Operators
immedate assignment operator =
delayed assignment operator :=
e.g.
p=2+3
2+3 is evaluated at the time of assignment, i.e. p is assigned with 5.
p:=2+3
2+3 is evaluated when the value of p is requested, i.e. p is assigned
with 2+3.
The delayed assignment operator is used in the definition of
a function or procedure.
6.2.2 Arithmetic Operators
-----------------------------------------------------------
plus + a+b 4
minus - a-b 4
mutilation * a*b 5
division / a/b 5
power ^ a^b 6
power ** a**b 6
factorial ! n! 6
positive + +a 7
negative - -a 7
----------------------------------------------------------
6.2.3 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 assignment operators
= and :=.
The result of a comparison of two real numbers is one of
the values 1 or 0. If the comparsion is not both real numbers, it left
unevaluated.
6.2.4 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.
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.
6.3 Expressions
An expression (i.e. expr) is combination of data and operators.
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*(x>0) mixed numeric and Boolean expression
The result of Boolean expression with logic operators is
1 or 0. Boolean expression like 1 < 3 or 1 > 4 return a real value 1
or 0. Numerical 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.
6.4 Statements
The statements include:
comment statement
evaluation statement
assignment statement
conditional statement
loop statement
switch statement
command statement
compound statement
include statement
end statement
SymbMath program must be terminated by the end statement.
6.4.1 Comment Statement
# 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.
6.4.2 Evaluation Statement
The evaluation statement has the format:
expression
SymbMath evaluates any expression which in a line and gives
the value of the expression. e.g.
Input:
3 + 4
Output:
7 # the value of 3+4
Input:
d(x^6, x)
Output:
6 x^5 # the value of d(x^6, x)
The last output can be saved to a variable for the later use
by the built-in variable "last", e.g. f=last.
6.4.3 Assignment Statement
The assignment statement specifies that a new value of expr2
be assigned to expr1, and saved into memory. The forms of the
assignment statements are
expr1 = expr2
expr1 := expr2
where = is the immediate assignment operator (expr2 is evaluated at
the time of assignment), and := is the delayed assignment operator
(expr2 is evaluated when the value of expr1 is requested).
Note that not only a single variable but also an expression
can be assigned. e.g. x=2, sin(x)/cos(x)=tan(x).
e.g. evaluate of d() and assign the result (6*x^5) to f.
f=d(x^6,x)
6.4.4 Conditional Statement
There are two conditional statement:
if(test, f, g)
if(test, f)
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.
if(condition, x) gives x if condition evaluates to 1, or no
output otherwise.
It is useful in definition of the use-defined function to left the
function unevaluted 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).
6.4.5 Loop Statement
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.
Input:
x=1
do(x=x+1, j from 1 to 5 step 1)
end
Output:
x=1
x=5
end
The conditional loops are probably more useful than the do()
loops if a number of iteration is unknown. It is
repeat(f, test)
The repeat() repeats to evaluate f until the test is true (i.e. the
result of the test is 1).
e.g.
Input:
x=1
repeat(x=x+1, x>5)
end
Output:
x=1
x=6
end
6.4.6 Switch Statement
The switch statement sets or changes the switch status. The
switch status is unchanged in memory until the new switch status is
assigned.
----------------------------------------------------------------------
Switch Action
lowercase=on convert letters into the lower-case letters.
lowercase=off not convert letters into the lower-case letters,
this is default.
output=basic output form is BASIC format, this is default.
output=fortran output form is FORTRAN format.
output=prolog output form is Prolog format (internal form).
output=twodim output form is two dimension.
output=off not display output.
output=on the same as ouput=basic
numerical=on convert numbers to floating-point numbers.
numerical=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.
expexpand=on exponent expansion. e.g. c^(a+b) to c^a*c^b.
expexpand=off disable exponent expansion, this is default.
lnexpand=on log expand, e.g. ln(a*b) to ln(a)+ln(b)
lnexpand=off disable log expansion, this is default.
----------------------------------------------------------------------
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).
When the output is written to a disk file, it is recommended
to set the switch output=basic.
6.4.7 Command Statement
The command statement neither evaluates any expression nor
saves any expression. It executes a command.
----------------------------------------------------------------------
Commands Action
last show and simplify the last output.
last[1] show the first element of the last output list.
clear(x) clear the variable x from memory.
clear(f(x)) clear the user-defined function f(x) from memory.
system(xx) execute the MS-DOS command xx.
end terminate the program or file.
---------------------------------------------------------------------
6.4.8 Compound Statement
The all above statements are simple statements. The compound
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
6.4.9 Include Statement
The include statement includes a file into the user program.
It seems to copy the included file into the user program.
The format of include statement is
include('filename')
The filename is any MS-DOS file anme.
e.g. to include a file named 'inte.sm'.
include('inte.sm')
The file to be included must be in the current directory.
After a file is included, users 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. Users can include
many files in the SymbMath program at a time. However, all names
of the variables are public and name conflicts must be avoided.
6.4.10 End Statement
Program must be terminated by the end statement. The end
statement is "end" in a single last line:
end
6.5. Output Form
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. When the switch output=twodim, the
output form is the two dimensional math notation, but the expression
of power written to a disk file may be strange (e.g. x^6 is written
as x6). The default switch is output=basic.
Table 6.5.1 output switch
---------------------------------------------------------------------
output=basic output form is BASIC format, this is default.
output=fortran output form is FORTRAN format.
output=prolog output form is Prolog format (internal form).
output=twodim output form is two dimension.
output=off not display output.
output=on the same as ouput=basic.
---------------------------------------------------------------------
The output switch only change the output format, neither affect
the internal format nor the calculation.
6.6 Input and Output
---------------------------------------------------------------------
include('flename') read (run or include) the disk file 'filename'.
openfile('filename') open the disk file 'filename' for writing.
closedfile('filename') closed the file 'filename' and return output
to screen.
---------------------------------------------------------------------
The filename is any MS-DOS filename.
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
end
-----------------------------------------------------------------------
run this SymbMath program
----------------------------------------------------------------------------
include('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) # find derivative of y and write the result to the file
closefile('y.out') # close the file and return output to screen
end
----------------------------------------------------------------------------
The contents of the file 'y.out':
---------------------------------------------------------------------
6*x^5
---------------------------------------------------------------------
In this way you can interface to other software (see 10. Interface with
Other Software).
These output 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=basic.
(continued on the file SymbMath.DO2)