5
A predicate is a function that returns a boolean value, i.e. {True} or {False}. Predicates are
6
often used in patterns, For instance, a rule that only holds for a
7
positive integer would use a pattern such as {n_IsPositiveInteger}.
9
*CMD < --- test for "less than"
17
e1, e2 - expressions to be compared
21
The two expression are evaluated. If both results are numeric, they
22
are compared. If the first expression is smaller than the second one,
23
the result is {True} and it is {False} otherwise. If either of the expression is not numeric, after
24
evaluation, the expression is returned with evaluated arguments.
26
The word "numeric" in the previous paragraph has the following
27
meaning. An expression is numeric if it is either a number (i.e. {IsNumber} returns {True}), or the
28
quotient of two numbers, or an infinity (i.e. {IsInfinity} returns {True}).
39
*SEE IsNumber, IsInfinity, N
41
*CMD > --- test for "greater than"
49
e1, e2 - expressions to be compared
53
The two expression are evaluated. If both results are numeric, they
54
are compared. If the first expression is larger than the second one,
55
the result is {True} and it is {False} otherwise. If either of the expression is not numeric, after
56
evaluation, the expression is returned with evaluated arguments.
58
The word "numeric" in the previous paragraph has the following
59
meaning. An expression is numeric if it is either a number (i.e. {IsNumber} returns {True}), or the
60
quotient of two numbers, or an infinity (i.e. {IsInfinity} returns {True}).
71
*SEE IsNumber, IsInfinity, N
73
*CMD <= --- test for "less or equal"
81
e1, e2 - expressions to be compared
85
The two expression are evaluated. If both results are numeric, they
86
are compared. If the first expression is smaller than or equals the
87
second one, the result is {True} and it is {False} otherwise. If either of the expression is not
88
numeric, after evaluation, the expression is returned with evaluated
91
The word "numeric" in the previous paragraph has the following
92
meaning. An expression is numeric if it is either a number (i.e. {IsNumber} returns {True}), or the
93
quotient of two numbers, or an infinity (i.e. {IsInfinity} returns {True}).
104
*SEE IsNumber, IsInfinity, N
106
*CMD >= --- test for "greater or equal"
114
e1, e2 - expressions to be compared
118
The two expression are evaluated. If both results are numeric, they
119
are compared. If the first expression is larger than or equals the
120
second one, the result is {True} and it is {False} otherwise. If either of the expression is not
121
numeric, after evaluation, the expression is returned with evaluated
124
The word "numeric" in the previous paragraph has the following
125
meaning. An expression is numeric if it is either a number (i.e. {IsNumber} returns {True}), or the
126
quotient of two numbers, or an infinity (i.e. {IsInfinity} returns {True}).
137
*SEE IsNumber, IsInfinity, N
139
*CMD != --- test for "not equal"
147
e1, e2 - expressions to be compared
151
Both expression are evaluated and compared. If they turn out to be
152
equal, the result is {False}. Otherwise, the result
155
The expression {e1 != e2} is equivalent to {Not(e1 = e2)}.
166
*CMD = --- test for equality of expressions
174
e1, e2 - expressions to be compared
178
Both expression are evaluated and compared. If they turn out to be equal, the
179
result is {True}. Otherwise, the result is {False}. The function {Equals} does
182
Note that the test is on syntactic equality, not mathematical equality. Hence
183
even if the result is {False}, the expressions can still be
184
<i>mathematically</i> equal; see the examples below. Put otherwise, this
185
function tests whether the two expressions would be displayed in the same way
186
if they were printed.
190
In> e1 := (x+1) * (x-1);
202
*CMD Not --- logical negation
209
{expr} -- a boolean expression
213
Not returns the logical negation of the argument expr. If {expr} is
214
{False} it returns {True}, and if {expr} is {True}, {Not expr} returns {False}.
215
If the argument is neither {True} nor {False}, it returns the entire
216
expression with evaluated arguments.
229
*CMD And --- logical conjunction
234
And(a1, a2, a3, ..., aN)
238
{a}1, ..., {a}N - boolean values (may evaluate to {True} or {False})
242
This function returns {True} if all arguments are true. The
243
{And} operation is "lazy", i.e. it returns {False} as soon as a {False} argument
244
is found (from left to right). If an argument other than {True} or
245
{False} is encountered a new {And} expression is returned with all
246
arguments that didn't evaluate to {True} or {False} yet.
258
In> And(True,a,True,b)
263
*CMD Or --- logical disjunction
268
Or(a1, a2, a3, ..., aN)
272
{a}1, ..., {a}N - boolean expressions (may evaluate to {True} or {False})
276
This function returns {True} if an argument is encountered
277
that is true (scanning from left to right). The
278
{Or} operation is "lazy", i.e. it returns {True} as soon as a {True} argument
279
is found (from left to right). If an argument other than {True} or
280
{False} is encountered, an unevaluated {Or} expression is returned with all
281
arguments that didn't evaluate to {True} or {False} yet.
289
In> Or(False,a,b,True)
294
*CMD IsFreeOf --- test whether expression depends on variable
298
IsFreeOf({var, ...}, expr)
302
expr - expression to test
304
var - variable to look for in "expr"
308
This function checks whether the expression "expr" (after being
309
evaluated) depends on the variable "var". It returns {False} if this is the case and {True}
312
The second form test whether the expression depends on <i>any</i> of
313
the variables named in the list. The result is {True} if none of the variables appear in the expression and {False} otherwise.
317
In> IsFreeOf(x, Sin(x));
319
In> IsFreeOf(y, Sin(x));
321
In> IsFreeOf(x, D(x) a*x+b);
323
In> IsFreeOf({x,y}, Sin(x));
326
The third command returns {True} because the
327
expression {D(x) a*x+b} evaluates to {a}, which does not depend on {x}.
331
*CMD IsZeroVector --- test whether list contains only zeroes
338
list - list to compare against the zero vector
342
The only argument given to {IsZeroVector} should be
343
a list. The result is {True} if the list contains
344
only zeroes and {False} otherwise.
348
In> IsZeroVector({0, x, 0});
350
In> IsZeroVector({x-x, 1 - D(x) x});
353
*SEE IsList, ZeroVector
355
*CMD IsNonObject --- test whether argument is not an {Object()}
362
expr - the expression to examine
366
This function returns {True} if "expr" is not of
367
the form {Object(...)} and {False}
372
In fact, the result is always {True}.
376
*CMD IsEven --- test for an even integer
387
This function tests whether the integer "n" is even. An integer is
388
even if it is divisible by two. Hence the even numbers are 0, 2, 4, 6,
389
8, 10, etcetera, and -2, -4, -6, -8, -10, etcetera.
398
*SEE IsOdd, IsInteger
400
*CMD IsOdd --- test for an odd integer
411
This function tests whether the integer "n" is odd. An integer is
412
odd if it is not divisible by two. Hence the odd numbers are 1, 3, 5,
413
7, 9, etcetera, and -1, -3, -5, -7, -9, etcetera.
422
*SEE IsEven, IsInteger
424
*CMD IsFunction --- test for a composite object
431
expr - expression to test
435
This function tests whether "expr" is a composite object, i.e. not an
436
atom. This includes not only obvious functions such as {f(x)}, but also expressions such as {x+5} and lists.
445
*SEE IsAtom, IsList, Type
447
*CMD IsAtom --- test for an atom
454
expr - expression to test
458
This function tests whether "expr" is an atom. Numbers, strings, and
459
variables are all atoms.
468
*SEE IsFunction, IsNumber, IsString
470
*CMD IsString --- test for an string
477
expr - expression to test
481
This function tests whether "expr" is a string. A string is a text
482
within quotes, eg. {"duh"}.
491
*SEE IsAtom, IsNumber
493
*CMD IsNumber --- test for a number
500
expr - expression to test
504
This function tests whether "expr" is a number. There are two kinds
505
of numbers, integers (e.g. 6) and reals (e.g. -2.75 or 6.0). Note that a
506
complex number is represented by the {Complex}
507
function, so {IsNumber} will return {False}.
520
*SEE IsAtom, IsString, IsInteger, IsPositiveNumber, IsNegativeNumber, Complex
522
*CMD IsList --- test for a list
529
expr - expression to test
533
This function tests whether "expr" is a list. A list is a sequence
534
between curly braces, e.g. {{2, 3, 5}}.
545
*CMD IsNumericList --- test for a list of numbers
548
IsNumericList({list})
555
Returns {True} when called on a list of numbers or expressions that evaluate to numbers using {N()}. Returns {False} otherwise.
559
*CMD IsBound --- test for a bound variable
566
var - variable to test
570
This function tests whether the variable "var" is bound, ie. whether
571
it has been assigned a value. The argument "var" is not evaluated.
584
*CMD IsBoolean --- test for a Boolean value
587
IsBoolean(expression)
591
expression - an expression
595
IsBoolean returns True if the argument is of a boolean type.
596
This means it has to be either True, False, or an expression involving
597
functions that return a boolean result, e.g.
598
{=}, {>}, {<}, {>=}, {<=}, {!=}, {And}, {Not}, {Or}.
606
In> IsBoolean(a And b)
611
*CMD IsNegativeNumber --- test for a negative number
622
{IsNegativeNumber(n)} evaluates to {True} if $n$ is (strictly) negative, i.e.
623
if $n<0$. If {n} is not a number, the functions return {False}.
627
In> IsNegativeNumber(6);
629
In> IsNegativeNumber(-2.5);
632
*SEE IsNumber, IsPositiveNumber, IsNotZero, IsNegativeInteger, IsNegativeReal
634
*CMD IsNegativeInteger --- test for a negative integer
641
{n} - integer to test
645
This function tests whether the integer {n} is (strictly)
646
negative. The negative integers are -1, -2, -3, -4, -5, etcetera. If
647
{n} is not a integer, the function returns {False}.
651
In> IsNegativeInteger(31);
653
In> IsNegativeInteger(-2);
656
*SEE IsPositiveInteger, IsNonZeroInteger, IsNegativeNumber
658
*CMD IsPositiveNumber --- test for a positive number
669
{IsPositiveNumber(n)} evaluates to {True} if $n$ is (strictly) positive, i.e.
670
if $n>0$. If {n} is not a number the function returns {False}.
674
In> IsPositiveNumber(6);
676
In> IsPositiveNumber(-2.5);
679
*SEE IsNumber, IsNegativeNumber, IsNotZero, IsPositiveInteger, IsPositiveReal
681
*CMD IsPositiveInteger --- test for a positive integer
688
{n} - integer to test
692
This function tests whether the integer {n} is (strictly) positive. The
693
positive integers are 1, 2, 3, 4, 5, etcetera. If {n} is not a integer, the
694
function returns {False}.
698
In> IsPositiveInteger(31);
700
In> IsPositiveInteger(-2);
703
*SEE IsNegativeInteger, IsNonZeroInteger, IsPositiveNumber
705
*CMD IsNotZero --- test for a nonzero number
716
{IsNotZero(n)} evaluates to {True} if {n} is not zero. In case {n} is not a
717
number, the function returns {False}.
726
*SEE IsNumber, IsPositiveNumber, IsNegativeNumber, IsNonZeroInteger
728
*CMD IsNonZeroInteger --- test for a nonzero integer
735
{n} - integer to test
739
This function tests whether the integer {n} is not zero. If {n} is
740
not an integer, the result is {False}.
744
In> IsNonZeroInteger(0)
746
In> IsNonZeroInteger(-2)
749
*SEE IsPositiveInteger, IsNegativeInteger, IsNotZero
751
*CMD IsInfinity --- test for an infinity
758
{expr} - expression to test
762
This function tests whether {expr} is an infinity. This is only the
763
case if {expr} is either {Infinity} or {-Infinity}.
767
In> IsInfinity(10^1000);
769
In> IsInfinity(-Infinity);
774
*CMD IsPositiveReal --- test for a numerically positive value
781
{expr} - expression to test
785
This function tries to approximate "expr" numerically. It returns {True} if this approximation is positive. In case no
786
approximation can be found, the function returns {False}. Note that round-off errors may cause incorrect
791
In> IsPositiveReal(Sin(1)-3/4);
793
In> IsPositiveReal(Sin(1)-6/7);
795
In> IsPositiveReal(Exp(x));
798
The last result is because {Exp(x)} cannot be
799
numerically approximated if {x} is not known. Hence
800
Yacas can not determine the sign of this expression.
802
*SEE IsNegativeReal, IsPositiveNumber, N
804
*CMD IsNegativeReal --- test for a numerically negative value
811
{expr} - expression to test
815
This function tries to approximate {expr} numerically. It returns {True} if this approximation is negative. In case no
816
approximation can be found, the function returns {False}. Note that round-off errors may cause incorrect
821
In> IsNegativeReal(Sin(1)-3/4);
823
In> IsNegativeReal(Sin(1)-6/7);
825
In> IsNegativeReal(Exp(x));
828
The last result is because {Exp(x)} cannot be
829
numerically approximated if {x} is not known. Hence
830
Yacas can not determine the sign of this expression.
832
*SEE IsPositiveReal, IsNegativeNumber, N
834
*CMD IsConstant --- test for a constant
841
{expr} - some expression
845
{IsConstant} returns {True} if the
846
expression is some constant or a function with constant arguments. It
847
does this by checking that no variables are referenced in the
848
expression. {Pi} is considered a constant.
852
In> IsConstant(Cos(x))
854
In> IsConstant(Cos(2))
856
In> IsConstant(Cos(2+x))
859
*SEE IsNumber, IsInteger, VarList
865
*CMD MatchLinear --- match an expression to a polynomial of degree one in a variable
868
MatchLinear(variable,expression)
872
{variable} - variable to express the univariate polynomial in
874
{expression} - expression to match
878
MatchLinear tries to match an expression to a linear (degree less than
879
two) polynomial. The function returns True if it could match, and
880
it stores the resulting coefficients in the variables 'a' and 'b'
881
as a side effect. The function calling this predicate should declare
882
local variables 'a' and 'b' for this purpose.
883
MatchLinear tries to match to constant coefficients which don't
884
depend on the variable passed in, trying to find a form 'a*x+b'
885
with 'a' and 'b' not depending on 'x' if 'x' is given as the variable.
889
In> MatchLinear(x,(R+1)*x+(T-1))
893
In> MatchLinear(x,Sin(x)*x+(T-1))
899
*CMD HasExpr, HasExprArith, HasExprSome --- check for expression containing a subexpression
903
HasExprArith(expr, x)
904
HasExprSome(expr, x, list)
908
{expr} -- an expression
910
{x} -- a subexpression to be found
912
{list} -- list of function atoms to be considered "transparent"
916
The command {HasExpr} returns {True} if the expression {expr} contains a literal subexpression {x}. The expression is recursively traversed.
918
The command {HasExprSome} does the same, except it only looks at arguments of a given {list} of functions. All other functions become "opaque" (as if they do not contain anything).
920
{HasExprArith} is defined through {HasExprSome} to look only at arithmetic operations {+}, {-}, {*}, {/}.
922
Note that since the operators "{+}" and "{-}" are prefix as well as infix operators, it is currently required to use {Atom("+")} to obtain the unevaluated atom "{+}".
926
In> HasExpr(x+y*Cos(Ln(z)/z), z)
928
In> HasExpr(x+y*Cos(Ln(z)/z), Ln(z))
930
In> HasExpr(x+y*Cos(Ln(z)/z), z/Ln(z))
932
In> HasExprArith(x+y*Cos(Ln(x)/x), z)
934
In> HasExprSome({a+b*2,c/d},c/d,{List})
936
In> HasExprSome({a+b*2,c/d},c,{List})
939
*SEE FuncList, VarList, HasFunc
941
*CMD HasFunc, HasFuncArith, HasFuncSome --- check for expression containing a function
945
HasFuncArith(expr, func)
946
HasFuncSome(expr, func, list)
950
{expr} -- an expression
952
{func} -- a function atom to be found
954
{list} -- list of function atoms to be considered "transparent"
958
The command {HasFunc} returns {True} if the expression {expr} contains a function {func}. The expression is recursively traversed.
960
The command {HasFuncSome} does the same, except it only looks at arguments of a given {list} of functions. Arguments of all other functions become "opaque" (as if they do not contain anything).
962
{HasFuncArith} is defined through {HasFuncSome} to look only at arithmetic operations {+}, {-}, {*}, {/}.
964
Note that since the operators "{+}" and "{-}" are prefix as well as infix operators, it is currently required to use {Atom("+")} to obtain the unevaluated atom "{+}".
968
In> HasFunc(x+y*Cos(Ln(z)/z), Ln)
970
In> HasFunc(x+y*Cos(Ln(z)/z), Sin)
972
In> HasFuncArith(x+y*Cos(Ln(x)/x), Cos)
974
In> HasFuncArith(x+y*Cos(Ln(x)/x), Ln)
976
In> HasFuncSome({a+b*2,c/d},/,{List})
978
In> HasFuncSome({a+b*2,c/d},*,{List})
981
*SEE FuncList, VarList, HasExpr