Arithmetic Arithmetic is allowed on vectors and scalars in SM, using the following operators, where expr is a expression and vector the name of a vector. Nonary (?): PI Pi Unary: -expr Change sign ABS(expr) Absolute value ACOS(expr) Arccosine ASIN(expr) Arcsine ATAN(expr) Arctangent COS(expr) Cosine CTYPE() Return CTYPEs DIMEN(vector) Dimension of a vector EXP(expr) Exponential GAMMA(expr,expr) Incomplete gamma fn INT(expr) Integral part LG(expr) Log_10 LN(expr) Log_e RANDOM(s_expr) Random numbers SIN(expr) Sine SQRT(expr) Square root STRING(expr) Convert to a string SUM(expr) Sum_i expr_i TAN(expr) Tangent VECTOR[expr] Elements of an array { list } Set vector to list < list > Set vector to list ( expr ) Raise precedence Binary: expr + expr Add expr - expr Subtract expr CONCAT expr Concatenate expr * expr Multiply expr / expr Divide expr ** expr Exponentiate expr & expr Bitwise AND expr | expr Bitwise OR expr % expr Modulus ATAN2(expr_y,expr_x) Atan2 There are also some special operators: HISTOGRAM(expr:expr) Construct histogram IMAGE(expr,expr) Extract cross section (exprs are coordinates) IMAGE[expr,expr] Extract cross section (exprs are indices) expr1 ? expr2 : expr3 expr2 if expr1 is true, else expr3 DO(s_expr, s_expr) Implicit DO loop DO(s_expr, s_expr, s_expr) Implicit DO loop with increment `ATAN2' is the same as C's function of the same name, and is equivalent to `ATAN(y/x)'. It gives a result in the range `-pi -- pi' dealing correctly with divisions by zero. CTYPE returns a vector of red + 256*green + 256*blue values; CTYPE(STRING) returns their names. GAMMA returns an incomplete Gamma function, so GAMMA(a,infty) = 1. RANDOM generates a vector of s_expr random numbers in the range [0,1]. If you don't specify a seed (using `SET RANDOM') one will be chosen for you based on the current time. DO(0,10,2) generates the vector "0 2 4 6 8 10", and may be used as part of an expression. The expression `VECTOR[expr]' results in a vector of the same dimension as the `expr', with elements taken from `VECTOR' (i.e. `VECTOR[INT(expr_i)]'). See, for example, the macro `interp'. You can also use `WORD([ expr [ , ... ]])' as part of an expression, where `WORD' is a macro taking zero or more arguments. The arguments are restricted to be either the names of vectors, strings, or numbers; sorry. The precedences are what you'd expect, with `**' being highest, then `*', `/' and `%', then `+' and `-', and then `CONCAT'. The logical operators and bitwise all have even lower precedence than `CONCAT'; ?: has the lowest priority of all. There is NO defined precedence for bitwise relative to logical operators --- you should always use parentheses. If you have defined an image file with the IMAGE command, `IMAGE(expr,expr)' is an expression to extract values from your image. The two expressions give the x and y values where the image is to be sampled. For example `SET x=0,1,.01 SET z=IMAGE(x,0.5)' will extract a horizontal cross section through an image. IMAGE[expr,expr] interprets the expressions as (0-based) indices into the image. As a special case, one or other of them may be '*' meaning, "all values". `HISTOGRAM(expr1:expr2)' constructs a histogram from a vector, where the data is in `expr1', and `expr2' (which must be sorted) gives the location of the bins. If the values of `expr2' are equally spaced, the `location' of the bin means the centre; if they are not, a bin is defined by saying that points with value (e2[i-1] + e2[i])/2 <= x < (e2[i] + e2[i+1])/2 go into the ith bin. Note that values on bin boundaries go into the higher bin. See `Logical' for the logical operators, `Strings' for string operators, and `whatis' for finding out if strings are numbers, words, vectors, or whatever.