** “msharpmath”, **The Simple is the Best

[100] 042 FAQ FAQ

//———————————————————————————————————————

// (Q) What is unique in m#math?

//———————————————————————————————————————

(A) Several unique innovations are implemented in m#math.

various data types (matrix, poly, vertex, csys, complex, double, signal)

- Umbrella grammar
- dot function
- tuple function
- all-in-one file handling

Among the above, the most impressive one would be the ‘** Umbrella**‘ which realizes ‘expression-look-alike’ treatment of equations. For example,

#> solve .x ( exp(x) = 5 ); // single nonlinear equation

#> solve .a.b ( a+b = 3, a*b = 2 ); // coupled nonlinear equations

#> plot .x( 0,pi ) ( |x|*sin(x) ); // plot 2d curve

#> int .x( 1,2 ) .y(x,2*x+1) ( exp(-x-y)*sin(x+y) ); // double integration

#> ode .t( 0,1 ) ( y’ = t*y+1, y = 1 ).plot; // ODE (Ordinary Differential Equation)

#> plot .r[21](0,1).t[61](0,6*pi) ( (r^(1/3)+t!/3).cyl .y ).cyl;

are almost similar to their relevant mathematical problems.

Another uniqueness could be the use of ** dot function**. Most of built-in functions start with a dot (.) and thus can be distinguished from user-defined variables.

#> I = .I(2,3) ; // ‘I’ for users’ name space, while ‘.I’ for name space of built-in functions

ans =

[ 1 0 0 ]

[ 0 1 0 ]

Also, it is possible to denote “expression-look-alike” functions such as the Bessel functions by dot functions

.J_nu(x) .I_nu+3/2(x) .K_nu+1/2 (x) .Y_nu+2/3(x)

The ‘** tuple**‘ is also useful to handle different types of data. For example,

#> (a,b,c) = ( 3 +2!, <1,2,3>, [1,2,3] );

a = 3 + 2!

b = < 1 2 3 >

c = [ 1 2 3 ]

As can be seen above, m#math employs a variety of data types including matrix, polynomial, double, complex, vertex, coordinate system, signal. Richness in data type however sacrifices the convenience in reference to data. For example, sqrt(-1) is NaN (not a number) in m#math, and thus sqrt(-1+0!) should be used instead.

From the standpoint of user-file management, no path is necessary to find a file. All functions can be included in one file and compiled for run.

//———————————————————————————————————————

// (Q) Between C-language and m#math?

//———————————————————————————————————————

(A) In conclusion, m#math can be regarded as a mini-C. Some keywords of C are implemented in m#math.

- if else do for while break continue goto
- switch case default return void double

m#math does not use a pointer except for array pointer. Although array pointer is used in m#math, no operation is allowed except subscript. As a mini-C, m#math does not have so many functions in C. Since the primary objective is ‘mathematics’, math-related functions are of importance in m#math.

Nevertheless, some points are helpful in use. For example,

#> double f(x)= |x|*sin(x); // in m#math

#> f++( [1,2,3] ); // function upgrade for matrix

#> f ‘ (3) ; f ” (3); // extention to differentiation

#> double area(a, b=a) = a*b; // dynamic default assignment

#> s=0; for[10] s += 10; // simple iteration, no index

are implemented for easy use.

//———————————————————————————————————————

// (Q) Between C++ and m#math ?

//———————————————————————————————————————

(A) Absolutely, m#math cannot be compared with C++ in power and efficiency. Remember that m#math is just an easy-to-use interpreter not a powerful compiler. The size of m#math is only a few MB !

However, the concept of objective-oriented is somehow realized in m#math by member function. For example,

#> A.inv ; A.row(i) ; // inverse and i-th row vector of a matrix A

#> z.x ; z.r ; // elements of complex number

are of major use in m#math. All the data types are of built-in nature, and no new class can be defined.

//———————————————————————————————————————

// (Q) Between MATLAB and m#math ?

//———————————————————————————————————————

(A) The structure of matrix and data type are of major difference. At present, please do not mention the level of capabilities yet. However, m#math utilizes a variety of data such as polynomial, vertex including matrix. Richness in data type helps users work in ‘expression-look-alike’ manner. For example, a polynomial can be evaluated, differentiated, sumed or differenced just by

#> p = .[1,0,0,0] ; // p(x) = x^3

#> p(2+3!); // p(z), z = 2+3!

#> p’ ; // p’(x) = 3x^2, differentiation

#> p~ ; // int p(x) dx = x^4/4, integration

#> p` ; // p(x)-p(x-1) = 3x^2 -3x +1, finite difference

#> p.~; // sum k^3 = (1/4)n^2(n+1)^2, series sum

all of which are treated by functions in matlab such as polyval(p,z).

In m#math, data type must be explicitly or implicitly defined and cannot be changed during run until cleared. In this regard, ‘double’ and ‘complex’ is different. This means that sqrt(-1) = NaN in m#math but sqrt(-1) = i in MATLAB. Since -1 is ‘double’, sqrt(-1) is treated as a ‘double’ data with no value. The correct usage in m#math is sqrt( -1 + 0! ) where ! is employed to denote a pure imaginary number rather than a factorial in mathematics.

Matrix dimension can be modified by some operations, but it cannot be changed by ‘subscript’ operation in m#math. Thus, when a variable A is not a priori defined,

#> A(10) = 3; // no pre-defined ‘A’ in m#math, while MATLAB creates a matrix A

Also, for a matrix A=[1,2], A = 0 becomes [0,0] in m#math but ’0′ in MATLAB.

The main cause of different treatment comes from the fact that m#math strives to be consistent with C-language. A unique advantage of using m#math is the approach of ‘expression-look-alike’ as can be seen in ‘Umbrella’ grammar.

From the aspect of function definition, *.math file of m#mathincludes multiple functions in one file. But *.m file of MATLAB defines one function for each file.

//———————————————————————————————————————

// (Q) Between MATHEMATICA and m#math ?

//———————————————————————————————————————

(A) m#math does not provide ‘symbolic operation’. Of course, grammars are very different between the two.

//———————————————————————————————————————

// (Q) Pitfalls in m#math?

//———————————————————————————————————————

(A) Most frequent errors in using m#math arise from confusion between ‘double’ and ‘complex’ data type. Since (-1) is ‘double’ data, sqrt(-1) tries to return ‘double’ data. In general, the function ’sqrt’ returns the same date type with the input. This means that

- sqrt(double)=double, sqrt(-1) = NaN // not a number
- sqrt(complex)=complex, sqrt(-1+0!) = 1! // complex number

Distinction between ‘double’ and ‘complex’ may seem redundant, but the main reason inherits from our desire to keep other valuable data type such as polynomial, vertex, csys (coordinate system). Otherwise, we have stick to matrix only, and treat all other data by matrices.

Similar to the above, subscript for a matrix can be misused.

- A(i,j) for real part
- A{i,j} for imaginary part
- A[i,j] for complex element (real is extended)

This could be the most annoying feature of m#math. By sacrificing this instead, we are successful in handling various data types including polynomials and vertices.

As for the Umbrella innovated in m#math, care should be taken for nesting of Umbrella. Nested Umbrella causes a serous error at present. For example,

#> double f(x) = int.t(0,x) ( t );

#> double g(x) = int.t(0,x) ( f(t) ); // f(x) includes Umbrella

leads to the most dangerous pitfall in m#math at this stage.