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)      (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 `Precision`. 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> Precision(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:

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.

Possible names supported at the moment 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.

- `=` -- function, 2 arguments
- `@` -- prefix operator, prec. `0`
- `And` -- macro, 1 or more arguments
- `ApplyPure` -- function, 2 arguments
- `ArrayCreate` -- function, 2 arguments
- `ArrayGet` -- function, 2 arguments
- `ArraySet` -- function, 3 arguments
- `ArraySize` -- function, 1 argument
- `Atom` -- function, 1 argument
- `BackQuote` -- bodied operator, prec. `KMaxPrecedence`
- `BitAnd` -- function, 2 arguments
- `BitOr` -- function, 2 arguments
- `BitXor` -- function, 2 arguments
- `BitsToDigits` -- function, 2 arguments
- `Bodied` -- function, 2 arguments
- `CTokenizer` -- function, 0 arguments
- `CharString` -- function, 1 argument
- `Check` -- macro, 2 arguments
- `Clear` -- macro, 1 or more arguments
- `CommonLispTokenizer` -- function, 0 arguments
- `ConcatStrings` -- function, 1 or more arguments
- `Concat` -- function, 1 or more arguments
- `CurrentFile` -- function, 0 arguments
- `CurrentLine` -- function, 0 arguments
- `CustomEval'Expression` -- function, 0 arguments
- `CustomEval'Locals` -- function, 0 arguments
- `CustomEval'Result` -- function, 0 arguments
- `CustomEval'Stop` -- function, 0 arguments
- `CustomEval` -- macro, 4 arguments
- `DebugFile` -- function, 1 argument
- `DebugLine` -- function, 1 argument
- `DefLoadFunction` -- function, 1 argument
- `DefLoad` -- function, 1 argument
- `DefMacroRuleBaseListed` -- macro, 2 arguments
- `DefMacroRuleBase` -- macro, 2 arguments
- `DefaultDirectory` -- function, 1 argument
- `DefaultTokenizer` -- function, 0 arguments
- `Delete` -- function, 2 arguments
- `DestructiveDelete` -- function, 2 arguments
- `DestructiveInsert` -- function, 3 arguments
- `DestructiveReplace` -- function, 3 arguments
- `DestructiveReverse` -- function, 1 argument
- `DigitsToBits` -- function, 2 arguments
- `DllDirectory` -- function, 1 argument
- `DllEnumerate` -- function, 0 arguments
- `DllLoad` -- function, 1 argument
- `DllUnload` -- function, 1 argument
- `Equals` -- function, 2 arguments
- `Eval` -- function, 1 argument
- `Exit` -- function, 0 arguments
- `FastAbs` -- function, 1 argument
- `FastArcCos` -- function, 1 argument
- `FastArcSin` -- function, 1 argument
- `FastArcTan` -- function, 1 argument
- `FastAssoc` -- function, 2 arguments
- `FastCeil` -- function, 1 argument
- `FastCos` -- function, 1 argument
- `FastExp` -- function, 1 argument
- `FastFloor` -- function, 1 argument
- `FastIsPrime` -- function, 1 argument
- `FastLog` -- function, 1 argument
- `FastMod` -- function, 2 arguments
- `FastPi` -- function, 0 arguments
- `FastPower` -- function, 2 arguments
- `FastSin` -- function, 1 argument
- `FastSqrt` -- function, 1 argument
- `FastTan` -- function, 1 argument
- `FindFile` -- function, 1 argument
- `FindFunction` -- function, 1 argument
- `FlatCopy` -- function, 1 argument
- `FromBase` -- function, 2 arguments
- `FromFile` -- bodied operator, prec. `KMaxPrecedence`
- `FromFile` -- macro, 2 arguments
- `FromString` -- bodied operator, prec. `KMaxPrecedence`
- `FromString` -- macro, 2 arguments
- `FullForm` -- function, 1 argument
- `GarbageCollect` -- function, 0 arguments
- `GenericTypeName` -- function, 1 argument
- `GetCoreError` -- function, 0 arguments
- `GetExtraInfo` -- function, 1 argument
- `GetPrecision` -- function, 0 arguments
- `GetPrettyPrinter` -- function, 0 arguments
- `GetTime` -- macro, 1 argument
- `GreaterThan` -- function, 2 arguments
- `Head` -- function, 1 argument
- `HistorySize` -- function, 1 argument
- `HoldArg` -- macro, 2 arguments
- `Hold` -- macro, 1 argument
- `If` -- macro, 2 or more arguments
- `InDebugMode` -- function, 0 arguments
- `Infix` -- function, 2 arguments
- `Insert` -- function, 3 arguments
- `IsAtom` -- function, 1 argument
- `IsBodied` -- function, 1 argument
- `IsBound` -- macro, 1 argument
- `IsExitRequested` -- function, 0 arguments
- `IsFunction` -- function, 1 argument
- `IsGeneric` -- function, 1 argument
- `IsInfix` -- function, 1 argument
- `IsInteger` -- function, 1 argument
- `IsList` -- function, 1 argument
- `IsNumber` -- function, 1 argument
- `IsPostfix` -- function, 1 argument
- `IsPrefix` -- function, 1 argument
- `IsPromptShown` -- function, 0 arguments
- `IsString` -- function, 1 argument
- `LazyGlobal` -- macro, 1 argument
- `LeftPrecedence` -- function, 2 arguments
- `Length` -- function, 1 argument
- `LessThan` -- function, 2 arguments
- `LispReadListed` -- function, 0 arguments
- `LispRead` -- function, 0 arguments
- `Listify` -- function, 1 argument
- `List` -- macro, 1 or more arguments
- `Load` -- function, 1 argument
- `LocalSymbols` -- bodied operator, prec. `KMaxPrecedence`
- `LocalSymbols` -- macro, 1 or more arguments
- `Local` -- macro, 1 or more arguments
- `MacroClear` -- function, 1 or more arguments
- `MacroLocal` -- function, 1 or more arguments
- `MacroRuleBaseListed` -- function, 2 arguments
- `MacroRuleBase` -- function, 2 arguments
- `MacroRulePattern` -- bodied operator, prec. `KMaxPrecedence`
- `MacroRulePattern` -- function, 5 arguments
- `MacroRule` -- bodied operator, prec. `KMaxPrecedence`
- `MacroRule` -- function, 5 arguments
- `MacroSet` -- macro, 2 arguments
- `MathAbs` -- function, 1 argument
- `MathAdd` -- function, 2 arguments
- `MathAnd` -- macro, 1 or more arguments
- `MathArcCos` -- function, 1 argument
- `MathArcTan` -- function, 1 argument
- `MathBitCount` -- function, 1 argument
- `MathCeil` -- function, 1 argument
- `MathDebugInfo` -- function, 1 argument
- `MathDivide` -- function, 2 arguments
- `MathDiv` -- function, 2 arguments
- `MathFac` -- function, 1 argument
- `MathFloor` -- function, 1 argument
- `MathGcd` -- function, 2 arguments
- `MathGetExactBits` -- function, 1 argument
- `MathIsSmall` -- function, 1 argument
- `MathLibrary` -- function, 0 arguments
- `MathMod` -- function, 2 arguments
- `MathMultiply` -- function, 2 arguments
- `MathNegate` -- function, 1 argument
- `MathNot` -- function, 1 argument
- `MathNth` -- function, 2 arguments
- `MathOr` -- macro, 1 or more arguments
- `MathPi` -- function, 0 arguments
- `MathSetExactBits` -- function, 2 arguments
- `MathSign` -- function, 1 argument
- `MathSubtract` -- function, 2 arguments
- `MaxEvalDepth` -- function, 1 argument
- `Not` -- function, 1 argument
- `OSVersion` -- function, 0 arguments
- `OpLeftPrecedence` -- function, 1 argument
- `OpPrecedence` -- function, 1 argument
- `OpRightPrecedence` -- function, 1 argument
- `Or` -- macro, 1 or more arguments
- `PatchLoad` -- function, 1 argument
- `PatchString` -- function, 1 argument
- `PatternCreate` -- function, 2 arguments
- `PatternMatches` -- function, 2 arguments
- `Postfix` -- function, 2 arguments
- `Precision` -- function, 1 argument
- `Prefix` -- function, 2 arguments
- `PrettyPrinter` -- function, 1 or more arguments
- `Prog` -- macro, 1 or more arguments
- `ReadCmdLineString` -- function, 1 argument
- `ReadToken` -- function, 0 arguments
- `Read` -- function, 0 arguments
- `Replace` -- function, 3 arguments
- `Retract` -- function, 2 arguments
- `RightAssociative` -- function, 1 argument
- `RightPrecedence` -- function, 2 arguments
- `RuleBaseArgList` -- function, 2 arguments
- `RuleBaseDefined` -- function, 2 arguments
- `RuleBaseListed` -- macro, 2 arguments
- `RuleBase` -- macro, 2 arguments
- `RulePattern` -- bodied operator, prec. `KMaxPrecedence`
- `RulePattern` -- macro, 5 arguments
- `Rule` -- bodied operator, prec. `KMaxPrecedence`
- `Rule` -- macro, 5 arguments
- `Secure` -- macro, 1 argument
- `SetExtraInfo` -- function, 2 arguments
- `SetStringMid` -- function, 3 arguments
- `Set` -- macro, 2 arguments
- `ShiftLeft` -- function, 2 arguments
- `ShiftRight` -- function, 2 arguments
- `StaSiz` -- function, 0 arguments
- `StringMid` -- function, 3 arguments
- `String` -- function, 1 argument
- `Subst` -- bodied operator, prec. `KMaxPrecedence`
- `Subst` -- function, 3 arguments
- `SystemCall` -- function, 1 argument
- `Tail` -- function, 1 argument
- `ToBase` -- function, 2 arguments
- `ToFile` -- bodied operator, prec. `KMaxPrecedence`
- `ToFile` -- macro, 2 arguments
- `ToStdout` -- bodied operator, prec. `KMaxPrecedence`
- `ToStdout` -- macro, 1 argument
- `ToString` -- bodied operator, prec. `KMaxPrecedence`
- `ToString` -- macro, 1 argument
- `TraceRule` -- bodied operator, prec. `KMaxPrecedence`
- `TraceRule` -- macro, 2 arguments
- `TraceStack` -- macro, 1 argument
- `TrapError` -- macro, 2 arguments
- `Type` -- function, 1 argument
- `UnFence` -- function, 2 arguments
- `UnList` -- function, 1 argument
- `Use` -- function, 1 argument
- `Version` -- function, 0 arguments
- `While` -- bodied operator, prec. `KMaxPrecedence`
- `While` -- macro, 2 arguments
- `WriteString` -- function, 1 argument
- `Write` -- function, 1 or more arguments
- `XmlExplodeTag` -- function, 1 argument
- `XmlTokenizer` -- function, 0 arguments
- `_` -- infix operator, prec. `0`
- `_` -- prefix operator, prec. `0`
- ``` -- macro, 1 argument
- ``` -- prefix operator, prec. `0`