2 * Introduction to Maxima's Database::
3 * Functions and Variables for Properties::
4 * Functions and Variables for Facts::
5 * Functions and Variables for Predicates::
8 @c -----------------------------------------------------------------------------
9 @node Introduction to Maxima's Database, Functions and Variables for Properties, Maxima's Database, Maxima's Database
10 @section Introduction to Maxima's Database
11 @c -----------------------------------------------------------------------------
13 @c -----------------------------------------------------------------------------
14 @node Functions and Variables for Properties, Functions and Variables for Facts, Introduction to Maxima's Database, Maxima's Database
15 @section Functions and Variables for Properties
16 @c -----------------------------------------------------------------------------
18 @c -----------------------------------------------------------------------------
20 @defvr {Property} alphabetic
22 @code{alphabetic} is a property type recognized by @mrefdot{declare}@w{}
23 The expression @code{declare(@var{s}, alphabetic)} tells Maxima to recognize
24 as alphabetic all of the characters in @var{s}, which must be a string.
26 See also @ref{Identifiers}.
32 @c declare ("~`@", alphabetic);
33 @c xx~yy`@ + @yy`xx + `xx@@yy~;
37 (%i1) xx\~yy\`\@@ : 1729;
39 (%i2) declare ("~`@@", alphabetic);
41 (%i3) xx~yy`@@ + @@yy`xx + `xx@@@@yy~;
42 (%o3) `xx@@@@yy~ + @@yy`xx + 1729
44 (%o4) [@@yy`xx, `xx@@@@yy~]
47 @opencatbox{Categories:}
48 @category{Declarations and inferences}
52 @c -----------------------------------------------------------------------------
54 @defvr {Property} bindtest
56 The command @code{declare(@var{x}, bindtest)} tells Maxima to trigger an error
57 when the symbol @var{x} is evaluated unbound.
61 @c declare (aa, bindtest);
69 (%i2) declare (aa, bindtest);
73 -- an error. Quitting. To debug this try debugmode(true);
81 @c NEEDS EXPANSION, CLARIFICATION, AND EXAMPLES
82 @c CROSS REF declare, properties, ETC
84 @c -----------------------------------------------------------------------------
86 @deffn {Property} constant
88 @code{declare(@var{a}, constant)} declares @var{a} to be a constant. The
89 declaration of a symbol to be constant does not prevent the assignment of a
90 nonconstant value to the symbol.
92 See @mref{constantp} and @mrefdot{declare}
93 @c WHAT EXACTLY ARE THE CONSEQUENCES OF DECLARING AN ATOM TO BE CONSTANT ??
98 (%i1) declare(c, constant);
108 @opencatbox{Categories:}
109 @category{Declarations and inferences}
114 @c -----------------------------------------------------------------------------
116 @deffn {Function} constantp (@var{expr})
118 Returns @code{true} if @var{expr} is a constant expression, otherwise returns
120 @c WHAT DOES MAXIMA KNOW ABOUT CONSTANT EXPRESSIONS ??
122 An expression is considered a constant expression if its arguments are
123 numbers (including rational numbers, as displayed with @code{/R/}),
124 symbolic constants such as @mrefcomma{%pi} @mrefcomma{%e} and @mrefcomma{%i}@w{}
125 variables bound to a constant or declared constant by @mrefcomma{declare}@w{}
126 or functions whose arguments are constant.
128 @code{constantp} evaluates its arguments.
130 See the property @mref{constant} which declares a symbol to be constant.
135 @c constantp (7 * sin(2));
136 @c constantp (rat (17/29));
137 @c constantp (%pi * sin(%e));
138 @c constantp (exp (x));
139 @c declare (x, constant);
140 @c constantp (exp (x));
141 @c constantp (foo (x) + bar (%e) + baz (2));
144 (%i1) constantp (7 * sin(2));
146 (%i2) constantp (rat (17/29));
148 (%i3) constantp (%pi * sin(%e));
150 (%i4) constantp (exp (x));
152 (%i5) declare (x, constant);
154 (%i6) constantp (exp (x));
156 (%i7) constantp (foo (x) + bar (%e) + baz (2));
161 @opencatbox{Categories:}
162 @category{Predicate functions}
167 @c NEEDS EXPANSION, CLARIFICATION, AND EXAMPLES
168 @c THIS ITEM IS EXTREMELY IMPORTANT
169 @c ENSURE THAT ALL KEYWORDS RECOGNIZED BY declare HAVE THEIR OWN DOCUMENTATION ITEMS !!
170 @c ALSO: HOW TO FIND THE LIST OF ALL SYMBOLS WHICH HAVE A GIVEN PROPERTY ??
172 @c -----------------------------------------------------------------------------
174 @deffn {Function} declare (@var{a_1}, @var{p_1}, @var{a_2}, @var{p_2}, @dots{})
176 Assigns the atom or list of atoms @var{a_i} the property or list of properties
177 @var{p_i}. When @var{a_i} and/or @var{p_i} are lists, each of the atoms gets
178 all of the properties.
180 @code{declare} quotes its arguments. @code{declare} always returns @code{done}.
182 As noted in the description for each declaration flag, for some flags
183 @code{featurep(@var{object}, @var{feature})} returns @code{true} if @var{object}
184 has been declared to have @var{feature}.
186 For more information about the features system, see @mrefdot{features} To
187 remove a property from an atom, use @mrefdot{remove}
189 @code{declare} recognizes the following properties:
192 @item @mref{additive}
193 Tells Maxima to simplify @var{a_i} expressions by the substitution
194 @code{@var{a_i}(x + y + z + ...)} @code{-->}
195 @code{@var{a_i}(x) + @var{a_i}(y) + @var{a_i}(z) + ...}.
196 The substitution is carried out on the first argument only.
198 @item @mref{alphabetic}
199 Tells Maxima to recognize all characters in @var{a_i} (which must be a
200 string) as alphabetic characters.
202 @item @mrefcomma{antisymmetric} @mrefcomma{commutative} @mref{symmetric}
203 Tells Maxima to recognize @var{a_i} as a symmetric or antisymmetric
204 function. @code{commutative} is the same as @code{symmetric}.
206 @item @mref{bindtest}
207 Tells Maxima to trigger an error when @var{a_i} is evaluated unbound.
209 @item @mref{constant}
210 Tells Maxima to consider @var{a_i} a symbolic constant.
211 @c WHAT MAXIMA KNOWS ABOUT SYMBOLIC CONSTANTS IS PRETTY LIMITED
212 @c DUNNO IF WE WANT TO GET INTO DETAILS HERE.
213 @c MAYBE IN THE DOCUMENTATION FOR CONSTANT (IF THERE IS SUCH)
215 @item @mrefcomma{even} @mref{odd}
216 Tells Maxima to recognize @var{a_i} as an even or odd integer variable.
218 @item @mrefcomma{evenfun} @mref{oddfun}
219 Tells Maxima to recognize @var{a_i} as an odd or even function.
222 Makes @var{a_i} known to the @code{ev} function so that @var{a_i} is bound
223 to @code{true} during the execution of @code{ev} when @var{a_i} appears as
224 a flag argument of @code{ev}.
227 Makes @var{a_i} known to @code{ev} so that the function named by @var{a_i}
228 is applied when @var{a_i} appears as a flag argument of @code{ev}.
232 Tells Maxima to recognize @var{a_i} as the name of a feature.
233 Other atoms may then be declared to have the @var{a_i} property.
235 @item @mrefcomma{increasing} @mref{decreasing}
236 Tells Maxima to recognize @var{a_i} as an increasing or decreasing
238 @c MAXIMA FAILS TO DEDUCE F(2) > F(1) FOR INCREASING FUNCTION F
239 @c AND FAILS TO DEDUCE ANYTHING AT ALL ABOUT DECREASING FUNCTIONS
240 @c REPORTED AS SF BUG # 1483194
242 @item @mrefcomma{integer} @mref{noninteger}
243 Tells Maxima to recognize @var{a_i} as an integer or noninteger variable.
245 @item @mref{integervalued}
246 Tells Maxima to recognize @var{a_i} as an integer-valued function.
248 @item @mrefcomma{lassociative} @mref{rassociative}
249 Tells Maxima to recognize @var{a_i} as a right-associative or
250 left-associative function.
253 Equivalent to declaring @var{a_i} both @code{outative} and
257 Tells Maxima to consider @var{a_i} a "main variable". A main variable
258 succeeds all other constants and variables in the canonical ordering of
259 Maxima expressions, as determined by @mrefdot{ordergreatp}
261 @item @mref{multiplicative}
262 Tells Maxima to simplify @var{a_i} expressions by the substitution
263 @code{@var{a_i}(x * y * z * ...)} @code{-->}
264 @code{@var{a_i}(x) * @var{a_i}(y) * @var{a_i}(z) * ...}.
265 The substitution is carried out on the first argument only.
269 Tells Maxima to recognize @var{a_i} as an n-ary function.
271 The @code{nary} declaration is not the same as calling the @code{nary}
272 function. The sole effect of @code{declare(foo, nary)} is to instruct the
273 Maxima simplifier to flatten nested expressions, for example, to simplify
274 @code{foo(x, foo(y, z))} to @code{foo(x, y, z)}.
276 @item @mref{nonarray}
277 Tells Maxima to consider @var{a_i} not an array. This declaration
278 prevents multiple evaluation of a subscripted variable name.
280 @item @mref{nonscalar}
281 Tells Maxima to consider @var{a_i} a nonscalar variable. The usual
282 application is to declare a variable as a symbolic vector or matrix.
285 Tells Maxima to parse @var{a_i} as a noun. The effect of this is to
286 replace instances of @var{a_i} with @code{'@var{a_i}} or
287 @code{nounify(@var{a_i})}, depending on the context.
289 @item @mref{outative}
290 Tells Maxima to simplify @var{a_i} expressions by pulling constant factors
291 out of the first argument.
293 When @var{a_i} has one argument, a factor is considered constant if it is
294 a literal or declared constant.
296 When @var{a_i} has two or more arguments, a factor is considered constant
297 if the second argument is a symbol and the factor is free of the second
301 Tells Maxima to recognize @var{a_i} as a positive function.
303 @item @mrefcomma{rational} @mref{irrational}
304 Tells Maxima to recognize @var{a_i} as a rational or irrational real
307 @item @mrefcomma{real} @mrefcomma{imaginary} @mref{complex}
308 Tells Maxima to recognize @var{a_i} as a real, pure imaginary, or complex
312 Tells Maxima to consider @var{a_i} a scalar variable.
314 @c OBSOLETE @code{special} (RECOGNIZED BY DECLARE BUT NEVER USED ANYWHERE)
315 @c OBSOLETE @code{analytic} (RECOGNIZED BY DECLARE BUT NEVER USED ANYWHERE)
318 Examples of the usage of the properties are available in the documentation
319 for each separate description of a property.
321 @opencatbox{Categories:}
322 @category{Declarations and inferences}
326 @c -----------------------------------------------------------------------------
329 @defvr {Property} decreasing
330 @defvrx {Property} increasing
332 The commands @code{declare(@var{f}, decreasing)} or
333 @code{declare(@var{f}, increasing)} tell Maxima to recognize the function
334 @var{f} as an decreasing or increasing function.
336 See also @mref{declare} for more properties.
343 (%i2) is(f(a) > f(b));
345 (%i3) declare(f, increasing);
347 (%i4) is(f(a) > f(b));
351 @opencatbox{Categories:}
352 @category{Declarations and inferences}
356 @c -----------------------------------------------------------------------------
359 @defvr {Property} even
360 @defvrx {Property} odd
362 @code{declare(@var{a}, even)} or @code{declare(@var{a}, odd)} tells Maxima to
363 recognize the symbol @var{a} as an even or odd integer variable. The
364 properties @code{even} and @code{odd} are not recognized by the functions
365 @mrefcomma{evenp} @mrefcomma{oddp} and @mrefdot{integerp}
367 See also @mref{declare} and @mrefdot{askinteger}
372 (%i1) declare(n, even);
374 (%i2) askinteger(n, even);
382 @opencatbox{Categories:}
383 @category{Declarations and inferences}
387 @c NEEDS EXPANSION AND CLARIFICATION
389 @c -----------------------------------------------------------------------------
391 @defvr {Property} feature
393 Maxima understands two distinct types of features, system features and features
394 which apply to mathematical expressions. See also @mref{status} for information
395 about system features. See also @mref{features} and @mref{featurep} for
396 information about mathematical features.
397 @c PROPERTIES, DECLARATIONS FALL UNDER THIS HEADING AS WELL
400 @code{feature} itself is not the name of a function or variable.
403 @c NEEDS CLARIFICATION, ESPECIALLY WRT THE EXTENT OF THE FEATURE SYSTEM
404 @c (I.E. WHAT KINDS OF THINGS ARE FEATURES ACCORDING TO featurep)
406 @c -----------------------------------------------------------------------------
408 @deffn {Function} featurep (@var{a}, @var{f})
410 Attempts to determine whether the object @var{a} has the feature @var{f} on the
411 basis of the facts in the current database. If so, it returns @code{true},
414 Note that @code{featurep} returns @code{false} when neither @var{f}
415 nor the negation of @var{f} can be established.
417 @code{featurep} evaluates its argument.
419 See also @mref{declare} and @mrefdot{features}
422 (%i1) declare (j, even)$
423 (%i2) featurep (j, integer);
427 @opencatbox{Categories:}
428 @category{Predicate functions}
429 @category{Declarations and inferences}
433 @c -----------------------------------------------------------------------------
435 @defvr {Declaration} features
437 Maxima recognizes certain mathematical properties of functions and variables.
438 These are called "features".
440 @code{declare (@var{x}, @var{foo})} gives the property @var{foo}
441 to the function or variable @var{x}.
443 @code{declare (@var{foo}, feature)} declares a new feature @var{foo}.
445 @code{declare ([red, green, blue], feature)}
446 declares three new features, @code{red}, @code{green}, and @code{blue}.
448 The predicate @code{featurep (@var{x}, @var{foo})}
449 returns @code{true} if @var{x} has the @var{foo} property,
450 and @code{false} otherwise.
452 The infolist @code{features} is a list of known features. These are
455 integer noninteger even
456 odd rational irrational
457 real imaginary complex
458 analytic increasing decreasing
459 oddfun evenfun posfun
460 constant commutative lassociative
461 rassociative symmetric antisymmetric
465 plus any user-defined features.
467 @code{features} is a list of mathematical features. There is also a list of
468 non-mathematical, system-dependent features. See @mrefdot{status}
473 @c declare (FOO, feature);
475 @c featurep (x, FOO);
478 (%i1) declare (FOO, feature);
480 (%i2) declare (x, FOO);
482 (%i3) featurep (x, FOO);
486 @opencatbox{Categories:}
487 @category{Declarations and inferences}
491 @c -----------------------------------------------------------------------------
493 @deffn {Function} get (@var{a}, @var{i})
495 Retrieves the user property indicated by @var{i} associated with
496 atom @var{a} or returns @code{false} if @var{a} doesn't have property @var{i}.
498 @code{get} evaluates its arguments.
500 See also @mref{put} and @mrefdot{qput}
503 @c put (%e, 'transcendental, 'type);
504 @c put (%pi, 'transcendental, 'type)$
505 @c put (%i, 'algebraic, 'type)$
506 @c typeof (expr) := block ([q],
508 @c then return ('algebraic),
509 @c if not atom (expr)
510 @c then return (maplist ('typeof, expr)),
511 @c q: get (expr, 'type),
513 @c then errcatch (error(expr,"is not numeric.")) else q)$
514 @c typeof (2*%e + x*%pi);
515 @c typeof (2*%e + %pi);
518 (%i1) put (%e, 'transcendental, 'type);
520 (%i2) put (%pi, 'transcendental, 'type)$
521 (%i3) put (%i, 'algebraic, 'type)$
522 (%i4) typeof (expr) := block ([q],
524 then return ('algebraic),
526 then return (maplist ('typeof, expr)),
527 q: get (expr, 'type),
529 then errcatch (error(expr,"is not numeric.")) else q)$
530 (%i5) typeof (2*%e + x*%pi);
532 (%o5) [[transcendental, []], [algebraic, transcendental]]
533 (%i6) typeof (2*%e + %pi);
534 (%o6) [transcendental, [algebraic, transcendental]]
537 @opencatbox{Categories:}
538 @category{Declarations and inferences}
542 @c -----------------------------------------------------------------------------
545 @defvr {Property} integer
546 @defvrx {Property} noninteger
548 @code{declare(@var{a}, integer)} or @code{declare(@var{a}, noninteger)} tells
549 Maxima to recognize @var{a} as an integer or noninteger variable.
551 See also @mrefdot{declare}
556 (%i1) declare(n, integer, x, noninteger);
564 @opencatbox{Categories:}
565 @category{Declarations and inferences}
569 @c -----------------------------------------------------------------------------
570 @anchor{integervalued}
571 @defvr {Property} integervalued
573 @code{declare(@var{f}, integervalued)} tells Maxima to recognize @var{f} as an
574 integer-valued function.
576 See also @mrefdot{declare}
584 (%i2) declare(f, integervalued);
591 @opencatbox{Categories:}
592 @category{Declarations and inferences}
596 @c -----------------------------------------------------------------------------
598 @deffn {Property} nonarray
600 The command @code{declare(a, nonarray)} tells Maxima to consider @var{a} not
601 an array. This declaration prevents multiple evaluation, if @var{a} is a
602 subscripted variable.
604 See also @mrefdot{declare}
611 @c declare(a, nonarray);
615 (%i1) a:'b$ b:'c$ c:'d$
620 (%i5) declare(a, nonarray);
627 @opencatbox{Categories:}
628 @category{Expressions}
632 @c NEEDS CLARIFICATION AND EXAMPLES
634 @c -----------------------------------------------------------------------------
636 @defvr {Property} nonscalar
638 Makes atoms behave as does a list or matrix with respect to the dot operator.
640 See also @mrefdot{declare}
642 @opencatbox{Categories:}
643 @category{Declarations and inferences}
649 @c -----------------------------------------------------------------------------
651 @deffn {Function} nonscalarp (@var{expr})
653 Returns @code{true} if @var{expr} is a non-scalar, i.e., it contains
654 atoms declared as non-scalars, lists, or matrices.
656 See also the predicate function @mref{scalarp} and @mrefdot{declare}
658 @opencatbox{Categories:}
659 @category{Predicate functions}
667 @c -----------------------------------------------------------------------------
669 @defvr {Property} posfun
671 @code{declare (f, posfun)} declares @code{f} to be a positive function.
672 @code{is (f(x) > 0)} yields @code{true}.
674 See also @mrefdot{declare}
676 @opencatbox{Categories:}
677 @category{Declarations and inferences}
682 @c NEEDS WORK ESPECIALLY EXAMPLES
683 @c WHOLE BUSINESS WITH PROPERTIES IS PRETTY CONFUSING, TRY TO CLEAR IT UP
685 @c -----------------------------------------------------------------------------
687 @deffn {Function} printprops @
688 @fname{printprops} (@var{a}, @var{i}) @
689 @fname{printprops} ([@var{a_1}, @dots{}, @var{a_n}], @var{i}) @
690 @fname{printprops} (all, @var{i})
692 Displays the property with the indicator @var{i} associated with the atom
693 @var{a}. @var{a} may also be a list of atoms or the atom @code{all} in which
694 case all of the atoms with the given property will be used. For example,
695 @code{printprops ([f, g], atvalue)}. @code{printprops} is for properties that
696 cannot otherwise be displayed, i.e. for @mrefcomma{atvalue}@w{}
697 @mrefcomma{atomgrad} @mrefcomma{gradef} and @mrefdot{matchdeclare}
699 @opencatbox{Categories:}
700 @category{Declarations and inferences}
701 @category{Display functions}
705 @c CROSS REF TO WHICH FUNCTION OR FUNCTIONS ESTABLISH PROPERTIES !! (VERY IMPORTANT)
706 @c NEEDS EXPANSION, CLARIFICATION, AND EXAMPLES
708 @c -----------------------------------------------------------------------------
710 @deffn {Function} properties (@var{a})
712 Returns a list of the names of all the properties associated with the atom
715 @opencatbox{Categories:}
716 @category{Declarations and inferences}
720 @c CROSS REF TO WHICH FUNCTION OR FUNCTIONS ESTABLISH PROPERTIES !! (VERY IMPORTANT)
721 @c NEEDS EXPANSION, CLARIFICATION, AND EXAMPLES
722 @c WHAT IS HIDDEN IN THE "etc" HERE ??
724 @c -----------------------------------------------------------------------------
726 @defvr {System variable} props
727 Default value: @code{[]}
729 @code{props} are atoms which have any property other than those explicitly
730 mentioned in @mrefcomma{infolists} such as specified by @mrefcomma{atvalue}@w{}
731 @mrefcomma{matchdeclare} etc., as well as properties specified in the
732 @mref{declare} function.
734 @opencatbox{Categories:}
735 @category{Declarations and inferences}
736 @category{Global variables}
740 @c CROSS REF TO WHICH FUNCTION OR FUNCTIONS ESTABLISH PROPERTIES !! (VERY IMPORTANT)
741 @c NEEDS EXPANSION, CLARIFICATION, AND EXAMPLES
743 @c -----------------------------------------------------------------------------
745 @deffn {Function} propvars (@var{prop})
747 Returns a list of those atoms on the @mref{props} list which
748 have the property indicated by @var{prop}. Thus @code{propvars (atvalue)}
749 returns a list of atoms which have atvalues.
751 @opencatbox{Categories:}
752 @category{Declarations and inferences}
756 @c CROSS REF TO OTHER FUNCTIONS WHICH PUT/GET PROPERTIES !! (VERY IMPORTANT)
757 @c NEEDS EXPANSION, CLARIFICATION, AND EXAMPLES
758 @c ARE PROPERTIES ESTABLISHED BY put THE SAME AS PROPERTIES ESTABLISHED BY declare OR OTHER FUNCTIONS ??
759 @c IS put (foo, true, integer) EQUIVALENT TO declare (foo, integer) FOR EXAMPLE ??
761 @c -----------------------------------------------------------------------------
763 @deffn {Function} put (@var{atom}, @var{value}, @var{indicator})
765 Assigns @var{value} to the property (specified by @var{indicator}) of
766 @var{atom}. @var{indicator} may be the name of any property, not just a
767 system-defined property.
769 @mref{rem} reverses the effect of @code{put}.
771 @code{put} evaluates its arguments.
772 @code{put} returns @var{value}.
774 See also @mref{qput} and @mrefdot{get}
779 (%i1) put (foo, (a+b)^5, expr);
782 (%i2) put (foo, "Hello", str);
784 (%i3) properties (foo);
785 (%o3) [[user properties, str, expr]]
786 (%i4) get (foo, expr);
789 (%i5) get (foo, str);
793 @opencatbox{Categories:}
794 @category{Declarations and inferences}
798 @c -----------------------------------------------------------------------------
800 @deffn {Function} qput (@var{atom}, @var{value}, @var{indicator})
802 Assigns @var{value} to the property (specified by @var{indicator}) of
803 @var{atom}. This is the same as @mrefcomma{put} except that the arguments are
806 See also @mrefdot{get}
814 (%i4) put (foo, bar, baz);
816 (%i5) properties (aa);
817 (%o5) [[user properties, cc]]
820 (%i7) qput (foo, bar, baz);
822 (%i8) properties (foo);
823 (%o8) [value, [user properties, baz]]
824 (%i9) get ('foo, 'baz);
828 @opencatbox{Categories:}
829 @category{Declarations and inferences}
833 @c -----------------------------------------------------------------------------
836 @defvr {Property} rational
837 @defvrx {Property} irrational
839 @code{declare(@var{a}, rational)} or @code{declare(@var{a}, irrational)} tells
840 Maxima to recognize @var{a} as a rational or irrational real variable.
842 See also @mrefdot{declare}
844 @opencatbox{Categories:}
845 @category{Declarations and inferences}
849 @c -----------------------------------------------------------------------------
853 @defvr {Property} real
854 @defvrx {Property} imaginary
855 @defvrx {Property} complex
857 @code{declare(@var{a}, real)}, @code{declare(@var{a}, imaginary)}, or
858 @code{declare(@var{a}, complex)} tells Maxima to recognize @var{a} as a real,
859 pure imaginary, or complex variable.
861 See also @mrefdot{declare}
863 @opencatbox{Categories:}
864 @category{Declarations and inferences}
868 @c CROSS REF TO OTHER FUNCTIONS WHICH PUT/GET PROPERTIES !! (VERY IMPORTANT)
869 @c NEEDS EXPANSION, CLARIFICATION, AND EXAMPLES
870 @c HOW DOES THIS INTERACT WITH declare OR OTHER PROPERTY-ESTABLISHING FUNCTIONS ??
871 @c HOW IS THIS DIFFERENT FROM remove ??
873 @c -----------------------------------------------------------------------------
875 @deffn {Function} rem (@var{atom}, @var{indicator})
877 Removes the property indicated by @var{indicator} from @var{atom}.
878 @code{rem} reverses the effect of @mrefdot{put}
880 @code{rem} returns @code{done} if @var{atom} had an @var{indicator} property
881 when @code{rem} was called, or @code{false} if it had no such property.
883 @opencatbox{Categories:}
884 @category{Declarations and inferences}
888 @c CROSS REF TO OTHER FUNCTIONS WHICH PUT/GET PROPERTIES !! (VERY IMPORTANT)
889 @c NEEDS EXPANSION, CLARIFICATION, AND EXAMPLES
890 @c HOW DOES THIS INTERACT WITH declare OR OTHER PROPERTY-ESTABLISHING FUNCTIONS ??
891 @c HOW IS THIS DIFFERENT FROM rem ??
893 @c -----------------------------------------------------------------------------
895 @deffn {Function} remove @
896 @fname{remove} (@var{a_1}, @var{p_1}, @dots{}, @var{a_n}, @var{p_n}) @
897 @fname{remove} ([@var{a_1}, @dots{}, @var{a_m}], [@var{p_1}, @dots{}, @var{p_n}], @dots{}) @
898 @fname{remove} ("@var{a}", operator) @
899 @fname{remove} (@var{a}, transfun) @
900 @fname{remove} (all, @var{p})
902 Removes properties associated with atoms.
904 @code{remove (@var{a_1}, @var{p_1}, ..., @var{a_n}, @var{p_n})}
905 removes property @code{p_k} from atom @code{a_k}.
907 @code{remove ([@var{a_1}, ..., @var{a_m}], [@var{p_1}, ..., @var{p_n}], ...)}
908 removes properties @code{@var{p_1}, ..., @var{p_n}}
909 from atoms @var{a_1}, @dots{}, @var{a_m}.
910 There may be more than one pair of lists.
912 @c VERIFY THAT THIS WORKS AS ADVERTISED
913 @code{remove (all, @var{p})} removes the property @var{p} from all atoms which
916 @c SHOULD REFER TO A LIST OF ALL SYSTEM-DEFINED PROPERTIES HERE.
917 The removed properties may be system-defined properties such as
918 @code{function}, @code{macro}, or @mrefdot{mode_declare}
919 @code{remove} does not remove properties defined by @mrefdot{put}
921 @c VERIFY THAT THIS WORKS AS ADVERTISED
922 @c IS transfun PECULIAR TO remove ?? IF SO, SHOW SPECIAL CASE AS @defunx
923 A property may be @code{transfun} to remove
924 the translated Lisp version of a function.
925 After executing this, the Maxima version of the function is executed
926 rather than the translated version.
928 @code{remove ("@var{a}", operator)} or, equivalently,
929 @code{remove ("@var{a}", op)} removes from @var{a} the operator properties
930 declared by @mrefcomma{prefix} @mrefcomma{infix}@w{}
931 @mxrefcomma{function_nary, nary} @mrefcomma{postfix} @mrefcomma{matchfix} or
932 @mrefdot{nofix} Note that the name of the operator must be written as a quoted
935 @code{remove} always returns @code{done} whether or not an atom has a specified
936 property. This behavior is unlike the more specific remove functions
937 @mrefcomma{remvalue} @mrefcomma{remarray} @mrefcomma{remfunction} and
940 @code{remove} quotes its arguments.
942 @c IN SERIOUS NEED OF EXAMPLES HERE
943 @opencatbox{Categories:}
944 @category{Declarations and inferences}
948 @c -----------------------------------------------------------------------------
950 @defvr {Property} scalar
952 @code{declare(@var{a}, scalar)} tells Maxima to consider @var{a} a scalar
955 See also @mrefdot{declare}
957 @opencatbox{Categories:}
958 @category{Declarations and inferences}
962 @c NEEDS CLARIFICATION AND EXAMPLES
964 @c -----------------------------------------------------------------------------
966 @deffn {Function} scalarp (@var{expr})
968 Returns @code{true} if @var{expr} is a number, constant, or variable declared
969 @mref{scalar} with @mrefcomma{declare} or composed entirely of numbers,
970 constants, and such variables, but not containing matrices or lists.
972 See also the predicate function @mrefdot{nonscalarp}
974 @opencatbox{Categories:}
975 @category{Predicate functions}
981 @c -----------------------------------------------------------------------------
982 @node Functions and Variables for Facts, Functions and Variables for Predicates, Functions and Variables for Properties, Maxima's Database
983 @section Functions and Variables for Facts
984 @c -----------------------------------------------------------------------------
986 @c -----------------------------------------------------------------------------
988 @deffn {Function} activate (@var{context_1}, @dots{}, @var{context_n})
990 Activates the contexts @var{context_1}, @dots{}, @var{context_n}.
991 The facts in these contexts are then available to
992 make deductions and retrieve information.
993 The facts in these contexts are not listed by @code{facts ()}.
995 The variable @mref{activecontexts} is the list
996 of contexts which are active by way of the @code{activate} function.
998 @opencatbox{Categories:}
999 @category{Declarations and inferences}
1003 @c -----------------------------------------------------------------------------
1004 @anchor{activecontexts}
1005 @defvr {System variable} activecontexts
1006 Default value: @code{[]}
1008 @code{activecontexts} is a list of the contexts which are active
1009 by way of the @mref{activate} function, as opposed to being active because
1010 they are subcontexts of the current context.
1012 @opencatbox{Categories:}
1013 @category{Declarations and inferences}
1017 @c -----------------------------------------------------------------------------
1019 @deffn {Function} askequal @
1020 @fname{askequal} (@var{expr1}, @var{expr2})
1022 @code{askequal(@var{expr1}, @var{expr2})} attempts to determine from the
1023 @code{assume} database whether @var{expr1} is equal to @var{expr2},
1024 and prompts the user if it cannot tell.
1026 If the user provides the answer,
1027 the answer is stored in the @code{assume} database
1028 for the duration of the evaluation of the expression currently in progress.
1029 When the evaluation is completed,
1030 the user-provided answer is removed from the database.
1032 @code{askequal} returns @code{yes} or @code{no},
1033 whether the answer was determined from the @code{assume} database
1034 or provided by the user.
1036 See also @mrefdot{equal}
1038 @opencatbox{Categories:}
1039 @category{Declarations and inferences}
1043 @c THERE IS PROBABLY MORE TO THE STORY THAN WHAT IS INDICATED HERE ...
1045 @c -----------------------------------------------------------------------------
1047 @deffn {Function} askinteger @
1048 @fname{askinteger} (@var{expr}, integer) @
1049 @fname{askinteger} (@var{expr}) @
1050 @fname{askinteger} (@var{expr}, even) @
1051 @fname{askinteger} (@var{expr}, odd)
1053 @code{askinteger (@var{expr}, integer)} attempts to determine from the
1054 @code{assume} database whether @var{expr} is an integer.
1055 @code{askinteger} prompts the user if it cannot tell otherwise,
1056 @c UMM, askinteger AND asksign DO NOT APPEAR TO HAVE ANY EFFECT ON THE assume
1058 and attempt to install the information in the database if possible.
1059 @code{askinteger (@var{expr})} is equivalent to
1060 @code{askinteger (@var{expr}, integer)}.
1062 @code{askinteger (@var{expr}, even)} and @code{askinteger (@var{expr}, odd)}
1063 likewise attempt to determine if @var{expr} is an even integer or odd integer,
1066 @opencatbox{Categories:}
1067 @category{Declarations and inferences}
1071 @c THERE IS PROBABLY MORE TO THE STORY THAN WHAT IS INDICATED HERE ...
1073 @c -----------------------------------------------------------------------------
1075 @deffn {Function} asksign (@var{expr})
1077 First attempts to determine whether the specified
1078 expression is positive, negative, or zero. If it cannot, it asks the
1079 user the necessary questions to complete its deduction. The user's
1080 answer is recorded in the data base for the duration of the current
1081 computation. The return value of @code{asksign} is one of @code{pos},
1082 @code{neg}, or @code{zero}.
1084 @opencatbox{Categories:}
1085 @category{Declarations and inferences}
1089 @c -----------------------------------------------------------------------------
1091 @deffn {Function} assume (@var{pred_1}, @dots{}, @var{pred_n})
1093 Adds predicates @var{pred_1}, @dots{}, @var{pred_n} to the current context.
1094 If a predicate is inconsistent or redundant with the predicates in the current
1095 context, it is not added to the context. The context accumulates predicates
1096 from each call to @code{assume}.
1098 @code{assume} returns a list whose elements are the predicates added to the
1099 context or the atoms @code{redundant} or @code{inconsistent} where applicable.
1101 The predicates @var{pred_1}, @dots{}, @var{pred_n} can only be expressions
1102 with the relational operators @code{< <= equal notequal >=} and @code{>}.
1103 Predicates cannot be literal equality @code{=} or literal inequality @code{#}
1104 expressions, nor can they be predicate functions such as @code{integerp}.
1106 Compound predicates of the form @code{@var{pred_1} and ... and @var{pred_n}}
1107 are recognized, but not @code{@var{pred_1} or ... or @var{pred_n}}.
1108 @code{not @var{pred_k}} is recognized if @var{pred_k} is a relational predicate.
1109 Expressions of the form @code{not (@var{pred_1} and @var{pred_2})}
1110 and @code{not (@var{pred_1} or @var{pred_2})} are not recognized.
1112 Maxima's deduction mechanism is not very strong;
1113 there are many obvious consequences which cannot be determined by @mrefdot{is}
1114 This is a known weakness.
1116 @code{assume} does not handle predicates with complex numbers. If a predicate
1117 contains a complex number @code{assume} returns @code{inconsistent} or
1120 @code{assume} evaluates its arguments.
1122 See also @mrefcomma{is} @mrefcomma{facts} @mrefcomma{forget}@w{}
1123 @mrefcomma{context} and @mrefdot{declare}
1128 @c assume (xx > 0, yy < -1, zz >= 0);
1129 @c assume (aa < bb and bb < cc);
1133 @c is (sinh (bb - aa) > 0);
1134 @c forget (bb > aa);
1135 @c prederror : false;
1136 @c is (sinh (bb - aa) > 0);
1137 @c is (bb^2 < cc^2);
1140 (%i1) assume (xx > 0, yy < -1, zz >= 0);
1141 (%o1) [xx > 0, yy < - 1, zz >= 0]
1142 (%i2) assume (aa < bb and bb < cc);
1143 (%o2) [bb > aa, cc > bb]
1145 (%o3) [xx > 0, - 1 > yy, zz >= 0, bb > aa, cc > bb]
1148 (%i5) is (yy < -yy);
1150 (%i6) is (sinh (bb - aa) > 0);
1152 (%i7) forget (bb > aa);
1154 (%i8) prederror : false;
1156 (%i9) is (sinh (bb - aa) > 0);
1158 (%i10) is (bb^2 < cc^2);
1162 @opencatbox{Categories:}
1163 @category{Declarations and inferences}
1167 @c -----------------------------------------------------------------------------
1168 @anchor{assumescalar}
1169 @defvr {Option variable} assumescalar
1170 Default value: @code{true}
1172 @code{assumescalar} helps govern whether expressions @code{expr}
1173 for which @code{nonscalarp (expr)} is @code{false}
1174 are assumed to behave like scalars for certain transformations.
1176 Let @code{expr} represent any expression other than a list or a matrix,
1177 and let @code{[1, 2, 3]} represent any list or matrix.
1178 Then @code{expr . [1, 2, 3]} yields @code{[expr, 2 expr, 3 expr]}
1179 if @code{assumescalar} is @code{true}, or @code{scalarp (expr)} is
1180 @code{true}, or @code{constantp (expr)} is @code{true}.
1182 If @code{assumescalar} is @code{true}, such
1183 expressions will behave like scalars only for commutative
1184 operators, but not for noncommutative multiplication @code{.}.
1186 When @code{assumescalar} is @code{false}, such
1187 expressions will behave like non-scalars.
1189 When @code{assumescalar} is @code{all}, such expressions will behave like
1190 scalars for all the operators listed above.
1192 @opencatbox{Categories:}
1193 @category{Declarations and inferences}
1197 @c -----------------------------------------------------------------------------
1200 @defvr {Option variable} assume_pos
1201 Default value: @code{false}
1203 When @code{assume_pos} is @code{true} and the sign of a parameter @var{x}
1204 cannot be determined from the current context
1205 @c WHAT ARE THOSE OTHER CONSIDERATIONS ??
1206 or other considerations,
1207 @code{sign} and @code{asksign (@var{x})} return @code{true}.
1208 This may forestall some automatically-generated @code{asksign} queries,
1209 such as may arise from @code{integrate} or other computations.
1211 By default, a parameter is @var{x} such that @code{symbolp (@var{x})}
1212 or @code{subvarp (@var{x})}.
1213 The class of expressions considered parameters can be modified to some extent
1214 via the variable @code{assume_pos_pred}.
1216 @code{sign} and @code{asksign} attempt to deduce the sign of expressions
1217 from the sign of operands within the expression.
1218 For example, if @code{a} and @code{b} are both positive,
1219 then @code{a + b} is also positive.
1221 However, there is no way to bypass all @code{asksign} queries.
1222 In particular, when the @code{asksign} argument is a
1223 difference @code{@var{x} - @var{y}} or a logarithm @code{log(@var{x})},
1224 @code{asksign} always requests an input from the user,
1225 even when @code{assume_pos} is @code{true} and @code{assume_pos_pred} is
1226 a function which returns @code{true} for all arguments.
1228 @c NEED EXAMPLES HERE
1229 @opencatbox{Categories:}
1230 @category{Declarations and inferences}
1234 @c -----------------------------------------------------------------------------
1235 @anchor{assume_pos_pred}
1236 @defvr {Option variable} assume_pos_pred
1237 Default value: @code{false}
1239 When @code{assume_pos_pred} is assigned the name of a function
1240 or a lambda expression of one argument @var{x},
1241 that function is called to determine
1242 whether @var{x} is considered a parameter for the purpose of @code{assume_pos}.
1243 @code{assume_pos_pred} is ignored when @code{assume_pos} is @code{false}.
1245 The @code{assume_pos_pred} function is called by @code{sign} and @code{asksign}
1246 with an argument @var{x}
1247 which is either an atom, a subscripted variable, or a function call expression.
1248 If the @code{assume_pos_pred} function returns @code{true},
1249 @var{x} is considered a parameter for the purpose of @code{assume_pos}.
1251 By default, a parameter is @var{x} such that @code{symbolp (@var{x})}
1252 or @code{subvarp (@var{x})}.
1254 See also @mref{assume} and @mrefdot{assume_pos}
1259 @c assume_pos: true$
1260 @c assume_pos_pred: symbolp$
1263 @c assume_pos_pred: lambda ([x], display (x), true)$
1266 @c asksign (foo (a));
1267 @c asksign (foo (a) + bar (b));
1268 @c asksign (log (a));
1274 (%i1) assume_pos: true$
1275 (%i2) assume_pos_pred: symbolp$
1280 (%i5) assume_pos_pred: lambda ([x], display (x), true)$
1285 (%i7) asksign (a[1]);
1290 (%i8) asksign (foo (a));
1294 (%i9) asksign (foo (a) + bar (b));
1300 (%i10) asksign (log (a));
1303 Is a - 1 positive, negative, or zero?
1307 (%i11) asksign (a - b);
1316 Is b - a positive, negative, or zero?
1322 @opencatbox{Categories:}
1323 @category{Declarations and inferences}
1327 @c -----------------------------------------------------------------------------
1329 @defvr {Option variable} context
1330 Default value: @code{initial}
1332 @code{context} names the collection of facts maintained by @mref{assume} and
1333 @mrefdot{forget} @code{assume} adds facts to the collection named by
1334 @code{context}, while @code{forget} removes facts.
1336 Binding @code{context} to a name @var{foo} changes the current context to
1337 @var{foo}. If the specified context @var{foo} does not yet exist,
1338 it is created automatically by a call to @mrefdot{newcontext}
1339 @c ISN'T THIS NEXT BIT EQUIVALENT TO THE FIRST ??
1340 The specified context is activated automatically.
1342 See @mref{contexts} for a general description of the context mechanism.
1344 @opencatbox{Categories:}
1345 @category{Declarations and inferences}
1349 @c UMM, I'M HAVING TROUBLE GETTING THE CONTEXT-SWITCHING STUFF TO BEHAVE AS EXPECTED
1350 @c SOME EXAMPLES WILL HELP A LOT HERE
1352 @c -----------------------------------------------------------------------------
1354 @defvr {Option variable} contexts
1355 Default value: @code{[initial, global]}
1357 @code{contexts} is a list of the contexts which
1358 currently exist, including the currently active context.
1360 The context mechanism makes it possible for a user to bind together
1361 and name a collection of facts, called a context.
1362 Once this is done, the user can have Maxima assume or forget large numbers
1363 of facts merely by activating or deactivating their context.
1365 Any symbolic atom can be a context, and the facts contained in that
1366 context will be retained in storage until destroyed one by one
1367 by calling @mref{forget} or destroyed as a whole by calling @mref{kill}@w{}
1368 to destroy the context to which they belong.
1370 Contexts exist in a hierarchy, with the root always being
1371 the context @code{global}, which contains information about Maxima that some
1372 functions need. When in a given context, all the facts in that
1373 context are "active" (meaning that they are used in deductions and
1374 retrievals) as are all the facts in any context which is a subcontext
1375 of the active context.
1377 When a fresh Maxima is started up, the user is in a
1378 context called @code{initial}, which has @code{global} as a subcontext.
1380 See also @mrefcomma{facts} @mrefcomma{newcontext} @mrefcomma{supcontext}@w{}
1381 @mrefcomma{killcontext} @mrefcomma{activate} @mrefcomma{deactivate}@w{}
1382 @mrefcomma{assume} and @mrefdot{forget}
1384 @opencatbox{Categories:}
1385 @category{Declarations and inferences}
1389 @c -----------------------------------------------------------------------------
1391 @deffn {Function} csign (@var{expr})
1393 Attempts to determine the sign of @var{expr} on the basis of the facts
1394 in the current data base without assuming that @var{expr} is
1395 real-valued. It returns one of the following answers: @code{pos}
1396 (positive), @code{neg} (negative), @code{zero}, @code{pz} (positive or
1397 zero), @code{nz} (negative or zero), @code{pn} (positive or negative),
1398 @code{pnz} (positive, negative, or zero), @code{imaginary}
1399 (purely imaginary), or @code{complex}, (complex, i.e. nothing known).
1401 Note that while this function does not assume that @var{expr} is
1402 real-valued, it still assumes that variables are real-valued unless
1403 declared otherwise. This means that @code{csign(z)} will return
1404 @code{pnz} unless @code{declare(z,complex)} or
1405 @code{declare(z,imaginary)} has been evaluated beforehand.
1407 See also @mrefdot{sign}
1409 @opencatbox{Categories:}
1410 @category{Declarations and inferences}
1414 @c -----------------------------------------------------------------------------
1416 @deffn {Function} deactivate (@var{context_1}, @dots{}, @var{context_n})
1418 Deactivates the specified contexts @var{context_1}, @dots{}, @var{context_n}.
1420 @opencatbox{Categories:}
1421 @category{Declarations and inferences}
1425 @c -----------------------------------------------------------------------------
1427 @deffn {Function} facts @
1428 @fname{facts} (@var{item}) @
1431 If @var{item} is the name of a context, @code{facts (@var{item})} returns a
1432 list of the facts in the specified context.
1434 If @var{item} is not the name of a context, @code{facts (@var{item})} returns a
1435 list of the facts known about @var{item} in the current context. Facts that
1436 are active, but in a different context, are not listed.
1438 @code{facts ()} (i.e., without an argument) lists the current context.
1440 @opencatbox{Categories:}
1441 @category{Declarations and inferences}
1445 @c -----------------------------------------------------------------------------
1447 @deffn {Function} forget @
1448 @fname{forget} (@var{pred_1}, @dots{}, @var{pred_n}) @
1449 @fname{forget} (@var{L})
1451 Removes predicates established by @mrefdot{assume}
1452 The predicates may be expressions equivalent to (but not necessarily identical
1453 to) those previously assumed.
1455 @code{forget (@var{L})}, where @var{L} is a list of predicates,
1456 forgets each item on the list.
1458 @opencatbox{Categories:}
1459 @category{Declarations and inferences}
1463 @c -----------------------------------------------------------------------------
1465 @deffn {Function} is (@var{expr})
1467 Attempts to determine whether the predicate @var{expr} is provable from the
1468 facts in the @code{assume} database.
1470 If the predicate is provably @code{true} or @code{false}, @code{is} returns
1471 @code{true} or @code{false}, respectively. Otherwise, the return value is
1472 governed by the global flag @mrefdot{prederror} When @code{prederror} is
1473 @code{true}, @code{is} complains with an error message. Otherwise, @code{is}
1474 returns @code{unknown}.
1476 @code{ev(@var{expr}, pred)} (which can be written @code{@var{expr}, pred} at
1477 the interactive prompt) is equivalent to @code{is(@var{expr})}.
1479 See also @mrefcomma{assume} @mrefcomma{facts} and @mrefdot{maybe}
1483 @code{is} causes evaluation of predicates.
1492 (%i2) is (%pi > %e);
1496 @code{is} attempts to derive predicates from the @code{assume} database.
1503 @c is (equal (a, c));
1506 (%i1) assume (a > b);
1508 (%i2) assume (b > c);
1514 (%i5) is (equal (a, c));
1518 If @code{is} can neither prove nor disprove a predicate from the @code{assume}
1519 database, the global flag @code{prederror} governs the behavior of @code{is}.
1525 @c prederror: false$
1529 (%i1) assume (a > b);
1531 (%i2) prederror: true$
1533 Maxima was unable to evaluate the predicate:
1535 -- an error. Quitting. To debug this try debugmode(true);
1536 (%i4) prederror: false$
1541 @opencatbox{Categories:}
1542 @category{Predicate functions}
1543 @category{Declarations and inferences}
1547 @c -----------------------------------------------------------------------------
1548 @anchor{killcontext}
1549 @deffn {Function} killcontext (@var{context_1}, @dots{}, @var{context_n})
1551 Kills the contexts @var{context_1}, @dots{}, @var{context_n}.
1553 If one of the contexts is the current context, the new current context will
1554 become the first available subcontext of the current context which has not been
1555 killed. If the first available unkilled context is @code{global} then
1556 @code{initial} is used instead. If the @code{initial} context is killed, a
1557 new, empty @code{initial} context is created.
1559 @code{killcontext} refuses to kill a context which is
1560 currently active, either because it is a subcontext of the current
1561 context, or by use of the function @mrefdot{activate}
1563 @code{killcontext} evaluates its arguments.
1564 @code{killcontext} returns @code{done}.
1566 @opencatbox{Categories:}
1567 @category{Declarations and inferences}
1571 @c -----------------------------------------------------------------------------
1573 @deffn {Function} maybe (@var{expr})
1575 Attempts to determine whether the predicate @var{expr} is provable from the
1576 facts in the @code{assume} database.
1578 If the predicate is provably @code{true} or @code{false}, @code{maybe} returns
1579 @code{true} or @code{false}, respectively. Otherwise, @code{maybe} returns
1582 @code{maybe} is functionally equivalent to @code{is} with
1583 @code{prederror: false}, but the result is computed without actually assigning
1584 a value to @code{prederror}.
1586 See also @mrefcomma{assume} @mrefcomma{facts} and @mrefdot{is}
1596 (%i1) maybe (x > 0);
1598 (%i2) assume (x > 1);
1600 (%i3) maybe (x > 0);
1604 @opencatbox{Categories:}
1605 @category{Predicate functions}
1606 @category{Declarations and inferences}
1610 @c -----------------------------------------------------------------------------
1612 @deffn {Function} newcontext @
1613 @fname{newcontext} (@var{name}) @
1614 @fname{newcontext} ()
1616 Creates a new, empty context, called @var{name}, which
1617 has @code{global} as its only subcontext. The newly-created context
1618 becomes the currently active context.
1620 If @var{name} is not specified, a new name is created (via @code{gensym}) and returned.
1622 @code{newcontext} evaluates its argument.
1623 @code{newcontext} returns @var{name} (if specified) or the new context name.
1625 @opencatbox{Categories:}
1626 @category{Declarations and inferences}
1630 @c -----------------------------------------------------------------------------
1632 @deffn {Function} sign (@var{expr})
1634 Attempts to determine the sign of @var{expr} on the basis of the facts in the
1635 current data base. It returns one of the following answers: @code{pos}
1636 (positive), @code{neg} (negative), @code{zero}, @code{pz} (positive or zero),
1637 @code{nz} (negative or zero), @code{pn} (positive or negative), or @code{pnz}
1638 (positive, negative, or zero, i.e. nothing known).
1640 Note that this function assumes that @var{expr} is a real-valued
1641 expression, such that for example @code{sign(sqrt(x))} will yield @code{pz}
1642 even though @code{sqrt(x)} may return a complex-valued result for @code{x<0}.
1644 See also @mrefdot{signum}
1646 @opencatbox{Categories:}
1647 @category{Declarations and inferences}
1651 @c -----------------------------------------------------------------------------
1653 @deffn {Function} supcontext @
1654 @fname{supcontext} (@var{name}, @var{context}) @
1655 @fname{supcontext} (@var{name}) @
1656 @fname{supcontext} ()
1658 Creates a new context, called @var{name}, which has @var{context} as a
1659 subcontext. @var{context} must exist.
1661 If @var{context} is not specified, the current context is assumed.
1663 If @var{name} is not specified, a new name is created (via @code{gensym}) and returned.
1665 @code{supcontext} evaluates its argument.
1666 @code{supcontext} returns @var{name} (if specified) or the new context name.
1668 @opencatbox{Categories:}
1669 @category{Declarations and inferences}
1673 @c -----------------------------------------------------------------------------
1674 @node Functions and Variables for Predicates, , Functions and Variables for Facts, Maxima's Database
1675 @section Functions and Variables for Predicates
1676 @c -----------------------------------------------------------------------------
1678 @c -----------------------------------------------------------------------------
1680 @deffn {Function} charfun (@var{p})
1682 Return 0 when the predicate @var{p} evaluates to @code{false}; return 1 when
1683 the predicate evaluates to @code{true}. When the predicate evaluates to
1684 something other than @code{true} or @code{false} (unknown), return a noun form.
1690 @c subst (x = -1, %);
1691 @c e : charfun ('"and" (-1 < x, x < 1))$
1692 @c [subst (x = -1, e), subst (x = 0, e), subst (x = 1, e)];
1695 (%i1) charfun (x < 1);
1696 (%o1) charfun(x < 1)
1697 (%i2) subst (x = -1, %);
1699 (%i3) e : charfun ('"and" (-1 < x, x < 1))$
1700 (%i4) [subst (x = -1, e), subst (x = 0, e), subst (x = 1, e)];
1704 @opencatbox{Categories:}
1705 @category{Mathematical functions}
1709 @c -----------------------------------------------------------------------------
1711 @deffn {Function} compare (@var{x}, @var{y})
1713 Return a comparison operator @var{op} (@code{<}, @code{<=}, @code{>}, @code{>=},
1714 @code{=}, or @code{#}) such that @code{is (@var{x} @var{op} @var{y})} evaluates
1715 to @code{true}; when either @var{x} or @var{y} depends on @code{%i} and
1716 @code{@var{x} # @var{y}}, return @code{notcomparable}; when there is no such
1717 operator or Maxima isn't able to determine the operator, return @code{unknown}.
1724 @c compare (%i, %i);
1725 @c compare (%i, %i + 1);
1726 @c compare (1/x, 0);
1727 @c compare (x, abs(x));
1730 (%i1) compare (1, 2);
1732 (%i2) compare (1, x);
1734 (%i3) compare (%i, %i);
1736 (%i4) compare (%i, %i + 1);
1738 (%i5) compare (1/x, 0);
1740 (%i6) compare (x, abs(x));
1744 The function @code{compare} doesn't try to determine whether the real domains of
1745 its arguments are nonempty; thus
1748 @c compare (acos (x^2 + 1), acos (x^2 + 1) + 1);
1751 (%i1) compare (acos (x^2 + 1), acos (x^2 + 1) + 1);
1755 @c IT IS NOT QUITE TRUE, WHAT ABOUT x=0 ?
1756 The real domain of @code{acos (x^2 + 1)} is empty.
1758 @opencatbox{Categories:}
1759 @category{Declarations and inferences}
1763 @c -----------------------------------------------------------------------------
1765 @deffn {Function} equal (@var{a}, @var{b})
1767 Represents equivalence, that is, equal value.
1769 By itself, @code{equal} does not evaluate or simplify.
1770 The function @mref{is} attempts to evaluate @code{equal} to a Boolean value.
1771 @code{is(equal(@var{a}, @var{b}))} returns @code{true} (or @code{false}) if
1772 and only if @var{a} and @var{b} are equal (or not equal) for all possible
1773 values of their variables, as determined by evaluating
1774 @code{ratsimp(@var{a} - @var{b})}; if @mref{ratsimp} returns 0, the two
1775 expressions are considered equivalent. Two expressions may be equivalent even
1776 if they are not syntactically equal (i.e., identical).
1778 When @code{is} fails to reduce @code{equal} to @code{true} or @code{false}, the
1779 result is governed by the global flag @mrefdot{prederror} When @code{prederror}
1780 is @code{true}, @code{is} complains with an error message. Otherwise, @code{is}
1781 returns @code{unknown}.
1783 In addition to @code{is}, some other operators evaluate @code{equal} and
1784 @code{notequal} to @code{true} or @code{false}, namely @mrefcomma{if}@w{}
1785 @mrefcomma{and} @mrefcomma{or} and @mrefdot{not}
1787 @c FOLLOWING STATEMENT IS MORE OR LESS TRUE BUT I DON'T THINK THE DETAILS ARE CORRECT
1788 @c Declarations (integer, complex, etc)
1789 @c for variables appearing in @var{a} and @var{b} are ignored by @code{equal}.
1790 @c All variables are effectively assumed to be real-valued.
1792 The negation of @code{equal} is @mrefdot{notequal}
1796 By itself, @code{equal} does not evaluate or simplify.
1799 @c equal (x^2 - 1, (x + 1) * (x - 1));
1800 @c equal (x, x + 1);
1804 (%i1) equal (x^2 - 1, (x + 1) * (x - 1));
1806 (%o1) equal(x - 1, (x - 1) (x + 1))
1807 (%i2) equal (x, x + 1);
1808 (%o2) equal(x, x + 1)
1813 The function @code{is} attempts to evaluate @code{equal} to a Boolean value.
1814 @code{is(equal(@var{a}, @var{b}))} returns @code{true} when
1815 @code{ratsimp(@var{a} - @var{b})} returns 0. Two expressions may be equivalent
1816 even if they are not syntactically equal (i.e., identical).
1819 @c ratsimp (x^2 - 1 - (x + 1) * (x - 1));
1820 @c is (equal (x^2 - 1, (x + 1) * (x - 1)));
1821 @c is (x^2 - 1 = (x + 1) * (x - 1));
1822 @c ratsimp (x - (x + 1));
1823 @c is (equal (x, x + 1));
1826 @c is (equal (x, y));
1830 (%i1) ratsimp (x^2 - 1 - (x + 1) * (x - 1));
1832 (%i2) is (equal (x^2 - 1, (x + 1) * (x - 1)));
1834 (%i3) is (x^2 - 1 = (x + 1) * (x - 1));
1836 (%i4) ratsimp (x - (x + 1));
1838 (%i5) is (equal (x, x + 1));
1840 (%i6) is (x = x + 1);
1842 (%i7) ratsimp (x - y);
1844 (%i8) is (equal (x, y));
1850 When @code{is} fails to reduce @code{equal} to @code{true} or @code{false},
1851 the result is governed by the global flag @code{prederror}.
1854 @c [aa : x^2 + 2*x + 1, bb : x^2 - 2*x - 1];
1855 @c ratsimp (aa - bb);
1856 @c prederror : true;
1857 @c is (equal (aa, bb));
1858 @c prederror : false;
1859 @c is (equal (aa, bb));
1862 (%i1) [aa : x^2 + 2*x + 1, bb : x^2 - 2*x - 1];
1864 (%o1) [x + 2 x + 1, x - 2 x - 1]
1865 (%i2) ratsimp (aa - bb);
1867 (%i3) prederror : true;
1869 (%i4) is (equal (aa, bb));
1870 Maxima was unable to evaluate the predicate:
1872 equal(x + 2 x + 1, x - 2 x - 1)
1873 -- an error. Quitting. To debug this try debugmode(true);
1874 (%i5) prederror : false;
1876 (%i6) is (equal (aa, bb));
1880 Some operators evaluate @code{equal} and @code{notequal} to @code{true} or
1884 @c if equal (y, y - 1) then FOO else BAR;
1885 @c eq_1 : equal (x, x + 1);
1886 @c eq_2 : equal (y^2 + 2*y + 1, (y + 1)^2);
1887 @c [eq_1 and eq_2, eq_1 or eq_2, not eq_1];
1890 (%i1) if equal (y, y - 1) then FOO else BAR;
1892 (%i2) eq_1 : equal (x, x + 1);
1893 (%o2) equal(x, x + 1)
1894 (%i3) eq_2 : equal (y^2 + 2*y + 1, (y + 1)^2);
1896 (%o3) equal(y + 2 y + 1, (y + 1) )
1897 (%i4) [eq_1 and eq_2, eq_1 or eq_2, not eq_1];
1898 (%o4) [false, true, true]
1901 Because @code{not @var{expr}} causes evaluation of @var{expr},
1902 @code{not equal(@var{a}, @var{b})} is equivalent to
1903 @code{is(notequal(@var{a}, @var{b}))}.
1906 @c [notequal (2*z, 2*z - 1), not equal (2*z, 2*z - 1)];
1907 @c is (notequal (2*z, 2*z - 1));
1910 (%i1) [notequal (2*z, 2*z - 1), not equal (2*z, 2*z - 1)];
1911 (%o1) [notequal(2 z, 2 z - 1), true]
1912 (%i2) is (notequal (2*z, 2*z - 1));
1916 @opencatbox{Categories:}
1917 @category{Operators}
1921 @c -----------------------------------------------------------------------------
1923 @deffn {Function} notequal (@var{a}, @var{b})
1925 Represents the negation of @code{equal(@var{a}, @var{b})}.
1931 @c maybe (equal (a, b));
1933 @c not equal (a, b);
1934 @c maybe (notequal (a, b));
1937 @c maybe (equal (a, b));
1939 @c maybe (notequal (a, b));
1944 (%i2) maybe (equal (a, b));
1946 (%i3) notequal (a, b);
1947 (%o3) notequal(a, b)
1948 (%i4) not equal (a, b);
1949 (%o4) notequal(a, b)
1950 (%i5) maybe (notequal (a, b));
1952 (%i6) assume (a > b);
1956 (%i8) maybe (equal (a, b));
1958 (%i9) notequal (a, b);
1959 (%o9) notequal(a, b)
1960 (%i10) maybe (notequal (a, b));
1964 @opencatbox{Categories:}
1965 @category{Operators}
1969 @c -----------------------------------------------------------------------------
1971 @deffn {Function} unknown (@var{expr})
1973 Returns @code{true} if and only if @var{expr} contains an operator or function
1974 not recognized by the Maxima simplifier.
1976 @opencatbox{Categories:}
1977 @category{Predicate functions}
1978 @category{Simplification functions}
1982 @c THIS FUNCTION APPEARS TO BE A HACK; SEE 4'TH ITEM BELOW
1983 @c DUNNO WHETHER WE CAN CLEAR THIS UP
1985 @c -----------------------------------------------------------------------------
1987 @deffn {Function} zeroequiv (@var{expr}, @var{v})
1989 Tests whether the expression @var{expr} in the variable @var{v} is equivalent
1990 to zero, returning @code{true}, @code{false}, or @code{dontknow}.
1992 @code{zeroequiv} has these restrictions:
1996 Do not use functions that Maxima does not know how to
1997 differentiate and evaluate.
1999 If the expression has poles on the real line, there may be errors
2000 in the result (but this is unlikely to occur).
2002 If the expression contains functions which are not solutions to first order
2003 differential equations (e.g. Bessel functions) there may be incorrect results.
2005 The algorithm uses evaluation at randomly chosen points for carefully selected
2006 subexpressions. This is always a somewhat hazardous business, although the
2007 algorithm tries to minimize the potential for error.
2010 For example @code{zeroequiv (sin(2 * x) - 2 * sin(x) * cos(x), x)} returns
2011 @code{true} and @code{zeroequiv (%e^x + x, x)} returns @code{false}.
2012 On the other hand @code{zeroequiv (log(a * b) - log(a) - log(b), a)} returns
2013 @code{dontknow} because of the presence of an extra parameter @code{b}.
2015 @opencatbox{Categories:}
2016 @category{Predicate functions}