home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast2.iso
/
calculat
/
sm30a.zip
/
SYMBMATH.DOC
< prev
next >
Wrap
Text File
|
1993-11-15
|
204KB
|
5,471 lines
SymbMath 3.0: A Symbolic Calculator with Learning
(Version 3.0)
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, s9300078@cumulus.csd.unsw.oz.au
Copyright (C) 1990-1993
Nov. 12, 1993
You should register with the author if you use SymbMath.
Contents
PART 1
1. Introduction
1.1 What is SymbMath
1.2 Capabilities
1.3 Shareware, Student and Advanced Versions
1.4 A List of Files in SymbMath
2. SymbMath Environment: Windows and Menus
2.1 File Menu
2.1.1 Open
2.1.2 New
2.1.3 Save Input
2.1.4 Save Output
2.1.5 DOS Shell
2.1.6 Exit
2.2 Input Menu
2.2.1 Edit Help Menu
2.2.1.1 Show help file
2.2.1.2 Cursor movement
2.2.1.3 Insert & Delete
2.2.1.4 Block functions
2.2.1.5 Wordstar-like
2.2.1.6 Miscellaneous
2.2.1.7 Global functions
2.3 Run Menu
2.4 Output Menu
2.4.1 Edit Help Menu
2.5 Color Menu
2.5.1 Menu line
2.5.2 Edit window
2.5.3 Output window
2.5.4 Status line
2.6 Help Menu
2.7 Example Menu
2.8 Keyword Menu
3. Programming in SymbMath
3.1. Data Types
3.1.1 Numbers
3.1.2 Constants
3.1.3 Variables
3.1.4 Patterns
3.1.5 Functions, Procedures and Rules
3.1.5.1 Standard Mathematical Functions
3.1.5.2 Calculus Functions
3.1.5.3 Test Functions
3.1.5.4 Miscellaneous Functions
3.1.5.5 User-defined Functions
3.1.5.6 Procedures
3.1.5.7 Rules
3.1.6 Equations
3.1.7 Inequalities
3.1.8 Arrays and Array Index
3.1.9 Lists and List Index
3.1.10 Strings
3.2. Expressions
3.2.1 Operators
3.2.1.1 Arithmetic Operators
3.2.1.1 Relational Operators
3.2.1.2 Logical Operators
3.2.2 Function Calls
3.3. Statements
3.3.1 Comment Statements
3.3.2 Evaluation Statements
3.3.3 Assignment Statements
3.3.4 Conditional
3.3.5 Loop
3.3.6 Switch
3.3.6.1 Output Switch
3.3.6.2 Case Switch
3.3.6.3 Numeric Switch
3.3.6.4 Expand Switch
3.3.6.5 ExpandExp Switch
3.3.7 Read and Write Statements
3.3.8 DOS Command Statements
3.3.9 Sequenece Statements
3.4. Libraries and Packages
3.4.1 Initial Package
3.4.2 Chemical Calculation Package
3.5. Interface with Other Software
PART 2
4. Examples
4.1 Calculation
4.1.1 Discontinuity and one-sided value
4.1.2 Undefined and indeterminate forms
4.2 Simplification
4.2.1 Assuming domain
4.2.2 Comparising and testing numbers
4.3 Defining Your Own Functions, Procedures and Rules
4.3.1 Defining Your Own Functions
4.3.1.1 Defining Conditional Functions
4.3.1.2 Defining Case Functions
4.3.1.3 Defining Piece-wise Functions
4.3.1.4 Defining Recursion Functions
4.3.1.5 Defining Multi-value Functions
4.3.2 Defining Your Own Procedures
4.3.3 Defining Your Own Rules
4.4 Limits
4.4.1 One-sided Limits
4.4.2 Numeric Limits: NLim()
4.5 Differentiation
4.5.1 One-sided derivatives
4.5.2 Defining f'(x)
4.6 Integration
4.6.1 Indefinite Integration
4.6.2 Definite Integration
4.6.3 Numeric Integration: NInte()
4.7 Solving Equations
4.7.1 Solving Algebraic Equations
4.7.2 Solve()
4.7.3 Polynomial Solver: PSolve()
4.7.4 Numeric Solver: NSolve()
4.7.5 Solving Differential Equations
4.7.6 Differential Solver: DSolve()
4.8 Sums, Products, Series and Polynomials
4.8.1 Partial Sum
4.8.2 Infinite Sum
4.8.3 Series
4.8.4 Polynomials
4.9 Arrays, Lists, Vectors and Matrices
4.9.1 Arrays
4.9.1.1 Entering Arrays
4.9.1.2 Accessing Arrays
4.9.1.3 Modifying Arrays
4.9.1.4 Operating Arrays
4.9.2 Lists
4.9.2.1 Entering Lists
4.9.2.2 Accessing Lists
4.9.2.3 Modifying Lists
4.9.2.4 Operating Lists
4.9.3 Vectors and Matrices
4.10 Statistics
4.11 Tables of Function Values
4.12 Conversion
4.12.1 Converting to Numbers
4.12.2 Converting to Lists
4.12.3 Converting to Strings
4.12.4 Converting to Table
4.13 Getting parts of expression
4.13.1 Getting type of data
4.13.2 Getting operators
4.13.3 Getting operatands
4.13.4 Getting coefficients
4.14 Database
4.14.1 Phone No. Database
4.14.2 Chemical Reaction Database
4.15 Learning from User
4.15.1 Learning integrals from derivatives
4.15.2 Learning complicated integrals from a simple indefinite integral
4.15.3 Learning definite integral from indefinite integral
4.15.4 Learning integrals from algebra
4.15.5 Learning complicated derivatives from a simple derivative
4.15.6 Learning complicated algebra from simple algebra
4.15.7 Learning vs. programming
5. Graphics
5.1 Drawing lines and arcs
5.2 Plotting y = f(x)
5.3 Plotting r = f(t) in polar coordinates
PART 3
6. Inside SymbMath
6.1 Internal Structure
6.2 Internal Format
7. System Limits
8. Keywords
8.1 Keywords in Functional Order
8.2 Keywords in Alphabetical Order
8.3 Glossary
9. References
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, table 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 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 symbolic, numeric and graphics computing
environment where you can set up, run and document your calculation,
and draw your graph.
SymbMath is database where you can search your database.
SymbMath is a multi-windowed text editor in which you can edit
many documents in many windows.
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:
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.
o User-defined functions: conditional, case, piecewise, recursion.
o 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.
o Limits: real, complex or one-sided limits, indeterminate forms.
o Complex: calculation, functions, derivatives, integration.
o Sum and product: partial, finite or infinite.
o Others: series, lists, arrays, vectors, matrices, tables, etc.
Also included are:
o Pull-down and pop-up menus, resizable and colourable windows.
o Programming in integrated edit-interpret-debug environment.
o On-line help, and on-line manual.
o Procedural, conditional, iterational, recursive, functional,
rule-based, logic, pattern-matching and graphic programming.
o Autoloaded library in the SymbMath language.
o Plotting functions and graphing.
o Searching database.
1.3 Shareware, Student and Advanced Versions
You should register with the author if you use SymbMath.
Please read the document file SymbMath.DOC 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.
On the MS-DOS prompt to install it, type
install
On the MS-DOS prompt to run it, type
SymbMath
SymbMath has three versions: Shareware Version A, Student
Version B and Advanced Version C. The shareware version lacks the
solve(), trig (except sin(x) and cos(x)), and hyerbolic functions,
(lack 10% keywords) and the student version lacks the hyerbolic
functions (lack 5% keywords). You cannot input these lack functions
in shareware or student version.
----------------------------------------------------------------------
Version Class Lacked Functions Price
Shareware A solve(), hyerbolic, US$10 or AU$15
trig (except sin(x), cos(x))
Student B hyerbolic US$50 or AU$70
Advanced C US$99 or AU$140
Libraries *.(x) US$20 or AU$25
.......................................................................
Upgrade same 50%
.......................................................................
Multiple copies >2 80%
.......................................................................
Site licence >10 copies 50%
-----------------------------------------------------------------------
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 a legal user 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 (e.g. oak.oakland.edu in /pub/msdos/calculator as sm30a.zip).
1.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 document file or manual file.
readme the read-me file, this file should be read first.
init.sm initial SymbMath program file.
*.sm packages (user SymbMath program files).
*.(x) the auto loaded libraries (external functions).
*.key the keyword files.
*.bgi BGI graphics drives.
*.chr stroked fonts.
prolog.err prolog error message file.
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.
shareware.txt shareware concept.
software.txt software available from the author.
update.txt the latest updates in SymbMath.
PlotData.txt introduction of PlotData.
------------------------------------------------------------------------
See Chapter 3.4 "Library and Package" for the detail of the *.(x)
and *.sm files.
2. SymbMath Environment: Windows and Menus
When you start SymbMath, the computer screen looks like:
--------------------------------------------------------------------------
| File Input Run Output Color Help Example Keyword |
---------------------------------- Input ---------------------------------
| |
| |
| |
--------------------------------------------------------------------------
---------------------------------- Output --------------------------------
| |
| |
| |
| |
--------------------------------------------------------------------------
SymbMath 3.0 | 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.
2.1 File Menu
The File menu has 5 choices in the pull-down menu:
-----------
|Open |
|New |
|Save |
|DOS shell|
|Exit |
-----------
2.1.1 Open
The Open command opens a file for edit in the Input window. This
command first opens 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 2.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
s go to the s filename, where s is any single letter.
-------------------------------------------------------------------
You select a file from the Directory window to open for edit in
the Input window.
2.1.2 New
The New command creates a new file, clears the Input window,
and changes the content of the status line to
----------------------------------------------------------------------------
Input filename | <F8> Last filename, -><- Edit, <Enter> Accept, <Esc> Abort
----------------------------------------------------------------------------
2.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.
2.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.
2.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.
2.1.6 Exit
The Exit command exits from SymbMath.
2.2 Input Menu
The Input menu goes into the Input window.
SymbMath includes a multi-windowed text editor for creating
and modifying program files. Usage of the editor is similar to
WordStar in nondocument mode, to Borland's SideKick, or to Borland's C
compiler.
Within the Input 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 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 2.2.1 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 2.2.1 Edit window commands
---------------------------------------------------------------------
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
--------------------------------------------------------------------------
F1 Help, F2 Save, F3 Open, F4 Replace, F5 Zoom, F7 XCopy, F8 XEdit, F10 End
--------------------------------------------------------------------------
indicates that to press <F1> key to get help.
Table 2.2.2 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 pressing <F1>, select the editing
command from its sub-menus by the arrow keys and <Enter>.
2.2.1 Edit Help Menu
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. You can select the edit command in the sub-menu by the
up or down key and <Enter>.
2.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 inteprets the users programm in the Input window.
You can run the program from the disk (see Chapter 3.4 Packages).
2.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 file
"output".
2.5 Color Menu
The Color menu has 4 choices:
---------------
|Menu line |
|Edit window |
|Output window|
|Status line |
---------------
When you choose one of them, a color pattern will come up. There
are 125 colors in the color pattern. Select your favour color by the
arrow keys and <Enter>.
2.5.1 Menu line
It is to change the menu line's color.
2.5.2 Edit window
It is to change the edit window's color.
2.5.3 Output window
It is to change the output window's color.
2.5.4 Status line
It is to change the status line's color.
2.6 Help Menu
The Help menu dispays the syntax of SymbMath language.
------------------
|How to help |
|Contents |
|Brief |
|Data |
|Function |
|Procedure & rule|
|eqUation |
|Array & list |
|Expression |
|commenT |
|eValuate |
|assigN |
|cOnditional |
|Loop |
|sWitch |
|Read & write |
|Sequence |
|librarY |
------------------
In the Help menu, 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 2.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>.
<Home> go to the beginning of the current line.
<End> go to the end of the current line.
<Pg Up> page up.
<Pg Dn> page down.
<Ctrl><Home> go to the beginning of the window.
<Ctrl><End> go to the end of the windo.
<Ctrl><Pg Up> go to the beginning of the help file.
<Ctrl><Pg Dn> go to the end of the help file.
<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.
x go to x, where x is a letter.
----------------------------------------------------------------------
There are other two helps in the Input, Output and Aux Edit
windows, press <F1> to pop-up the Edit Help menu, or press <Shift><F1> to
open a Help File window for manual.
2.7 Example Menu
The Example menu shows examples in SymbMath language.
---------------
|Calculate |
|Simplify |
|assUme |
|comparE |
|deFine |
|Limit |
|Differentiate|
|Integrate |
|sOlve |
|suM |
|Vector |
|stAtistics |
|Table |
|conveRt |
|Get parts |
|databasE |
|learN |
|draW |
|Plot |
---------------
2.7 Keyword Menu
The Keyword menu showes keywords in the SymbMath language.
--------------------
|Topic order |
|Alphabetical order|
|Index |
|Library index |
--------------------
The Topic order 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 letter, its filename is the first
8 letter 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 *.(x)).
3. 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 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.
In the following examples, a line of "IN: " means input, which
you type in the Edit window, then leave the Edit 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.
3.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 recognize it.
3.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 numeric:=off, but when the switch numeric:=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.
3.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 rigth-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 3.1.1. 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 discontinuty, 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
3.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. 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, 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 4.2
Simplification and Assumption).
3.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 in SymbMath language are similar with patterns in such
language as MATHEMATICA.
3.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
automately loaded when it is needed. (See Chapter 3.4 Library and Package).
The usgae 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.
3.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 3.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 when
x=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) 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)
--------------------------------------------------------------------------
3.1.5.2 Calculus Functions
Calculus functions are for calculus calculation. The first
arguement of the function is for evaluation, and the second arguement
is a varilable that is with repsect to.
Table 3.1.5.2 Calculus Functions
----------------------------------------------------------------------
Functions Meanings
subs(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 nth order derivative of y with respect to an
undefined variable x.
d(y) implicit differentiation.
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,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.
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(y'(x)=f(x,y), y(x), x) solve differential equations.
sum(y, x from xmin to xmax) sum of y step=1.
sum(y, x from xmin to xmax step dx) sum of y.
prod(y, x from xmin to xmax) product of y step=1.
prod(y, x from xmin to xmax step dx) product of y.
---------------------------------------------------------------------
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(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).
Examples:
-------------------------------------------------------------------
differentiation d() d(x^2,x)
integration inte() inte(x^2,x)
limit lim() lim(sin(x)/x, x = 0)
--------------------------------------------------------------------
3.1.5.4 Test Functions
Table 3.1.5.4.1 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 3.1.5.4.2 type(x) functions
--------------------------------------------------
x type(x)
1 "integer"
1.1 "real"
2/3 "ratio"
1+i "complex"
sin(x) "sin()"
[1,2] "[]"
a "variable"
a+b "+"
a*b "*"
a^b "^"
"a" "string"
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".
3.1.5.3 Miscellaneous Functions
Table 3.1.5.3 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, or rearrange the equation.
---------------------------------------------------------------------
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)
-----------------------------------------------------------
where x is an undefined variable.
Conversion functions convert a type of data to another
type of data.
Table 3.1.5.4 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 3.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.
----------------------------------------------------------------------
Above functions can be operated and chained, like the standard
functions.
3.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. The maximum number of arguments
in the users-defined functions on this version is 6, but that in the
users-defined rules on this version is 2.
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.
3.1.5.6 Procedures
A procedure is similar to a function, but the right side of
assigment in its definition is multi statements grouped by block().
block(a,b,c) groups a,b,c and only returns the last arguement as its
value, or returns the second last arguement as its value if the last
arguement is local(). It is used as grouper in definition of a procedure.
All variables in block are global, except for variables declared by
local().
e.g. f(x_):=block(p:=x^6,p,local(p))
Remember that you can split a line of program into multi-lines
program at comma ,.
3.1.5.7 Rules
Defining rules is similar to defining functions. In definition
of function, all arguements of function are simple variables, but in
definition of rules, the first arguement 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
3.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.
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].
3.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
3.1.8 Arrays and Array Index
Arrays are the same as arrays 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.
3.1.9 Lists and List Index
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.
3.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.
Strings can be storeed in variables, concatenated, removed,
lengthed, 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: remove("b" from "ab") # remove "b" from "ab"
OUT: "a"
IN: length("abc") # count length of "abc"
OUT: 3
IN: number("123") # convert string "123" into number 123
OUT: 123
3.2. Expressions
Expressions (i.e. expr) are made up of operators and operands.
Most operator are binary, that is, they take two operands; the rest
are unary and take only one operand. Binary operators use the usal
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
3.2.1 Operators
Table 3.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
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).
3.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
power ** a**b 6
positive + +a 7
negative - -a 7
--------------------------------------------------------------------
3.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 comparsion is not both real numbers, it left unevaluated.
3.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.
3.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 decalaration 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 .fun when needed.
Some examples of function calls follow:
sin(x) # will load the library sin.fun when needed
inte(x^2, x) # will load the library inte.fun when needed
3.3 Statements
3.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.
3.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.
3.3.3 Assignment Statements
The assignement 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 assignemts 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 assignmemt 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).
3.3.4 Conditional
There are two conditional functions:
if(test then x)
if(test then x else y)
if(condition then x) gives x if condition evaluates to 1, or no
output otherwise.
if(condition then x else 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 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).
3.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:=1
OUT: x := 1
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
3.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 ouput:=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.
----------------------------------------------------------------------
3.3.6.1. Output Switch
When the switch output:=math, the output displays the math symbol
notation (e.g. π).
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.
Example 3.3.6.1
In the Input window, you type
inte(pi*sin(x)^2,x)
You see the display of your input in the Output window as
⌠ π sin(x)^2 dx
--------------------------------------
Math symbol Typing
π pi
⌠ f(x) dx inte(f(x),x)
√x sqrt(x)
a b a*b
-------------------------------------
3.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).
3.3.6.3 Numeric Switch
Example.
IN: 1/2
OUT: 1/2
IN: numeric:=on
IN: 1/2
OUT: 0.5
3.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
3.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
3.3.7 Read and Write Statements
The format of the readfile statement is
readfile("filename")
The filename is any MS-DOS file anme. It seems to copy the file into the
user program.
e.g. to read a file named "inte.sm":
readfile("inte.sm")
The file to be read must be in the current directory.
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")
...
closefile("file")
Table 3.3.7. Reading and Writing Statements
---------------------------------------------------------------------
readchar read a charactor 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 arguement, 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.
3.3.8 DOS Command
You can executes a DOS command in SymbMath language by
system("dir")
3.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
3.4. Libraries and Packages
A library is a file of an external function, which filename is its
function name within 8 letters plus extension .(x). e.g. the library named
sin.(x) is a file of the sin(x) function definition.
You can protect a library (e.g. sin.(x)) for write-protect by
the DOS command:
attrib +r sin.(x)
or for hidden-protect by the DOS command:
attrib +h sin.(x)
You can remove the write-protect of a library by the DOS command:
attrib -r sin.(x)
or remove the hidden-protect by the DOS command:
attrib -h sin.(x)
The library (*.(x) file) is similar to the MS-DOS .bat file. You
need not 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.(x) will be autoloaded. 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.(x) 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 .(x). It is recommanded that its filename has the extension .sm.
A package is similiar to a libarary, 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. inte.sm is the filename of the integral package as
the name of integral function is inte().
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.
Alternately, a part of the package file rather than the whole
package file can be copied into the Input window by pressing <F7>
(external copy) in order to save memory space.
You can convert a package of f.sm into a library by renaming f.sm
to f.(x) for auto loading, or a library f.(x) to a package by renaming
f.(x) to f.sm for not auto loading.
There are many libraries and packages. The following are some
of them.
Table 3.4.1 Libraries and Packages
------------------------------------------------------------------------
File Name Package Function
plot.(x) plotting functions.
d.(x) derivatives.
inte.(x) integrals.
sin.(x) sin(x) function.
cos.(x) cos(x) function.
fac.(x) n!.
sign.(x) sign(x) function.
abs.(x) abs(x) function.
arg.(x) arg(x) function.
sum.(x) sum function.
NInte.(x) numeric integration.
NSolve.(x) numeric solver of equation.
DSolve.(x) differential equation solver.
gamma.(x) gamma function.
ei.(x) exponential integral function.
series.(x) Taylor series.
partSum.(x) partial sum.
infSum.(x) infinite sum.
sinh.(x) sinh(x) function.
cosh.(x) cosh(x) function.
average.(x) average([x]) function.
listSum.(x) sum of list of data.
react.(x) chemical reactions database.
phoneNo.(x) phone No. database.
.......................................................................
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.
tExpand.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 intefacing software PlotData.
-----------------------------------------------------------------------
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.
3.4.1 Initial Package
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")
3.4.2 ExpandLn Package
The lnexpand.sm package does the logarithmic expansion.
e.g. ln(a*b) is expanded into ln(a)+ln(b).
3.4.3 Chemical Calculation Package
SymbMath recognizes 100 symbols of chemical elements and
converts them into their atomic weights after the chemical package of
"Chemical.sm" is read.
Example 3.4.3.1.
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 3.4.3.2.
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
3.5. Interface with Other Software
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 "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 3.5.1.
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.
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.
4. Examples
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.
4.1 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 only gives a principle value if there
are multi-values, except for the solve() and root().
Example 4.1.1.
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 4.1.2.
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 4.1.3.
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 4.1.4.
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 arguement can be calculated.
Example 4.1.5.
IN: sign(1+i), sign(-1-i), i^2
OUT: 1, -1, -1
Example 4.1.6.
IN: exp(inf+pi*i)
OUT: -inf
IN: ln(last)
OUT: inf + pi*i
The built-in constants of inf or -inf, zero or -zero, and
discont or undefined can be used as numbers in calculation of
expressions or functions.
4.1.1 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 4.1.7.
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
4.1.2 Undefined and indeterminate form
If the function value is undefined, it may be indetermate form
(e.g. 0/0, inf/inf), you can evaluate it by lim() (see Chapter 4.4 Limits).
4.2 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 factorized 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 factorized by
factor(y, x)
Example.
IN: factor(x^2+5*x+6, x)
OUT: (2 + x) (3 + x)
Note that Shareware version of SymbMath cannot do this factor as
it lacks solve().
Example 4.2.1.
Reduce sqrt(x^2).
IN: sqrt(x^2)
OUT: x*sign(x)
This output can be further simplified if you know proporties of x.
A first way is to evaluate x*sign(x) when sign(x) = 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).
4.2.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.
You can restrict the domain of a variable by assuming the variable
is even, odd, integer, real number, positive or negative.
Example 4.2.3.
IN: isreal(b) := 1 # assume b is real
IN: sqrt(b^2)
OUT: abs(b)
Table 4.2 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).
Simplification in different domains
---------------------------------------------------------------------
exprsseion 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
----------------------------------------------------------------------
4.2.2 Comparising and testing numbers
You can compare two numbers by relational operators
a > b
a < b
a <= b
a >= b
a <> b
a == b
Example 4.2.5.
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 4.2.6.
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 squre of a variable a^2 > 0 if you know the
property of the variable.
Example 4.2.7.
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 is* 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.3 Defining Your Own Functions, Procedures and Rules
4.3.1 Defining Your Own Functions
Anytime when you find yourself using the same expression over
and over, you should turn it into a function.
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 arguement 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 4.3.1.
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.3.1.1 Defining Conditional Functions
You can define a conditional function by the if() function:
f(x_) := if(x>0 then 1)
f(x_) := if(x>0 then x^2 else x)
or by inequalities:
f(x_) := x>0
f(x_) := (x>0) * x^2 + (x<=0) * x
On the first definition by if(), when f() is called it gives 1 if x>0,
or left unevaluated otherwise. On the second definition by the if(), when
f() is called it gives x^2 if x>0, x if x<=0, or left unevaluated
otherwise. On the third definision by the inequality, when f() 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 f() is called, it is evaluated for any
numeric or symbolic value of x.
Remember that the words "then" and "else" can be replaced by
comma ,.
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) then 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 4.3.2.
evaluate to x^2 only if x is number, by defining a conditional function.
IN: f(x_) := if(isnumber(x) then x^2)
IN: f(2), f(a)
OUT: 4, f(a)
IN: f(x_) := if(x>0 then x^2)
IN: f(2), f(-2), f(a)
OUT: 4, f(-2), f(a)
IN: f(x_) := if(x>0 then x^2 else x)
IN: f(2), f(-2), f(a)
OUT: 4, 2, f(a)
4.3.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 then 1)
IN: f(u_) := if( u > 1 and u < 2 then 2)
IN: f(v_) := if( v > 2 and v < 3 then 3)
IN: f(0.2), f(1.2), f(2.2)
OUT: 1, 2, 3
4.3.1.3 Defining Piece-wise Functions
You can define a piece-wise function.
Example 4.3.3.
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'(x), diff(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'(x)
OUT: (x < 0) + 2 x (x > 0)
IN: diff(f(x), x=3)
OUT: 6
4.3.1.4 Defining Recursion Functions
You can define a recursion function.
Example.
IN: factoria(n_) := if(n > 1, (n-1)*factoria(n-1))
IN: factoria(1) := 1
4.3.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]
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 .(x) as the filename. e.g. saving above factoria
function as the factoria.(x) file (see Section 3.6 Libraies and Packages).
4.5.2 Defining Your Own Procedures
You can define a function as a procedure by
f(x_) := block(command1, command2, ..., commadN)
f(x_) := block(command1, command2, ..., commandN, local(a))
By default, all variables within procedure are global, except for
variables declared by local(). The mult-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 mult-line can be teminated by a comma,
(not by a comma and a blank space). Local() must be the last one in
block().
Example 4.5.2.
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 from 1 to 2)
4.5.3 Defining Your Own 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 4.5.3.1
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 4.5.3.2
IN: sin(-x_) := -sin(x)
IN: sin(-a)
OUT: -sin(a)
Example 4.5.3.3
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 4.5.3.4
define Laplace transform rules.
IN: laplace(sin(t_), t_) := 1/(t^2+1)
IN: laplace(sin(s), s)
OUT: 1/(s^2 + 1)
4.4 Limits
4.4.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 you 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 4.4.2.
Evaluate y=exp(1/x) at x=0, if the result is discontinuty, 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 # discontinuty at x=0
IN: subs(y, x = 0+zero), subs(y, x = 0-zero)
OUT: inf, 0
Example 4.4.3:
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 functiuons.
# 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 4.4.1.
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
4.4.2 Numeric limits: NLim()
If symbolic limit sometines fall, you should try numeric limit by
nlim(y, x=x0)
4.5 Differentiation
Differentiate an expression y with respest to x by
d(y, x)
Differentiate a simple function f(x) by
f'(x)
Differentiate y in order ( order > 0 ) by
d(y, x, order)
Differentiate y when x = x0 by
diff(y, x = x0)
Differentiate y when x = x0 in order (order > 0) by
diff(y, x = x0, order)
Example 4.5.1.
Differentiate sin(x) and x^(x^x).
IN: sin'(x) # sin'(x) 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), x must be a simple variable and f(x)
must be not evaluated.
f'(x0) is different from diff(f(x), x=x0). f'(x0) first evaluates
f(x0), then differentiate the result of f(x0). But diff(f(x), x=x0) first
differentiate 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), and sin'(0) gives d(0,0) as sin(0) is evaluated to 0
before differentiation. diff(sin(x),x=0) gives 1.
Example 4.5.2.
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))
4.5.1 One-sided derivatives
Differentiate y when x = x0-zero or 0+zero (the left- or right-
sided derivative) by
diff(y, x = x0-zero)
diff(y, x = x0+zero)
Example.
IN: diff(ln(x), x=0)
OUT: discont # discontinulity at x=0
IN: diff(ln(x), x=0-zero) # left-sided derivative at x=0-
OUT: -inf
IN: diff(ln(x), x=0+zero) # right-sied derivative at x=0+
OUT: inf
4.5.2 Defining f'(x)
Defining derivatives is similar to defining rules. You only need
to define derivatives of a simple function, as SymbMath automately apply
the chain rule to its complicated function.
Example 4.5.2.2.
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)
4.6 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 inte.(x) library),
then do integration again (see Chapter 4.14 Learning from User).
4.6.1 Indefinite Integration
Find the indefinite integrals of expr by
inte(expr, x)
Find the double indefinite integrals by
inte(inte(expr, x), y)
Note that the arbitrary constant is not represented.
Example 4.6.1.
Find integrals of 1/a, 1/b and 1/x, knowing a >0, b is real.
IN: assume(a>0), isreal(b):=1
IN: inte(1/a, a), inte(1/b, b), inte(1/x, x)
OUT: ln(a), ln(|b|), ln(x*sign(x))
Example 4.6.2.
Find indefinite integrals.
IN: inte(sin(a*x+b), x) # integrands involving sin(x)
OUT: -cos(b + a x)/a
IN: inte( sin(x)/x^2, x)
OUT: ci(x) - sin(x)/x
IN: inte( x*sin(x), x)
OUT: -x cos(x) + sin(x)
IN: inte(sin(x)*cos(x), x)
OUT: (1/2)*sin(x)^2
IN: inte( e^(x^6), x) # integrands involving e^x
OUT: 1/6 ei(-5/6, x^6)
IN: inte( x^2*e^x, x)
OUT: ei(2, x)
IN: inte( x*e^(-x), x)
OUT: -e^(-x) - x e^(-x)
IN: inte( e^x/sqrt(x), x)
OUT: ei(-0.5, x)
IN: inte(x^1.5*exp(x), x)
OUT: ei(1.5, x)
IN: inte(sin(x)*e^x, x) # integrals involving sin(x) and e^x
OUT: 1/2 * (sin(x) - cos(x)) * e^x
IN: inte( x*ln(x), x) # integrands involving ln(x)
OUT: -1/4 x^2 + 1/2 x^2 ln(x)
IN: inte( ln(x)^6, x)
OUT: li(6, x)
IN: inte( ln(x)/(√x), x)
OUT: -4 √x + 2 √x ln(x)
IN: inte( ln(x)/sqrt(1 + x), x)
OUT: -4 √(1 + x) + 2 √(1 + x) ln(x) - 2 ln((-1 + √(1 + x))/(1 + √(1 + x)))
IN: inte( 1/(a x + b), x) # integrands involving polynomials
OUT: ln((b + a x) sign(b + a x))/a
IN: inte( x/(x^2 + 5 x + 6), x)
OUT: 1/2 ln(|6 + 5 x + x^2|) - 5/2 ln(|(2 + x)/(3 + x)|)
IN: inte( (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 4.6.3.
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: inte(u*d(u,t)+v*d(v,t)+w*d(w,t), t)
OUT: 63 t^2
Example 4.6.4.
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: inte(x^2*e^x, x)
OUT: ei(2,x) # ei()
IN: readfile("ExpandEi.sm")
IN: 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 4.6.5
IN: inte(f(x_), x_) := sin(x)
IN: inte(f(t), t)
OUT: sin(t)
4.6.2 Definite Integration
Find definite integrals by external functions
inte(expr, x from xmin to xmax)
inte(expr, x from xmin to singularity to xmax)
Example 4.6.6.
Find the definite integral of y=exp(1-x) with respect to x taken
from 0 to infinity.
IN: inte(exp(1-x), x from 0 to inf)
OUT: e
Example 4.6.7.
do discontinuous integration of 1/x^2 and 1/x^3 with discontinuty at x=0.
IN: inte(1/x^2, x from -1 to 2) # singularity at x=0
OUT: inf
IN: inte(1/x^3, x from -1 to 1) # singularity at x=0
OUT: 0
IN: inte(sqrt((x-1)^2), x from 0 to 2) # singularity at x=1
OUT: 1
SymbMath usually detect singularity, but sometime it cannot,
in this case you must provide singularity.
Example:
IN: inte(1/(x-1)^2, x from 0 to 1 to 2) # provide singularity at x=1
OUT: inf
Example 4.6.8
do complex integration.
IN: inte(1/x, x from i to 2*i)
OUT: ln(2)
4.6.3 Numeric Integration: NInte()
The external function
ninte(y, x from xmin to xmax)
does numeric integration.
Example 4.6.3.1.
Compare numeric and symbolic integrals of 4/(x^2+1) with
respect to x taken from 0 to 1.
IN: ninte(4/(x^2+1), x from 0 to 1)
OUT: 3.1415
IN: num(inte(4/(x^2+1), x from 0 to 1))
OUT: 3.1416
4.7 Solving Equations
4.7.1 Solving Algebraic Equations
The equations can be operated (e.g. +, -, *, /, ^, expand(),
diff(), inte()). 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 4.7.1.
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.
4.7.2 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).
Shareware version has not this solve() function.
Example 4.7.2.
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 4.7.3.
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 4.7.4.
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 4.7.5.
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)]
4.7.3 Polynomial Sovler: 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.
4.7.4 Numeric Solver: NSolve()
The external functions
nsolve(f(x) = x, x)
nsolve(f(x) = x, x,x0)
numericly solves an algebraic equation with an initial value x0. By
default x0=1. nsolve() only gives one solution near x0, omitting other
solutions.
Example 4.7.4.1.
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
4.7.5 Solving Differential Equations
You can solve the differential equations:
y'(x) = f(x)
by integrating the equation.
y'(x) is the same as d(y(x),x).
Example: 4.7.4.1
solve y'(x)=sin(x) by integral.
IN: inte( y'(x) = sin(x), x)
OUT: y(x) = constant - cos(x)
4.7.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 4.7.6.1
Solve y'(x) = sin(x) by dsolve().
IN: dsolve( y'(x) = sin(x), y(x), x)
OUT: y(x) = constant - cos(x)
Example 4.7.6.2
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 4.7.6.3
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
4.8 Sums, Products, Series and Polynomials
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(expr, x from xmin to xmax)
sum(expr, x from xmin to xmax step dx)
prod(expr, x from xmin to xmax)
prod(expr, x from xmin to xmax step 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 from 1 to 10)
for 1 + 2 + .. + 10.
sum(3^j, j from 0 to 10 step 2)
for 1 + 3^2 + ... + 3^10.
Here are some sample Taylor polynomials:
sum(x^j/j!, j from 0 to n)
for exp(x).
sum((-1)^j*x^(2*j+1)/(2*j+1)!, j from 0 to n)
for sin(x) of degree 2*n+2.
Remember, the 3 keywords (from, to and step) can be replaced by
the comma ,.
4.8.1. Partial Sum
The function
partsum(f(x),x)
finds the partial sum (symbolic sum).
Example 4.8.1.1.
Find the sum of 1^2 + 2^2 ... + n^2.
IN: partsum(n^2, n)
OUT: 1/6 n (1 + n) (1 + 2 n)
4.8.2 Infinite Sum
The function
infsum(f(x),x)
finds the infinite sum, i.e. sum(f(x), x from 0 to inf).
Example:
IN: infsum(1/n!, n)
OUT: e
4.8.3. Series
The external functions
series(f(x), x)
series(f(x), x, order)
to find the Taylor series at x=0. The arguement (order) is optional and
defaults to 5.
Example 4.8.3.1.
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),
you may be able to calculate the function value at any x, by series
expansion. Accurary of calculation depends on the order of series
expansion. Higher order, more accuracy, but longer calculation time.
Example 4.8.3.2.
calculate f(i), knowing f'(x)=-sin(x) and f(0)=1.
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(i)
OUT: 37/24
4.8.4 Polynomials
Polynomials are automately 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 with x by
factor(poly, x)
e.g.
IN: factor(x^2+5*x+6, x)
OUT: (2 + x) (3 + x)
Note that Shareware version of SymbMath cannot do this factor as
it lacks solve().
4.9 Arrays, Lists, Vectors and Matrices
You can construct arrays and lists of arbitrary length, and the
entries in the arrays and lists can be of any type of value whatsoever:
constants, expressions with undefined variables, or equations.
A vector and 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]].
4.9.1 Arrays
4.9.1.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)
4.9.1.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
4.9.1.3 Modifying Arrays
You can modify an array by assigning new value into its index
IN: a[1]:=2
4.9.1.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
4.9.2 Lists
4.9.2.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 arguement:
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)
4.9.2.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], ... ]
4.9.2.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.
4.9.2.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
inte()).
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)
4.9.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 diff() and inte().
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.
represnt 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
represnt 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]]
4.10 Statistics
The functions:
average(x), max(x), min(x), listsum(x), length(x)
do statistical operations.
A list of numbers can be calculation on staticstics.
Example 4.10.1.
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
4.11 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 4.11.1.
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).
4.12 Conversion
Different types of data may be converted each other.
4.12.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 interger number by
tranc(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")
4.12.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 lsit of multiphiers 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) ]
4.12.3 Converting to strings
You can convert numbers to strings by
string(123)
IN: string(123)
OUT: "123"
4.12.4 Converting to Table
A list of real numbers can be converted to a table by
table()
Example 4.12.1.
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
4.13 Getting parts of expression
4.13.1 Getting type of data
You can get type of data by
type(x)
IN: type(2)
OUT: "integer"
4.13.2 Getting operators
You also can get operators by
type(x)
IN: type(a>b)
OUT: ">"
IN: type(sin(x))
OUT: "sin()"
4.13.3 Getting operatands
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
4.13.4 Getting coefficients
A coefficient of x^n in an expression can be picked up by
coef(p, x^n)
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 4.8.4 Polynomials for detail).
4.14 Database
After you creat a database file as a library (external function),
you can search your database by finding its function value.
4.14.1 Phone No. Database
If you have created the database file "phoneNo.(x)" as follow:
-------------------------------------
phoneno("huang") := "6974643"
phoneno("john") := "12345"
--------------------------------------
you can find out phone No. of someone from the phone No. database
file "phoneNo.(x)" by the external function
phoneno("name")
Example 4.14.1
find out phone No. of huang.
IN: phoneno("huang")
OUT: "6974643"
4.14.2 Chemical Reaction Database
You can predict products for chemical reactions from the
database file "react.(x)".
Example 4.14.2.
What are the products when HCl + NaOH react ?
IN: react(HCl+NaOH)
OUT: H2O + NaCl
4.15 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.
4.15.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'(x).
Example 4.15.1.1 :
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.
Input:
IN: inte(f(x), x) # check SymbMath whether or not it had already
# known integral of f(x)
OUT: inte(f(x), x)
IN: inte(f(x), x, 1, 2)
OUT: inte(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: inte(f(x), x)
OUT: x*f(x) - e^x
IN: inte(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.
An other example is
IN: f'(x_) := 1/sqrt(1-x^2)
IN: inte(f(x), x)
OUT: sqrt(1 - x^2) + x*f(x)
IN: inte(k*f(a*x+b), x)
OUT: k*(sqrt(1 - (b + a*x)^2) + (b + a*x)*f(b + a*x))/a
IN: inte(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 4.15.1.2 :
IN: f'(x_) := eval(inte(cos(x),x))
OUT: f'(x_) := sin(x)
IN: inte(f(x), x)
OUT: -sin(x)
IN: inte(f(a*x + b), x)
OUT: -sin(b + a*x)/a
IN: inte(x*f(x), x)
OUT: -cos(x) - x*sin(x)
IN: inte(x^1.5*f(x), x)
OUT: 1.5*inte(sqrt(x)*sin(x), x) - x^1.5*sin(x)
IN: inte(x^2*f(x), x)
OUT: -2*x*cos(x) + 2*sin(x) - x^2*sin(x)
IN: inte(x*f(x^2), x)
OUT: -sin(x^2)
IN: inte(x^3*f(x^2), x)
OUT: -0.5*cos(x^2) - 0.5*x^2*sin(x^2)
IN: inte(f(x)/(x^1.5), x)
OUT: -2/sqrt(x)*f(x) + 2*inte(sin(x)/sqrt(x), x)
IN: inte(f(x)/(x^2), x)
OUT: -f(x)/x + si(x)
4.15.2 Learning complicated indefinite integrals from a simple
indefinite integral
You supply a simple indefinite integral, and in return, SymbMath
will perform the related complicated integrals.
Example 4.15.2.1 :
Check whether SymbMath already knowns the following integrals or not.
IN: inte(f(x), x)
OUT: inte(f(x), x)
IN: inte((2*f(x)+x), x)
OUT: inte((2*f(x)+x), x)
IN: inte(inte(f(x)+y), x), y)
OUT: inte(inte(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: inte(f(x_), x_) := f(x) - x
IN: inte(2*f(x)+x, x)
OUT: 2*f(x) - 2*x + 1/2*x^2
IN: inte(inte(f(x)+y, x), y)
OUT: f(x)*y - x*y + x*y^2
You can also ask SymbMath to perform the following integrals:
inte(inte(f(x)+y^2, x), y),
inte(inte(f(x)*y, x), y),
inte(x*f(x), x),
triple integral of f(x)-y+z, or others.
4.15.3 Learning definite integral from indefinite integral
You continue to ask indefinite integral.
IN: inte(inte(f(x)+y, x from 0 to 1), y from 0 to 2)
OUT: 2 f(1)
4.15.4 Learning complicated derivatives from a 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 4.15.4.1 :
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), input f'(x_) = 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.
4.15.5 Learning integration from algebra
If you show SymbMath algebra, SymbMath can learn integrals
from that algebra.
Example 4.15.5.1 :
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: inte(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.
4.15.6 Learning complicated algebra from simple algebra
SymbMath has the ability to learn complicated algebra from simple
algebra.
Example 4.15.6.1:
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)
4.15.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 diffrent 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'(x) and/or one intergral of f(x)),
SymbMath will determine how to go about solutions of many problems.
If the learning is saved as a library, then you need not to
teach SymbMath again when you run SymbMath next time.
5. Graphics
5.1 Drawing lines and arcs
SymbMath includes extensive facilities for graphing. It supports
BGI-graphics, which graphics commands are the same as those in 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)
-------------------------------------------------
Before graphing, you should initialize the graphics system and puts
the computer hardware into graphics mode by the command:
graph
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 color and style of the line can be set by setcolor() and
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 an integer in the range 0..15, or one of the color words if
package color.sm has been loaded.
You can set the background color for your graphs with the command
setbkcolor(color)
where color is an integer in the range 0..15, or one of the color words if
package color.sm has been loaded.
Table 5.1 Color word and Its value in package color.sm
------------------------------------------------------------------
color word 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
Finally you should go back the text mode by the command:
text
Example 5.1:
# 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
5.2. Plotting y = f(x)
You can plot a function of y = f(x) on the xy-plane by a single
external function
plot(f(x),x)
plot(f(x),x,xmin,xmax)
plot(f(x),x,xmin,xmax,ymin,ymax)
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 a function of x^3.
IN: plot(x^3,x)
5.3 Plotting r = f(t) in polar coordinates
You can graph the portion of a polar curve r = f(t) that lies in
the window with a single external function:
polar(f(t),t)
polar(r, t,tmin,tmax)
polar(r, t,tmin,tmax,rmin,rmax)
f(t) can be a function with bound variable t or an expression involving t.
For example, to graph the cardoid r = 1+cos(t), execute the command
polar(1+cos(t),t)
The variable t covers the domain (0, 2π); you can change this default by
specifying a range for t:
polar(1+cos(t), t,0,pi)
6. Inside SymbMath
6.1 Internal Structure
As an expert system, SymbMath consists of three major
components: a knowledge base, an inference engine, and a global data
base. The knowledge base is a set of rules, the inference engine is a
rule interpreter for utilizing 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 6.1 Structure of SymbMath
Table 6.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
text editor, help, windows.
System interface: numeric computation software, graphic
software (e.g. PlotData), 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.
---------------------------------------------------------------------
6.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"))
7. 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^307)^(10^307) to -(10^-307)^(10^-307), 0, (10^-307)^(10^-307)
to (10^307)^(10^307), 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.E307 to -1.E-307, 0, 1.E-307 to 1.E307, 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 6.
10. The maximum arguments of the user-defined rule is 2 and the
maximum pattern is 3. Only following rules are available:
--------------------------------------------------------------------------
f(a_ + b_) f(a_ + b_, x_) d(s(x_), x_) inte(c(x_), x_)
f(a_ - b_) f(a_ - b_, x_) d(s(n_,x_), x_)
f(a_ * b_) f(a_ * b_, x_)
f(a_ ^ b_) f(a_ ^ b_, x_)
f(s(a_)) f(c(x_), x_)
f(-a_) f(a, x_)
f'(x_) f(a_, x)
---------------------------------------------------------------------------
where s() is a simple function, c() is a complicated function.
8. Keywords
SymbMath has three versions: Shareware Version A, Student
Version B and Advanced Version C. The shareware version lacks the
solve(), trig (except sin(x) and cos(x)), and hyerbolic functions,
(lack 10% keywords) and the student version lacks the hyerbolic
functions (lack 5% keywords). You cannot input these lack functions
in shareware or student version.
Upper- and lower-case letters are different until the switch
lowercase is set to on (i.e. lowercase := on).
All keywords are lower-case letters until the switch lowercase
:= on.
There are two types of the keywords: internal and external.
The internal keywords have been compiled into the SymbMath system,
so you cannot change them. The external ones are in files, so you
can change their name or property. Usages of both types are the same.
The following only includes the internal and some external
keywords. You can define your own keyword and add your defined function.
If some keywords do not work, you should check whether or not the
libraries *.(x) are in the default directory.
8.1 Keywords in Topic Order
---------------------------------------------------------------------
1. Algebraic operators: +, -, *, /, ^, **, ().
2. Relational operators: ==, >, >=, <, <=, <>.
3. Assignments: :=
4. Equation: solve(x^2=1,x), solve([x+y=b,x-y=c], [x,y]), psolve(f(x), x),
nsolve(cos(x)=x,x), dsolve(y'(x)=f(x,y), y(x),x), =.
5. Comment: #.
6. Built-in constants: i, e, pi, inf, zero, constant, discont, c_inf,
undefined.
7. Built-in variables: last.
8. Logic operators: and, or, not(x).
9. Algebraic functions: -x, sqrt(x), n!, fac(n), mod(x,y), div(x,y),
random(x), expand(x), factor(x), factor(y,x), root(x,n).
10. Complex to real: re(x), im(x), abs(x), |x|, arg(x), sign(x).
11. Exponential functions: exp(x), ln(x), log10(x).
12. Trig functions: sin(x), cos(x), tan(x), csc(x), sec(x), cot(x),
asin(x), acos(x), atan(x), acot(x), asec(x), acsc(x), atan2(x,y).
13. Hyperbolic functions: sinh(x), cosh(x), tanh(x), csch(x), sech(x),
coth(x), asinh(x), acosh(x), atanh(x), acoth(x), acsch(x),
asech(x).
14. Special math functions: ei(x), ei(n,x), gamma(x), gamma(n,x), erf(x),
si(x), ci(x), li(x), li(n,x).
15. Defining functions: f(x_):=x^2, f(x_) := if(x>0 then x^2).
16. Defining procedures: f(x_):=block(p:=x^2,p,local(p))
17. Defining rules: log(x_ * y_) := log(x) + log(y).
18. Clear: clear(x), clear(f(x)), clear(a>0).
19. Calculus functions:
d(y,x), d(y,x,order), diff(y, x = x0), f'(x), inte(), ninte(),
subs(y, x = x0), lim(y, x = x0), nlim(y, x=x0), laplace(y,x),
sum(y, x,xmin,xmax,dx), partsum(y,x), infsum(y,x),
prod(y, x,xmin,xmax,dx), series(y,x), series(y,x,order).
20. Conversion functions:
ratio(x), round(x), trunc(x), nume(2/3), deno(2/3), table(),
number(x), string(x), term(a+b), mult(a*b), type(x).
21. Numeric computation: num(x), nsolve(), ninte(), nlim(), numeric:=on.
22. Test functions: isodd(x), iseven(x), isinteger(x), isratio(x),
isreal(x), iscomplex(x), isnumber(x), islist(x), isfree(y,x),
issame(x), islarger(a,b), isless(a,b), type(x)=="real".
23. Table: table(f, x,xmin,xmax,dx).
24. Arrays and array index: a[1]:=1, do(a[x]:=x, x,xmin,xmax,dx), a[1].
25. Lists and list index: [a,b], [list()], member([a],j), last[1].
26. Statistics: average(x), max(x), min(x), listsum(x), length(x).
27. Switches: numeric, output, expand, expandexp, lowercase,
:=, on, off, basic, fortran, prolog, math.
28. DOS Commands: system("dir").
29. Comma: , , from, to, step, then, else, until.
30. Assume: assume(a>0), isreal(x):=1.
31. Conditional: if(x>0 then x), if(x>0 then x else -x).
32. Loop: repeat(expr until x>5), do(expr, x,xmin,xmax,dx),
list(y,x,xmin,xmax).
33. Reading: readfile("file"), readchar, readline.
34. Writing: openfile("file"), closefile("file"), writes(x), null, block(),
newline.
35. Plot: plot(x^3,x), dotplot(x^3,x), polar(1+t,t).
36. Graph: graph, text, line(), lineto(x,y), linerel(dx,dy), ellipse(),
putpixel(x,y,color), moveto(x,y), moverel(dx,dy), arc(), getmaxx,
getmaxy, setcolor(white), setbkcolor(red), setviewport(),
setlinestyle(), settextstyle(font,dir,size), circle(), oval(),
settextjustify(hor,ver), getx, gety, getbkcolor, getcolor.
37. String: "123", concat(a,b), remove(b,ab), length(a), string(1),
reverse(x).
38. Getting parts: type(x), left(x), right(x), term(a+b), mult(), coef(),
coefall(), power(x^n), base(x^n), argue(x), sequence(x),
re(x), im(x), int(x), frac(x).
--------------------------------------------------------------------------
8.2 Keywords in Alphabetical Order
---------------------------------------------------------------------------
abs(x) acos(x) acosh(x) acot(x) acoth(x)
acsc(x) acsch(x) and arc() arg(x)
argue(x) asec(x) asech(x) asin(x) asinh(x)
assume(x>0) assumed atan(x) atan2(x,y) atanh(x)
average(x)
base(x^n) basic block()
ci(x) circle() clear(x) cleared closefile()
coef() coefall(y,x) concat(a,b) constant cos(x)
cosh(x) cot(x) coth(x) csc(x) csch(x)
c_inf
d() degree deno(x) diff() div(x,y)
discont do() done dotplot() dsolve()
e ei() ellipse() else eval()
erf(x) exp(x) expand(x) expand expandexp
f'(x) fac(x) factor() fortran frac(x)
from
gamma(x) gamma(n,x) gcd(a,b) getbkcolor getcolor
getmaxx getmaxy getx gety graph
i if() im(x) inf infsum(y,x)
int(x) inte() iscomplex(x) iseven(x) isfree(y,x)
isinteger(x) islarger(a,b) isless(a,b) islist(x) isodd(x)
isratio(x) isreal(x) issame(x,y) isnumber(x)
laplace(y,x) last left(x) length() li()
lim() line() lineto(x,y) linerel(dx,dy) list()
listsum(x) ln(x) local() log10(x) lowercase
math max(x) member(x,n) min(x) mod(x,y)
moveto(x,y) moverel(dx,dy) mult(x)
newline ninte() nlim(y,x=x0) not(x) nsolve()
null num(x) number(x) nume(x) numeric
off on openfile("x") or order(y,x)
output oval()
partsum(y,x) pi plot(y,x) phoneno(x) polar()
power(x^n) prod() prolog psolve() putpixel()
random random(x) ratio(x) re(x) react(x)
readchar readfile("x") readline remove(b,ab) repeat()
reverse(a) right(x) root() round(x)
sec(x) sech(x) series() sequence([]) setbkcolor()
setcolor() setlinestyle() settextjustify()settextstyle() setviewport()
si(x) sign(x) sin(x) sinh(x) solve(eq,x)
sqrt(x) subs() sum() step string(x)
system(dos)
table() tan(x) tanh(x) term() text
then to trunc(x) type(x)
undefined until
writes(x)
zero
+ - * / ^
** () [] = :=
== > >= < <=
<> ! # , |x|
"x" '
-----------------------------------------------------------------------
8.3 Glossary
--------------------------------------------------------------------------
* 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 external
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 external
acosh(x) is the inverse hyerbolic cosine function of x.
The inverse function of cosh(x).
See also: acosh, cosh.
* acot external
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 external
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 external
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 external
acsch(x) is the inveres 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 unevalated.
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 external
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 external
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 external
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 external
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 external
asinh(x) is the inverse hyperbolic sine function of x. The inverse
function of sinh(x).
See also: asinh, sinh.
* assume external
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 aslo: sign, isodd, iseven, isinteger, isreal, isnumber, clear.
e.g. assume(x>0), assume(x>0, y<0), iseven(x):=1
* assumed external
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 external
atanh(x) is the inverse hyperbolic tangent function of x. The inverse
function of tanh(x).
See also: tanh.
* average external
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 arguement as its
value, or returns the second last arguement as its value if the last
arguement is local(). It is used as grouper in definition of a procedure.
All variables in block are global, except for variables declared by
local().
e.g. f(x_):=block(p:=x^6,p, local(p))
See also: local.
* ci external
ci(x) is cos integral, ci(x) = inte(cos(x)/x, x).
See also: si, ei, gamma, erf.
* circle external
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 external
cosh(x) is the hyerbolic cosine function of x.
cosh(x)=(exp(x)+exp(-x))/2. x can be complex numbers.
See also: acosh.
* cot external
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 external
coth(x) is the hyerbolic cotangent function of x. coth(x)=1/tanh(x).
See also: acoth, tanh.
* csc external
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 external
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'(x) .
e.g. d(sin(x),x) gives cos(x).
d(y, x, n) external
It gives the n-th order derivative of y with respect to an undefined
variable x.
e.g. d(sin(x),x,2) gives -sin(x).
See also: diff, f'(x), lim, inte, ninte.
* degree external
degree gives the number of radians in one degree. degree=pi/180.
You can multipy 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 external
diff(y, x = x0) differentiates y when x = x0.
See also: d, inte, lim.
e.g. diff(x^6, x = 1) gives 6.
* 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:=1, 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 external
dotplot(y, x) plots y with dots.
dotplot(y, x,xmin,xmax)
dotplot(y, x,xmin,xmax,ymin,ymax)
See also: plot, polar.
e.g. dotplot(x^3, x)
* dsolve external
dsolve(y'(x)=f(x,y), y(x), x) solves the first order variables
separable and linear differential equations. The y'(x) must be
alone on the left hand side of the equations.
See also: solve, nsolve.
e.g. dsolve(y'(x) = sin(x), y(x), 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 (baes 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 external
ei(x) is the exponential integral function Ei(x),
ei(x) = inte(e^t/t, t,-inf,x), ei'(x) = e^x/x.
ei(n,x) is the incomplete exponential integral function,
ei(n,x) = inte(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 external
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 external
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)*inte(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'(x) external
f'(x) differentiates f(x) with respect to x. f'(x)=d(f(x),x). f'(x0) is
diferent from diff(f(x), x=x0): f'(x0) first evaluates f(x0), then
differentiates the value of f(x0); diff(f(x), x=x0) first differentates
f(x), then replace x = x0.
See also: d.
e.g. sin'(x) gives cos(x).
* fac external
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 factorizes y.
See also: expand, expandexp.
e.g.
IN: factor(a^2 + 2*a*b + b^2)
OUT: (a+b)^2
factor(y, x) external
It factorizes 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 external
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.
* from external
The comma, the same as the comma (,).
The 6 keywords: from, to, step, then, else, until are the same as comma ,.
See also: to, step, then, else, until , ,.
* gamma external
gamma(n) is the gamma function Γ(n),
gamma(n) = inte(t^(n-1)*e^(-t), t,0,inf), gamma(n) = (n-1)!.
gamma(n,x) is the incomplete gamma function, gamma(n,x) =
inte(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 external
gcd(a,b) gives the greatest commom dividor 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 colum 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 colum 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 initializes 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 freez 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
if(condition then x)
It gives x if condition evaluates to 1, or left unevaluated otherwise.
if(condition then x else y)
It gives x if condition evaluates to 1, y if it evaluates to 0, or
left unevaluated if the condition is neither 1 nor 0.
Note that the words then and else can be replaced by comma ,.
It is useful in definition of the use-defined function to left the
function unevaluted 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 external
infsum(y,x) is infinite sum.
See also: partsum, sum.
* int external
int(x) gives the integer part of number x. int(x)=trunc(x).
See also: frac, trunc.
e.g. int(2.3) gives 2.
* inte internal + external
inte() is the integral function.
inte(y,x) internal
It finds the indefinite integral of y with respect to an undefined
variable x.
inte(y,x,xmin,xmax) external
It finds the definite integral of y with respect to the variable x taken
from x=xmni to x=xmax.
inte(y,x,xmin,x1,xmax) external
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 external
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 external
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 simliar 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 external
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: righ.
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 external
li(x) is the ln integral function,
li(x) = inte(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) =
inte(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 internal
lim(y, x = x0)
It finds the limiting value of y when x = x0.
lim(y, x = x0+zero)
It finds the right-sided limit as x approches to x0 from the positive
(+inf) direction (x = x0+).
lim(y, x = x0-zero)
It finds the left-sided limit as x approches 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 external
listsum(x) converts a list into sum.
See also: average, max, min.
e.g. listsum([a,b] gives a+b.
* ln internal+external
ln(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 varirables in block().
local() must be the last arguement within block().
See also: block
e.g. f(x_) := block(p:=x^2,p,local(p))
* log10 external
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 swicth 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 convertion, 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 external
max(x) gives maximum of x.
See also: min, average, listsum, length.
e.g. max([1,2,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 external
min(x) gives minimum of x.
See also: max, average, listsum, length.
e.g. min([1,2,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) external
It gives the n-th multiplier of x if possible.
mult(x_,n_) := member(mult(x), n).
e.g. mult(a*b*c, 1) gives a.
See also: mult, term, type.
* newline internal
newline writes a new line. The output following the command newline will
be written on next line.
* ninte external
ninte(y, x from xmin to xmax) numerically integrates y.
See also: inte.
e.g. ninte(x^2, x from 0 to 1) gives
* nlim external
nlim(y, x=x0) numerically limits y when x=x0.
See also: lim.
e.g. nlim(sin(x)/x, x=0) gives 1.
* not external
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 external
nsolve(cos(x)=x, x)
It numerically solves equation with default initial x0=1.
nsolve(x^2=1, x,x0)
It numerically solves the equation with initial x0.
It only gives a root near x0 if equation has multi roots.
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 appreas as an output expression, no output is printed.
See also: block, output.
e.g. block(output:=on, null).
* num internal
num(x) gives the numeric value of x. It converts all numbers
to the real number.
See also: numeric.
e.g. num(pi) gives 3.1416.
* 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 external
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 external
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
* partsum external
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 external
pi=3.1416..., as the built-in constant, pi is converted to 3.1416...
when the switch numeric:=on.
See also: e.
* plot external
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. plot(x^3,x)
* polar external
polar(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.
polar(r,t,tmin,tmax)
polar(r,t,tmin,tmax,rmin,rmax)
See also: dotplot, polar.
e.g. polar(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 external
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 external
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
pupixel(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,red), readchar, text
* random internal
random gives a uniformly distributed pseudorandom real in
the range 0 to 1.
random(n) gives a uniformly distributed pseudorandom 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 charactor from the keyboard. It is useful to freez
the graphics by readchar. This is similar to pause, but it returns the
charactor 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 interanl
readline reads a line of strings from the keyboard.
See also: readchar, readfile, readline, writes.
* remove internal
remove("b", "ab") removes string "a" from string "ab".
See also: concate.
e.g. remove("b", "ab") gives "a".
* 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 external
reverse(x) reverses a list x in reverse order.
See also: member.
e.g. reverse([1,2,3]) gives [3,2,1].
* 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 external
root(x,n) gives all branch of n-th root. The first member of list is the
P.V.
e.g. root(4,2) gives [2,-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 external
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 external
sech(x) is the hyperbolic secant function of x. sech(x)=1/cosh(x).
See also: asech, cosh.
* series external
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 arguement 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(red), line(100,100,200,200), readchar,
text.
See also: setcolor.
* setcolor internal
setcolor(x) sets the foreground color, where the arguement 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(red), 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 charactor size.
it only works on the graphics mode.
e.g. graph, textstyle(2,1,2), writescr("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 unvisible if it 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 external
si(x) is the sin integral, si(x) = inte(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 external
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)
It solves a polynomial ordered up to 4.
solve([expr1=expr2,expr3=expr4], [x,y])
It solves systems of linear equations.
It gives all symbolic solutions.
See also: nsolve.
e.g. solve(x^2+5*x+6=0, x), solve([x+y=3, x-y=1], [x,y]).
* 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(f,x,xmin,xmax) external
It evaluates the sum of f when x runs from xmin to xmax with the default
step dx=1.
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).
* step external
step is the comma, the same as the comma , .
The 6 keywords: from, to, step, then, else, until are the same as comma ,.
See also: from, to, then, else, until, ,.
* 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) external
It produces a table of the function values from x=-5 to x=5 with step 1.
table(f,x,xmin,xmax) external
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 external
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) external
It gives the n-th term of x if possible. term(x_,n_) := member(term(x),n).
See also: mult, 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
* then external
comma. The same as comma ,.
The 6 keywords: from, to, step, then, else, until are the same as comma ,.
See also: from, to, step, else, until, ,.
* to external
to is the comma, the same as the comma (,).
The 6 keywords: from, to, step, then, else, until are the same as comma ,.
See also: from, step, then, else, until, ,.
* 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.
e.g.
------------------------------
x type(x)
1 "integer"
1.1 "real"
2/3 "ratio"
1+i "complex"
sin(x) "sin()"
[1,2] "[]"
a "variable"
a+b "+"
a*b "*"
a^b "^"
"a" "string"
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
* until external
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, else, until, ,.
* 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 rigth-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.
** power in FORTRAN, the same as ^ in BASIC, 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
:= assigment.
, comma
The words from, to, step, then, else and until are the same as ,.
" string sign. e.g. "filename.sm".
|x| the same as abs(x).
' f'(x) is the same as d(f(x),x).
# comment statement
e.g. # this is demo.
[] list. e.g. [a,b,c]
()
-------------------------------------------------------------------------
9. References
[1] Huang, W., Proceedings of the workshop on symbolic and numeric
computation, Helsinki University, Finland, 1991, p 185-186.
[2] Huang, W., Int. J. Math. Educ. Sci. Tech., 1992, 23(1), 160-165.
[3] Microbit, IEEE Micro, 1992, 12(1), 76.
[4] Huang, W., IEEE Micro, 1992, 12(3), 80.
[5] Huang, W., Abs. Amer. Math. Soc., 1992, 13(3), 343-344.
[6] Huang, W., Abs. Amer. Math. Soc., 1992, 13(5), 518.
[7] Huang, W., Abs. Amer. Math. Soc., 1992, 13(6), 535.
[8] Huang, W., SIGSMALL/PC Notes, 1992, 18(1&2), 63-64.
[9] Long, G., Australian PC World, 1992, June, 117-119.
[10] Iwaschkin, R., PC Plus, 1993, June, 281.
[11] Long, G., Australian PC World, 1993, July, 147.
[12] Arnold, S., Reflections, 1993, May, 18(2), 55-64.