Sin, Cos, Tan | trigonometric functions |
ArcSin, ArcCos, ArcTan | inverse trigonometric functions |
Exp | exponential function |
Ln | natural logarithm |
Sqrt | square root |
Abs | absolute value or modulus |
Sign | sign of a number |
Complex | construct a complex number |
Re | real part of a complex number |
Im | imaginary part of a complex number |
I | imaginary unit |
Conjugate | complex conjugate |
Arg | argument of a complex number |
RootsOfUnity | find the n complex roots of unity |
!, !!, ***, Subfactorial | factorial and related functions |
Bin | binomial coefficients |
Eulerian | Eulerian numbers |
Add | find sum of a list of values |
Sum | find sum of a sequence |
Average | average of a list of values |
Factorize | product of a list of values |
Min | minimum of a number of values |
Max | maximum of a number of values |
IsZero | test whether argument is zero |
IsRational | test whether argument is a rational |
Numer | numerator of an expression |
Denom | denominator of an expression |
Commutator | commutator of two objects |
Taylor | univariate Taylor series expansion |
InverseTaylor | Taylor expansion of inverse |
ReversePoly | solve h(f(x))=g(x)+O(x^n) for h |
BigOh | drop all terms of a certain order in a polynomial |
Newton | solve an equation numerically with Newton's method |
D | differentiation |
Curl | curl of a vector field |
Diverge | divergence of a vector field |
Integrate | integration |
Simplify | try to simplify an expression |
RadSimp | simplify expression with nested radicals |
Rationalize | convert floating point numbers to fractions |
Solve | solve one or more algebraic equations |
SuchThat | find a value which makes some expression zero |
Eliminate | substitute and simplify |
PSolve | solve a polynomial equation |
Pi() | numerical approximation of Pi |
Random, RandomSeed | (pseudo-)random number generator |
RngCreate, RngSeed, Rng | manipulate random number generators as objects |
Limit | limit of an expression |
TrigSimpCombine | combine products of trigonometric functions |
LagrangeInterpolant | polynomial interpolation |
Fibonacci | Fibonacci sequence |
Sin(x) Cos(x) Tan(x) |
Yacas knows some trigonometric identities, so it can simplify to exact results even if N is not used. This is the case, for instance, when the argument is a multiple of Pi/6 or Pi/4.
These functions are threaded, meaning that if the argument x is a list, the function is applied to all entries in the list.
In> Sin(1) Out> Sin(1); In> N(Sin(1),20) Out> 0.84147098480789650665; In> Sin(Pi/4) Out> Sqrt(2)/2; |
ArcSin(x) ArcCos(x) ArcTan(x) |
Note that the number y is not unique. For instance, Sin(0) and Sin(Pi) both equal 0, so what should ArcSin(0) be? In Yacas, it is agreed that the value of ArcSin(x) should be in the interval [-Pi/2, Pi/2]. The same goes for ArcTan(x). However, ArcCos(x) is in the interval [0,Pi].
Usually, Yacas leaves these functions alone unless it is forced to do a numerical evaluation by the N function. If the argument is -1, 0, or 1 however, Yacas will simplify the expression. If the argument is complex, the expression will be rewritten using the Ln function.
These functions are threaded, meaning that if the argument x is a list, the function is applied to all entries in the list.
In> ArcSin(1) Out> Pi/2; In> ArcSin(1/3) Out> ArcSin(1/3); In> Sin(ArcSin(1/3)) Out> 1/3; In> N(ArcSin(0.75)) Out> 0.848062; In> N(Sin(%)) Out> 0.7499999477; |
Exp(x) |
This function is threaded, meaning that if the argument x is a list, the function is applied to all entries in the list.
In> Exp(0) Out> 1; In> Exp(I*Pi) Out> -1; In> N(Exp(1)) Out> 2.7182818284; |
Ln(x) |
This function is threaded, meaning that if the argument x is a list, the function is applied to all entries in the list.
In> Ln(1) Out> 0; In> Ln(Exp(x)) Out> x; In> D(x) Ln(x) Out> 1/x; |
Sqrt(x) |
This function is threaded, meaning that if the argument x is a list, the function is applied to all entries in the list.
In> Sqrt(16) Out> 4; In> Sqrt(15) Out> Sqrt(15); In> N(Sqrt(15)) Out> 3.8729833462; In> Sqrt(4/9) Out> 2/3; In> Sqrt(-1) Out> Complex(0,1); |
Abs(x) |
This function is connected to the Sign function by the identity "Abs(x) * Sign(x) = x" for real "x".
This function is threaded, meaning that if the argument x is a list, the function is applied to all entries in the list.
In> Abs(2); Out> 2; In> Abs(-1/2); Out> -1/2; In> Abs(3+4*I); Out> 5; |
Sign(x) |
This function is connected to the Abs function by the identity Abs(x)*Sign(x)=x for real x.
This function is threaded, meaning that if the argument x is a list, the function is applied to all entries in the list.
In> Sign(2) Out> 1; In> Sign(-3) Out> -1; In> Sign(0) Out> 1; In> Sign(-3) * Abs(-3) Out> -3; |
Complex(r, c) |
c -- imaginary part
Note that, at the moment, many functions in Yacas assume that all numbers are real unless it is obvious that it is a complex number. Hence Im(Sqrt(x)) evaluates to 0 which is only true for nonnegative "x".
In> I Out> Complex(0,1); In> 3+4*I Out> Complex(3,4); In> Complex(-2,0) Out> -2; |
Re(x) |
In> Re(5) Out> 5; In> Re(I) Out> 0; In> Re(Complex(3,4)) Out> 3; |
Im(x) |
In> Im(5) Out> 0; In> Im(I) Out> 1; In> Im(Complex(3,4)) Out> 4; |
I |
In> I Out> Complex(0,1); In> I = Sqrt(-1) Out> True; |
Conjugate(x) |
In> Conjugate(2) Out> 2; In> Conjugate(Complex(a,b)) Out> Complex(a,-b); |
Arg(x) |
In> Arg(2) Out> 0; In> Arg(-1) Out> Pi; In> Arg(1+I) Out> Pi/4; |
RootsOfUnity(n) |
In> RootsOfUnity(3) Out> {Complex(-1/2,Sqrt(3/4)),Complex(-1/2,-Sqrt(3/4)),1}; In> RootsOfUnity(1) Out> {1}; In> RootsOfUnity(2) Out> {-1,1}; |
n! n!! a *** b Subfactorial(m) |
The "double factorial" function n!! calculates n*(n-2)*(n-4)*.... This product terminates either with 1 or with 2 depending on whether n is odd or even. If n=0 the function returns 1.
The "partial factorial" function a *** b calculates the product a*(a+1)*... which is terminated at the least integer not greater than b. The arguments a and b do not have to be integers; for integer arguments, a *** b = b! /(a-1)!. This function is sometimes a lot faster than evaluating the two factorials, especially if a and b are close together. If a>b the function returns 1.
The Subfactorial function can be interpreted as the number of permutations of m objects in which no object appears in its natural place, also called "derangements."
The factorial functions are threaded, meaning that if the argument n is a list, the function will be applied to each element of the list.
Note: For reasons of Yacas syntax, the factorial sign ! cannot precede other non-letter symbols such as + or *. Therefore, you should enter a space after ! in expressions such as x! +1.
The factorial functions terminate and print an error message if the arguments are too large (currently the limit is n<65535) because exact factorials of such large numbers are computationally expensive and most probably not useful. One can call LnGammaNum() to evaluate logarithms of such factorials to desired precision.
In> 5! Out> 120; In> 1 * 2 * 3 * 4 * 5 Out> 120; In> (1/2)! Out> Sqrt(Pi)/2; In> 7!!; Out> 105; In> 1/3 *** 10; Out> 17041024000/59049; In> Subfactorial(10) Out> 1334961; |
Bin(n, m) |
This is equal to the number of ways to choose "m" objects out of a total of "n" objects if order is not taken into account. The binomial coefficient is defined to be zero if "m" is negative or greater than "n"; Bin(0,0)=1.
In> Bin(10, 4) Out> 210; In> 10! / (4! * 6!) Out> 210; |
Eulerian(n,m) |
In> Eulerian(6,2) Out> 302; In> Eulerian(10,9) Out> 1; |
Add(val1, val2, ...) Add({list}) |
{list} -- list of expressions to add
In> Add(1,4,9); Out> 14; In> Add(1 .. 10); Out> 55; |
Sum(var, from, to, body) |
from -- integer value to iterate from
to -- integer value to iterate up to
body -- expression to evaluate for each iteration
Warning: Sum does not evaluate its arguments var and body until the actual loop is run.
In> Sum(i, 1, 3, i^2); Out> 14; |
Average(list) |
In> Average({1,2,3,4,5}); Out> 3; In> Average({2,6,7}); Out> 5; |
Factorize(list) Factorize(var, from, to, body) |
var -- variable to iterate over
from -- integer value to iterate from
to -- integer value to iterate up to
body -- expression to evaluate for each iteration
If the second calling sequence is used, the expression "body" is evaluated while the variable "var" ranges over all integers from "from" up to "to", and the product of all the results is returned. Obviously, "to" should be greater than or equal to "from".
In> Factorize({1,2,3,4}); Out> 24; In> Factorize(i, 1, 4, i); Out> 24; |
Min(x,y) Min(list) |
list -- list of values from which the minimum is sought
In> Min(2,3); Out> 2; In> Min({5,8,4}); Out> 4; |
Max(x,y) Max(list) |
list -- list of values from which the maximum is sought
In> Max(2,3); Out> 3; In> Max({5,8,4}); Out> 8; |
IsZero(n) |
In> IsZero(3.25) Out> False; In> IsZero(0) Out> True; In> IsZero(x) Out> False; |
IsRational(expr) |
In> IsRational(5) Out> False; In> IsRational(2/7) Out> True; In> IsRational(a/b) Out> True; In> IsRational(x + 1/x) Out> False; |
Numer(expr) |
In> Numer(2/7) Out> 2; In> Numer(a / x^2) Out> a; In> Numer(5) Out> 5; |
Denom(expr) |
In> Denom(2/7) Out> 7; In> Denom(a / x^2) Out> x^2; In> Denom(5) Out> 1; |
Commutator(a, b) |
In> Commutator(2,3) Out> 0; In> PrettyPrinter("PrettyForm"); True In> A := { {0,x}, {0,0} } / \ | ( 0 ) ( x ) | | | | ( 0 ) ( 0 ) | \ / In> B := { {y,0}, {0,z} } / \ | ( y ) ( 0 ) | | | | ( 0 ) ( z ) | \ / In> Commutator(A,B) / \ | ( 0 ) ( x * z - y * x ) | | | | ( 0 ) ( 0 ) | \ / |
Taylor(var, at, order) expr |
at -- point to get Taylor series around
order -- order of approximation
expr -- expression to get Taylor series for
In> PrettyForm(Taylor(x,0,9) Sin(x)) 3 5 7 9 x x x x x - -- + --- - ---- + ------ 6 120 5040 362880 Out> True; |
InverseTaylor(var, at, order) expr |
at -- point to get inverse Taylor series around
order -- order of approximation
expr -- expression to get inverse Taylor series for
In> PrettyPrinter("PrettyForm") True In> exp1 := Taylor(x,0,7) Sin(x) 3 5 7 x x x x - -- + --- - ---- 6 120 5040 In> exp2 := InverseTaylor(x,0,7) ArcSin(x) 5 7 3 x x x --- - ---- - -- + x 120 5040 6 In> Simplify(exp1-exp2) 0 |
ReversePoly(f, g, var, newvar, degree) |
var -- a variable
newvar -- a new variable to express the result in
degree -- the degree of the required solution
This function is used to determine the Taylor series expansion of the inverse of a function "f": if we take "g(var)=var", then "h(f(var))=var" (up to order "degree"), so "h" will be the inverse of "f".
In> f(x):=Eval(Expand((1+x)^4)) Out> True; In> g(x) := x^2 Out> True; In> h(y):=Eval(ReversePoly(f(x),g(x),x,y,8)) Out> True; In> BigOh(h(f(x)),x,8) Out> x^2; In> h(x) Out> (-2695*(x-1)^7)/131072+(791*(x-1)^6) /32768 +(-119*(x-1)^5)/4096+(37*(x-1)^4) /1024+(-3*(x-1)^3)/64+(x-1)^2/16; |
BigOh(poly, var, degree) |
var -- a free variable
degree -- positive integer
In> BigOh(1+x+x^2+x^3,x,2) Out> x+1; |
Newton(expr, var, initial, accuracy) Newton(expr, var, initial, accuracy,min,max) |
var -- free variable to adjust to find a zero
initial -- initial value for "var" to use in the search
accuracy -- minimum required accuracy of the result
min -- minimum value for "var" to use in the search
max -- maximum value for "var" to use in the search
The function will iterate using Newton's method until it estimates that it has come within a distance accuracy of the correct solution, and then it will return its best guess. In particular, it may loop forever if the algorithm does not converge.
When min and max are supplied, the Newton iteration takes them into account by returning Fail if it failed to find a root in the given range. Note this doesn't mean there isn't a root, just that this algorithm failed to find it due to the trial values going outside of the bounds.
In> Newton(Sin(x),x,3,0.0001) Out> 3.1415926535; In> Newton(x^2-1,x,2,0.0001,-5,5) Out> 1; In> Newton(x^2+1,x,2,0.0001,-5,5) Out> Fail; |
D(var) expr D(list) expr D(var,n) expr |
list -- a list of variables
expr -- expression to take derivatives of
n -- order of derivative
The D operator is threaded in both var and expr. This means that if either of them is a list, the function is applied to each entry in the list. The results are collected in another list which is returned. If both var and expr are a list, their lengths should be equal. In this case, the first entry in the list expr is differentiated with respect to the first entry in the list var, the second entry in expr is differentiated with respect to the second entry in var, and so on.
The D operator returns the original function if n=0, a common mathematical idiom that simplifies many formulae.
In> D(x)Sin(x*y) Out> y*Cos(x*y); In> D({x,y,z})Sin(x*y) Out> {y*Cos(x*y),x*Cos(x*y),0}; In> D(x,2)Sin(x*y) Out> -Sin(x*y)*y^2; In> D(x){Sin(x),Cos(x)} Out> {Cos(x),-Sin(x)}; |
Curl(vector, basis) |
basis -- list of variables forming the basis
Curl(f,x) = { D(x[2]) f[3] - D(x[3]) f[2], D(x[3]) f[1] - D(x[1]) f[3], D(x[1]) f[2] - D(x[2]) f[1] } |
In> Curl({x*y,x*y,x*y},{x,y,z}) Out> {x,-y,y-x}; |
Diverge(vector, basis) |
basis -- list of variables forming the basis
Diverge(f,x) = D(x[1]) f[1] + ... + D(x[n]) f[n], |
In> Diverge({x*y,x*y,x*y},{x,y,z}) Out> y+x; |
Integrate(var, x1, x2) expr Integrate(var) expr |
x1 -- first point of definite integration
x2 -- second point of definite integration
expr -- expression to integrate
Some simple integration rules have currently been implemented. Polynomials, quotients of polynomials, the functions Sin, Cos, Exp, and Ln, and products of these functions with polynomials can be integrated.
In> Integrate(x,a,b) Cos(x) Out> Sin(b)-Sin(a); In> Integrate(x) Cos(x) Out> Sin(x)+C9; |
Simplify(expr) |
In> a*b*a^2/b-a^3 Out> (b*a^3)/b-a^3; In> Simplify(a*b*a^2/b-a^3) Out> 0; |
RadSimp(expr) |
It does this by trying all possible combinations for e1, e2, ... Every possibility is numerically evaluated using N and compared with the numerical evaluation of "expr". If the approximations are equal (up to a certain margin), this possibility is returned. Otherwise, the expression is returned unevaluated.
Note that due to the use of numerical approximations, there is a small chance that the expression returned by RadSimp is close but not equal to expr. The last example underneath illustrates this problem. Furthermore, if the numerical value of expr is large, the number of possibilities becomes exorbitantly big so the evaluation may take very long.
In> RadSimp(Sqrt(9+4*Sqrt(2))) Out> Sqrt(8)+1; In> RadSimp(Sqrt(5+2*Sqrt(6)) \ +Sqrt(5-2*Sqrt(6))) Out> Sqrt(12); In> RadSimp(Sqrt(14+3*Sqrt(3+2 *Sqrt(5-12*Sqrt(3-2*Sqrt(2)))))) Out> Sqrt(2)+3; |
But this command may yield incorrect results:
In> RadSimp(Sqrt(1+10^(-6))) Out> 1; |
Rationalize(expr) |
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}; |
Solve(eq, var) Solve(eqlist, varlist) |
var -- single variable
eqlist -- list of identity equations
varlist -- list of variables
The first calling sequence solves the equation "eq" for the variable "var". Use the == operator to form the equation. The value of "var" which satisfies the equation, is returned. Note that only one solution is found and returned.
To solve a system of equations, the second form should be used. It solves the system of equations contained in the list "eqlist" for the variables appearing in the list "varlist". A list of results is returned, and each result is a list containing the values of the variables in "varlist". Again, at most a single solution is returned.
The task of solving a single equation is simply delegated to SuchThat. Multiple equations are solved recursively: firstly, an equation is sought in which one of the variables occurs exactly once; then this equation is solved with SuchThat; and finally the solution is substituted in the other equations by Eliminate decreasing the number of equations by one. This suffices for all linear equations and a large group of simple nonlinear equations.
In> Solve(a+x*y==z,x) Out> (z-a)/y; In> Solve({a*x+y==0,x+z==0},{x,y}) Out> {{-z,z*a}}; |
This means that "x = (z-a)/y" is a solution of the first equation and that "x = -z", "y = z*a" is a solution of the systems of equations in the second command.
An example which Solve cannot solve:
In> Solve({x^2-x == y^2-y,x^2-x == y^3+y},{x,y}); Out> {}; |
SuchThat(expr, var) |
var -- variable (or subexpression) to solve for
Basically, only expressions in which "var" occurs only once are handled; in fact, SuchThat may even give wrong results if the variables occurs more than once. This is a consequence of the implementation, which repeatedly applies the inverse of the top function until the variable "var" is reached.
In> SuchThat(a+b*x, x) Out> (-a)/b; In> SuchThat(Cos(a)+Cos(b)^2, Cos(b)) Out> Cos(a)^(1/2); In> Expand(a*x+b*x+c, x) Out> (a+b)*x+c; In> SuchThat(%, x) Out> (-c)/(a+b); |
Eliminate(var, value, expr) |
value -- new value of "var"
expr -- expression in which the substitution should take place
In> Subst(Cos(b), c) (Sin(a)+Cos(b)^2/c) Out> Sin(a)+c^2/c; In> Eliminate(Cos(b), c, Sin(a)+Cos(b)^2/c) Out> Sin(a)+c; |
PSolve(poly, var) |
var -- a variable
In> PSolve(b*x+a,x) Out> -a/b; In> PSolve(c*x^2+b*x+a,x) Out> {(Sqrt(b^2-4*c*a)-b)/(2*c),(-(b+ Sqrt(b^2-4*c*a)))/(2*c)}; |
Pi() |
In> Pi() Out> 3.14159265358979323846; In> Sin(3*Pi/2) Out> -1; In> Sin(3*Pi()/2) Out> Sin(4.7123889804); In> Precision(35) Out> True; In> Pi() Out> 3.14159265358979323846264338327950288; |
Random() RandomSeed(init) |
*PARAMS init -- positive integer, initial random seed
The random number generator can be initialized by calling RandomSeed with an integer value. Each seed value will result in the same sequence of pseudo-random numbers.
RngCreate() RngCreate(init) RngCreate(option=value,...) RngSeed(r, init) Rng(r) |
option -- atom, option name
value -- atom, option value
r -- a list, RNG object
RngCreate returns a list which is a well-formed RNG object. Its value should be saved in a variable and used to call Rng and RngSeed.
Rng(r) returns a floating-point random number between 0 and 1 and updates the RNG object r. (Currently, the Gaussian option makes a RNG return a complex random number instead of a real random number.)
RngSeed(r,init) re-initializes the RNG object r with the seed value init. The seed value should be a positive integer.
The RngCreate function accepts several options as arguments. Currently the following options are available:
If the initial seed is not specified, the value of 76544321 will be used.
The gauss option will create a RNG object that generates pairs of Gaussian distributed random numbers as a complex random number. The real and the imaginary parts of this number are independent random numbers taken from a Gaussian (i.e. "normal") distribution with unit variance.
Note that unlike the global Random function, the RNG objects created with RngCreate are independent RNGs and do not affect each other. They generate independent streams of pseudo-random numbers. However, the Random function is slightly faster.
In> r1:=RngCreate(seed=1,dist=gauss) Out> {"GaussianRNGDist","RNGEngine'LCG'2",{1}} In> Rng(r1) Out> Complex(-1.6668466417,0.228904004); In> Rng(r1); Out> Complex(0.0279296109,-0.5382405341); |
In> [r2:=RngCreate(engine=advanced);Rng(r2);] Out> 0.3653615377; |
In> RngSeed(r1, 1) Out> True; In> Rng(r1) Out> Complex(-1.6668466417,0.228904004); |
Limit(var, val) expr Limit(var, val, dir) expr |
val -- a number
dir -- a direction (Left or Right)
expr -- an expression
The second calling sequence is used for unidirectional limits. If one gives "dir" the value Left, the limit is taken as "var" approaches "val" from the positive infinity; and Right will take the limit from the negative infinity.
In> Limit(x,0) Sin(x)/x Out> 1; In> Limit(x,0) (Sin(x)-Tan(x))/(x^3) Out> -1/2; In> Limit(x,0) 1/x Out> Undefined; In> Limit(x,0,Left) 1/x Out> -Infinity; In> Limit(x,0,Right) 1/x Out> Infinity; |
TrigSimpCombine(expr) |
This function is used in for instance Integrate, to bring down the expression into a simpler form that hopefully can be integrated easily.
In> PrettyPrinter("PrettyForm"); True In> TrigSimpCombine(Cos(a)^2+Sin(a)^2) 1 In> TrigSimpCombine(Cos(a)^2-Sin(a)^2) Cos( -2 * a ) Out> In> TrigSimpCombine(Cos(a)^2*Sin(b)) Sin( b ) Sin( -2 * a + b ) -------- + ----------------- 2 4 Sin( -2 * a - b ) - ----------------- 4 |
LagrangeInterpolant(xlist, ylist, var) |
ylist -- list of function values
var -- free variable for resulting polynomial
The lists "xlist" and "ylist" should be of equal length. Furthermore, the entries of "xlist" should be all distinct to ensure that there is one and only one solution.
This routine uses the Lagrange interpolant formula to build up the polynomial.
In> f := LagrangeInterpolant({0,1,2}, \ {0,1,1}, x); Out> (x*(x-1))/2-x*(x-2); In> Eval(Subst(x,0) f); Out> 0; In> Eval(Subst(x,1) f); Out> 1; In> Eval(Subst(x,2) f); Out> 1; In> PrettyPrinter("PrettyForm"); True In> LagrangeInterpolant({x1,x2,x3}, {y1,y2,y3}, x) y1 * ( x - x2 ) * ( x - x3 ) ---------------------------- ( x1 - x2 ) * ( x1 - x3 ) y2 * ( x - x1 ) * ( x - x3 ) + ---------------------------- ( x2 - x1 ) * ( x2 - x3 ) y3 * ( x - x1 ) * ( x - x2 ) + ---------------------------- ( x3 - x1 ) * ( x3 - x2 ) |
Fibonacci(n) |
The Fibonacci sequence is 1, 1, 2, 3, 5, 8, 13, 21, ... where every number is the sum of the two preceding numbers. Formally, it is defined by F(1)=1, F(2)=1, and F(n+1)=F(n)+F(n-1), where F(n) denotes the n-th Fibonacci number.
In> Fibonacci(4) Out> 3; In> Fibonacci(8) Out> 21; In> Table(Fibonacci(i), i, 1, 10, 1) Out> {1,1,2,3,5,8,13,21,34,55}; |