Div, Mod | Division with remainder |
Gcd | Greatest common divisor |
Lcm | Least common multiple |
<<, >> | Shift operators |
FromBase, ToBase | Conversion from/to non-decimal base |
Precision | Sets the precision |
GetPrecision | Returns the current precision |
N | Numerical approximation |
Rationalize | Convert floating point numbers to fractions |
IsPrime | Test whether argument is a prime number |
IsPrimePower | Test whether argument is a prime power |
Factors | Factorization |
Factor | Factorization, in pretty form |
PAdicExpand | p-adic expansion |
ContFrac | Continued fraction expansion |
Decimal | Decimal representation of a rational |
TruncRadian | Remainder modulo 2*Pi |
Floor | Round a number downwards |
Ceil | Round a number upwards |
Round | Round a number to the nearest integer |
Pslq | Search for integer relations between reals |
If Div(x,y) returns "a" and Mod(x,y) equals "b", then these numbers satisfy x = a*y + b and 0 <= b < y.
In> Div(5,3) Out> 1; In> Mod(5,3) Out> 2; |
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) |
If the second calling form is used, Gcd will return the greatest common divisor of all the integers or polynomials in "list". It uses the identity
Gcd({a,b,c}) = Gcd(Gcd(a,b),c) |
In> Gcd(55,10) Out> 5; In> Gcd({60,24,120}) Out> 12; |
Lcm(n,m) = Div(n*m,Gcd(n,m)) |
In> Lcm(60,24) Out> 120; |
In> 1 << 10 Out> 1024; In> -1024 >> 10 Out> -1; |
These functions use the p-adic expansion capabilities of the built-in arbitrary precision math libraries.
In> FromBase(2,111111) Out> 63; In> ToBase(16,255) Out> ff; |
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; |
In> GetPrecision(); Out> 10; In> Precision(20); Out> True; In> GetPrecision(); Out> 20; |
Application of the N operator will make Yacas calculate floating point representations of functions whenever possible. In addition, the variable Pi is bound to the value of pi up to the required precision.
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; |
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.
In> {1.2,3.123,4.5} Out> {1.2,3.123,4.5}; In> Rationalize(%) Out> {6/5,3123/1000,9/2}; |
This function essentially checks for all integers between 2 and the square root of "n" whether they divide "n", and hence may take a long time for large numbers.
In> IsPrime(1) Out> False; In> IsPrime(2) Out> True; In> IsPrime(10) Out> False; In> IsPrime(23) Out> True; In> Select("IsPrime", 1 .. 100) Out> {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; |
This function essentially checks for all integers between 2 and the square root of "n" for the largest divisor, and then tests whether "n" is a power of this divisor. So it will take a long time for large numbers.
In> IsPrimePower(9) Out> True; In> IsPrimePower(10) Out> False; In> Select("IsPrimePower", 1 .. 50) Out> {2,3,4,5,7,8,9,11,13,16,17,19,23,25,27,29,31,32,37,41,43,47,49}; |
The factorization is returned as a list of pairs. The first member of each pair is the factor, while the second member denotes the power to which this factor should be raised. So the factorization "x = p1^n1 * ... * p9^n9" is returned as {{p1,n1}, ..., {p9,n9}}.
In> Factors(24); Out> {{2,3},{3,1}}; In> Factors(2*x^3 + 3*x^2 - 1); Out> {{2,1},{x+1,2},{x-1/2,1}}; |
In> PrettyForm(Factor(24)); 3 2 * 3 Out> True; In> PrettyForm(Factor(2*x^3 + 3*x^2 - 1)); 2 / 1 \ 2 * ( x + 1 ) * | x - - | \ 2 / Out> True; |
In> PrettyForm(PAdicExpand(1234, 10)); 2 3 3 * 10 + 2 * 10 + 10 + 4 Out> True; In> PrettyForm(PAdicExpand(x^3, x-1)); 2 3 3 * ( x - 1 ) + 3 * ( x - 1 ) + ( x - 1 ) + 1 Out> True; |
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.
In> PrettyForm(ContFrac(N(Pi))) 1 --------------------------- + 3 1 ----------------------- + 7 1 ------------------ + 15 1 -------------- + 1 1 -------- + 292 rest + 1 Out> True; In> PrettyForm(ContFrac(x^2+x+1, 3)) x ---------------- + 1 x 1 - ------------ x -------- + 1 rest + 1 Out> True; |
In> Decimal(1/22) Out> {0,0,{4,5}}; In> N(1/22,30) Out> 0.045454545454545454545454545454; |
The library uses the formula
/ r \ r - MathFloor| ------ | * 2 * Pi \ 2 * Pi / |
In> 2*Pi() Out> 6.283185307; In> TruncRadian(6.28) Out> 6.28; In> TruncRadian(6.29) Out> 0.0068146929; |
In> Floor(1.1) Out> 1; In> Floor(-1.1) Out> -2; |
In> Ceil(1.1) Out> 2; In> Ceil(-1.1) Out> -1; |
In> Round(1.49) Out> 1; In> Round(1.51) Out> 2; In> Round(-1.49) Out> -1; In> Round(-1.51) Out> -2; |
The numbers in "xlist" must evaluate to floating point numbers if the N operator is applied on them.
In> Pslq({ 2*Pi+3*Exp(1) , Pi , Exp(1) },20) Out> {1,-2,-3}; |