Yacas users function reference

+ , - , * , / , ^ ,

Arithmetic


Arithmetic operations

Standard math library
Calling Sequence:
x+y (precedence 6)
+x
x-y (precedence 5)
-x
x*y (precedence 3)
x/y (precedence 3)
x^y (precedence 2)
Parameters:
x and y - some objects for which arithmetic operations are defined.
Description:
These are the basic arithmetic operations. They can work on integers, rational numbers, complex numbers, vectors, matrices and lists.
These operators are implemented in the standard math library (as opposed to being built-in). This means that they can be extended by the user.
Examples:
In> 2+3
Out> 5;
In> 2*3
Out> 6;
See Also:


Div , Mod , Gcd , Lcm , << , >> , FromBase , ToBase , Precision , GetPrecision , Rationalize , IsPrime , IsPrimePower , Factors , PAdicExpand , ContFrac , Decimal , TruncRadian ,

Other operations on numbers


Div and Mod

Standard math library
Calling Sequence:
Div(x,y)
Mod(x,y)
Parameters:
x and y - integers
Description:
Div performs integer division and Mod returns the remainder after division. Div and Mod are also defined for polynomials.
Examples:
In> Div(5,3)
Out> 1;
In> Mod(5,3)
Out> 2;
See Also:


Gcd

Standard math library
Calling Sequence:
Gcd(n,m)
Gcd(list)
Parameters:
n,m - integers or univariate polynomials
list - a list of all integers or all univariate polynomials
Description:
Gcd(n,m) returns the greatest common divisor of n and m. The gcd is the largest number that divides n and m. The library code calls MathGcd, which is an internal function. This function implements the binary Euclidean algorithm for determining the greatest common divisor:
Routine for calculating Gcd(n,m)

1) if n = m then return n
2) if both n and m are even then return 2*Gcd(n/2,m/2)
3) if exactly one of n or m (say n) is even then return Gcd(n/2,m)
4) if both n and m are odd and, say, n>m then return Gcd( (n-m)/2,m)
This is a rather fast algorithm on computers that can efficiently shift integers.
Gcd(list), with list a list of arbitrary length of integers, will return the greatest common divisor of all the integers listed. For lists Gcd uses the identity
Gcd({a,b,c}) = Gcd(Gcd(a,b),c)
Examples:
In> Gcd(55,10)
Out> 5;
In> Gcd({60,24,120})
Out> 12;
See Also:
Lcm ,


Lcm

Standard math library
Calling Sequence:
Lcm(n,m)
Parameters:
n,m - integers
Description:
Lcm(n,m) : returns the least common multiple of a and b. The least common multiple L of two numbers n,m is the number L=Lcm(n,m) for which there are two integers p,q so such that p*n=q*m=L. This is calculated with the formula:
Lcm(n,m) = Div(n*m,Gcd(n,m))
This means it also works on polynomials, since Div, Gcd and multiplication are also defined for them.
Examples:
In> Lcm(60,24)
Out> 120;
See Also:
Gcd ,


<< and >>

Standard math library
Calling Sequence:
n<<m and n>>m
Parameters:
n,m - integers
Description:
These operators shift integers to the left or to the right. They are similar to the c shift operators. These are sign-extended shifts, so they act like multiplication or division by powers of 2.
Examples:
Examples:
1<<10; should evaluate to 1024
-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.


PAdicExpand(n,p)

PAdicExpand returns the p-adic expansion of n:

n = a0 +a1*p +a2*p^2+...

So for instance
In> PrettyForm(PAdicExpand(1234,10))

                   2     3
4 + 3 * 10 + 2 * 10  + 10 

Out> True;
This function should also work on polynomials.


ContFrac(x) or ContFrac(x,maxdepth)

Return the continued fraction expansion of a floating point number. Example:
In> PrettyForm(ContFrac(N(Pi)))

                 1             
3 + ---------------------------
                   1           
    7 + -----------------------
                     1         
        15 + ------------------
                       1       
             1 + --------------
                          1    
                 292 + --------
                       1 + rest


Decimal(frac)

Decimal(frac) : return the infinite decimal representation of a number. This function returns a list, with the first element being the number before the decimal point and the last element the sequence of digits that will repeat forever. All the intermediate list elements are the initial digits.

Example:
In> Decimal(1/22)
Out> {0,0,{4,5}};
In> N(1/22,30)
Out> 0.045454545454545454545454545454;


TruncRadian

Standard math library
Calling Sequence:
TruncRadian(r)
Parameters:
r - a radian
Description:
TruncRadian calculates r mod 2*Pi, returning a value between 0 and 2*Pi. This function is used in the trigonometry functions, just before doing the numerical calculation. It greatly speeds up the calculation if the value passed is a big number.

The library uses the formula

             /   r    \         
r - MathFloor| ------ | * 2 * Pi
             \ 2 * Pi /         


where r and 2*Pi are calculated with twice the precision used in the environment to make sure there is no rounding error in the significant digits.

Examples:
In> 2*Pi()
Out> 6.283185307;
In> TruncRadian(6.28)
Out> 6.28;
In> TruncRadian(6.29)
Out> 0.0068146929;
See Also:
Sin , Cos , Tan ,


Sin , Cos , Tan , ArcSin , ArcCos , ArcTan , Exp , Ln , Sqrt , Abs , Complex , Re , Im , I , ! , Bin , Sum , Average , Factorize , Min , Max , IsZero , IsRational , Numer , Denom , N , Commutator , Taylor , InverseTaylor , ReversePoly , Newton , D , Diverge , Curl , Integrate , Simplify , Rationalize , Conjugate , Solve , SuchThat , Eliminate , PSolve , Pi , Fibonacci , Random , VarList , Limit , TrigSimpCombine , LagrangeInterpolant ,

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.


Abs(x)

Abs(x) : calculate the absolute value 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) and Sum({list})

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}) : 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) and Factorize({list})

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.

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


Min(x,y), Min({...}), Max(x,y) and Max({...})

Min and Max return the minimum and maximum value of their arguments respectively. Min and max can either be called with two numbers as arguments, or with a list of numbers.


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) and N(r,digits)

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.

Use N(r,digits) to do the calculation using the specified number of digits after the decimal. For example N(Pi,50) would evaluate pi to 50 digits.


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,value,degree) func

InverseTaylor(var,value,degree) func : build a taylor series expansion of the inverse of function func, with respect to variable var around value, upto degree. InverseTaylor uses the function ReversePoly to perform the task.


ReversePoly(f,g,var,newvar,degree)

ReversePoly(f,g,var,newvar,degree) : Given polynomials f(var) and h(var), determine a polynomial h(newvar) for which h(f(var)) = g(var). The resulting polynomial will be of degree degree. The only requirement is that the first derivative of f should not be zero.

This function is used to determine the taylor series expansion of a function: if g(var)=var, then h(f(var))=var, so h will be the inverse of f.


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}

Alternatively, you can call D with "D(variable,n)expression". In that case the n-th derivative will be taken.


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

Solve can solve simple sets of equations. Pass the equations in a list, as well as the variables to be solved for. The solver will then use SuchThat, in combination with Eliminate, to simplify the equations. This suffices for all linear equations and a large group of simple non-linear equations.

When the variable argument receives a list of variables to solve for, Solve returns a list of results, with each result being a solution to the set of equations.


SuchThat(function,var)

SuchThat(function,var) : try to find a simple expression for variable var, given the equality function=0. This function basically only handles expressions where the variable var only occurs once. It does its work by applying the inverse of the top function, until the variable is reached.


Eliminate(var,replace,function)

Eliminate(var,replace,function) : replace all instances of var in function with relpace and call Simplify on the resulting expression.


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.


LagrangeInterpolant({xlist},{ylist},var)

LagrangeInterpolant({xlist},{ylist},var) : given a set of points (x_i,y_i) with all nonzero y_i, find the polynomial that goes through these points. The first argument passed to the function should be the list of x_i values, the second one should be the list of y_i values, and the third argument should be the variable used to build up the polynomial.

This routine uses the Lagrange interpolant formula to build up the polynomial. For three terms this is:
In> PrettyForm(LagrangeInterpolant(MakeVector(x,3),MakeVector(y,3),x))

y1 * ( x - x2 ) * ( x - x3 )   y2 * ( x - x1 ) * ( x - x3 ) 
---------------------------- + ---------------------------- 
 ( x1 - x2 ) * ( x1 - x3 )      ( x2 - x1 ) * ( x2 - x3 )   

  y3 * ( x - x1 ) * ( x - x2 )
+ ----------------------------
   ( x3 - x1 ) * ( x3 - x2 )  

Out> True;


LeviCivita , Permutations , InProduct , CrossProduct , ZeroVector , BaseVector , Identity , IsMatrix , Normalize , ZeroMatrix , Transpose , Determinant , DiagonalMatrix , Trace , Inverse , CoFactor , Minor , SolveMatrix , CharacteristicEquation , EigenValues , EigenVectors ,

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.


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


EigenValues

Standard math library
Calling Sequence:
EigenValues(matrix)
Parameters:
matrix - a square matrix
Description:
EigenValues returns the eigenvalues of a matrix. The eigenvalues x of a matrix M are the numbers such that M*v=x*v for some vector.
It first determines the characteristic equation, and then factorizes this equation, returning the roots of the characteristic equation det(matrix-x*identity).
Examples:
In> M:={{1,2},{2,1}}
Out> {{1,2},{2,1}};
In> EigenValues(M)
Out> {3,-1};
See Also:
EigenVectors , CharacteristicEquation ,


EigenVectors

Standard math library
Calling Sequence:
EigenVectors(matrix,eigenvalues) Standard math library
Parameters:
matrix - matrix - a square matrix
eigenvalues - list of eigenvalues as returned by EigenValues
Description:
EigenVectors returns a list of the eigenvectors of a matrix. It uses the eigenvalues and the matrix to set up n equations with n unknowns for each eigenvalue, and then calls Solve to determine the values of each vector.
Examples:
In> M:={{1,2},{2,1}}
Out> {{1,2},{2,1}};
In> e:=EigenValues(M)
Out> {3,-1};
In> EigenVectors(M,e)
Out> {{-ki2/ -1,ki2},{-ki2,ki2}};
See Also:
EigenValues , CharacteristicEquation ,


Expand , Degree , Coef , PSolve , Div , Mod , Content , PrimitivePart , RandomPoly , LeadingCoef , Monic , BigOh ,

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) or Degree(expression, variable)

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

The version accepting an additional variable as an argument can be used to get the degree of a multivariate polynomial with respect to that variable. Example: Degree(a+b*x^3,a);returns 1.


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.

The argument to parameter order can also be a list of integers, in which case this function returns a list of coefficients.


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.


Div(n,m)

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


Mod(n,m)

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


Content(poly)

Content(poly) : determine the content of a univariate polynomial. The content is the greatest common divisor of each term in the polynomial. The content of 2*x^2+4*x should be 2*x for instance.


PrimitivePart(poly)

PrimitivePart(poly) : determine the primitive part of a univariate polynomial. This is defined as PrimitivePart(poly)*Content(poly) = poly, and can easily be checked with Expand(PrimitivePart(poly)*Content(poly)) which should be equal to Expand(poly).


RandomPoly(var,deg,coefmin,coefmax)

RandomPoly(var,deg,coefmin,coefmax) : generate a random polynomial in variable var, of degree deg, with coefficients ranging from coefmin to coefmax (inclusive).


LeadingCoef(poly)

LeadingCoef(poly) : get the leading coefficient of the polynomial poly. If there are more variables in poly, you can specify which variable is the main one, by adding it as an argument:
In> LeadingCoef(a*x^2+2,x)
Out> a;


Monic(poly)

Monic(poly) : return the monic part of the polynomial poly. This is poly/LeadingCoef(poly). This function also accepts a second argument, specifying the variable of the univariate polynomial:
In> f:=a*x^2+b
Out> a*x^2+b;
In> PrettyForm(Monic(f,x))

b    2
- + x 
a     

Out> True;


BigOh(_uv,_var,_degree)

BigOh(poly,var,degree) : Given a polynomial poly in variable var, drop all terms of order degree or higher.


Head , Tail , Length , Nth , DestructiveReverse , List , UnList , Listify , Concat , Delete , Insert , DestructiveInsert , DestructiveDelete , Replace , DestructiveReplace , FlatCopy , Contains , Find , Append , DestructiveAppend , RemoveDuplicates , Push , Pop , PopFront , PopBack , Swap , Count , Intersection , Union , Difference , FillList , Drop , Take , Partition , Assoc , AssocIndices , Flatten , UnFlatten , Type , NrArgs , BubbleSort , Table , TableForm , MapSingle , Map , RandomIntegerVector , MakeVector , Select ,

List operations

Most objects that can be of variable size are represented as lists (linked lists internally). Yacas does implement arrays, which are faster when the number of elements in a collection of objects doesn't change. Operations on lists have better support in the current system.


Head

Internal function
Calling Sequence:
Head(list)
Parameters:
list - a list
Description:
Returns the first element of a list.
Examples:
In> Head({a,b,c})
Out> a;
See Also:
Tail , Length ,


Tail

Internal function
Calling Sequence:
Tail(list)
Parameters:
list - a list
Description:
Returns a list without its first element.
Examples:
In> Tail({a,b,c})
Out> {b,c};
See Also:
Head , Length ,


Length

Internal function
Calling Sequence:
Length(object)
Parameters:
object - a list, array or string
Description:
Length returns the length of a list. This function also works on strings and arrays.
Examples:
In> Length({a,b,c})
Out> 3;
In> Length("abcdef");
Out> 6;
See Also:
Head , Tail , Nth ,


Nth({list},index)

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


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.


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,c};".


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.


Flatten

Standard math library
Calling Sequence:
Flatten(expression,operator)
Parameters:
expression - an expression
operator - string with the contents of an infix operator.
Description:
Flatten flattens an expression with respect to a specific operator, converting the result into a list. This is useful for unnesting an expression. Flatten is typically used in simple simplification schemes.
Examples:
In> Flatten(a+b*c+d,"+");
Out> {a,b*c,d};
In> Flatten({a,{b,c},d},"List");
Out> {a,b,c,d};
See Also:
UnFlatten ,


UnFlatten

Standard math library
Calling Sequence:
UnFlatten(list,operator,identity)
Parameters:
list - list of objects the operator is to work on operator - infix operator identity - identity of the operator
Description:
UnFlatten is the inverse operation of Flatten. Given a list, it can be turned into an expression representing for instance the addition of these elements by calling UnFlatten with "+" as argument to operator, and 0 as argument to identity (0 is the identity for addition, since a+0=a). For multiplication the identity element would be 1.
Examples:
In> UnFlatten({a,b,c},"+",0)
Out> a+b+c;
In> UnFlatten({a,b,c},"*",1)
Out> a*b*c;
See Also:
Flatten ,


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


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("+",{{a,b},{c,d}}) would return {a+c,b+d}.


RandomIntegerVector(nr,from,to)

RandomIntegerVector(nr,from,to) : generate a vector of random integers p in the range [from,to] (including from and to).


MakeVector(var,n)

MakeVector(var,n) : return a vector of unique numbered variable names. Example:
In> MakeVector(a,3)
Out> {a1,a2,a3};


Select(predicate,list)

Select(predicate,list) : return a sublist of list, containing all elements for which the predicate returned after applying the predicate on that list element. Example:
In> Select("IsInteger",{a,b,2,c,3,d,4,e,f})
Out> {2,3,4};


: , @ , /@ , .. ,

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}


MaxEvalDepth , Hold , Eval , While , Until , If , SystemCall , Function , Use , For , ForEach , Apply , LocalSymbols , Subst , WithValue , TraceExp , TraceRule ,

Control flow functions


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.


Hold(expression)

Hold(expression) : returns expression unevaluated.


Eval(expression)

Eval(expression) : Re-evaluates expression.


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


Until(predicate) body

Until repeats a statement until a predicate becomes true. A difference with While is that the statement is evaluated at least once, as opposed to While where the body statement is evaluated zero or more times.


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


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.


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.


Use("file")

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


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.


LocalSymbols(...)body

Given the symbols passed as the first arguments to LocalSymbols a set of local symbols will be created, and creates unique ones for them, typically of the form $, where symbol was the symbol entered by the user, and number is a unique number. This scheme was used to such a generated symbol can not accientally be entered by a user. Example:
In> LocalSymbols(a,b)a+b
Out> $a6+ $b6;
This is useful in cases where a guaranteed free variable is needed, like in the macro-like functions (For, While, etc.).


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)


WithValue(variable,value,expression)

WithValue(variable,value,expression) : evaluate expression, with variable set to value. variable and value can be lists of variables and values.


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;


< , > , <= , >= , != , = , Not , And , Or , IsFreeOf , IsZeroVector , IsNonObject , IsEven , IsOdd , IsFunction , IsAtom , IsString , IsNumber , IsInteger , IsList , IsBound , IsBoolean , IsNegativeNumber , IsNegativeInteger , IsPositiveNumber , IsPositiveInteger , IsNotZero , IsNonZeroInteger , IsInfinity , IsConstant ,

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) or IsFreeOf(expression,{varlist})

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

When a list of variables is passed, IsFreeOf returns True iff the expression is independent of all the variables listed. "IsFreeOf(x+y,{a,b});" would return True, and "IsFreeOf(x+y,{a,x});" would return 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(...).


IsEven(n) and IsOdd(n)

Returns whether the integer n is even or odd (an integer n is even if n divided by 2 is also an integer).


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.


IsBoolean

Standard math library
Calling Sequence:
IsBoolean(expression)
Parameters:
expression - an expression
Description:
IsBoolean returns True if the argument is of a boolean type. This means it has to be either True, False, or an expression involving functions that return a boolean result, like =, >, <, >=, <=, !=, And, Not, Or.
Examples:
In> IsBoolean(a)
Out> False;
In> IsBoolean(True)
Out> True;
In> IsBoolean(a And b)
Out> True;

See Also:
True , False ,


Predicates on numbers

These predicates return whether the argument is a number, and of a specific type.


IsNegativeNumber(n)


IsNegativeInteger(n)


IsPositiveNumber(n)


IsPositiveInteger(n)


IsNotZero(n)


IsNonZeroInteger(n)


IsInfinity(n)

Returns True if the argument is either Infinity or -Infinity


IsConstant

Standard math library
Calling Sequence:
IsConstant(expression)
Parameters:
expression - some expression
Description:
IsConstant returns True if the expression is some constant or a function with constant arguments. It does this by checking that no variables are referenced in the expression.
Examples:
In> IsConstant(Cos(x))
Out> False;
In> IsConstant(Cos(2))
Out> True;
In> IsConstant(Cos(2+x))
Out> False;
See Also:
IsNumber , IsInteger ,


CanProve ,

Propositional logic theorem prover


CanProve(proposition)

Calling Sequence:
CanProve(proposition)
Parameters:
proposition - a logical proposition
Description:
Yacas has a small built-in propositional logic theorem prover. It can be invoked with a call to CanProve.
An example of a proposition is 'if a implies b and b implies c then a implies c'. Yacas supports the following operators

~ negation, read as 'not'
& conjunction, read as 'and'
| disjunction, read as 'or'
=> implication, read as 'implies'
So the above mentioned proposition would be represented by
( (a=>b)&(b=>c) ) => (a=>c)
Yacas can prove that is correct by applying CanProve to it:
In> CanProve(( (a=>b)&(b=>c) ) => (a=>c))
Out> True;
It does this the following way: in order to prove proposition p, it suffices to prove that ~p is false. It continues to simplify ~p using the rules

~ (~x)      --> x        eliminate double negation
x=>y        --> ~x | y   eliminate implication
~(x&y)      --> ~x | ~y  De Morgan's law
~(x | y)    --> ~x & ~y  De Morgan's law
(x & y) | z --> (x|z)&(y|z)  Distribution
x | (y & z) --> (x|y)&(x|z)  Distribution
And the obvious other rules: 'True|x --> True' etc. The above rules will translate the proposition into a form
(p1 | p2 | ...) & (q1 | q2 | ...) &...
If any of the clauses is false, the entire expression will be false. In the next step, clauses are scanned for situations of the form:
(p|Y) & (~p|Z) --> (Y|Z)
If this combination (Y|Z) is empty, it is false, and thus the entire proposition is false.

As a last step, the algorithm negates the result again. This has the added advantage of simplifying the expression further.

Examples:
In> CanProve(a | ~a)         
Out> True;
In> CanProve(True | a)       
Out> True;
In> CanProve(False | a)      
Out> a;
In> CanProve(a & ~a)         
Out> False;
In> CanProve(a |b|(a&b))     
Out> a|b;

See Also:
True , False ,


% , True , False , EndOfFile , Infinity , Pi ,

Constants


%

% evaluates to the previous result on the command line. % is a global variable that is bound to the previous result from the command line. To actually evaluate the previous result, call Eval(%). This will generally not be needed, so using % in places where the result is needed will suffice.

Typical examples are Simplify(%) and PrettyForm(%)to simplify and show the result in a nice form respectively.


True and False

True and False are typically the result of boolean expressions like 2 < 3 and True And False.


EndOfFile

EndOfFile : End of file marker when reading from file. If a file contains the expression EndOfFile; the operation will stop reading the file at that point.


Infinity

Infinity represents infinity. It can be the result of certain calculations.

Note that for most analytic functions Yacas understands Infinity. Thus Infinity*2 will return Infinity, and a < Infinity will evaluate to True.


Pi

Pi represents the value of pi. When the N(..) function is used, Pi is set to the correct value. It is probably better to use Pi than Pi(), for simplification purposes.


:= , Set , Clear , Local , ++ , -- , Object , LazyGlobal ,

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.


LazyGlobal

Internal function
Calling Sequence:
LazyGlobal(var)
Parameters:
var - variable (held argument)
Description:
LazyGlobal enforces that a global variable will re-evaluate when used. The global variable needs to exist for this function to work. Also, this functionality doesn't survive if Clear(var) is called afterwards.

Places where this is used include the global variables % and I.

The use of lazy in the name stems from the concept of lazy evaluation. The object the global variable is bound to will only be evaluated when called. The LazyGlobal property only holds once: after that, the result of evaluation is stored in the global variable, and it won't be reevaluated again:
In> a:=Hold(Taylor(x,0,30)Sin(x))
Out> Taylor(x,0,30)Sin(x);
In> LazyGlobal(a)
Then the first time you call a it evaluates Taylor(...) and assigns the result to a. The next time you call a it immediately returns the result. LazyGlobal is called for "%" each time "%" changes.

Examples:
In> a:=Hold(2+3)
Out> 2+3;
In> a
Out> 2+3;
In> LazyGlobal(a)
Out> True;
In> a
Out> 5;

See Also:
Set , Clear , Local ,


FullForm , Echo , PrettyForm , PrettyPrinter , Write , WriteString , Space , NewLine , DefaultDirectory , FromFile , FromString , ToString , Read , LispRead , ReadToken , ToFile , Load , Use , DefLoad , FindFile ,

Input/Output


FullForm(expression)

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


Echo({...})

Echo writes the contents of the list passed to it to the current output, and calls NewLine(). If an entry in the list is a string it writes the string unstringified. Example:
f(x):=x^2;
Echo({"The square of two is ",f(2)});
which should write out "The square of two is 2" to the current output


PrettyForm(expr)

PrettyForm shows the expression in a nicer form, closer to the notation usually used when a human writes down an expression. Example:
In> PrettyForm(Taylor(x,0,9)Sin(x))

     /  3 \    5     /  7 \      9  
    -\ x  /   x     -\ x  /     x   
x + ------- + --- + ------- + ------
       6      120    5040     362880

Out> True;
This is generally useful when the result of a calculation is more complex than a simple number.


PrettyPrinter("printer")

PrettyPrinter("printer") : set up the function printer to print out the results on the command line. Example:
PrettyPrinter("PrettyForm");
This function can be reset to the internal printer with PrettyPrinter()


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.


Atom , String , ConcatStrings , Prog , Check , Prefix , Postfix , Bodied , Infix , IsInfix , IsPrefix , IsPostfix , OpPrecedence , RightAssociative , LeftPrecedence , RightPrecedence , RuleBase , Rule , HoldArg , TryRetract , UnFence , MacroSet , MacroClear , MacroLocal , MacroRuleBase , MacroRule , Secure ,

Programming


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)


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


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",precedence)

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


Infix("oper",precedence)

Infix("oper",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.


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


MathNot , MathAnd , MathOr , BitAnd , BitOr , BitXor , Equals , LessThan , GreaterThan , ShiftLeft , ShiftRight ,

Built-in functions


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.


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.


IsGeneric , GenericTypeName , ArrayCreate , ArraySize , ArrayGet , ArraySet , ArrayCreateFromList , ListFromArray ,

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.