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