Yacas function reference

Arithmetic

x+y (precedence 6)

Addition.

+x

Unary plus.

x-y (precedence 5)

Subtraction.

-x

Unary minus.

x*y (precedence 3)

Multiplication.

x/y (precedence 3)

Division.

x^y (precedence 2)

Raising "x" to the power of "y".

Div(x,y)

Div(x,y) : integer division.

Mod(x,y)

Mod(x,y) : integer remainder after division.

number<<bits

number<<bits : Shift "number" "bits" to the left. Example: "1<<10;" should evaluate to "1024".

number>>bits

number>>bits : Shift "number" "bits" to the right. Example: "1024>>10;" should evaluate to "1".

FromBase(base,number)

FromBase(base,number) : Conversion of numbers to base 10 numbers. Example: "ToBase(2,255);" should return "11111111".

ToBase(base,number)

ToBase(base,number) : Conversion of numbers from base 10 numbers. Example: "ToBase(16,255);" should return "ff".

Precision(n)

Precision(n) : Specifies that calculations should be performed with a precision of "n" digits.

GetPrecision()

GetPrecision() : return the current precision used for calculations.

Rationalize(x)

Rationalize(x) : Convert all floating point numbers to rationals in expression x.

IsPrime(n)

IsPrime(n) : returns True if n is prime, False otherwise.

IsPrimePower(n)

IsPrimePower(n) : returns True if there is a prime p such that p^m = n.

Factors(n)

Factors(n) : factorizes n. Returns a list containing the factors.

Calculus

Sin(x)

Sin(x) : Calculate sinus of x.

Cos(x)

Cos(x) : Calculate cosinus of x.

Tan(x)

Tan(x) : Calculate tangent of x.

ArcSin(x)

ArcSin(x) : Calculate arc-sinus of x.

ArcCos(x)

ArcCos(x) : Calculate arc-cosinus of x.

ArcTan(x)

ArcTan(x) : Calculate acr-tangent of x.

Exp(x)

Exp(x) : Calculate e^x.

Ln(x)

Ln(x) : Calculate natural logarithm of x.

Sqrt(x)

Sqrt(x) : calculate the square root of x.

Complex(x,y)

This represents a complex number x+I*y.

Re(z)

Return real part of complex number z.

Im(z)

Return imaginary part of complex number z.

I

This is the pure imaginary number I (for which i*I=-1). You can type 2+I*3, which would evaluate to Complex(2,3). Re and Im return the real and imaginary parts of a number respectively.

n!

Factorial. n! evaluates to n*(n-1)*(n-2)*....*1.

Bin(n,m)

Bin(n,m) evaluates to n!/(n!*(n-m)!)

Sum(var,from,to,body)

Sum(var,from,to,body) : Sum does a summation over "body", setting variable "var" from "from" upto and including "to", incrementing it by 1 each time.

Sum({list})

Sum({list}) : calculate the sum of the elements in a list. Example : Sum({1,2,3}) evaluates to 6.

Average({list})

Average({list}) : calculate the average of the elements in a list. Example : Average({1,2,3}) evaluates to 2.

Factorize(var,from,to,body)

Factorize(var,from,to,body) : Factorize does a factorization over "body", setting variable "var" from "from" upto and including "to", incrementing it by 1 each time.

IsZero(x)

IsZero(x) : Returns wether x is zero or not.

IsRational(r)

IsRational(r) : Rational numbers are anything like a/b, or 2/5.

Numer(r)

Numer(r) : Return numerator of a rational number.

Denom(r)

Denom(r) : Return denominator of a rational number.

N(r)

N(r) : Rational numbers and other analytic functions (Sin, Cos, etc.) are not evaluated into floating point numbers, as it is usually the exact answer the user is after. By using N these functions will be evaluated into floating point numbers.

Commutator(a,b)

Commutator(a,b) : Return "a b - b a". For numbers and such this is zero, for matrices in general it isn't.

Taylor(var,var0,order)function

Taylor(var,var0,order)function : Return the Taylor series expansion of function "function", with respect to variable "var", around "var=var0", upto order "order".

InverseTaylor(var,degree) func

InverseTaylor(var,degree) func : build a taylor series expansion of the inverse of function func, with respect to variable var, upto degree.

Newton(function,variable,initial,accuracy)

Newton(function,variable,initial,accuracy) : Find a zero of "function", as a function of "variable", starting around value "initial", and continuing until the value for "variable" is maximally "accuracy" away from the correct value.

D(variable) expression

D(variable) expression : Calculate analytic derivative of an expression. "D(x) Sin(x);" "Cos(x);". The D operator is also threaded: "D({x,y,z}) Sin(x*y)" will return {Cos(x*y)*y,Cos(x*y)*x,0}

Diverge(vector, basis)

Diverge(vector, basis) : Calculate the divergence of a vector. Example: "Diverge(FillList(x*y,3),{x,y,z})" will return {y,x,0}

Curl(vector, basis)

Curl(vector, basis) : Calculate the curl of a vector. Example: "Curl(FillList(x*y,3),{x,y,z})" will return {x,-y,y-x}

Integrate(var,from,to) body

Integrate(var,from,to) body : integrate body over variable var=from to var=to. Currently, only polynomials can be integrated.

Simplify(expr)

Simplify(expr) : Simplify tries to simplify an expression as much as possible.

Rationalize(expr)

Rationalize(expr) : convert every real number in expr into a rational number.

Conjugate(expr)

Conjugate(expr) : return the conjugate of expr (given that all variables are real or integer).

Solve(expr1=expr2,variable)

Solve(expr1=expr2,variable) : A very simple solver. It can for now solve expressions where the variable to be solved for only occurs once. "Solve(a+x*y=z,x);" would evaluate to "(z-a)/y".

PSolve(expr,var)

PSolve(expr) : solve expr=0 with respect to variable var, treating it expr as a polynomial. It currently solves upto degree 2.

Pi()

Pi() : Returns pi to the current precision.

Fibonacci(n)

Fibonacci(n) : Calculate Fibonacci number "n".

Random()

Random() : Returns a random number between 0 and 1.

VarList(expression)

VarList(expression) : Returns a list with all the variables "expression" depends on. Example: "VarList(Sin(x));" should return "{x};".

Limit(variable,value) function

Limit(variable,value)function : determine the value "function" converges to when "variable" goes to "value" from positive infinity. Examples : "Limit(x,0) Sin(x)/x;" evaluates to "1", and "Limit(x,0) (Sin(x)-Tan(x))/(x^3);" evaluates to "-1/2".

TrigSimpCombine(expression)

TrigSimpCombine(expression) : This is the module that does the trigonometric simplification: Cos(...)*Sin(...) -> Cos(...)+Sin(...)

It also tries to simplify the resulting expression as much as possible, trying to combine all like terms.

Linear Algebra

LeviCivita({list})

LeviCivita({list}) : "LeviCivita" implements the Levi Civita symbol. This is generally useful for tensor calculus. {list} should be a list of integers, and this function returns 1 if the integers are in successive order, eg. {1,2,3,...} would return 1. Swapping two elements of this list would return -1. So, LeviCivita( {2,1,3} ) would evaluate to -1.

Permutations({list})

Permutations({list}) : Permutations returns a list with all the premutations of the original list.

InProduct(a,b)

InProduct(a,b) (or alternatively a . b) : Calculate the inproduct of two vectors.

CrossProduct(a,b)

CrossProduct(a,b) (or alternatively a X b) : Calculate the crossproduct of two three-dimensional vectors.

ZeroVector(n)

ZeroVector(n) : ZeroVector returns a list with n zeroes.

BaseVector(row,n)

BaseVector(row,n) : BaseVector returns a vector with item row set to 1, the other n-1 set to zero.

Identity(n)

Identity(n) : Identity returns a identity matrix of dimension n x n.

IsVector(x)

IsVector(x) : Predicate checking if the object x is a vector. Note: matrices are also considered vectors, so if x is a matrix, then IsVector(x) will return True.

IsMatrix(x)

IsMatrix(x) : Predicates checking if the object x is a matrix.

Normalize(v)

Normalize(v) : Return the normalized vector v.

ZeroMatrix(n,m)

ZeroMatrix(n,m) : Returns a matrix with n rows and m columns, all zeros.

Transpose(M)

Transpose(M) : Return the transpose of a matrix M.

Determinant(M)

Determinant(M) : Return the determinant of a matrix M.

DiagonalMatrix(v)

DiagonalMatrix(v) : Return a square matrix with the elements of vector v on the diagonal of the matrix. All other elements are zero.

Trace(M)

Trace(M) : Return the trace of a matrix M (defined as the sum of the elements on the diagonal of the matrix).

Inverse(M)

Inverse(M) : Return the inverse of matrix M. The determinant of M should be non-zero.

CoFactor(M,i,j)

CoFactor(M,i,j) : This function returns the cofactor of a matrix around the element (i,j). The cofactor is the minor times (-1)^(i+j)

Minor(M,i,j)

Minor(M,i,j) : This function returns the minor of a matrix around the element (i,j). The minor is the determinant of the matrix excluding the ith row and jth column.

SolveMatrix(M,v)

SolveMatrix(M,v) : This function returns the vector x that satisfies the equation "M x = v". The determinant of M should be non-zero.

CharacteristicEquation(matrix,var)

CharacteristicEquation(matrix,var) : calculate characteristic equation of "matrix", using "var". The zeros os this equation are the eigenvalues of the matrix, Det(matrix-I var);

Polynomials

Expand(expr)

Expand(expr) : expands a univariate. Example: Expand((1+x)^2) would evaluate to 1+2*x+x^2. If the expression depends on more than one variable, you can specify which variable to expand to using Expand(expr,var); Also, you can expand to multiple variables, by specifying the order in which to expand, in a list, using Expand(expr,{varlist}).

Degree(expr)

Degree(expr) : return the degree of a polynomial. Example: Degree((1+x)^2); evaluates to 2.

Coef(expr,var,order)

Coef(expr,var,order) : return the coefficient of order for expression expr treated as a univariate with respect to the variable var.

PSolve(expr,var)

PSolve(expr,var) : solve expr=0, treating expr as a polynomial in the variable var. The result returned is the value var should take for expr=0 to be true. This has been implemented for polynomials upto degree 2.

Gcd(n,m)

Gcd(n,m) : Greatest common divisors are also defined for polynomials.

Div(n,m)

Div(n,m) : div is also defined for polynomials.

Mod(n,m)

Mod(n,m) : mod is also defined for polynomials.

List operations

Head({list})

Head({list}) : Returns the first element of the list "{list}". Example: "Head({a,b,c});" should return "a;".

Nth({list},index)

Nth({list},index) : Returns the element in the list "{list}" at position "index", where the first element is 1.

Tail({list})

Tail({list}) : Returns the list "{list}" without the first element.

DestructiveReverse({list})

DestructiveReverse({list}) : Returns the list {list} in reverse order. The list is reversed in place, so the original is changed into nonsense. Use FlatCopy to avoid this.

Length({list})

Length({list}) : Returns the length of the list {list}.

List(...)

List(...) : Returns a list with ... as its elements, after they were evaluated. This is the same as entering "{...};".

UnList({list})

UnList({list}) : Changes the list {list} into an expression specified in the elements of the list. This means the first element is treated as the command, and the elements following are the arguments to that command. "{list}" is evaluated before the operation is performed. Example: "UnList({Cos,x});" would evaluate to "Cos(x);".

Listify(expression)

Listify(expression) : Inverse of UnList: it converts the expression "expression" into a list. Eg. "Listify(a(b));" evaluates to "{a,b};".

Concat(...)

Concat(...) : concatenates the lists in ... after evaluation. Eg. "Concat({a,b},{c,d});" returns "{a,b,c,d};".

Delete({list},index)

Delete({list},index) : Deletes an element at position "index" from the list "{list}", and returns that list. "{list}" and "index" are evaluated first. The first index in list is 1.

Insert({list},index,element)

Evaluates arguments, and inserts "element" in "{list}" at position "index", where position 1 means insert at the front of the existing list. The result is returned, and the original list is left unchanged.

DestructiveInsert({list},index,element)

DestructiveInsert({list},index,element) : The Destructive... versions actually perform the operations on the original lists. So, if a variable is bound to a list, the list the variable points to is actually modified. This is more efficient memory-wise and in execution if the same variable is going to be set to the result.

DestructiveDelete({list},index)

DestructiveDelete({list},index) : The Destructive... versions actually perform the operations on the original lists. So, if a variable is bound to a list, the list the variable points to is actually modified. This is more efficient memory-wise and in execution if the same variable is going to be set to the result.

Replace({list},index,element)

This replaces an element, much like calling Delete and Insert in sequence.

DestructiveReplace({list},index,element)

This replaces an element, much like calling DestructiveDelete and DestructiveInsert in sequence.

FlatCopy({list})

FlatCopy({list}) : Copying of the contents of a list. It is not recursed into, only the first level is copied. This is useful in combination with the destructive commands that actually modify lists in place (for efficiency).

Contains({list},element)

Contains({list},element) : Returns whether "{list}" contains element "element".

Find(list,item)

Find(list,item) : returns the index of item in the list. Example: Find({a,b,c,d},c) returns 3.

Append({list},element)

Append({list},element) : Append an element {{I:element}} to list {{I:{list} }}.

DestructiveAppend({list},element)

DestructiveAppend({list},element) : Append an element {{I:element}} to list {{I:{list} }}.

RemoveDuplicates({list})

RemoveDuplicates({list}) : Returns a list with exactly one occurrence of each element that is also in "{list}".

Push(stack,element)

These implement a stack (represented as a list). "Push" adds an element in front of the list. "Pop" then removes and returns any element you need from the list. "PopFront" and "PopBack" pop the first and last element of the stack respectively.

Pop(stack,index)

These implement a stack (represented as a list). "Push" adds an element in front of the list. "Pop" then removes and returns any element you need from the list. "PopFront" and "PopBack" pop the first and last element of the stack respectively.

PopFront(stack)

These implement a stack (represented as a list). "Push" adds an element in front of the list. "Pop" then removes and returns any element you need from the list. "PopFront" and "PopBack" pop the first and last element of the stack respectively.

PopBack(stack)

These implement a stack (represented as a list). "Push" adds an element in front of the list. "Pop" then removes and returns any element you need from the list. "PopFront" and "PopBack" pop the first and last element of the stack respectively.

Swap({list},i1,i2)

Swap({list},i1,i2) : Swap elements with indices "i1" and "i2" in the list "{list}".

Count({list},element)

Count({list},element) : Returns number of occurrences of "element" in "{list}".

Intersection({list1},{list2})

Intersection({list1},{list2}) : returns the intersection of two lists. Example : "Intersection({a,b},{b,c});" would evaluate to "{b};".

Union({list1},{list2})

Union({list1},{list2}) : returns the union of two lists. Example : "Union({a,b},{b,c});" would evaluate to "{a,b,b};".

Difference({list1},{list2})

Difference({list1},{list2}) : returns the difference of two lists.

FillList(aItem, aLength)

FillList(aItem, aLength) : create a list with length aLength, filling it with aItem. Example: "FillList(0,5)" returns {0,0,0,0,0}

Drop(list,which)

Drop( list, n ) gives 'list' with its first n elements dropped
Drop( list, -n ) gives 'list' with its last n elements dropped
Drop( list, {m,n} ) gives 'list' with elements m through n dropped

Take(list,which)

Take( list, n ) gives the first n elements of 'list'
Take( list, -n ) gives the last n elements of 'list'
Take( list, {m,n} ) elements m through n of 'list'

Partition( list, n )

Partition( list, n ) partitions 'list' into non-overlapping sublists of length n

Assoc(key,assoclist)

Treat assoclist as a traditional assoc list well known from Lisp, and return the element stored with key. This functionality is probably best accessed through the [[ ]] operator.

AssocIndices(list)

Return the list of keys in the associated list assoclist.

Functional operators

item:list

prepends an item to a list, or a string. Examples: a:b:c:{} -> {a,b,c}
"hello":" ":"world" -> "hello world"

"oper" @ arg

Applies an operator to arguments. Examples: "Sin" @ a -> Sin(a) "Sin" @ {a,b} -> Sin(a,b)

oper /@ arglist

Applies an operator to arguments in a list, in a threaded manner. Example: "Sin" /@ {a,b} -> {Sin(a),Sin(b)}

n .. m

returns a list of numbers from n upto m. Example: 1 .. 4 -> {1,2,3,4}

Predicates

x < y (prec. 9)

x < y : Return True if "x" is smaller than "y", False otherwise.

x > y (prec. 9)

x > y : Return True if "x" is larger than "y", False otherwise.

x <= y (prec. 9)

x <= y : Return True if "x" is smaller than or equals "y", False otherwise.

x >= y (prec. 9)

x >= y : Return True if "x" is larger than or equals "y", False otherwise.

x!=y (prec. 9)

x!=y : Return True if "x" is not equal to "y", False otherwise.

x=y (prec. 9)

x=y : This operator performs the same action as Equals(x,y). It returns True if x and y would be displayed on screen the same, False otherwise.

Not(x)

Not(x) : Same as MatNot. Just nicer notation. Returns "True" if "x" is "False", "False" of x is "True".

x And y (prec. 100)

x And y : Infix version of boolean and.

x Or y (prec. 101)

x Or y : Infix version of boolean or.

IsFreeOf(expression,variable)

Returns wether "expression" depends on "variable". "expression" is evaluated beforehand. Example: "IsFreeOf(x+y,x);" evaluates to "False".

IsZeroVector(vector)

Returns wether "vector" only contains zeroes. "vector" should be a list.

IsNonObject(x)

IsNonObject(x) : returns true if x is not of the form Object(...).

Constants

%

% evaluates to the previous result on the command line.

True

True : boolean true.

False

False : boolean false

EndOfFile

EndOfFile : End of file marker when reading from file.

Variables

x:=y

x:=y : Assignment. The ":=" operator can be used for three different types of assignment: Assigning a variable: as in "x:=2;", Defining a new function: as in "f(x):=Sin(2*x);", or Assigning a list item a value: as in "list[[i]] := 2;"

Set(variable, value)

Set(variable, value) : Sets variable to evaluated value and returns "True".

Clear(...)

Clear(...) : Makes sure variables specified in "..." are not bound any more to a value, and returns True.

Local(...)

Local(...) : Mark the variables in the unevaluated argument list as local variables (local within a Prog block or a function).

x++

x++ : increment the variable "x".

x--

x-- : decrement the variable "x".

Object("predicate",object)

Object("predicate",object) : declaration of an incomplete object. This function returns "object" as soon as "predicate" returns "True" on it. Example: "Object("IsNumber",x);" returns itself, where if x was an integer, it would return that integer.

Input/Output

FullForm(expression)

FullForm(expression) : Displays evaluated form of "expression", and returns it.

Write(...)

Write(...) : Write out the expressions contained in "..." (evaluated).

WriteString(string)

WriteString(string) : Writes out a literal string, which should be of the form "string" (surrounded by quotes). The argument is evaluated.

Space(nr)

Space(nr) : Print out "nr" spaces. The "nr" argument is optional, the default value being 1.

NewLine(nr)

NewLine(nr) : Print out "nr" newlines. The "nr" argument is optional, the default value being 1.

DefaultDirectory("path")

DefaultDirectory("path") : When loading files, yacas is also allowed to look in the folder "path". path will be prepended to the file name before trying to load the file. Yacas first tries to load a file from the current directory, and otherwise it tries to load from directories defined with this function, in the order they are defined. Note there will be at least one directory specified at start-up time, defined during compilation. This is the directory Yacas searches for the initialization scripts and standard scripts.

FromFile("file") body

FromFile("file") body : Open "file" for reading, and execute body, returning its result.

FromString("string") body

FromString("string") body : use "string" to parse from when issuing a read from file, and execute body, returning its result.

ToString() body

ToString redirects all output (from Write or WriteString, for instance) to a string, and returns this string.

Read()

Read() : Read expression from current input, and return result. When the end of an input file is encountered, the token atom "EndOfFile" is returned.

LispRead()

Read() : Read expression from current input, and return result. When the end of an input file is encountered, the token atom "EndOfFile" is returned.

This function is different from Read() in that it parses an expression in lisp syntax: so you need to type (+ a b) in stead of a+b. The advantage of lisp syntax is that it is less unambiguous than the infix operator grammar Yacas uses by default.

ReadToken()

ReadToken() : Read token from current input, and return result. When the end of an input file is encountered, the token atom "EndOfFile" is returned.

ToFile("file")

ToFile("file") : Open "file" for writing, and execute body, returning its result.

Load("filename")

Load("filename") : Reads in and evaluates expressions from the file with file name filename. See also "Use".

Use("filename")

Use("filename") : Reads in and evaluates expressions from the file with file name filename if it hasn't been loaded before. This function makes sure the file will at least have been loaded, but not loaded twice. See also "Load".

DefLoad("filename")

DefLoad("filename") : Loads a file filename.def, which should have a list of functions, terminated by a }. This tells the system to load the file "filename" as soon as the user calls one of the functions named in the file (if not done so already). This allows for faster startup times, since not all of the rules databases need to be loaded, just the descriptions on which files to load for which functions.

FindFile(name)

FindFile returns the file that would be opened when a Load(name) would be invoked. It returns the full path to the file.

Programming

Hold(expression)

Hold(expression) : returns expression unevaluated.

Eval(expression)

Eval(expression) : Re-evaluates expression.

Atom("atom")

Atom("atom") : Returns an atom with the string representation given as the evaluated argument. Example: "Atom("foo");" returns "foo".

String(atom)

String(atom) : Inverse of Atom: turns atom into "atom".

ConcatStrings(strings)

ConcatStrings(strings) : Concatenate strings. Example: "ConcatStrings("a","b","c");" will return "abc".

/* comment */

A comment block in a source file.

Prog(...)

Prog(...) : Evaluate the arguments in order, and return the result of the last evaluated expression. This is the same as the "[ ... ]" constuct, that is, "Prog(a,b);" is the same as typing "[a;b;];" and is very useful for writing out function bodies (the "[...]" construct is converted into "Prog(...)" during the parsing stage)

While(predicate) body

While(predicate) body : Keep on evaluating "body" while "predicate" evaluates to "True". "predicate" is tested before evaluating the body. While returns "True".

If(predicate,then,else)

If(predicate,then,else) : If statement. If "predicate" evaluates to "True", return result of evaluating the "then" body, else if there is a "else" body, return that result, otherwise return "False".

Check(predicate,"error")

Check(predicate,"error") : If "predicate" doesn't evaluate to "True", then current operation will be stopped, and execution will jump right back to the command line, showing "error". Use this to assure that some condition is met during evaluation of expressions (guarding against internal errors).

SystemCall(string)

SystemCall(string) : This will call a command in the surrounding shell Yacas was invoked from. SystemCall can be used to pass commands to other programs or the operating system.

PreFix("operator")

PreFix("operator") : Defines a new operator for the prefix parser to understand.

PostFix("oper")

PostFix("oper") : Defines a new operator for the postfix parser to understand.

Bodied("oper")

Bodied("oper") : Defines a new operator for the bodied parser to understand.

InFix("operator",precedence)

InFix("operator",precedence) : Defines a new operator for the infix parser to understand. "precedence" is evaluated.

IsInFix("str"), IsPreFix("str"), IsPostFix("str")

Returns wether str is an infix, prefix, or postfix operator. IsInFix("+") should return True. IsInFix("a") should return False.

OpPrecedence("str")

Returns the precedence of the infix operator str. OpPrecedence("+") should return 6.

RightAssociative("operator")

makes the operator right-associative. Example: RightAssociative("*") would make multiplication right-associative. Take care not to abuse this function, because the reverse, making an infix operator left-associative, is not implemented.

LeftPrecedence("oper",precedence), RightPrecedence("oper",precedence)

oper should be an infix operator. This function call tells the infix expression printer to bracket the left or right hand side of the expression if its precedence is larger than precedence. This functionality was required in order to display a-(b-c) correctly. a+b+c is the same as a+(b+c), but a-(b-c) is not the same as a-b-c.

RuleBase("operator",{params})

RuleBase("operator",{params}) : Define a new rules table entry for a function "operator", with {params} as the parameter list.

Rule("operator",arity,precedence,predicate) body

Rule("operator",arity,precedence,predicate) body : Define a rule for the function "operator" with "arity", "precedence", "predicate" and "body". "precedence" is checked from low to high. The arity for a rules database equals the number of arguments. Different rules data bases can be built for functions with the same name but with a different number of arguments. Rules with a low value will be tried before rules with a high value, so a rule with precedence 0 will be tried before a rule with precedence 1.

HoldArg("operator",parameter)

HoldArg("operator",parameter) : Specify that parameter (which should be part of a parameter list for a function "operator") should not be evaluated before used. This will be declared for all arities of "operator", at the moment this function is called, so it is best called after all RuleBase calls for this operator.

TryRetract("operator",arity)

TryRetract("operator",arity) : Remove a rulebase with some specific arity, if it exists at all.

UnFence("operator",arity)

UnFence("operator",arity) : When applied to a user function, the bodies defined for the rules for "operator" with given arity can see the local variables from the calling function. This is useful for defining macro-like procedures (looping and the such). The For and ForEach functions defined in the standard packages use this, for instance.

MacroSet, MacroClear,MacroLocal, MacroRuleBase,MacroRule

Same as their non-macro counterparts, except that their arguments are evaluated before the required action is performed. This is useful in macro-like procedures.

Function("operator",{arguments} ) body

Function("operator",{arguments} ) body : Use this to declare a simple function, one that doesn't need an entire rules data base.

Uses("file")

Uses("file") : This function loads a file if it was not already loaded with Uses.

Type(expression)

Type(expression) : Returns a string representation of the type of "expression". "Type(Cos(x));" would evaluate to "Cos", for instance.

NrArgs(expression)

NrArgs(expression) : Returns number of arguments in top-level function of "expression". "NrArgs(Cos(x));" would evaluate to "1".

For(start,predicate,increment) body

For(start,predicate,increment) body : Looping in a C style. "start" gets called, and then "body" as long as "predicate" evaluates to True", evaluating "increment" each time after body was evaluated. Returns "True".

ForEach(item,{list}) body

ForEach(item,{list}) body : This function loops over each element in {list}, assigning it to the variable "item", and calling "body". Returns "True".

Apply("oper",{list})

Apply("oper",{list}) : This function applies a operator to the arguments mentioned in the list. Eg. "Apply("+",{2,3});" would evaluate to "5". You can also apply pure functions, declared using the form {varlist,body}. Example: "Apply( {{x,y},x+y} , {2,3} );" would also evaluate to 5.

BubbleSort({list},"compare")

BubbleSort({list},"compare") : Sort the list {list}, using "compare" as the operator to compare elements. "compare" gives the relation that should be true for neighbouring elements in the list after sorting.

Table(body,var,from,to,step)

Table(body,var,from,to,step) : Generate a list of values from "body", by assigning variable "var" values from "from" upto "to", incrementing "step" each time.

TableForm({list})

Tableform({list}) : TableForm writes out a list in a nicer readable form, eg. one line for each element in the list.

MapSingle("operator",{list})

MapSingle("operator",{list}) : MapSingle performs Apply on every item in {list}, returning a list of the results.

Map("operator",{lists})

Map("operator",{lists}) : {lists} should be a list of lists each the same size. Map performs Apply on every set of items in {lists}, returning a list of the results. Eg. Map("+",{{1,2},{2,3}}) would return {3,5}.

Secure(body)

Secure evaluates body in a safe environment, where file opening and system calls are not allowed. This can protect the system when an unsafe evaluation is done (Like a script sent over the internet to be evaluated on a computer).

Subst(from,to)body

Subst replaces any occurrence of from in body with to.
Example: Subst(x,Sin(y)) x+x -> Sin(y)+Sin(y)

TraceExp(expression)

TraceExp(expression) : turn on tracing facility, and evaluate expression. This is useful for tracing the evaluation of small routines interactively from the command line.

Tracerule(template)expression

Tracerule(template)expression : turn on tracing facility given the template, and evaluate expression. the template is an example of the function to trace on. template=x+y would trace all additions, showing the arguments passed in, and the result of the addition. Only user-defined functions can be traced.

This is useful for tracing a function that is called from within another function. This way you can see how your function behaves in the environment it is used in.

An example invocation of TraceRule is
In( 1 ) = TraceRule(x+y)2+3*5+4;

Which should then show something to the effect of
    ENTER:2+3*5+4

ENTER:2+3*5

ARG:2 <- 2

ARG:3*5 <- 15

LEAVE:2+3*5 -> 17

ARG:2+3*5 <- 17

ARG:4 <- 4

LEAVE:2+3*5+4 -> 21

Out( 0 ) = 21;

Built-in

MathNot(expression)

MathNot(expression) : Returns "False" if "expression" evaluates to "True", and vice versa.

MathAnd(...)

MathAnd(...) : Lazy and: returns True" if all args evaluate to "True", and does this by looking at first, and then at the second argument, until one is "False". If one is "False" it immediately returns "False" without evaluating the rest. This is faster, but also means that none of the arguments should cause side effects when they are evaluated.

MathOr(...)

MathOr(...) : MathOr is the or equivalent of And. It is lazy-evaluated too. "And(...)" and "Or(...)" do also exist. You can define them as infix operators yourself, so you have the choice of precedence. In the standard scripts they are in fact declared as infix operators, so you can write "expr1 And expr".

BitAnd(n,m), BitOr(n,m), BitXor(n,m)

BitAnd(n,m), BitOr(n,m), BitXor(n,m) : return bitwise and, or and xor of two numbers.

Equals(a,b)

Equals(a,b) : Compares evaluated a and b recursively (stepping into expressions). so "Equals(a,b)" returns "True" if the expressions would be printed exactly the same, and "False" otherwise.

LessThan(a,b), GreaterThan(a,b)

LessThan(a,b), GreaterThan(a,b) : Comparing numbers.

IsFunction(expr)

IsFunction(expr) : Predicate that checks the type of a object. cos(a) is a function.

IsAtom(expr)

IsAtom(expr) : Predicate that checks the type of a object. Atoms are any object that can be represented with a text string (that is, excluding lists).

IsString(expr)

IsString(expr) : Predicate that checks the type of a object. Strings have the form "string", that is, with quotes.

IsNumber(expr)

IsNumber(expr) : Predicate that checks the type of a object. 1.2 or 1 are numbers.

IsInteger(expr)

IsInteger(expr) : Predicate that checks the type of a object. 1 is a integer.

IsList(expr)

IsList(expr) : Predicate that checks the type of a object. {cos,a} is a list.

IsBound(var)

IsBound(var) :Predicate that checks the type of a object. IsBound checks to see if variable var is bound.

Math...

MathGcd(n,m) (Greatest Common Divisor), MathAdd(x,y), MathSubtract(x,y), MathMultiply(x,y), MathDivide(x,y), MathSqrt(x) (Square root), MathFloor(x), MathCeil(x), MathAbs(x), MathMod(x,y), MathExp(x), MathLog(x) (Natural logarithm), MathPower(x,y), MathSin(x), MathCos(x), MathTan(x), MathArcSin(x), MathArcCos(x), MathArcTan(x), MathDiv(x,y), MathMod(x,y) : MathSqrt(x) (Square root), Calculation of sin,cos,tan etc. of x. x HAS to be a number. The reason Math is prepended to the names is you might want to derive equivalent non-evaluating functions. The Math... versions require the arguments to be numbers.

Fast...

FastExp(x), FastLog(x) (Natural logarithm), FastPower(x,y), FastSin(x), FastCos(x), FastTan(x), FastArcSin(x), FastArcCos(x), FastArcTan(x) : Versions of these functions using the internal c version. These should then at least be faster than the arbitrary precision versions.

ShiftLeft(number,bits), ShiftRight(number,bits)

ShiftLeft(number,bits), ShiftRight(number,bits) : Shift number bits to left or right.

MaxEvalDepth(n)

Use this command to set the maximum evaluation depth. This will catch any infinite recursion. For example, f(x):=f(x); and then f(x) would keep on calling f(x), which would call f(x), which would call f(x)... etcetera. The interpreter will halt if the call is n deep. The default value is 100000.

Generic objects

Generic objects are objects that are implemented in c++, but can be accessed through the Yacas interpreter.

IsGeneric(object)

IsGeneric(object) : returns whether an object is a generic object type.

GenericTypeName(object)

GenericTypeName(object) : returns a string representation of the name of a generic object.
Example: GenericTypeName(ArrayCreate(10,1)) sould return "Array".

ArrayCreate(size,init)

Create an array the with size elements, all initialized to the value init.

ArraySize(array)

Return the size of an array (number of elements in the array).

ArrayGet(array,index)

Get the element at position index in the array passed. Arrays are treated as base-one, so index set to 1 would return the first element.
Arrays can also be accessed through the [[]] operators. So array[[index]] would return the same as ArrayGet(array,index).

ArraySet(array,index,element)

Set the element at position index in the array passed to the value passed in as argument to element. Arrays are treated as base-one, so index set to 1 would set first element.
Arrays can also be accessed through the [[]] operators. So array[[index]]:=element would do the same as ArraySet(array,index,element).

ArrayCreateFromList(list)

Creates an array from the contents of the list passed in.

ListFromArray(array)

Creates a list from the contents of the array passed in.