DrMath for Java

Online Computer Algebra System

 

 

Dr. Weiguang HUANG

DrHuang Pty Ltd

 

Phone: (61) 0413008019

E-mail: info@DrHuang.com, drHuang@mail.com

http://www.DrHuang.com/

http://www.DrHuang.net/

 

 

26 Aug. 2000

 

 


Copyright (C) 1990-2000

 

 


Contents

 

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

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

1.1. What is DrMath....................................................... 7

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

1.3. Shareware License................................................ 8

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

2. Calculation...................................................... 9

2.1. Exact Calculation..................................................... 9

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

2.3. Undefined and Indeterminate Form....................... 10

3. Simplification................................................ 11

3.1. Assuming Domain.................................................. 12

3.2. Comparing and Testing Numbers........................... 13

4. Defining Functions, Procedures and Rules 13

4.1. Defining Functions.............................................. 14

4.1.1. Defining Conditional Functions........................................................................ 14

4.1.2. Defining Case Functions................................................................................ 15

4.1.3. Defining Piece-wise Functions........................................................................ 15

4.1.4. Defining Recursion Functions......................................................................... 15

4.1.5. Defining Multi-Value Functions........................................................................ 15

4.2. Defining Procedures............................................. 16

4.3. Defining Rules...................................................... 16

5. Limits......................................................... 17

5.1. One-sided Limits.................................................. 17

5.2. Numeric Limits: NLim().......................................... 17

6. Differentiation............................................... 17

6.1. One-sided Derivatives.......................................... 18

6.2. Defining Derivatives............................................. 18

7. Integration.................................................... 18

7.1. Indefinite Integration.............................................. 18

7.2. Definite Integration................................................ 20

7.3. Numeric Integration: NInt().................................... 21

8. Solving Equations..................................... 21

8.1. Solving Algebraic Equations.................................. 21

8.2. Equation Solver: Solve()....................................... 21

8.3. Polynomial Solver: PSolve()................................. 22

8.4. Numeric Solver: NSolve()..................................... 22

8.5. Solving Differential Equations............................... 23

8.6. Differential Solver: DSolve()................................. 23

9. Sums and Products..................................... 23

9.1. Partial Sum........................................................... 24

9.2. Infinite Sum.......................................................... 24

10. Series and Polynomials.............................. 24

10.1. Series................................................................ 24

10.2. Polynomials........................................................ 24

11. Lists and Arrays, Vectors and Matrices..... 25

13. Conversion................................................ 25

13.1. Converting to Numbers....................................... 25

14. Getting Parts of Expression.................... 25

14.1. Getting Type of Data.......................................... 25

14.2. Getting Operators............................................... 25

14.3. Getting Operand................................................. 26

15. Graphics.................................................... 26

15.1. Drawing Lines and Arcs...................................... 26

15.2. Plotting f(x)......................................................... 26

15.3. Plotting Parametric Functions x(t) and y(t).......... 26

15.4. Plotting f(t) in Polar Coordinates....................... 27

15.5. Plotting Data....................................................... 27

16. Learning from User.................................... 27

16.1. Learning Integrals from a Derivative................... 27

16.2. Learning Complicated Integrals from a Simple Integral 28

16.3. Learning Definite Integral from Indefinite Integral 28

16.4. Learning Complicated Derivatives from Simple Derivative 28

16.5. Learning Integration from Algebra....................... 29

16.6. Learning Complicated Algebra from Simple Algebra 29

16.7. Learning versus Programming............................ 29

PART 2 Programmer's Guide........................ 31

17. Programming in DrMath............................ 31

17.1. Data Types......................................................... 31

17.1.1. Numbers..................................................................................................... 31

17.1.2. Constants................................................................................................... 32

17.1.3. Variables.................................................................................................... 32

17.1.4. Patterns...................................................................................................... 33

17.1.5. Functions, Procedures and Rules.................................................................. 34

17.1.5.1. Standard Mathematical Functions.............................................................. 34

17.1.5.2. Calculus Functions................................................................................... 35

17.1.5.3. Test Functions.......................................................................................... 36

17.1.5.4. Miscellaneous Functions........................................................................... 37

17.1.5.5. User-defined Functions........................................................................... 37

17.1.5.6. Procedures............................................................................................... 38

17.1.5.7. Rules....................................................................................................... 38

17.1.6. Equations................................................................................................... 38

17.1.7. Inequalities.................................................................................................. 39

17.2. Expressions...................................................... 39

17.2.1. Operators................................................................................................... 39

17.2.1.1. Arithmetic Operators................................................................................. 40

17.2.1.2. Relational Operators.................................................................................. 40

17.2.1.3. Logical Operators.................................................................................... 40

17.2.2. Function Calls............................................................................................. 40

17.3. Statements....................................................... 41

17.3.1. Comment Statements.................................................................................. 41

17.3.2. Evaluation Statements................................................................................. 41

17.3.3. Assignment Statements............................................................................... 41

17.3.4. Conditional.................................................................................................. 42

17.3.5. Loop........................................................................................................... 42

17.3.9. Sequence Statements.................................................................................. 43

17.4. Libraries............................................................. 43

17.5. Interface with Other Software........................................................................... 44

Part 3 Reference Guide..................................... 45

19. DrMathEnvironment: Windows and Menus 45

19.1. File Menu........................................................... 45

19.1.1. Open.......................................................................................................... 45

19.1.2. Import Data................................................................................................. 45

19.1.3. Save Input................................................................................................... 45

19.1.4. Save Output................................................................................................ 45

19.1.5. Print........................................................................................................... 45

19.1.6. Exit............................................................................................................ 45

19.2. Input Window...................................................... 46

19.3. Run Menu........................................................... 46

19.4. Graph Menu........................................................ 46

19.5. Option Menu....................................................... 46

20. Inside DrMath............................................ 47

20.1. Internal Structure................................................ 47

20.2. Internal Format................................................... 48

21. System Extension....................................... 48

22. Keywords............................................... 48

22.1. Keywords in Topic Order................................. 48

22.2. Keywords in Alphabetical Order........................ 52

22.3. Library Name................................................... 53

22.4. Glossary.......................................................... 54

23. References.................................................. 64

 


PART 1 User's Guide

 

1. Introduction

1.1. What is DrMath

 

DrMath (former Visual Math) is an online symbolic math and computer algebra system.

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

DrMath 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 (eg. it learns many derivatives involving an unknown function f(x) from one derivative).

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

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

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

It runs on any machine that supports Java.

 

 

1.2. Capabilities

 

It can provide analytical and numeric answers for:

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

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

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

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

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

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

* Complex: calculation, functions, derivatives, and integration.

* Sum and product: partial, finite or infinite.

* Series.

Also included are:

* External functions in library as if standard functions.

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

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

 

 

 

1.3. Shareware License

 

It is assumed that you agree the Shareware license, which you should register by US$20 with author after 20 days or you should delete it.

Please read all *.TXT files before running DrMath. Please copy-and-paste examples in this document to practise. The printed document (100+ pages) is available from author.

If you get the DrMath on ZIP format (eg. .zip), you should unzip it with parameter -d by

pkunzip -d vm32a c:\DrMath

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

 

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.

 

1.4 A List of Files in DrMath

 

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

In home directory DrMath:

 

DrMath.html HTML page to run applet.

DrMath.bat batch file to run this application.

DrMath.exe Windows application.

 

 

In directory VMath\library:

 

*.vm the auto loaded libraries (external functions).

 

 

In directory DrMath\text:

 

DrMath.txt introduction of DrMath.

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

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

comment*.txt comments on DrMath.

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 DrMath.

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

 

 


2. Calculation

 

You have choice to run DrMath or SymbMath engine. Their syntaxes are some different. Both syntaxes are case-sensitive. A first letter of each word in DrMath keywords is upper case, but all keywords are lower case in SymbMath. This document is for DrMath only. Please read the document SymbMath.doc for SymbMath.

In the following examples, a line of "In: " means input, which you type in the Input window, then run the program by clicking the "Run" menu; 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.

# and // are for comment statements.

You can split a line of command into multi-lines of command by the semi-column ;, similar to Java

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

 

 

2.1. Exact Calculation

 

DrMath gives the exact value of calculation by default, or the approximate value of numeric calculation when by N(). Mathematical functions are usually not evaluated until by N().

DrMath 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, eg. Ln(Infinity), Exp(Infinity), etc. DrMath contains many algorithms for performing numeric calculations. eg. Ln(I), I^I, (2.3)^(-3.2), 2^3^4^5^6^7^8^9, etc.

Note that DrMath usually gives a principle value if there are multi-values, but the Solve() and Root() can give all values.

 

Example:

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

In: 1/2+1/3

# exact calculation;

Out: 5/6

 

In: N(1/2+1/3)

# numeric calculation;

Out: 0.8333333333

 

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

 

Example:

Evaluate Sin(x) when x=Pi, x=180 degree, x=I.

In: Sin(Pi), Sin(180*Degree)

Out: 0, 0

 

In: Sin(I), N(Sin(I))

Out: Sin(I), 1.175201 I

 

Example:

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

In: minute:=60*second;

In: v:=2*meter/second;

In: t:=2*minute;

In: d0:=10*meter;

In: v*t+d0;

Out: 250 meter;

 

Evaluate the expression value by

Replace(y, x, x0)

 

Example:

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

In: z:=x^2;

# assign x^2 to z;

In: Replace(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 Replace(), the variable x is automatically cleared after evaluation, i.e. the variable x in Replace() is local variable. The operation by assignment is global while the operation by internal function is local, but operation by external function is global. This rule also applies to other operations.

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

 

Example .

In: Sign(1+I), Sign(-1-I), I^2;

Out: 1, -1, -1

 

Example:

In: Exp(Infinity);

Out: -Infinity

 

In: Ln(Infinity);

Out: Infinity

 

The built-in constants (eg. Infinity) can be used as numbers in calculation of expressions or functions.

 

 

2.2. Discontinuity and One-sided Value

 

Some math functions are discontinuous at x=x0, and only have one-sided function value.

 

2.3. Undefined and Indeterminate Form

 

If the function value is undefined, it may be indeterminate form (eg. 0/0, Infinity/Infinity), you can evaluate it by Lim().

 

 

3. Simplification

 

DrMath 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)

 

Example:

In: Expand((a+b)^2);

Out: a^2 + 2 a b + b^2

 

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

............... 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

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

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

 

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

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

 

Expressions can be factorised by

Factor(x)

eg.

In: Factor(a^2 + 2*a*b + b^2);

Out: (a + b)^2

 

Polynomials of order less than 5 can be factorised by

Factor(y, x)

 

Example:

In: Factor(x^2+5*x+6, x);

Out: (2 + x) (3 + x)

 

Example:

Reduce Sqrt(x^2).

In: Sqrt(x^2);

Out: x*Sign(x)

 

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

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

 

In: Sqrt(x^2);

Out: x*Sign(x)

 

 

3.1. Assuming Domain

 

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

 

In: Assume(x > 0, y <0);

# assume x > 0, y < 0;

 

In: Sqrt(x^2), Sqrt(y^2), Sqrt(z^2);

Out: x*Sign(x), y*Sign(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, Abs(x) < Infinity and all variables are complex, except that variables in inequalities are real, as usual only real numbers can be compared. eg. x is complex in Sin(x), but y is real in y > 1.

Table 3.1 Assuming

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

Assume Assignment Meaning

 

Assume(x>y) x>y := True # assume x > y

Assume(x>=y) x>=y := True # assume x >= y

Assume(x<y) x<y := True # assume x < y

Assume(x<=y) x<=y := True # assume x <= y

Assume(x==y) x==y := True # assume x == y

Assume(x<>y) x<>y := True # assume x <> y

IsEven(b) := True # assume b is even

IsOdd(b) := True # assume b is odd

IsInteger(b) := True # assume b is integer

IsRational(b) := True # assume b is ratio

IsReal(b) := True # assume b is real

IsComplex(b) := True # assume b is complex

IsNumber(b) := True # assume b is number

IsFree(y,x) := True # assume y is free of x

Sign(b) := True # assume b is positive complex

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

 

The Assume() can be cleared by Clear(). eg. Clear(x>y).

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

 

Example:

 

In: IsReal(b) := True;

# assume b is real;

In: Sqrt(b^2);

Out: Abs(b);

 

 

Table 3.3 Simplification in different domains

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

expression complex real x > 0

 

Sqrt(x^2) x Sign(x) Abs(x) x

x*Sign(x) x Sign(x) Abs(x) x

Abs(x)*Sign(x) Abs(x) Sign(x) x x

Abs(x)/x Abs(x)/x 1/Sign(x) 1

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

 

 

3.2. Comparing and Testing Numbers

 

You can compare two numbers by relational operators:

a > b

a < b

a <= b

a >= b

a <> b

a == b

 

Example:

In: 2 > 1, 2 < 1

Out: True, False

 

 

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

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

IsEven(x)

IsOdd(x)

IsInteger(x)

IsReal(x)

IsNumber(x)

IsFree(y,x)

 

Example:

In: IsEven(2)

# is 2 even ?

Out: True

 

Note that comparison by the Is* functions return either True or False otherwise, but comparison by relational operators gives True, False, or left unevaluated otherwise.

 

 

4. Defining Functions, Procedures and Rules

 

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

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

You can make your defined function as if the built-in function, by saving your definition into disk file as a library with the function name plus extension .vm as the filename. eg. save the factorial function as the factorial.vm file (see Section Libraries).

 

 

4.1. Defining Functions

 

You can define your own functions by

f(x_) := x_^2

Here are some function definitions:

f(x_) := Cos(x_ + Pi/3)

g(x_, y_) := x_^2 y_^2

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

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

y := f(3.2)

z := g(4.1, -5.3)

 

Example:

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

In: g(x) := x^2;

In: g(2), g(a), g(x);

Out: g(2), g(a), x^2;

# work only for a symbolic value x;

 

In: f(x_) := x_^2;

In: f(2), f(a);

Out: 4, a^2

# work for any value;

 

 

4.1.1. Defining Conditional Functions

 

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

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

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

On the first definition by If(), when f1() is called it gives 1 if x>0, or left unevaluated otherwise. On the second definition by the If(), when f2() is called it gives x^2 if x>0, x if x<=0, or left unevaluated otherwise.

 

You can define a function evaluated only for numbers by

f(x_) := If(IsNumber(x_) , x_^2)

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

Example:

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

 

In: f(x_) := If(IsNumber(x_) , x_^2);

In: f(2), f(a);

Out: 4, f(a);

 

In: f(x_) := If(x_>0 , x_^2);

In: f(2), f(-2), f(a);

Out: 4, f(-2), f(a);

 

In: f(x_) := If(x_>0 , x_^2 , x_);

In: f(2), f(-2), f(a);

Out: 4, 2, f(a);

 

 

4.1.2. Defining Case Functions

 

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

Example:

 

In: f(x_) := If( x_ > 0 And x_ < 1 , 1);

In: f(u_) := If( u_ > 1 And u_ < 2 , 2);

In: f(v_) := If( v_ > 2 And v_ < 3 , 3);

In: f(0.2), f(1.2), f(2.2);

Out: 1, 2, 3;

 

 

4.1.3. Defining Piece-wise Functions

 

You can define a piece-wise function.

 

Example:

define

 

/ x if x < 0

f(x) = 0 if x = 0

\ x^2 if x > 0

 

then evaluate f(-2), f(0), f(3), f(a).

 

In: f(x_) := If(x_<0, x_, x_^2);

In: f(-2), f(0), f(3), f(a);

Out: -2, 0, 9, f(a);

 

 

 

4.1.4. Defining Recursion Functions

 

You can define a recursion function.

Example:

In: factorial(1) := 1;

In: factorial(n_) := If(n_ > 1, (n_-1)*factorial(n_-1));

 

 

4.1.5. Defining Multi-Value Functions

 

You can define a function with the multi function values.

Example:

In: squreroot(x_) := (Sqrt(x_), 0-Sqrt(x_));

In: squreroot(4);

Out: 2, -2

 

 

4.2. Defining Procedures

 

You can define a function as a procedure by

f(x_) := Block(command1, command2, ..., command_N)

 

By default, all variables in Block() are local. The multi-statement should be grouped by Block(). The Block() only outputs the result of the last statement as its value. The multi-line statement must be terminated by the ;.

 

Example:

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

 

In: nint(y_,x_,a_,b_) := Block(

dd:=(b_-a_)/50,

aa:=a_+dd,

bb:=b_-dd,

y0:=Replace(y_, x_ , a_),

yn:=Replace(y_, x_ , b_),

(Sum(y_,x_,aa,bb,dd)+(y0+yn)/2)*dd);

 

In: nint(x^2, x, 1, 2);

 

 

4.3. Defining Rules

 

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

 

Example:

Define log rules.

In: log(x_ * y_) := log(x_) + log(y_);

In: log(x_ ^ n_) := n_*log(x_);

In: log(a*b);

Out: log(a) + log(b);

 

Example:

In: Sin(-x_) := 0-Sin(x_);

In: Sin(-a);

Out: -Sin(a);

 

Example:

Define derivatives (see Chapter Defining ).

In: D(f(x_), x_) := Sin(x_);

In: D(f(t), t);

Out: Sin(t);

 

Example:

Define integrals (see Chapter Indefinite Integration).

In: Int(f(x_),x_) := Sin(x_);

In: Int(f(t),t);

Out: Sin(t);

 

Example:

Define the trig simplification rules.

In: simplify(Sin(x_)^2, x_) := 1/2*(1-Cos(x_));

In: simplify(Sin(x)^2,x);

Out: 1/2 (1 - Cos(x));

 

Example:

Define Laplace transform rules.

In: laplace(Sin(t_), t_) := 1/(t_^2+1);

In: laplace(Sin(s), s);

Out: 1/(s^2 + 1);

 

 

5. Limits

5.1. One-sided Limits

 

 

5.2. Numeric Limits: NLim()

 

If symbolic limit falls, you should try numeric limit by

NLim(y, x,x0)

 

 

6. Differentiation

 

Differentiate an expression y with respect to x by

D(y, x)

Differentiate y in the n order ( n > 0 ) by

D(y, x, n)

Example:

Differentiate Sin(x) and x^(x^x).

In: 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)));

 

 

Example:

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

In: f := Sin(x^2+y^3)+Cos(2*(x^2+y^3));

In: D(f, x);

Out: 2 x Cos(x^2 + y^3) - 4 x Sin(2 (x^2 + y^3));

 

In: D(D(f, x), y);

# mixed derivative with x and y;

Out: -6 x y^2 Sin(x^2 + y^3) - 12 x y^2 Cos(2 (x^2 + y^3));

 

6.1. One-sided Derivatives

 

 

6.2. Defining Derivatives

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

 

Example:

In: D(f(x_),x_) := Sin(x_);

In: D(f(x),x);

Out: Sin(x);

 

In: D(f(x^6), x)

Out: 6 x^5 Sin(x^6)

 

 

7. Integration

 

You can find integrals of x^m*Exp(x^n), x^m*Exp(-x^n), Exp((a*x+b)^n), Exp(-(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, eg. expand the integrand by Expand().

If symbolic integration fails, you should add integral rules into the Int.vm library file, then do integration again (see Chapter Learning From User).

 

 

7.1. Indefinite Integration

 

Find the indefinite integrals of expr by

Int(expr, x)

Find the double indefinite integrals by

Int(Int(expr, x), y)

Note that the arbitrary constant is not represented.

 

Example:

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

 

In: Assume(a>0), IsReal(b):=True;

In: Int(1/a, a), Int(1/b, b), Int(1/x, x);

Out: Ln(a), Ln(Abs(b)), Ln(x*Sign(x));

 

Example:

Find indefinite integrals.

 

In: Int(Sin(a*x+b), x);

# integrands involving Sin(x);

Out: -Cos(b + a x)/a;

 

In: Int( Sin(x)/x^2, x);

Out: ci(x) - Sin(x)/x;

 

In: Int( x*Sin(x), x);

Out: -x Cos(x) + Sin(x);

 

In: Int(Sin(x)*Cos(x), x);

Out: (1/2)*Sin(x)^2;

 

In: Int( E^(x^6), x);

# integrands involving e^x;

Out: 1/6 Ei(-5/6, x^6);

 

In: Int( x^2*Exp(x), x);

Out: Ei(2, x);

 

In: Int( Exp(x)/Sqrt(x), x);

Out: Ei(-0.5, x);

 

In: Int(x^1.5*Exp(x), x);

Out: Ei(1.5, x);

 

In: Int(Sin(x)*Exp(x), x);

# integrals involving Sin(x) and e^x;

Out: 1/2 * (Sin(x) - Cos(x)) * e^x;

 

In: Int( x*Ln(x), x);

# integrands involving Ln(x);

Out: -1/4 x^2 + 1/2 x^2 Ln(x);

 

In: Int( Ln(x)^6, x);

Out: Li(6, x);

 

In: Int( Ln(x)/Sqrt(x), x);

Out: -4 Sqrt(x) + 2 Sqrt(x) Ln(x);

 

In: Int( 1/(x), x);

Out: Ln((x) Sign(x));

 

 

Example:

Find the line integral.

 

In: x:=2*t;

In: y:=3*t;

In: z:=5*t;

In: u:=x+y;

In: v:=x-y;

In: w:=x+y+z;

In: Int(u*D(u,t)+v*D(v,t)+w*D(w,t), t);

Out: 63 t^2;

 

Example:

Integrate x^2*e^x, then expand it by the mean of the packages "ExpandEi.vm" (expand Ei(n,x)). The packages "ExpandGa.vm" (expand Gamma(n,x)) and "ExpandLi.vm" (expand Li(n,x)) are similar one.

 

In: Int(x^2*Exp(x), x);

Out: Ei(2,x);

In: ExpandEi(Ei(2, x));

Out: x^2 Exp(x) - 2 x Exp(x) + 2 Exp(x);

 

Defining integrals is similar to defining rules.

Example:

 

In: Int(f(x_), x_) := Sin(x_);

In: Int(f(t), t);

Out: Sin(t);

 

 

7.2. Definite Integration

 

Find definite integrals by external functions

Int(expr, x , xmin , xmax)

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

 

Example:

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

 

In: Int(Exp(1-x), x , 0 , Infinity);

Out: E;

 

Example:

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

 

In: Int(1/x^2, x , -1 , 2);

# singularity at x=0;

Out: Infinity;

 

In: Int(1/x^3, x , -1 , 1);

# singularity at x=0;

Out: 0

 

In: Int(Sqrt((x-1)^2), x , 0 , 2);

# singularity at x=1;

Out: 1

 

DrMath can detect singularity, but sometime it cannot, in this case you must provide singularity.

 

Example:

In: Int(1/(x-1)^2, x , 0 , 1 , 2);

# provide singularity at x=1;

Out: Infinity

 

Example:

complex integration.

 

In: Int(1/x, x , I , 2*I);

Out: Ln(2)

 

 

7.3. Numeric Integration: NInt()

 

The external function

NInt(y, x , xmin , xmax)

does numeric integration.

Example:

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

 

In: NInt(4/(x^2+1), x , 0 , 1);

Out: 3.1415

 

In: N(Int(4/(x^2+1), x , 0 , 1));

Out: 3.1416

 

 

8. Solving Equations

8.1. Solving Algebraic Equations

 

The equations can be operated (eg. +, -, *, /, ^, Expand(), D(), Int()). The operation is done on both sides of the equation, as by hand. You can find roots of polynomial, algebraic equations, systems of equations, differential and integral equations.

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: eq1-eq2;

Out: 2 y = 2;

 

Example:

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

 

In: eq1 := Sqrt(x + 2*k) - Sqrt(x - k) = Sqrt(k);

Out: eq1 := Sqrt(x + 2*k) - Sqrt(x - k) = Sqrt(k);

 

In: eq1^2;

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

 

 

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

 

 

8.2. Equation Solver: Solve()

 

The Solve() functions

 

Solve(expr1 = expr2, x)

 

solve a polynomial and systems of linear equations on one step. 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.

 

Example:

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

 

In: Solve(a+b*x+x^2 = 0, x);

# solve or re-arrange the equation for x;

Out: (-b/2 + Sqrt((b/2)^2 - a), -b/2 - Sqrt((b/2)^2 - a));

 

 

Example:

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

 

In: N(Solve(x^3+x^2+x+5 = 2*x+6, x));

Out: (1, -1, -1)

 

The function Solve() not only solves for a simple variable x but also solves for an unknown function, eg. Ln(x).

 

Example:

Solve the equation for Ln(x).

 

In: Solve(Ln(x)^2+5*Ln(x) = -6, Ln(x));

Out: (-2, -3);

 

 

8.3. Polynomial Solver: PSolve()

 

The external function

PSolve(f(x), x)

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

 

eg.

In: PSolve(x^2+5*x+6, x);

Out: (-2, -3)

 

 

8.4. Numeric Solver: NSolve()

 

The external functions

NSolve(f(x) , x)

NSolve(f(x) , x,x0)

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

 

Example:

In: NSolve( Cos(x) - x, x);

Out: x = 0.73911289091;

 

In: NSolve( Sin(x) , x,0);

Out: x = 0;

# only gives one solution near x0=0;

 

In: NSolve( Sin(x) , x,3);

Out: x = 3.14;

# only gives one solution near x0=3;

 

 

8.5. Solving Differential Equations

 

You can solve the differential equations:

y'(x) = f(x)

by integrating the equation.

Example:

solve y'(x)=Sin(x) by integration.

In: Int( D(y(x),x) = Sin(x), x)

Out: y(x) = constant - Cos(x)

 

 

8.6. Differential Solver: DSolve()

 

9. Sums and Products

 

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 , xmin , xmax)

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

Product(expr, x , xmin , xmax)

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

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

Here are some examples:

Sum(j, j from 1 to 10)

for 1 + 2 + .. + 10.

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

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

Here are some sample Taylor polynomials:

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

for Exp(x).

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

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

 

 

9.1. Partial Sum

 

The function

PartialSum(f(x),x)

finds the partial sum (symbolic sum).

 

Example:

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

 

In: PartialSum(n^2, n)

Out: 1/6 n (1 + n) (1 + 2 n)

 

 

9.2. Infinite Sum

 

The function

InfiniteSum(f(x), x)

finds the infinite sum, i.e. Sum(f(x), x , 0 , Infinity).

 

Example:

In: InfiniteSum(1/n!, n);

Out: E

 

10. Series and Polynomials

10.1. Series

 

The functions

Taylor(f(x), x)

Taylor(f(x), x, order)

Taylor(f(x), x, order, x0)

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

Example:

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

 

In: Taylor(Cos(x), x);

Out: 1 - 1/2 x^2 + 1/24 x^4;

 

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

 

10.2. Polynomials

 

Polynomials are automatically sorted in order from low to high.

 

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

Factor(poly, x)

 

eg.

In: Factor(x^2+5*x+6, x)

Out: (2 + x) (3 + x)

 

11. Lists and Arrays, Vectors and Matrices

 

 

13. Conversion

 

Different types of data may be converted each other.

 

 

13.1. Converting to Numbers

 

The complex number is converted to the real number by

Re(z), Im(z), Abs(z), Arg(z), Sign(z)

The real number is converted to the integer number by

Floor(x)

Ceil(x)

The rational number is converted to the real number by

N(x)

 

14. Getting Parts of Expression

14.1. Getting Type of Data

 

You can get type of data by

Type(x)

 

In: Type(2);

Out: Integer

 

 

14.2. Getting Operators

 

You also can get operators by

Type(x)

 

In: Type(a>b);

Out: >

 

In: Type(Sin(x));

Out: Sin()

 

 

14.3. Getting Operand

 

 

15. Graphics

 

DrMath includes extensive facilities for graphing.

 

 

15.1. Drawing Lines and Arcs

 

15.2. Plotting f(x)

 

You can plot a function of y = f(x) on the xy-plane by external function:

 

Plot(f(x),x)

Plot(f(x),x,xmin,xmax)

Plot(f(x),x,xmin,xmax,ymin,ymax)

Plot(f(x),x,xmin,xmax,ymin,ymax,NoPoint)

 

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 DrMath 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.

If you want your circles and squares to look correct --that is, if you want one vertical unit to be really the same distance as one horizontal unit--you should select window parameters so that the horizontal axis is 1.4 times as long as the vertical axis.

 

Example 5.2:

plot x^3 and Sin(x).

In: Plot(x^3,x);

In: Plot(Sin(x),x);

 

15.3. Plotting Parametric Functions x(t) and y(t)

 

You can plot the parametric functions of x=x(t) and y=y(t) by

 

ParametricPlot(x(t),y(t),t)

ParametricPlot(x(t),y(t),t,tmin,tmax)

ParametricPlot(x(t),y(t),t,tmin,tmax,ymin,ymax)

 

Example:

In: ParametricPlot(Sin(t),Sin(2*t),t)

 

 

15.4. Plotting f(t) in Polar Coordinates

 

You can graph the portion of a polar curve r = f(t) that lies in the window with external function:

 

PolarPlot(f(t),t)

PolarPlot(r, t,tmin,tmax)

PolarPlot(r, t,tmin,tmax,rmin,rmax)

 

f(t) can be a function with bound variable t or an expression involving t.

 

Example:

Plot a circle r = 1 in polar coordinates.

In: PolarPlot(1,t)

 

The variable t covers the domain (0, 2*Pi); you can change this default by specifying a range for t:

PolarPlot(1, t,0,Pi)

 

15.5. Plotting Data

 

You can plot data in a data file by the Import menu.

 

 

 

16. Learning from User

 

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

 

 

16.1. Learning Integrals from a Derivative

 

16.2. Learning Complicated Integrals from a Simple Integral

 

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

 

Example:

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

 

In: Int(f(x), x);

Out: Int(f(x), x);

 

In: Int((2*f(x)+x), x);

Out: Int((2*f(x)+x), x);

 

In: Int(Int(f(x)+y), x), y);

Out: Int(Int(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: Int(f(x_), x_) := f(x_) x_;

In: Int(2*f(x)+x, x);

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

 

In: Int(Int(f(x)+y, x), y);;

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

 

You can also ask DrMath to perform the following integrals:

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

Int(Int(f(x)*y, x), y),

Int(x*f(x), x),

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

 

 

16.3. Learning Definite Integral from Indefinite Integral

 

You continue to ask indefinite integral.

 

In: Int(Int(f(x)+y, x , 0 , 1), y , 0 , 2);

Out: 2 f(1)

 

 

16.4. Learning Complicated Derivatives from Simple Derivative

 

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

 

Example:

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

 

In: D(f(x^2)^6, x);

Out: 12 x f(x^2)^5 f'(x^2);

 

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

 

In: D(f(x_),x_) := df(x_);

In: D(f(x^2)^6, x);

Out: 12 x f(x^2)^5 df(x^2);

 

This time you get the complete derivative.

 

16.5. Learning Integration from Algebra

 

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

 

Example :

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

 

In: f(x) := 1/2-1/2*Cos(2*x);

In: Int(f(x), x);

Out: 1/2 x - 1/4 Sin(2 x);

 

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

 

 

16.6. Learning Complicated Algebra from Simple Algebra

 

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

 

Example:

Transform log(x*y) into log(x)+log(y) in an expression.

 

 

 

16.7. Learning versus Programming

 

The difference between learning and programming is as follows: the learning process of DrMath is very similar to the way human beings learn, and that is accomplished by knowing certain rule that can be applied to several problems. Programming is different in the way that the programmers have to accomplish many tasks before he can begin to solve a problem. First, the programmer defines many subroutines for the individual integrands (eg. f(x), f(x)+y^2, 2*f(x)+x, x*f(x), etc.), and for individual integrals (eg. 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 DrMath 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 integral of f(x)), DrMath will determine how to go about solutions of many problems.

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

 

 


PART 2 Programmer's Guide

 

17. Programming in DrMath

 

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

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

The DrMath 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 DrMath language is:

data -> expression -> statement -> program

Note that upper and lower case letters are different in DrMath language, (eg. abc is different from ABC).

In the following examples, a line of "In: " means input, which you type in the Input window, run the program by clicking the menu "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.

 

 

17.1. Data Types

 

The data types in DrMath 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 DrMath can recognise it.

 

 

17.1.1. Numbers

 

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

In fact, the range of the input real numbers is

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

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

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

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

 

 

For examples:

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

Numbers Type

 

23 integer

2/3 rational

0.23 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.

 

 

17.1.2. Constants

 

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

 

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

Built-in Constants Meanings

 

Pi:=3.1415926536 the circular constant.

E:=2.7182818285 the base of the natural logarithms.

I:=Sqrt(-1) the imaginary sign of complex numbers.

Infinity infinity.

-Infinity negative infinity.

Undefined the undefined value, eg. indeterminate forms:

0/0, Infinity/Infinity, 0*Infinity, 0^0, etc.

True

False

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

 

The Infinity can be computed as if numbers.

 

Example:

In: Infinity+2;

Out: Infinity

 

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

 

Example: evaluate Exp(1/x) and Sin(x)/x at x=0.

 

In: f(x_) := Exp(1/x);

Out: f(x_) := Exp(1/x);

 

In: f(0);

Out: Discont;

# f(0) is discontinuity, only has one sided value;

 

 

In: Replace(Sin(x)/x, x , 0);

Out: undefined;

 

 

 

17.1.3. Variables

 

The sequence of characters is used as the name of variables. Variable names can be up to 128 characters long. They must begin with a letter and use only letters and digits. DrMath knows upper and lower case distinctions in variable names, so AB, ab, Ab and aB are the different variables. They are case sensitive.

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

<variable-name> := expression

eg. x := 2 + 3 # assign value to x

Variables can be used like constants in expressions.

For example:

a := 2 + 3

b := a*4

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

 

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

x := 4 # Now x is defined

y # y returns 7, but its value is still the formula 3 + x

x := 7 # revalue x

y # new value for y

 

Note that in symbolic computation, the variable has not only a numeric value but also a symbolic value.

Symbolic values for variables are useful mostly for viewing the definitions of functions and symbolic differentiation and integration.

Watch out for infinite recursion here. Defining

x := x+3

when x has no initial value, it will not cause an immediate problem, but any future reference to x will result in an infinite recursion !

A value can be assigned to the variable, by one of three methods:

(1) the assignment :=,

(2) the user-defined function f(),

(3) Replace(y, x , x0).

 

eg.

y:=x^2;

x:=2;

# assignment;

y

f(2)

# if f(x) has been defined, eg. f(x_):=x^2.

Replace(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, Abs(x) < Infinity and all variables are complex, except that variables in inequalities are real, as usual only real numbers can be compared. eg. x is complex in Sin(x), but y is real in y > 1.

You can restrict the domain of a variable by assuming the variable is even, odd, integer, real number, positive or negative (see Chapter Simplification and Assumption).

 

 

17.1.4. Patterns

 

Patterns stand for classes of expressions.

 

x_ any expression, given the name x.

 

Patterns should appear on both sides of the assignment. Patterns are only used in definition of functions, procedures and rules.

Patterns are used to define functions and rules for pattern match.

 

 

17.1.5. Functions, Procedures and Rules

 

These are two types of functions: internal and external. The internal function is compiled into the DrMath system. The external function is the library written in DrMath language, which is automatically loaded when it is needed (see Chapter Library). You can change the property or name of the external function by modifying its library file, or you add a new external function by creating its library file, but you cannot change the internal function.

 

 

17.1.5.1. Standard Mathematical Functions

 

All below standard functions, (except for random(x), n!, fac(n) and atan2(x,y)), can be differentiated and integrated symbolically.

 


Table 17.1.5.1 Standard Mathematical Functions

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

Functions Meanings

 

n! factorial of n.

Sqrt(x) square root, the same as x^0.5.

Exp(x) the same as e^x.

Sign(x) 1 when re(x) > 0, or both re(x) = 0 and im(x) > 0; 0 whenx=0;

-1 otherwise.

Abs(x) absolute value of x.

Ln(x) natural logarithmic function of x, based on e.

Sin(x) sine function of x.

Cos(x)

Tan(x)

Csc(x)

Sec(x)

Cot(x)

Asin(x) arc sine function of x, the inverse of Sin(x).

Acos(x)

Atan(x)

Acot(x)

Asec(x)

Acsc(x)

Atan2(x,y)

Sinh(x) hyperbolic sine function of x.

Cosh(x)

Tanh(x)

Asinh(x) arc hyperbolic sine function of x, the inverse of sinh(x).

Acosh(x)

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

 

 

17.1.5.2. Calculus Functions

 

Calculus functions are for calculus calculation. The first argument of the function is for evaluation, and the second argument is a variable that is with respect to.

 

 

Table 17.1.5.2 Calculus Functions

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

Functions Meanings

 

Replace(y, x , x0) evaluates y when x = x0.

 

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.

 

Int(y, x) find the indefinite integral of y with respect to an undefined variable x.

Int(y,x,a,b) find the definite integral of y with respect to an undefined variable x taken from x=a to x=b.

Int(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.

Int(y, x , a , b) the same as Int(y,x,a,b).

Int(y) implicit integration, used to integrate the differential equations.

 

Sum(y, x , xmin , xmax) sum of y step=1.

Sum(y, x , xmin , xmax , dx) sum of y.

 

Product(y, x , xmin , xmax) product of y step=1.

Product(y, x , xmin , xmax , dx) product of y.

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

 

If a second argument x is omitted in the functions D(y) and Int(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:

Int(Int(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-argument functions. eg. Int(f(x), x, 0, 1) are the same as Int(f(x), x from 0 to 1).

 

Examples:

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

differentiation D() D(x^2,x)

integration Int() Int(x^2,x)

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

 

 

17.1.5.3. Test Functions

 

Table 17.1.5.3.1 The is*(x) Functions

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

Function Meaning

 

IsOdd(x) test if x is an odd number.

IsEven(x) test if x is an even number.

IsInteger(x) test if x is an integer number.

IsRational(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.

IsFree(y,x) test if y is free of x.

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

 

All of the is* functions give either True or False otherwise.

The Type(x) gives the type of x. Its value is a string.

 


Table 17.1.5.3.2 The Type(x) functions

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

x Type(x)

 

1 Integer

1.1 Real

2/3 Rational

1+I Complex

Sin(x) Sin()

a Symbol

a+b +

a*b *

a^b ^

a=b =

a==b ==

a>b >

a>=b >=

a<b <

a<=b <=

a<>b <>

a,b ,

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

 

 

17.1.5.4. Miscellaneous Functions

 

Table 17.1.5.4.1 Algebra Functions

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

Expand(F) expand (a+b)^2 to a^2 + 2*a*b + b^2.

Factor(F) factorise a^2 + 2*a*b + b^2 to (a+b)^2.

Solve(f(x)=0, x) solve polynomial and systems of linear equations

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

 

For example:

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

solving Solve() Solve(x^2+1 = 0, x)

expanding ExpanD() Expand((a+b)^2)

factoring Factor() Factor(a*c+b*c)

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

 

Conversion functions convert a type of data to another type of data.

 

Table 17.1.5.4.2 Conversion Functions

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

Re(x) real part of complex numbers.

Im(x) imaginative part of complex numbers.

N(x) convert x to the floating-point number.

Floor(x) convert x to the rounded integer.

Ceil(x) convert x to the truncated integer.

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

 

 

Above functions can be operated and chained, like the standard functions.

 

 

17.1.5.5. User-defined Functions

 

You can define the new functions, which include the standard functions, calculus functions, and algebraic operators.

Define a new function f(x) by

f(x_) := x_^2

and then call f(x) as the standard functions. The function name can be any name.

Clears a variable or function from assignment by

Clear(x) # clear x from assignment.

Clear(f(x)) # clear f(x) from assignment.

Clear(a>0) # clear a>0 from assignment.

Variables can be used in function definitions. It leads to an important difference between functions and variables. When a variable is defined, all terms of the definition are evaluated. When a function is defined, its terms are not evaluated; they are evaluated when the function is evaluated. That means that if a component of the function definition is changed, that change will be reflected the next time the function is evaluated.

 

 

17.1.5.6. Procedures

 

A procedure is similar to a function, but the right side of assignment in its definition is multi statements grouped by Block(). The Block(a,b,c) groups a,b,c and only returns the last argument as its value. It is used as grouper in definition of a procedure. All variables in block are local.

 

eg. f(x_):=Block(p:=x^6,p);

Remember that you can split a line of statement into multi-lines statement by ending ;

 

 

17.1.5.7. Rules

 

A rule is similar to a function. In definition of function, all arguments of function are simple variables, but in definition of rules, the first argument may be a complicated expression.

 

eg.

f(x_,y_) := x_^2+y_^2 # defining function

f(x_,y_) := Block(a:=2, a+x_^2+y_) # defining procedure

log(x_ * y_) := log(x_)+ log(y_) # defining rule

 

 

 

17.1.6. Equations

 

An equation is an equality of two sides linked by an equation sign =, eg. x^2+p = 0, where the symbol = stands for an equation. Note that the symbols "=", "==" and ":=" are different: ":=" is the assignment, "==" is the equal sign, but "=" is the equation sign.

 

Example:

In: 2 = 2;

Out: 2 = 2;

# unevaluated;

 

In: 2 == 2;

Out: True;

 

 

 

17.1.7. Inequalities

 

eg.

a < b less than

a <= b less than or equal to

a > b greater than

a >= b greater than or equal to

a == b equal to

a <> b not equals

 

17.2. Expressions

The expressions (i.e. expr) are made up of operators and operands. Most operators are binary, that is, they take two operand; the rest are unitary and take only one operand. Binary operators use the usual algebraic form, eg. 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.

eg.

a+b+3 numeric expression,

a>0 Boolean expression

a>0 and b>0 Boolean expression

17.2.1. Operators

 

Table 17.2.1 Operators

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

Operation Operators Examples Order

 

comma , a:=2, b:=3 1

assignment := p:=2+3 2

and and a>2 and a<8 2

or or a>2 or b>2 2

equation = x^2+x+1 = 0 3

equal == a==2 3

larger than > a>2 3

larger and equal >= a>=2 3

less than < a<2 3

less and equal <= a<=2 3

unequal <> a<>2 3

plus + a+b 4

minus - a-b 4

mutilation * a*b 5

division / a/b 5

power ^ a^b 6

factorial ! n! 6

positive + +a 7

negative - -a 7

function f() Sin(x) 7

parentheses () (a+b)*c 7

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

 

All functions have the same 7th order.

Operations with higher order precede, otherwise operations with equal precedence are performed from left to right. These are the usual algebraic conventions.

a^b^c is the same as (a^b)^c.

You can get operators by Type(x).

 

 

17.2.1.1. Arithmetic Operators

 

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

plus + a+b 4

minus - a-b 4

mutilation * a*b 5

division / a/b 5

power ^ a^b 6

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

 

 

17.2.1.2. Relational Operators

 

Before you can write loops, you must be able to write statements that evaluate to True or False, and before you can do that, you must be able to write useful statements with logical values. In mathematics, these are relational statements.

DrMath 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

 

DrMath 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 True or False. If the comparison is not both real numbers, it left unevaluated.

 

 

17.2.1.3. Logical Operators

 

DrMath 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 DrMath 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.

DrMath uses the "short-circuit" definition of And and Or when the arguments are Boolean. Short-circuit evaluation is used because often one condition must be tested before another is meaningful.

 

 

17.2.2. Function Calls

 

A function call activates the function specified by the function name. The function call must have a list of actual parameters if the corresponding function declaration contains a list of formal parameters. Each parameter takes the place of the corresponding formal parameter. If the function is external, the function call will automatically load the library specified by its function name plus extension .vm when needed.

Some examples of the function calls follow:

Sin(x) # load the library Sin.vm when needed

Int(x^2, x) # load the library Int.vm when needed

 

 

17.3. Statements

17.3.1. Comment Statements

 

# and // are the comment statement signs.

You can add comments into a line, or even produce a single line which is entirely a comment, by preceding the comment sign with #.

 

For example:

# This is my program;

3 + 4

# My first calculation;

 

Comments make your calculations more understandable, whether you are making a printed record of what you are doing or if you just want to jot some notes to yourself while you are working.

 

 

17.3.2. Evaluation Statements

 

The evaluation statement has the format:

 

Expression;

 

DrMath evaluates any expression which in a line and gives the value of the expression. eg.

 

In: 3 + 4;

Out: 7;

 

In: D(x^6, x);

Out: 6 x^5;

 

 

17.3.3. Assignment Statements

 

The assignment in DrMath language is similar to assignment in such language as PASCAL.

An assignment operator is :=

The assignment statement specifies that a new value of expr2 be assigned to expr1, and saved into memory. The form of the assignment statements is

 

expr1 := expr2;

 

You can use assignment for storing result.

You can assign the result of calculation or any formula to a variable with a command like: X := SIN(4.2).

The assignments are useful for long calculations. You can save yourself a lot of recalculations by always storing the results of your calculations in your own variables instead of leaving them in the default variable last.

You can destroy the assignment to X with the command Clear(X). If X stored a large list, you could regain a considerable amount of memory by clearing X. Also, since a variable and a function can have the same name, you can clear a variable p, not a function p(x).

The assignment operator is also used in the definition of a function or procedure.

Variables can be used in function definitions, and that leads to an important difference between functions and variables. When a variable is defined, all terms of the definition are evaluated. When a function is defined, its terms are not evaluated; they are evaluated when the function is evaluated. That means that if a component of the function definition is changed, that change will be reflected the next time the function is evaluated.

 

eg.

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 (ie. expr2 is evaluated when the value of expr1 is requested).

Clear a variable, function or expression from assignment by

 

Clear(x) # clear x from assignment.

Clear(f(x)) # clear f(x) from assignment.

Clear(a>0) # clear a>0 from Assume(a>0).

 

 

17.3.4. Conditional

 

There are two conditional functions:

If(test , x)

If(test , x , y)

 

If(condition , x) gives x if condition evaluates to True, or no output otherwise.

If(condition , x , y) gives x if condition evaluates to True, y if it evaluates to False, or no output if it evaluates to neither True or False.

It is useful in definition of the use-defined function to left the function unevaluated if the argument of the function is not number. eg. define f(x_) := If(IsNumber(x_), 1), then call f(x), f(10) gives 1, and f(a) gives f(a).

 

 

17.3.5. Loop

 

You can use two kinds of loops in DrMath, fixed length loops controlled by For() and variable-length loops controlled by While(). The For() loop is similar to the FOR loop in BASIC language.

The control variable in the For() loop is not limited to integer values. You can say:

 

For(x , xmin , xmax , dx, body);

 

It is similar to

FOR x := xmin TO xmax STEP dx

body

NEXT x

where xmin, xmax, and dx are real values. If STEP dx is omitted, it defaults to 1.

 

eg.

In: x:=0;

Out: x := 0;

In: For( j , 1 , 5 , 1, x:=x+1);

Out: x := 5;

 

The conditional loops are probably more useful than the For() loops if a number of iteration is unknown. It is

While(test, body);

The While() repeats to evaluate body while the test is True.

 

Example:

In: x:=1;

Out: x := 1;

 

In: While(x<5, x:=x+1 );

Out: x := 6;

 

 

17.3.9. Sequence Statements

 

The all above statements are simple statements. The sequence statement specifies that its component statements are to be executed in the same sequence as they are written. They are separated by the separators (comma ","). eg.

a+b, 2+3;

 

 

17.4. Libraries

 

A library is a file of an external function, which filename is its function name plus extension .vm. eg. the library named Sin.vm is a file of the Sin(x) function definition.

The library (the *.vm file) is similar to the MS-DOS *.BAT file. You do not need to load or read the library by any command. DrMath automatically load the library when it is needed. For example, when you use the Sin(x) function first time, the library Sin.vm will be auto-loaded. The library must be in the default directory, otherwise the library is not loaded and the function is not working. Only the assignments in the library can be loaded, and others in the library will be omitted, but all of these assignments will be not evaluated when they are loaded. You can clear the library Sin.vm 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.

There are many libraries. The following are some of them.

 

Table 17.4.1 Libraries

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

File Name Function

 

Plot.vm plotting functions.

D.vm derivatives.

Int.vm integrals.

Sum.vm sum function.

NInt.vm numeric integration.

NSolve.vm numeric solver of equation.

DSolve.vm differential equation solver.

Gamma.vm gamma function.

Ei.vm exponential integral function.

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

 

 

17.5. Interface with Other Software

 

You can run DrMath from another software as a engine. Another software sends a text file to DrMath, then run DrMath in background, get result back from DrMath.

 

 


Part 3 Reference Guide

 

19. DrMath Environment: Windows and Menus

 

DrMath is a text editor in which you can copy-and-paste anywhere in a file and between files, even from other documents outsides DrMath.

The screen is divided into four areas: a menu line, an Input window, an Output window, and the Graph window.

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.

 

 

19.1. File Menu

 

19.1.1. Open

 

The Open menu opens a file for edit in the Input window. This menu first opens a Directory window to choose a file for edit. You select a file from the Directory window to open for edit in the Input window.

 

19.1.2. Import Data

 

It imports data from a file for data plot.

 

19.1.3. Save Input

 

The "Save Input" menu saves the file in the Input window into disk under a different name or in a different directory.

 

 

19.1.4. Save Output

 

The "Save Output" menu saves the file in the Output window into disk under a different name or in a different directory.

 

 

19.1.5. Print

 

 

19.1.6. Exit

 

 

 

19.2. Input Window

 

You can copy-and-paste from and to your document by right-button clicking on the text field to pop-up menu. For second way of copy-and-paste, first select the text, then key in Ctrl+C (i.e. press the Ctrl key and the C key at the same time), then point to where you want to paste, and finally key in Ctrl+V (i.e. press the Ctrl key and the V key at the same time).

 

19.3. Run Menu

 

The Run menu executes the user program in the Input window, outputs the results in the Output window.

 

19.4. Graph Menu

 

It changes graph of size and colour. Click on the "Zoom In" or "Zoom Out" menu under the Graph menu to zoom.

 

19.5. Option Menu

The TeX menu converts output to TeX format.

 


20. Inside DrMath

20.1. Internal Structure

 

As an expert system, DrMath consists of three major components: a knowledge base, an inference engine, and a global database. The knowledge base is a set of rules. The inference engine is a rule interpreter for utilising the knowledge base in the solution of the problem, and the global data base is a working memory for keeping track of the problem status, the data from the data file for the particular problem, and the solution of sub-problems. In addition, it contains a natural language interface for input and output natural languages (eg. mathematical formulas, chemical reactions).

 

 

User Library disk

/|\ | /|\

| | |

\|/ \|/ \|/

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

| Natural Language Interface |

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

/|\

|

\|/

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

------->| Inference Engine |<----------

| ------------------------------ |

\|/ \|/

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

| Knowledge Base | | Global Data Base |

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

/|\

|

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

| Data File |

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

 

Figure 20.1 Structure of DrMath

 

 


 

Table 20.1 Characteristics of DrMath

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

Function: Symbolic computation.

Domain: Mathematics.

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, editor, windows.

System interface: numeric computation software, graphic software, etc.

Input format: Math formulas, numbers, BASIC or FORTRAN codes,

Output format: Math notation, TeX codes,

Input from: Keyboard, disk.

Output to: Screen, disk, printer.

Tool language: Java.

Computer: Any machine that supports Java

Memory: 16 MBytes.

Operating system: Any OS that support Java.

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

 

 

20.2. Internal Format

 

21. System Extension

 

You can add feature into DrMath by developing library that is auto-loaded. You also can extend Java class that is auto-loaded.

22. Keywords

 

Upper- and lower-case letters are different. A first letter of each word in DrMath keywords is upper-case.

There are two types of the keywords: internal and external. The internal keywords have been compiled into the DrMath 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 are in the default library directory.

 

 

22.1. Keywords in Topic Order

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

Arithmetic operators:

+, -, *, / plus, minus, times, division

^ power

()

 

Relational operators:

== equals

> greater than

>= greater than or equal

< less than

<= less than or equal

<> not equal

 

Assignments:

:=

 

Equation:

=

Solve(x^2=1,x) solve x^2=1 for x

PSolve(f(x),x) solve f(x)=0 for x

NSolve(Cos(x)=x,x) numerically solve f(x)=0 for x with initial x0=1

NSolve(f(x)=0,x,x0) numerically solve f(x)=0 for x with initial x0

 

Comment:

#

//

 

Built-in constants:

I, E, Pi, Infinity, True, False

 

Logic operators:

And, Or, Not(x)

 

Algebraic functions:

-x minus x

Sqrt(x) square root of x

n! factorial of n

Expand(x) expand x

Factor(x) factor x

Factor(y,x)

 

Complex to real:

Re(x) real part of the complex number x

Im(x) imaginative part of the complex number x

Abs(x) absolute value of x

Arg(x) argument of complex number x

Sign(x) sign of complex number of x

 

Exponential functions:

Exp(x) natural exponential of x, Exp(x)=E^x

Ln(x) natural logarithm of x

 

Trig functions:

Sin(x) sine of x

Cos(x) cosine of x

Tan(x) tangent of x

Csc(x) cosecant of x

Sec(x) secant of x

Cot(x) cotangent of x

 

Inverse trig functions:

Asin(x) angle whose sine is x

Acos(x) angle whose cosine is x

Atan(x) angle whose tangent is x

Atan2(x,y) angle whose tangent is x/y

 

Hyperbolic functions:

Sinh(x) hyperbolic sine of x

Cosh(x) hyperbolic cosine of x

Tanh(x) hyperbolic tangent of x

 

Special math integral functions:

Ei(x) exponential integral function

Ei(n,x) incomplete exponential integral function Int(t^(n-1)*Exp(t), t,-Infinity,x)

Gamma(n) gamma function Int(t^(n-1)*Exp(-t), t,0,Infinity)=(n-1)!

Gamma(n,x) incomplete gamma function Int(t^(n-1)*Exp(-t), t,0,x)

Erf(x) error function 2/Sqrt(Pi)*Int(Exp(-t^2),t,0,x)

Si(x) sine integral function Int(Sin(x)/x)

Ci(x) cosine integral function Int(Cos(x)/x)

Li(x) log integral function Int(1/Ln(t), t,0,x)

Li(n,x) incomplete log integral function Int(Ln(t)^n, t,0,x)

 

Defining functions:

f(x_) := x_^2

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

 

Defining procedures:

f(x_) := Block(p:=x_^2,p)

 

Defining rules:

log(x_ * y_) := log(x_)+log(y_)

 

Clear:

Clear(x) clear variable x

Clear(f(x)) clear function f(x)

Clear(a>0) clear unequal a>0

 

Calculus functions:

Differentiating:

D(y,x) differentiate y with respect to x

D(y,x,n) differentiate y with respect to x in the n-th order

 

Integrating:

Int(y,x) integrate y with respect to x

Int(y,x,xmin,xmax) integrate y with respect to x from xmin to xmax

NInt(y,x,xmin,xmax) numerically integrate y w.r.t. x from xmin to xmax

 

Substituting:

Replace(y,x,x0) replace x by x0 in y

 

Laplace(y,x) Laplace transform

 

Sum(y, x,xmin,xmax,dx) sum of y w.r.t x from xmin to xmax step dx

PartSum(y,x) partial sum of y

InfSum(y,x) infinite sum of y

 

Product(y, x,xmin,xmax,dx) product of y w.r.t x from xmin to xmax step dx

 

Taylor(y,x) series of y at x=0 to order of 5

Taylor(y,x,order) series of y at x=0 to order

 

Conversion functions:

Floor(x) convert x to the rounded integer closet to x

Ceil(x) convert x to the truncated integer closet to x

Type(x) type of x

 

Numeric computation:

N(x) numeric value of x

NSolve(Cos(x)-x,x) numerically solve Cos(x)-x=0 w.r.t. x with initial x0=0.1

NSolve(Cos(x)-x,x,x0) numerically solve Cos(x)-x=0 w.r.t. x with initial x0

NInt(y,x,xmin,xmax) numerically integrate y w.r.t. x from xmin to xmax

 

Test functions:

IsConstant(x) test if x is a constant

IsOdd(x) test if x is odd

IsEven(x) test if x is even

IsInteger(x) test if x is integer

IsRational(x) test if x is rational number

IsReal(x) test if x is real

IsComplex(x) test if x is complex

IsNumber(x) test if x is a number

IsFree(y,x) test if y is free of x

Type(x)==Real test if x is real

 

Comma:

,

 

Assume:

Assume(a>0) assume a > 0

IsReal(x):=True assume x is real

 

Conditional:

If(x>0 , x) if x > 0 then x

If(x>0 , x , 0-x) if x > 0 then x else -x

 

Loop:

While(x<5, body ) while x<5, repeat body

For(x,xmin,xmax,dx, body) do body w.r.t. x from xmin to xmax with step dx

 

Getting parts:

Type(x) type of x

Re(x) real part

Im(x) imaginative part

 

Graph:

Plot(y,x) plot y w.r.t. x from x=-5 to 5, from y=-5 to 5

Plot(y,x,xmin,xmax) plot y w.r.t. x from x=xmin to xmax, from y=-5 to 5

Plot(y,x,xmin,xmax,ymin,ymax)

plot y w.r.t. x from x=xmin to xmax, from y=ymin to ymax

 

ParametricPlot(x(t),y(t),t) parametric plot x(t) and y(t) w.r.t. t from t=0 to 2*Pi

ParametricPlot(x(t),y(t),t,tmin,tmax) parametric plot x(t) and y(t) w.r.t. t from t=tmin to tmax

 

PolarPlot(r(t),t) polar plot r(t) w.r.t. t from t=0 to 2*Pi

PolarPlot(r(t),t,tmin,tmax) polar plot x(t) and y(t) w.r.t. t from t=tmin to tmax

 

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

 


 

22.2. Keywords in Alphabetical Order

 

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

 

+ - * / ^

** () // = :=

== > >= < <=

<> ! # , ;

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

 


22.3. Library Name

 

You can use library as standard functions by library name without extension. E.g. Abs, not Abs.vm. Please see file name in the vmath\library directory.

 

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

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


22.4. Glossary

 

The keywords indicated internal are the internal functions or constants, otherwise they are the external.

 

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

* Abs

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 Infinity.

See also: Abs, Arg, Sign, Re, Im.

eg.

In: Abs(-1), Abs(-I)

Out: 1, 1

 

* Acos

Acos(x) is the arc cosine function of x. The inverse function of Cos(x). The result is given in radians.

See also: Acos, Cos.

 

* Acosh

Acosh(x) is the inverse hyperbolic cosine function of x. The inverse function of Cosh(x).

See also: Acosh, Cosh.

 

* Acot

Acot(x) is the arc cotangent function of x. The inverse function of Cot(x). The result is given in radians. Acot(x)=Pi/2-Atan(x).

See also: Acot, Cot.

 

* Acoth

Acoth(x) is the inverse hyperbolic cotangent function of x. The inverse function of Coth(x). Acoth(x)=Atanh(1/x).

See also: Acoth, Coth.

 

* Acsc

Acsc(x) is the arc cosecant function of x. The inverse function of Csc(x). The result is in radians. Acsc(x)=Pi/2-Asin(x).

See also: acsc, csc.

 

* Acsch

Acsch(x) is the inverse hyperbolic cosecant function of x. The inverse function of Csch(x). Acsch(x)=Asinh(1/x).

See also: Acsch, Csch.

 

* And

logic operator. It is bitwise and. The result is True, False or unevaluated.

See also: Or.

 

* Arg

Arg(x) gives the argument (phase angle) of x in radians. It only gives the principle value (P.V.): -Pi < arg(x) <= Pi. arg(x) = atan2(re(x),im(x)). x can be complex number. For positive real x, Arg(x)=0.

See also: Abs, Arg, Sign, Atan2.

eg. N(Arg(I)) gives 1.5..

* Asec

Asec(x) is the arc secant function of x. The inverse function of Sec(x). The result is given in radians.

See also: Asec, Sec.

 

* Asech

Asech(x) is the inverse hyperbolic secant function of x. The inverse function of Sech(x). Asech(x)=Acosh(1/x).

See also: Asech, Sech.

 

* Asin

Asin(x) is the arc sine function of x. The inverse function of Sin(x). The result is given in radians.

See also: Asin, Sin.

 

* Asinh

Asinh(x) is the inverse hyperbolic sine function of x. The inverse function of Sinh(x).

See also: Asinh, Sinh.

 

* Assume

Assume(x > 1) assumes the variable x > 1 in real domain.

By default, Abs(x) < Infinity and all variables are complex, except that variables in inequalities are real, as usual only real numbers can be compared. eg. x is complex in Sin(x), but y is real in y > 1.

You can restrict the domain of a variable by assuming the variable is even, odd, integer, real number, positive or negative. The Assume() can be cleared by Clear().

See also: Sign.

eg. Assume(x>0), Assume(x>0, y<0), IsEven(x):=True

 

* Atan

Atan(x) is the arc tangent function of x. The inverse function of tan(x). The result is given in radians.

See also: atan, tan.

 

* Atan2 internal

Atan2(x,y) returns the radian angle of (x,y).

Atan2(x,y) = Sign(y)*Pi/2 if x=0

= atan(y/x) if x>0

= atan(y/x)+Pi if x<0, y>=0

= atan(y/x)-Pi if x<0, y<0 .

Thus atan2(x,y) takes its value of -Pi < atan2(x,y) <= Pi.

See also: atan, arg.

 

* Atanh

atanh(x) is the inverse hyperbolic tangent function of x. The inverse function of tanh(x).

See also: tanh.

 

* Block internal

Block(a,b,c) groups a,b,c and only returns the last argument as its value. It is used as grouper in definition of a procedure. All variables in block are local.

See also: local.

eg. f(x_):=Block(p:=x_^6,p)

 

* Ceil internal

Ceil(x) converts x to the rounded integer closest to x.

See also: Floor.

 

* Ci

Ci(x) is cos integral, Ci(x) = Int(Cos(x)/x, x).

See also: Si, Ei, Gamma, Erf.

 

* Clear internal

Clear(y) clears values and definitions for the variable, function or expression y from memory.

See also: assume, :=.

eg. Clear(p), Clear(f(x)), Clear(a>0)

 

* Cos

Cos(x) is the cosine function of x. The angle x is measured in radians (multiply by degree to convert from degrees). x can be complex numbers.

See also: Acos, Sec.

 

* Cosh

Cosh(x) is the hyperbolic cosine function of x. Cosh(x)=(Exp(x)+Exp(-x))/2. x can be complex numbers.

See also: Acosh.

 

* Cot

Cot(x) is the cotangent function of x. The angle x is measured in radians. (multiply by degree to convert from degrees). cot(x)=1/tan(x).

See also: Acot, Tan.

 

* Coth

Coth(x) is the hyperbolic cotangent function of x. coth(x)=1/tanh(x).

See also: acoth, tanh.

 

* Csc

Csc (x) is the cosecant function of x. The angle x is measured in radians (multiply by degree to convert from degrees). Csc(x)=1/Sin(x) x can be complex numbers.

See also: Acsc, Sin.

 

* Csch

csch(x) is the hyperbolic cosecant function of x. csch(x)=1/sinh(x). x can be complex numbers.

See also: acsch, sinh.

 

* D

D() gives the partial derivative.

 

D(y,x) internal

It differentiate y with respect to x.

eg. D(x^2,x) gives 2*x.

eg. D(Sin(x),x) gives Cos(x).

 

D(y, x, n)

It gives the n-th order derivative of y with respect to an undefined variable x.

eg. D(Sin(x),x,2) gives -Sin(x).

 

See also: Int, NInt.

 

* Degree

degree gives the number of radians in one degree. degree=Pi/180. You can multiply by degree to convert from degree to radians.

See also: Pi.

eg. 45*degree, Sin(45*degree).

 

* 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, Infinity.

 

* For internal

For(x,xmin,xmax,dx, expr) evaluates expr with the x looping from xmin to xmax on step dx.

See also: repeat, list.

eg.

In: x:=0, For(j,1,5,1, x:=x+1);

Out: x := 5;

 

* Done internal

It indicates that the command has been done. See also: assumed, cleared.

 

* E

(1) e is the exponential constant (base of natural logarithms), E=2.718..., the built-in constant, E is converted to 2.718... by N(E). e^x is the same as Exp(x).

(2) e is the exponential part of a floating point number, the same as E.

eg. 1.1e2 is the same as 1.1E2.

See also: Exp.

 

* Ei

Ei(x) is the exponential integral function Ei(x), Ei(x) = Int(e^t/t, t,-Infinity,x), ei'(x) = e^x/x.

 

Ei(n,x) is the incomplete exponential integral function, Ei(n,x) = Int(t^n*e^t, t,-Infinity,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.

 

* Erf

Erf(x) is the error function of x. It is the probability integral function or the integral of the Gaussian distribution. Erf(x) = 2/Sqrt(Pi)*Int(Exp(-t^2),t,0,x), D(Erf(x),x) = 2/Sqrt(Pi)*Exp(-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.

 

* Expand

(1) ExpanD(y) expands out products and positive powers in y. ExpanD() works only on positive integer powers.

See also: factor.

eg. ExpanD((a+b)^2) gives a^2 + 2*a*b + b^2.

 

(2) the switch of expansion.

expand:=on eg. c*(a+b) to c*a+c*b.

expand:=off disable expansion, this is default.

See also: expandexp.

 

* ExpandExp

The exponential expansion.

eg. c^(a+b) to c^a*c^b.

See also: expand.

 

* Gamma

Gamma(n) is the Gamma function _(n), Gamma(n) = Int(t^(n-1)*Exp(-t), t,0,Infinity), Gamma(n) = (n-1)!.

 

Gamma(n,x) is the incomplete Gamma function, Gamma(n,x) = Int(t^(n-1)*Exp(-t), t,0,x), D(Gamma(n,x),x) = x^n*Exp(-x) Gamma(n,0) = 0, Gamma(n,Infinity) = Gamma(n) = (n-1)!.

Gamma(n,x) is similar to Gamma(n).

See also: Ei, Erf, Ci, Si, Li.

 

* 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.

eg. 1+2*I.

 

* If internal

If(condition,x) gives x if condition evaluates to True, or left unevaluated otherwise.

 

If(condition,x,y)

gives x if condition evaluates to True, y if it evaluates to False, or left unevaluated if the condition is neither True nor False.

It is useful in definition of the use-defined function to left the function unevaluated if the argument of the function is not number.

See also: .

eg.

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.

eg. Im(1+2*I) gives 2.

 

* Infinity internal

Infinity is a positive infinity, as the built-in constant.

See also:

eg. Infinity+2*Infinity gives Infinity, 1/Infinity gives 0.

 

* InfSum

InfSum(y,x) is infinite sum.

See also: PartSum, Sum.

 

* Int

Int() is the integral function.

 

Int(y,x) internal

It finds the indefinite integral of y with respect to an undefined variable x.

 

Int(y,x,xmin,xmax)

It finds the definite integral of y with respect to the variable x taken from x=xmni to x=xmax.

 

Int(y,x,xmin,x1,xmax)

It finds the definite integral of y from x=xmin to x=x1, then from x=x1 to x=xmax. x1 is singularity.

See also: NInt.

 

* IsComplex internal

IsComplex(x) tests if x is complex. It gives True if x is complex, or False otherwise.

See also: IsComplex, IsEven, IsFree, IsInteger, IsOdd, IsReal, IsRational, IsNumber, IsConstant.

eg. IsComplex(I) gives True.

 

* IsConstant

It tests if x is a constant.

* IsEven

IsEven(x) gives True if x is an even integer, or False otherwise. You can assume x is even by IsEven(x) := True.

See also: IsComplex, IsEven, IsFree, IsInteger, IsOdd, IsReal, IsRational, IsNumber, IsConstant.

eg. IsEven(2) gives True, IsEven(3) gives False.

 

* IsFree internal

IsFree(y,x) gives True if y is free of x, or False otherwise. You can assume y is free of x by IsEven(y,x) := True.

See also: IsComplex, IsEven, IsFree, IsInteger, IsOdd, IsReal, IsRational, IsNumber, IsConstant.

eg. IsFree(a*b,x) gives True, IsFree(x*y,x) gives False.

 

* IsInteger internal

IsInteger(x) gives True if x is an integer, or False otherwise. You can assume x is integer by IsInteger(x) := True.

See also: IsComplex, IsEven, IsFree, IsInteger, IsOdd, IsReal, IsRational, IsNumber, IsConstant.

eg. IsInteger(2) gives True, IsInteger(3.2) gives False.

 

* IsOdd internal

IsOdd(x) gives True if x is an odd integer, or False otherwise. You can assume x is odd by IsOdD(x) := True.

See also: IsComplex, IsEven, IsFree, IsInteger, IsOdd, IsReal, IsRational, IsNumber, IsConstant.

eg. IsOdd(3) gives True, IsOdd(2) gives False.

 

* IsRational internal

IsRational(x) gives True if x is ratio, or False otherwise. You can assume x is ratio by IsOdD(x) := True.

See also: IsComplex, IsEven, IsFree, IsInteger, IsOdd, IsReal, IsRational, IsNumber, IsConstant.

eg. IsRational(2/3) gives True, IsRational(2) gives False.

 

* IsReal internal

IsReal(x) gives True if x is real, or False otherwise. You can assume x is real by IsReal(x) := 1.

See also: IsComplex, IsEven, IsFree, IsInteger, IsOdd, IsReal, IsRational, IsNumber, IsConstant.

eg. IsReal(2.2) gives True, IsReal(a) gives False.

 

* IsNumber internal

IsNumber(x) gives True if x is a number, or False otherwise. You can assume x is a number by IsNumber(x) := True.

See also: IsComplex, IsEven, IsFree, IsInteger, IsOdd, IsReal, IsRational, IsNumber, IsConstant.

eg. IsNumber(2.2) gives True, IsNumber(a) gives False.

 

* Laplace

Laplace(y,x) gives Laplace transform of y.

eg. Laplace(Sin(t),t) gives 1/(1+t^2).

 

* Li

Li(x) is the Ln integral function, Li(x) = Int(1/Ln(t), t,0,x) = Ei(Ln(x)), D(Li(x),x)=1/Ln(x).

 

Li(n,x) is the incomplete ln integral function, Li(n,x) = Int(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.

 

* Ln

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.

 

* NInt

NInt(y, x , xmin , xmax) numerically integrates y.

See also: Int.

eg. NInt(x^2, x , 0 , 1)

 

* Not

Not(x) is logic not. It gives True if x=False, or False if x=True.

See also: And, Or.

 

* NSolve

NSolve(Cos(x)=x,x,x0) numerically solves the equation with initial x0 and iteration n, using Newston's method. By default n=5, you can increase the n value if you want more close to exact solution. It only gives one root near x0 if equation has multi roots.

 

NSolve(Cos(x)=x, x) numerically solves equation with default initial x0=1 and n=5.

NSolve(Cos(x)=x, x,x0) numerically solves the equation with initial x0 and n=5.

See also: solve, dsolve.

eg. NSolve(Sin(x)=0, x,3) gives 3.14.

 

* Null internal

Null is a symbol used to indicate the absence of an expression or a result. When it appears as an output expression, no output is printed.

 

* N internal

N(x) gives the numeric value of x. It converts all numbers to the real number.

See also: numeric.

eg. N(Pi) gives 3.1416.

 

* Or internal

The logic operator. The result is True or False.

See also: And.

 

* ParametricPlot

plot the parametric functions of x=x(t) and y=y(t) by

ParametricPlot(x(t),y(t),t)

ParametricPlot(x(t),y(t),t,tmin,tmax)

ParametricPlot(x(t),y(t),t,tmin,tmax,ymin,ymax)

See also: Plot,PolarPlot.

eg. ParametricPlot(Sin(t),Sin(2*t),t)

 

* Pi

Pi=3.1416..., as the built-in constant, Pi is converted to 3.1416... when the switch numeric:=on.

See also: E.

 

* Plot

Plot(y,x) plots a function y=f(x) in xy plane with the default values x from -5 to 5, and y from -5 to 5.

Plot(y,x,xmin,xmax)

Plot(y,x,xmin,xmax,ymin,ymax)

See also: PolarPlot.

eg. Plot(x^3,x)

 

* PolarPlot

PolarPlot(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.

PolarPlot(r,t,tmin,tmax)

PolarPlot(r,t,tmin,tmax,rmin,rmax)

See also: Plot.

eg. graph, PolarPlot(1,t)

 

* Product

Product(f,x,xmin,xmax) with the default step dx = 1.

Product(f,x,xmin,xmax,dx) evaluates the product of f when x runs from

xmin to xmax with step dx.

See also: Sum.

 

* PSolve

PSolve(f(x), x) solves polynomial f(x)=0 for x. The order of polynomial < 3.

See also: Solve, NSolve.

eg. PSolve(x^2+5*x+6, x) gives [-2,-3].

 

* Re internal

Re(x) gives the real part of the complex number x.

See also: Im, Abs, Sign.

eg. Re(1+2*I) gives 1.

 

* Sec

Sec(x) is the secant function of x. The angle x is measured in radians (multiply by degree to convert from degrees). Sec(x)=1/Cos(x).

 

* Sech

Sech(x) is the hyperbolic secant function of x. sech(x)=1/cosh(x).

 

* Taylor

Taylor(y, x) gives series expansion of y at x=0 to order of 5.

Taylor(y, x, order) gives series expansion of y at x=0 to order.

See also: Sum.

eg. Taylor(Sin(x),x) gives x - 1/6*x^3 + 1/120*x^5.

 

* Si

Si(x) is the sin integral, Si(x) = Int(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) := True.

eg. Sign(2) gives 1, Sign(1+I) gives 1.

See also: Abs, Arg, Re, Im.

 

* Sin

Sin(x) is the sine function of x. The angle x is measured in radians. (multiply by degree to convert from degrees).

 

* Sinh

Sinh(x) is the hyperbolic sine function of x. Sinh(x) = (Exp(x)-Exp(-x))/2.

 

* Solve internal

Solve(x^2=0, x) solves a polynomial ordered up to 4.

See also: NSolve.

eg. Solve(x^2+5*x+6=0, x).

 

* 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, ^.

eg. Sqrt(4) gives 2, N(Sqrt(2*I)) gives 1+I.

 

* Replace internal

Replace(y, x,x0) replace x in y with x0.

eg. Replace(x^6, x,x0) gives x0^6.

 

* Sum

Sum(f,x,xmin,xmax)

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)

It evaluates the sum of f when x runs from xmin to xmax with step dx.

 

See also: Product.

eg. Sum(2^n,n,1,5,1.1), Sum(x^n,n,1,5).

 

* Tan

Tan(x) is the tangent function of x. The angle x is measured in radians (multiply by degree to convert from degrees).

 

* Tanh

Tanh(x) is the hyperbolic tangent function of x.

 

* True

Logical value.

 

* Type internal

Type(x) gives the type of x. Its value is a string. Note that the output of strings in DrMath is without two quotation marks.

eg.

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

x Type(x)

 

1 Integer

1.1 Real

2/3 Rational

1+I Complex

f(x) f()

a symbol

a+b +

a*b *

a^b ^

a=b =

a==b ==

a>b >

a>=b >=

a<b <

a<=b <=

a<>b <>

a,b ,

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

 

You also can test x, eg. 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, Infinity/Infinity, 0*Infinity, 0^0. You should try again by lim(y, x=x0).

 

* While internal

While(True, body) repeats body while test is true.

See also: For.

eg.

In: x:=1, While(x<5, x:=x+1);

Out: x := 6

 

+ add or positive sign. eg. a+b.

- subtract or negative sign. eg. a-b, -1.

* multiply. eg. a*b.

/ divide. eg. a/b.

^ power in BASIC, the same as ** in FORTRAN, eg. 2^3 gives 8.

! factorial, eg. 100!

 

< less than.

<= less than or equal to.

> greater than.

>= greater than or equal to.

 

<> unequal

== equal

a==b gives True if a is equal to b, False if a is not equal to b, or left unevaluated otherwise. It can test two complex numbers or expressions. It gives True if a and b are the same expression or left unevaluated otherwise.

eg. 2==2 gives True, a==a gives True.

 

= equation sign

eg. x^6+1 = 0

 

:= assignment.

 

, comma

; the end of statement

# comment statement

// comment statement

()

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

 

23. References

 

1. SymbMath document symbmath.doc or symbmath.doc.html.