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:
In> Lcm(60,24)
Out> 120;
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

Standard math library
Calling Sequence:
Decimal(frac)
Parameters:
frac - a rational number
Description:
Decimal returns 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.
Examples:
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: