(directly go to documentation on : MathNot, MathAnd, MathOr, BitAnd, BitOr, BitXor, Equals, GreaterThan, LessThan, Math..., Fast..., ShiftLeft, ShiftRight, IsPromptShown, GetTime. )

5. 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 bitwise and operation
BitOr bitwise or operation
BitXor bitwise xor operation
Equals check equality
GreaterThan comparison predicate
LessThan comparison predicate
Math... arbitrary-precision math functions
Fast... double-precision math functions
ShiftLeft built-in bitwise shift left operation
ShiftRight built-in bitwise shift right operation
IsPromptShown test for the Yacas prompt option
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 -- bitwise and operation


BitOr -- bitwise or operation


BitXor -- bitwise xor operation

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 -- comparison predicate


LessThan -- comparison predicate

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)      (add two numbers)
MathSubtract(x,y) (subtract two numbers)
MathMultiply(x,y) (multiply two numbers)
MathDivide(x,y)   (divide two numbers)
MathSqrt(x)    (square root, must be x>=0)
MathFloor(x)   (largest integer not larger than x)
MathCeil(x)    (smallest integer not smaller than x)
MathAbs(x)     (absolute value of x, or |x| )
MathExp(x)     (exponential, base 2.718...)
MathLog(x)     (natural logarithm, for x>0)
MathPower(x,y) (power, x ^ y)
MathSin(x)     (sine)
MathCos(x)     (cosine)
MathTan(x)     (tangent)
MathSinh(x)     (hyperbolic sine)
MathCosh(x)     (hyperbolic cosine)
MathTanh(x)     (hyperbolic tangent)
MathArcSin(x)   (inverse sine)
MathArcCos(x)   (inverse cosine)
MathArcTan(x)   (inverse tangent)
MathArcSinh(x)  (inverse hyperbolic sine)
MathArcCosh(x)  (inverse hyperbolic cosine)
MathArcTanh(x)  (inverse hyperbolic tangent)
MathDiv(x,y)    (integer division, result is an integer)
MathMod(x,y)    (remainder of division, or x mod y)

Description:
These commands perform the calculation of elementary mathematical functions. The arguments must be numbers. 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.

Note that all functions, such as the MathPower, MathSqrt, MathAdd etc., accept integers as well as floating-point numbers. The resulting values may be integers or floats. If the mathematical result is an exact integer, then the integer is returned. For example, MathSqrt(25) returns the integer 5, and MathPower(2,3) returns the integer 8. In such cases, the integer result is returned even if the calculation requires more digits than set by Builtin'Precision'Set. However, when the result is mathematically not an integer, the functions return a floating-point result which is correct only to the current precision.

Example:
In> Builtin'Precision'Set(10)
Out> True
In> Sqrt(10)
Out> Sqrt(10)
In> MathSqrt(10)
Out> 3.16227766
In> MathSqrt(490000*2^150)
Out> 26445252304070013196697600
In> MathSqrt(490000*2^150+1)
Out> 0.264452523e26
In> MathPower(2,3)
Out> 8
In> MathPower(2,-3)
Out> 0.125


Fast... -- double-precision math functions

Internal function
Calling format:

FastLog(x) (natural logarithm), FastPower(x,y), FastArcSin(x)

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


ShiftLeft -- built-in bitwise shift left operation


ShiftRight -- built-in bitwise shift right operation

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.


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 .