MathNot , MathAnd , MathOr , BitAnd, BitOr, BitXor , Equals , GreaterThan, LessThan , Math... , Fast... , ShiftLeft, ShiftRight , IsPromptShown , MathLibrary , GetTime .

Built-in (core) functions

Yacas comes with a small core of built-in functions and a large library of user-defined functions. Some of these core functions are documented in this chapter.

MathNot built-in logical "not"
MathAnd built-in logical "and"
MathOr built-in logical "or"
BitAnd, BitOr, BitXor bitwise arithmetic
Equals check equality
GreaterThan, LessThan comparison predicates
Math... arbitrary-precision math functions
Fast... double-precision math functions
ShiftLeft, ShiftRight built-in bit shifts
IsPromptShown test for the Yacas prompt option
MathLibrary obtain current math library name
GetTime measure the time taken by an evaluation

It is important for a developer to know which functions are built-in and cannot be redefined or Retract-ed. Also, core functions may be somewhat faster to execute than functions defined in the script library. All core functions are listed in the file corefunctions.h in the src/ subdirectory of the Yacas source tree. The declarations typically look like this:

SetCommand(LispSubtract, "MathSubtract");
Here LispSubtract is the Yacas internal name for the function and MathSubtract is the name visible to the Yacas language. Built-in bodied functions and infix operators are declared in the same file.


MathNot -- built-in logical "not"

Internal function
Calling format:
MathNot(expression)

Description:
Returns "False" if "expression" evaluates to "True", and vice versa.


MathAnd -- built-in logical "and"

Calling format:
MathAnd(...)

Description:
Lazy logical 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 of the arguments is False, And 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 -- built-in logical "or"

Internal function
Calling format:
MathOr(...)

MathOr is the basic logical "or" function. Similarly to And, it is lazy-evaluated. And(...) and Or(...) do also exist, defined in the script library. You can redefine 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, BitOr, BitXor -- bitwise arithmetic

Internal function
Calling format:
BitAnd(n,m)
BitOr(n,m)
BitXor(n,m)

Description:
These functions return bitwise "and", "or" and "xor" of two numbers.


Equals -- check equality

Internal function
Calling format:
Equals(a,b)

Description:
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.


GreaterThan, LessThan -- comparison predicates

Internal function
Calling format:
GreaterThan(a,b)
LessThan(a,b)

Parameters:
a, b -- numbers or strings
Description:
Comparing numbers or strings (lexicographically).

Example:
In> LessThan(1,1)
Out> False;
In> LessThan("a","b")
Out> True;


Math... -- arbitrary-precision math functions

Internal function
Calling format:
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)
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)

Description:
Calculation of sin, cos, tan and other mathematical functions. The argument must be a number. The reason for the prefix Math is that the library needs to define equivalent non-numerical functions for symbolic computations, such as Exp, Sin and so on.


Fast... -- double-precision math functions

Internal function
Calling format:

FastExp(x), FastLog(x) (natural logarithm), FastPower(x,y), FastSin(x), FastCos(x), FastTan(x), FastArcSin(x), FastArcCos(x), FastArcTan(x)

Description:
Versions of these functions using the C++ library. These should then at least be faster than the arbitrary precision versions.


ShiftLeft, ShiftRight -- built-in bit shifts

Internal function
Calling format:
ShiftLeft(expr,bits)
ShiftRight(expr,bits)

Description:
Shift bits to the left or to the right.


IsPromptShown -- test for the Yacas prompt option

Internal function
Calling format:
IsPromptShown()
Description:
Returns False if Yacas has been started with the option to suppress the prompt, and True otherwise.


MathLibrary -- obtain current math library name

Internal function
Calling format:
MathLibrary()
Description:
Returns a string that describes the currently used arbitrary-precision arithmetic library name.

Possible names are "Internal" and "Gmp", indicating the internal math library libyacasnumbers and the GNU Multiple Precision library libgmp.

Example:
In>  MathLibrary()
Out> "Internal";


GetTime -- measure the time taken by an evaluation

Internal function
Calling format:
GetTime(expr)
Parameters:
expr -- any expression
Description:
The function GetTime(expr) evaluates the expression expr and returns the time needed for the evaluation. The result is returned as a floating-point number of seconds. The value of the expression expr is lost.

The result is the "user time" as reported by the OS, not the real ("wall clock") time. Therefore, any CPU-intensive processes running alongside Yacas will not significantly affect the result of GetTime.

Example:
In> GetTime(Simplify((a*b)/(b*a)))
Out> 0.09;

See also:
Time .


Full listing of core functions

The following Yacas functions are currently declared in corefunctions.h as core functions. The list indicates whether a function is a real function (evaluating its arguments) or a macro (not evaluating its arguments). Also a function can either take a fixed number of arguments or a variable number (say, 2 or more). Some kernel functions are additionally declared as operators (bodied, prefix, infix, postfix) with the given precedence.