Yacas users function reference
DefaultDirectory
,
PrettyPrinter
,
Help
,
HistorySize
,
Startup configuration
Yacas allows you to configure a few things at startup. The file
~/.yacasrc will be executed when Yacas is run. The followinf functions
can be useful when used in the ~/.yacasrc file.
DefaultDirectory
Internal function
Calling Sequence:
DefaultDirectory(path)
Parameters:
path - a string containing a full path where yacas script files reside
Description:
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.
This means that "path" should end with a forward slash (under unix-like
operating systems).
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.
Examples:
In> DefaultDirectory("/home/user/myscripts/");
Out> True;
|
See Also:
Load
,
Use
,
DefLoad
,
FindFile
,
PrettyPrinter
Standard math library
Calling Sequence:
PrettyPrinter(printer)
Parameters:
printer - a string containing the name of a function that can
pretty-print an expression
Description:
PrettyPrinter(printer) sets up the function printer to print
out the results on the command line.
This function can be reset to the internal printer with
PrettyPrinter()
Examples:
In> Taylor(x,0,5)Sin(x)
Out> x-x^3/6+x^5/120;
In> PrettyPrinter("PrettyForm");
True
Out>
In> Taylor(x,0,5)Sin(x)
3 5
x x
x - -- + ---
6 120
Out>
In> PrettyPrinter();
Out> True;
In> Taylor(x,0,5)Sin(x)
Out> x-x^3/6+x^5/120;
|
See Also:
PrettyForm
,
Write
,
Help
Standard math library
Calling Sequence:
Help()
Help(function)
Parameters:
function - a string containing the name of a function to show help for
Description:
When help is requested by the user, by typing ?function or ??, the
functions Help() (for ??) and Help(function) (for ?function) are called.
By default, lynx is used as a browser. The help resides in the subdirectory
documentation/ under the directory the math scripts were installed in. So
the help files can be found using FindFile.
Examples:
To use netscape for browsing help, enter the following commands:
Help(_f) <-- SystemCall("netscape ":FindFile("documentation/ref.html"):"#":f);
Help() := SystemCall("netscape ":FindFile("documentation/books.html"));
|
See Also:
SystemCall
,
FindFile
,
HistorySize
Internal function
Calling Sequence:
HistorySize(n)
Parameters:
n - number of lines to store in history file
Description:
When exiting, yacas saves the command line history to a
file ~/.yacas_history . By default it will only save the last 50
lines, to save space on the harddisk. This can be overridden with this
function. Passing -1 tells the system to save all the lines.
Examples:
In> HistorySize(200)
Out> True;
In> quit
|
See Also:
+
,
-
,
*
,
/
,
^
,
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
,
N
,
Rationalize
,
IsPrime
,
IsPrimePower
,
Factors
,
Factor
,
PAdicExpand
,
ContFrac
,
Decimal
,
TruncRadian
,
Floor
,
Ceil
,
Round
,
Pslq
,
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:
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 and ToBase
Internal function
Calling Sequence:
FromBase(base,number)
ToBase(base,number)
Parameters:
base - a base to write the numbers in
number - a number to write out in the base representation
Description:
Conversion of numbers to and from base 10 numbers.
These functions use the p-adic expansion capabilities of the built-in
arbitrary precision math libraries.
Examples:
In> FromBase(2,111111)
Out> 63;
In> ToBase(16,255)
Out> ff;
|
See Also:
Precision and GetPrecision
Internal function
Calling Sequence:
Precision(n)
GetPrecision()
Parameters:
n - required number of digits precision
required for following calculations, in base 10.
Description:
Precision and GetPrecision can be used to get and set the
required number of digits of precision in base 10 in the environment.
All subsequent floating point operations will allow for at least n
digits after the decimal point.
Examples:
In> Precision(10)
Out> True;
In> N(Sin(1))
Out> 0.8414709848;
In> Precision(20)
Out> True;
In> N(Sin(1))
Out> 0.84147098480789650665;
In> GetPrecision()
Out> 20;
|
See Also:
N
,
N
Standard math library
Calling Sequence:
N(expression)
N(expression,precision)
Parameters:
expression - expression to evaluate
precision - precision to use
Description:
Normally numeric values are left as-is as long
as possible in calculations using division, or trigonometric functions
like Sin, Cos, etcetera.
N forces Yacas to calculate floating point representations
of functions whenever possible, using the current precision or the
specified precision.
In addition, the variable Pi is bound to the value of pi up to the
required precision.
Examples:
In> 1/2
Out> 1/2;
In> N(1/2)
Out> 0.5;
In> Sin(1)
Out> Sin(1);
In> N(Sin(1),10)
Out> 0.8414709848;
In> Pi
Out> Pi;
In> N(Pi,20)
Out> 3.14159265358979323846;
|
See Also:
Precision
,
GetPrecision
,
Rationalize
Standard math library
Calling Sequence:
Rationalize(expression)
Parameters:
expression - expression to rationalize
Description:
Rationalize scans the entire expression replacing all floating
point values into rational representations p/q for some integers p and
q, such that the division of p by q gives the original floating point
value up to the number of digits of the original floating point value.
It does this by finding the smallest integer n such that
multiplying the number with 10^n is an integer. Then it divides by 10^n
again, depending on the internal gcd calculation to reduce the resulting
division of integers.
Examples:
In> Sin(1.234)
Out> Sin(1.234);
In> Rationalize(%)
Out> Sin(617/500);
|
See Also:
N
,
Precision
,
GetPrecision
,
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.
Factor and Factors
Standard math library
Calling Sequence:
Factor(x)
Factors(x)
Parameters:
x - an integer number or univariate polynomial to factor
Description:
Factors decomposes integer numbers or univariate polynomials
into a product of primes or irreducible polynomials.
The result of Factors is a list of lists of the form {p,n}, where each
p^n divides the original x.
Factor shows the result of Factors in a nicer human readable format.
Examples:
In> Factors(12)
Out> {{2,2},{3,1}};
In> PrettyForm(Factor(12))
2
2 * 3
|
See Also:
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
Standard math library
Calling Sequence:
ContFrac(x) or ContFrac(x,maxdepth)
Parameters:
x - expression to break down
maxdepth - maximum required depth of result
Description:
Return the continued fraction expansion of a floating point
number, or of a polynomial. This is especially useful for
polynomials, since series expansions that converge slowly
will typically converge a lot faster if calculated using
a continued fraction expansion.
Examples:
In> PrettyForm(ContFrac(N(Pi)))
1
3 + ---------------------------
1
7 + -----------------------
1
15 + ------------------
1
1 + --------------
1
292 + --------
1 + rest
|
See Also:
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
,
Floor
Standard math library
Calling Sequence:
Floor(x)
Parameters:
x - a number
Description:
Floor returns the largest integer smaller than x.
Examples:
In> Floor(1.1)
Out> 1;
In> Floor(-1.1)
Out> -2;
|
See Also:
Ceil
,
Round
,
Ceil
Standard math library
Calling Sequence:
Ceil(x)
Parameters:
x - a number
Description:
Ceil returns the smallest integer larger than x.
Examples:
In> Ceil(1.1)
Out> 2;
In> Ceil(-1.1)
Out> -1;
|
See Also:
Floor
,
Round
,
Round
Standard math library
Calling Sequence:
Round(x)
Parameters:
x - a number
Description:
Round returns the integer closest to x. 0.5 is rounded down.
Examples:
In> Round(1.49)
Out> 1;
In> Round(1.51)
Out> 2;
In> Round(-1.49)
Out> -1;
In> Round(-1.51)
Out> -2;
|
See Also:
Floor
,
Ceil
,
Pslq
Standard math library
Calling Sequence:
Pslq(xlist,precision)
Parameters:
xlist - list of floating point numbers
precision - required number of digits precision of calculation
Description:
The Pslq is an integer relation detection algorithm.
Given a list of constants x find coefficients sol[i] such that
sum(sol[i]*x[i], i=1..n) = 0 (where n=Length(x)).
x is the list of real expressions. N(x[i]) must evaluate to floating
point numbers.
Examples:
In> Pslq({ 2*Pi+3*Exp(1) , Pi , Exp(1) },20)
Out> {1,-2,-3};
|
Note: in this example the system detects correctly that
1* (2*Pi+3*E) -2*(Pi) - 3*(E) = 0
See Also:
Sin
,
Cos
,
Tan
,
ArcSin
,
ArcCos
,
ArcTan
,
Exp
,
Ln
,
Sqrt
,
Abs
,
Sign
,
Complex
,
Re
,
Im
,
I
,
!
,
Bin
,
Sum
,
Average
,
Factorize
,
Min
,
Max
,
IsZero
,
IsRational
,
Numer
,
Denom
,
Commutator
,
Taylor
,
InverseTaylor
,
ReversePoly
,
Newton
,
D
,
Diverge
,
Curl
,
Integrate
,
Simplify
,
RadSimp
,
Rationalize
,
Conjugate
,
Solve
,
SuchThat
,
Eliminate
,
PSolve
,
Pi
,
Fibonacci
,
Random
,
VarList
,
Limit
,
TrigSimpCombine
,
LagrangeInterpolant
,
Calculus
Trigonometric functions
Standard math library
Calling Sequence:
Sin(x)
Cos(x)
Tan(x)
ArcSin(x)
ArcCos(x)
ArcTan(x)
Parameters:
x - some number
Description:
These functions represent the trigonometric functions and their
inverses. Yacas leaves them alone even if x is a number, trying to keep
the result as exact as possible. The floating point approximations of
these functions can be forced by using the N(...) functions.
Yacas knows some trigonometric identities, so it can simplify to exact
results even if N is not used. This is the case when the arguments are
of the form Pi, Pi/2 etcetera.
Examples:
In> Sin(1)
Out> Sin(1);
In> N(Sin(1),20)
Out> 0.84147098480789650665;
In> Sin(Pi/4)
Out> Sqrt(2)/2;
|
See Also:
N
,
Pi
,
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, Sign
Standard math library
Calling Sequence:
Abs(x)
Sign(x)
Parameters:
x - a number
Description:
Abs(x) returns the absolute value of a number.
Abs(x)*Sign(x) should always be equal to x. Sign(x) returns 1
if the number is positive, -1 otherwise.
Examples:
In> Abs(-2)
Out> 2;
In> Sign(-2)
Out> -1;
|
See Also:
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.
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. Some simple integration rules have currently been implemented.
Transcendental functions, polynomials, products of transcendental functions
and polynomials, and rational functions.
Simplify(expr)
Simplify(expr) : Simplify tries to simplify an expression as much
as possible. It does this by grouping powers within terms, and then
grouping like terms.
RadSimp
Standard math library
Calling Sequence:
RadSimp(expression)
Parameters:
expression - an expression containing nested radicals
Description:
RadSimp tries to unnest nested radicals. It does this using
a simple brute force method, and tries to write it out as an
expression of the form Sqrt(e1) + Sqrt(e2) + ... .
Examples:
In> RadSimp(Sqrt(9+4*Sqrt(2)))
Out> 1+Sqrt(8);
In> RadSimp(Sqrt(5+2*Sqrt(6))+Sqrt(5-2*Sqrt(6)))
Out> Sqrt(12);
In> RadSimp(Sqrt(14+3*Sqrt(3+2*Sqrt(5-12*Sqrt(3-2*Sqrt(2))))))
Out> 3+Sqrt(2);
|
See Also:
Simplify
,
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
Standard math library
Calling Sequence:
SuchThat(expression,variable)
Parameters:
expression - an expression to solve for
variable - subexpression to look for
Description:
SuchThat(expression,var) : try to find a simple expression for variable var,
given the equality expression=0. This function basically only handles
expressions where the variable only occurs once. It does its work
by applying the inverse of the top function, until the variable is
reached. Variable can also refer to an expression, in which case it
will try to eliminate for that expression.
Examples:
In> SuchThat(a+b*x,x)
Out> (-a)/b;
In> SuchThat(Cos(a)+Cos(b)^2,Cos(b))
Out> (-Cos(a))^(1/2);
In> Expand(a*x+b*x+c,x)
Out> c+(a+b)*x;
In> SuchThat(%,x)
Out> (-c)/(a+b);
|
See Also:
Solve
,
Subst
,
Simplify
,
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
,
IsHermitean
,
IsUnitary
,
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
,
IsHermitean
Standard math library
Calling Sequence:
IsHermitean(A)
Parameters:
A - square matrix
Description:
IsHermitean(A) returns True if A is Hermitean and False
otherwise. A is a Hermitean matrix iff Conjugate(Transpose(A))=A.
For real matrices A is tested to be symmetric.
Examples:
In> IsHermitean({{0,I},{-I,0}})
Out> True;
In> IsHermitean({{0,I},{2,0}})
Out> False;
|
See Also:
IsUnitary
,
IsUnitary
Standard math library
Calling Sequence:
IsUnitary(A)
Parameters:
A - square matrix
Description:
This function tries to find out if A is unitary.
Matrix A is orthogonal iff A^(-1) = Transpose(Conjugate(A)). This is
equivalent to the fact that the columns of A build an orthonormal system
(in respect to the scalar product defined by InProduct).
Examples:
In> IsUnitary({{0,I},{-I,0}})
Out> True;
In> IsUnitary({{0,I},{2,0}})
Out> False;
|
See Also:
IsHermitean
,
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
,
PatchString
,
Function
,
Use
,
For
,
ForEach
,
Apply
,
LocalSymbols
,
Subst
,
WithValue
,
SetHelpBrowser
,
TraceStack
,
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.
PatchString
Internal function
Calling Sequence:
PatchString(string)
Parameters:
string - a string to patch
Description:
This function does the same as PatchLoad, but it works on a string
in stead of on the contents of a text file. See PatchLoad for more
details.
Examples:
In> PatchString("Two plus three is <? Write(2+3); ?> ");
Out> "Two plus three is 5 ";
|
See Also:
PatchLoad
,
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.
SetHelpBrowser
Standard math library
Calling Sequence:
SetHelpBrowser(helpbrowser)
Parameters:
helpbrowser - string containing a html browser to use for help
Description:
This function sets the help browser you want to use to
browse the help online. It calls helpbrowser with the html
page as first argument. The default is lynx. If you want to
use a different browser by default it suffices to create a
file ~/.yacasrc. and add a line to set the browser in there.
Examples:
In> SetHelpBrowser("netscape")
Out> "netscape";
In> ??
|
See Also:
TraceStack
Internal function
Calling Sequence:
TraceStack(expression)
Parameters:
expression - an expression to evaluate
Description:
TraceStack shows the calling stack after an error occurred.
It shows the last few items on the stack, not to flood the screen.
These are usually the only items of interest on the stack.
This is probably by far the most useful debugging function in
Yacas. It shows the last few things it did just after an error
was generated somewhere.
For each stack frame, it shows if the function evaluated was a
built-in function or a user-defined function, and for the user-defined
function, the number of the rule it is trying whether it was evaluating
the pattern matcher of the rule, or the body code of the rule.
This functionality is not offered by default because it slows
down the evaluation code.
Examples:
Here is an example of a function calling itself recursively,
causing Yacas to flood its stack:
In> f(x):=f(Sin(x))
Out> True;
In> TraceStack(f(2))
Debug> 982 : f (Rule # 0 in body)
Debug> 983 : f (Rule # 0 in body)
Debug> 984 : f (Rule # 0 in body)
Debug> 985 : f (Rule # 0 in body)
Debug> 986 : f (Rule # 0 in body)
Debug> 987 : f (Rule # 0 in body)
Debug> 988 : f (Rule # 0 in body)
Debug> 989 : f (Rule # 0 in body)
Debug> 990 : f (Rule # 0 in body)
Debug> 991 : f (Rule # 0 in body)
Debug> 992 : f (Rule # 0 in body)
Debug> 993 : f (Rule # 0 in body)
Debug> 994 : f (Rule # 0 in body)
Debug> 995 : f (User function)
Debug> 996 : Sin (Rule # 0 in pattern)
Debug> 997 : IsList (Internal function)
Error on line 1 in file [CommandLine]
Max evaluation stack depth reached.
Please use MaxEvalDepth to increase the stack size as needed.
|
See Also:
TraceExp
,
TraceRule
,
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
Internal function
Calling Sequence:
Not bool
Parameters:
bool - a boolean expression
Description:
Not returns the logical negation of the argument bool. If bool is
False it returns True, and if the argument is True Not returns False.
If the argument is neither True nor False it returns the entire
expression with evaluated arguments.
Examples:
In> Not True
Out> False;
In> Not False
Out> True;
In> Not(a)
Out> Not a;
|
See Also:
And
,
Or
,
And
Internal function
Calling Sequence:
a1 And a2
And(a1,a2,a3,...,an)
Parameters:
a1 .. an - boolean values (True or False)
Description:
This function returns True if all arguments are true. The
And operation is lazy, it returns False as soon as a False argument
is found (from left to right). If an argument other than True or
False is encountered a new And expression is returned with all
arguments that didn't evaluate to True or False yet.
Examples:
In> True And False
Out> False;
In> And(True,True)
Out> True;
In> False And a
Out> False;
In> True And a
Out> And(a);
In> And(True,a,True,b)
Out> b And a;
|
See Also:
Or
,
Not
,
Or
Internal function
Calling Sequence:
a1 Or a2
Or(a1,a2,a3,...,an)
Parameters:
a1 .. an - boolean values (True or False)
Description:
This function returns True if an argument is encountered
that is true (scanning from left to right). The
Or operation is lazy, it returns True as soon as a True argument
is found (from left to right). If an argument other than True or
False is encountered a new Or expression is returned with all
arguments that didn't evaluate to True or False yet.
Examples:
In> True Or False
Out> True;
In> False Or a
Out> Or(a);
In> Or(False,a,b,True)
Out> True;
|
See Also:
And
,
Not
,
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
Standard math library
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
Not negation, read as 'not'
And conjunction, read as 'and'
Or disjunction, read as 'or'
=> implication, read as 'implies'
So the above mentioned proposition would be represented by
( (a=>b) And (b=>c) ) => (a=>c)
|
Yacas can prove that is correct by applying CanProve
to it:
In> CanProve(( (a=>b) And (b=>c) ) => (a=>c))
Out> True;
|
It does this the following way: in order to prove proposition p, it
suffices to prove that Not p is false. It continues to simplify Not p
using the rules
Not ( Not x) --> x eliminate double negation
x=>y --> Not x Or y eliminate implication
Not (x And y) --> Not x Or Not y De Morgan's law
Not (x Or y) --> Not x And Not y De Morgan's law
(x And y) Or z --> (x Or z) And (y Or z) Distribution
x Or (y And z) --> (x Or y) And (x Or z) Distribution
|
And the obvious other rules: 'True Or x --> True' etc.
The above rules will translate the proposition into a form
(p1 Or p2 Or ...) And (q1 Or q2 Or ...) And ...
|
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 Or Y) And ( Not p Or Z) --> (Y Or Z)
|
If this combination (Y Or 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 Or Not a)
Out> True;
In> CanProve(True Or a)
Out> True;
In> CanProve(False Or a)
Out> a;
In> CanProve(a And Not a)
Out> False;
In> CanProve(a Or b Or (a And b))
Out> a Or b;
|
See Also:
True
,
False
,
And
,
Or
,
Not
,
%
,
True
,
False
,
EndOfFile
,
Infinity
,
Pi
,
Constants
%
Internal function
Calling Sequence:
%
Parameters:
Description:
% evaluates to the previous result on the command line. % is a global
variable that is bound to the previous result from the command line.
Using % will evaluate the previous result (This uses the functionality
offered by the LazyGlobal command).
Typical examples are Simplify(%) and PrettyForm(%)to simplify and show the result in a nice
form respectively.
Examples:
In> Taylor(x,0,5)Sin(x)
Out> x-x^3/6+x^5/120;
In> PrettyForm(%)
3 5
x x
x - -- + ---
6 120
|
See Also:
LazyGlobal
,
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
,
Write
,
WriteString
,
Space
,
NewLine
,
FromFile
,
FromString
,
ToString
,
Read
,
LispRead
,
ReadToken
,
ToFile
,
Load
,
Use
,
DefLoad
,
FindFile
,
PatchLoad
,
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.
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.
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.
PatchLoad
Internal function
Calling Sequence:
PatchLoad(filename)
Parameters:
filename - the file to patch
Description:
PatchLoad loads in a file and outputs the contents to the current
output. The file can contain blocks delimited by <? and ?>
(meaning Yacas Begin and Yacas End). The piece of text between
such delimiters is treated as a separate file with Yacas instructions,
which is then loaded and executed. All output of write statements
in that block will be written to the same current output.
This is similar to the way php works. You can have a static text file
with dynamic content generated by Yacas.
See Also:
PatchString
,
Load
,
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. This function can also be called with an additional argument
for the precedence of the prefix operator.
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.
DllLoad
,
StubApiCStart
,
StubApiCShortIntegerConstant
,
StubApiCInclude
,
StubApiCFunction
,
StubApiCRemark
,
StubApiCSetEnv
,
StubApiCFile
,
StubApiCStruct
,
The Yacas plugin structure
Yacas supports dynamically loading libraries at runtime. This allows
it to interface with other libraries that support additional
functionality. For example, there could be a plugin enabling
the user to script a user interface from within Yacas, or a
specific powerful library to do numeric calculations.
The plugin feature is currently in an experimental stage. There
are some examples in the plugins/ directory. These are not built
by default because they cannot be guaranteed to compile on every
platform (yet). The plugins need to be compiled after Yacas itself
has been compiled and installed successfully. The plugins/ directory
contains a README file with more details on compilation.
In addition to the plugin structure in the Yacas engine, there is
a 'cstubgen' module (currently still in development) that allows
rapid scripting of a plugin. Essentially all that is required is
to write a file that looks like the header file of the original
library, but written in Yacas syntax. the 'cstubgen' module is then
able to write out a c++ file that can be compiled and linked with
the original library, and then loaded from within Yacas. Including
a function in the plugin will typically take just one line of
Yacas code. There are a few examples in the plugins/
directory (the files ending with api.stub). The make file
makefile.plugin is configured to automatically convert these to
the required c++ files.
In addition to the c++ stub file cstubgen also automatically generates
some documentation on the functions included in the stub. This
documentation is put in a file with extension 'description'.
The plugin facility is not supported for each platform yet. Specifically,
it is only supported on platforms that support the elf binary format.
(loading DLLs is platform-dependent).
This chapter assumes the reader is comfortable programming in c++.
DllLoad
Internal function
Calling Sequence:
DllLoad(file)
Parameters:
file - file name of the plugin
Description:
DllLoad forces Yacas to load the dynamic link library (.so file
under Linux). The full path to the DLL has to be specified,
or the file needs to be in a path where dlopen can find it.
Examples:
In> DllLoad("./libopengl.so");
Out> True;
|
See Also:
StubApiCStart
Standard math library
Calling Sequence:
StubApiCStart()
Parameters:
Description:
To start up generating a c stub file for linking a c library with
Yacas. A stub specification file needs to start with this
function call, to reset the internal state of Yacas for emitting
a stub c++ file.
See Also:
StubApiCShortIntegerConstant
,
StubApiCInclude
,
StubApiCFunction
,
StubApiCFile
,
StubApiCSetEnv
,
StubApiCShortIntegerConstant
Standard math library
Calling Sequence:
StubApiCShortIntegerConstant(const,value)
Parameters:
const - string representing the global variable to be bound runtime
value - integer value the global should be bound to
Description:
define a constant 'const' to have value 'value'. The value should
be short integer constant. This is useful for linking in
defines and enumerated values into Yacas.
If the library for instance has a define
#define FOO 10
Then
StubApiCShortIntegerConstant("FOO","FOO")
will bind the global variable FOO to the value for FOO defined in
the library header file.
See Also:
StubApiCStart
,
StubApiCInclude
,
StubApiCFunction
,
StubApiCFile
,
StubApiCSetEnv
,
StubApiCInclude
Standard math library
Calling Sequence:
StubApiCInclude(file)
Parameters:
file - file to include from the library the plugin is based on
Description:
Declare an include file (a header file for the library, for instance)
The delimiters need to be specified too. So, for a standard library
like the one needed for opengl, you need to specify
StubApiCInclude("<GL/gl.h>")
and for user include file:
StubApiCInclude("\"GL/gl.h\"")
See Also:
StubApiCStart
,
StubApiCShortIntegerConstant
,
StubApiCFunction
,
StubApiCFile
,
StubApiCSetEnv
,
StubApiCFunction
Standard math library
Calling Sequence:
StubApiCFunction(returntype,fname,args)
StubApiCFunction(returntype,fname,fname2,args)
Parameters:
returntype - return type of library function
fname - function of built-in function
fname2 - (optional) function name to be used from within Yacas
args - list of arguments to the function
Description:
This function declares a library function, along with its
calling sequence. cstubgen will then generate the c++ code
required to call this function.
Return type, function name, and list of arguments should be
literal strings (surrounded by quotes).
If fname2 is not supplied, it will be assumed to be the same as fname.
The return types currently supported are "int", "double" and "void".
The argument values that are currently supported
are "int", "double", and "input_string".
Argument types can be specified simply as a string referring to their
type, like "int", or they can be lists with an additional element
stating the name of the variable: {"int","n"}. The variable
will then show up in the automatically generated documentation as
having the name n.
Examples:
To define the opengl function glVertex3d that accepts three
doubles and returns void:
StubApiCFunction("void","glVertex3d",{"double","double","double"});
|
See Also:
StubApiCStart
,
StubApiCShortIntegerConstant
,
StubApiCInclude
,
StubApiCFile
,
StubApiCSetEnv
,
StubApiCRemark
Standard math library
Calling Sequence:
StubApiCRemark(string)
Parameters:
string - remark string to be added to the documentation
Description:
StubApiCRemark adds a piece of text to the stub documentation
file that gets generated automatically. The documentation is put in
a .description file while the input file is being processed, so adding
a remark on a function just after a function declaration adds a remark
on that function.
See Also:
StubApiCShortIntegerConstant
,
StubApiCInclude
,
StubApiCFunction
,
StubApiCSetEnv
,
StubApiCFile
,
StubApiCSetEnv
Standard math library
Calling Sequence:
StubApiCSetEnv(func)
Parameters:
func - function to call to set the environment variable
Description:
This function forces the plugin to call the function func, with as
argument LispEnvironment& aEnvironment. This lets the plugin store
the environment class (which is needed for almost any thing to do with
Yacas), somewhere in a global variable. aEnvironment can then be used
from within a callback function in the plugin that doesn't take the
extra argument by design.
There needs to ba a function in the plugin somewhere of the form
static LispEnvironment* env = NULL;
void GlutSetEnv(LispEnvironment& aEnv)
{
env = &aEnv;
}
|
Then calling
StubApiCSetEnv("GlutSetEnv");
|
will force the plugin to call GlutSetEnv at load time. All functions
in the plugin will then have access to the Yacas environment.
See Also:
StubApiCStart
,
StubApiCShortIntegerConstant
,
StubApiCInclude
,
StubApiCFunction
,
StubApiCFile
,
StubApiCFile
Standard math library
Calling Sequence:
StubApiCFile(basename)
Parameters:
basename - basename for the generation of the stub file
Description:
Generate the c++ stub file, "basename.cc", and a documentation file
named "basename.description". The descriptions are automatically
generated while adding functions and constants to the stub.
See Also:
StubApiCStart
,
StubApiCShortIntegerConstant
,
StubApiCInclude
,
StubApiCFunction
,
StubApiCSetEnv
,
StubApiCStruct
Standard math library
Calling Sequence:
StubApiCStruct(name)
StubApiCStruct(name,freefunction)
Parameters:
name - name of structure
freefunction - function that can be called to clean up the object
Description:
StubApiCStruct declares a struct in a specific library. The name
should be followed by an asterisk (clearly showing it is a pointer).
After that, in the stub api definition, this type can be used as
argument or return type to functions to the library.
By default the struct will be deleted from memory with a normal
call to free(...). This can be overriden with a function given
as second argument, freefunction. This is needed in the case where
there are additional operations that need to be performed in order
to delete the object from memory.
Examples:
in a library header file, define:
typedef struct SomeStruct
{
int a;
int b;
} SomeStruct;
|
Then in the stub file you can declare this struct by calling:
StubApiCStruct("SomeStruct*")
|
See Also:
,
,
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.