INTRODUCTION:
Numerical v.s. Symbolic
Computing

LT20, 4:00-6:00pm
Wed, 8 Jan 2003

A. Numerical Computation

With some exceptions, most programming languages are designed for numerical computing, e.g., Fortran, C, and matlab package. The most obvious limitations are (1) limited range of integers, (2) finite accuracy of floating-point numbers.

B. Symbolic Computing

Symbolic computing environment overcomes the two limitations (arbitrary sizes for integers, and a user-specified accuracy in floating point calculation).   Most importantly, symbolic packages provide the ability of manipulating formulas, e.g., differentiation or integration of a function.  The disadvantage of symbolic systems is that it is typically many times slower than a compiled program.

Symbolic Packages (Languages)

(1)  LISP:  low level but powerful programming language.
(2)  Maple, Mathematica:  two popular symbolic computing packages.
(3)  and many other special packages: reduce, axiom, etc.

How to run Mathematica

A. Text-Based Interfaces

Log into your UNIX system, type

math

You are engaged in a dialog with the system, one line at time, RETURN to enter an input.

How to run Mathematica
B. Notebook Interfaces (GUI)

Log into your Windows system (Start button, Programs, Mathematica),  or UNIX GUI, click or type

mathematica

You can access the help as well as the whole book "Mathematica: a system for doing Mathematics by Computer" by S. Wolfram inside the Mathematica.

IMPORTANT :  You execute an Mathematica Expression with 
		SHIFT - ENTER

Arbitrary Large Integers

Simple integer calculations

2 + 2

2^90

+, -, *, /, ^ 
for add,subtract,multiply, divide,and power,as usual.

Space can be used as multiplication sign, e.g.,

2 3

[This can cause unintended result as x*y is same as x y, but xy without a space between x and y is a single variable called xy.]

Integer functions (GCD[a,b], greatest common divisor, FactorInteger[a], etc):

GCD[10, 4]

FactorInteger[40]

This means 40 = (2^3) 5.

Function arguments are enclosed in square brakets [  ...  ].

Floating Point with Arbitrary Precision

Floating point numbers are entered with the decimal point:

2.3  +  1.2

3.14159265358979323850000 -  Pi

You can type as many digits as you like, they are all significant.  Pi or π is a symbolic representation of the exact value of π (not an approximate of it), i.e., the ratio of circumference to diameter of a circle.   Beside Pi, we also have E (such that Log[E] = 1), I = (Sqrt[-1]), and Infinity (∞), as symbolic math constants.  In summary:

Pi or π        3.14159 ... 
E                    2.71828 ... 
I                   (Sqrt[-1])  (imaginary unit)
Infinity  or  ∞

The function N[...] converts an exact number into floating point. (N[ ] does not increase the precision of a number, though).

N[Pi, 25]

Mathematica' s rules 

\(for\ numerical\ \(calculations : 
		\(\((1)\) : \ 
            If\ input\ is\ exact\)\), \ 
      the\ computation\ will\ be\ performed\ exactly . 
		\(\((2)\) : \ 
            If\ input\ is\ approximate\), \ the\ result\ is\ approximate, \ 
      with\ accuracy\ not\ great\ than\ the\ \(\(input\)\(.\)\)\)

Precision[ ] tells you the number of significant figures, the Accuracy[ ] tells you the number of digits after the decimal point.  SetPrecision[ ] raises precision to required number of significant figures.

Precision[1.34]

Accuracy[134.0]

x  =  SetPrecision[1.3,  28]

Precision[x]

y  =  x * 1.0;  Precision[y]

Why x has 28 digits of precision but y is only 16?   (This is because Mathematica works with two types of floating-point numbers, machine precision and arbitrary precision.  If input is given with less than machine precision, it will take as machine precision.)

Mathematica has a large collection of math functions such as the table below.  Note that all functions take arguments in the form of square brackets, and all built-in functions are Capitalized.

Sqrt[x]                 square root ((Sqrt[x]))
Exp[x] or E^x     exponential 
Log[x]                    natural log
Log[b, x]             logarithm to base b
Sin[x],Cos[x],Tan[x]    trig
n!                             factorial
Abs[x]                    absolute value   
Max[
      a, b,  .. ]
Mod[n, m]             n  modulo  m

See the mathematica quick reference sheet or Sec.3.2 for more.

Symbol Data Type

Like any programming languages, Mathematica provided with the usual data type of integer, floating point numbers and advanced structures.   In addition, Mathematica provides a type called "Symbol" for symbolic computation.  For example:

x  +  3  x

The function Head[...] tells you what data type a particular expression is.

Head[x]

Head[3]

Head[3  +  I ]

Head[2.0]

Some Examples of Symbolic Computation

Expand[ (1 + x)^2]

Factor[ 1  +  4 x  +  3  x^2]

Solve[ {y^2  +  x  - y  == 0,  
        y  -  x^2   + 2 ==  0},  {x, y}]

D[Sin[x], x]

D[x^2,  {x,  2}]

Integrate[ (1 + x)^3/(1 - x^2)^2,  x]

Simplify[Sin[x]^2  +  Cos[x]^2]

Graphical Computations

Mathematica supports graphics in a convenient way, as well as more advanced programming environment.  A simple plot :

Plot[ Sin[x],  {x,  -Pi,  Pi}]

Plot3D[ 
      Exp[-(x^2 + y^2)],  {x,  -2, 2},  {y,  -2,  
        2}]

g =  
      Graphics[ { Circle[{1, 2}, 0.5],  
          Line[ {{0, 0},  {1, 0},  {1, 1}}]}]

Show[g,  AspectRatio  ->  Automatic]

READINGS

Introduction to Mathematica:  section 1.1 to 1.6
Notebook interface section 1.3.4 to 1.3.9.
(Part of Chapter 1, A Practical Introduction to Mathematica).

The section number refers to the on-line 
as well as printed Mathematica book sections.