Maxima 5.44.0 Manual: Functions and Variables for Facts

Next: Functions and Variables for Predicates, Previous: Functions and Variables for Properties, Up: Maxima's Database [Contents][Index]

### 11.3 Functions and Variables for Facts

Function: activate (context_1, …, context_n)

  Activates the contexts context_1, …, context_n. The facts in these contexts are then available to make deductions and retrieve information. The facts in these contexts are not listed by `facts ()`.

  The variable `activecontexts` is the list of contexts which are active by way of the `activate` function.

  ·

  Categories: Declarations and inferences

System variable: activecontexts

  Default value: `[]`

  `activecontexts` is a list of the contexts which are active by way of the `activate` function, as opposed to being active because they are subcontexts of the current context.

  ·

  Categories: Declarations and inferences

Function: askinteger
`askinteger` (expr, integer)
`askinteger` (expr)
`askinteger` (expr, even)
`askinteger` (expr, odd)

  `askinteger (expr, integer)` attempts to determine from the `assume` database whether expr is an integer. `askinteger` prompts the user if it cannot tell otherwise, and attempt to install the information in the database if possible. `askinteger (expr)` is equivalent to `askinteger (expr, integer)`.

  `askinteger (expr, even)` and `askinteger (expr, odd)` likewise attempt to determine if expr is an even integer or odd integer, respectively.

  ·

  Categories: Declarations and inferences

Function: asksign (expr)

  First attempts to determine whether the specified expression is positive, negative, or zero. If it cannot, it asks the user the necessary questions to complete its deduction. The user’s answer is recorded in the data base for the duration of the current computation. The return value of `asksign` is one of `pos`, `neg`, or `zero`.

  ·

  Categories: Declarations and inferences

Function: assume (pred_1, …, pred_n)

  Adds predicates pred_1, …, pred_n to the current context. If a predicate is inconsistent or redundant with the predicates in the current context, it is not added to the context. The context accumulates predicates from each call to `assume`.

  `assume` returns a list whose elements are the predicates added to the context or the atoms `redundant` or `inconsistent` where applicable.

  The predicates pred_1, …, pred_n can only be expressions with the relational operators `< <= equal notequal >=` and `>`. Predicates cannot be literal equality `=` or literal inequality `#` expressions, nor can they be predicate functions such as `integerp`.

  Compound predicates of the form `pred_1 and ... and pred_n` are recognized, but not `pred_1 or ... or pred_n`. `not pred_k` is recognized if pred_k is a relational predicate. Expressions of the form `not (pred_1 and pred_2)` and `not (pred_1 or pred_2)` are not recognized.

  Maxima’s deduction mechanism is not very strong; there are many obvious consequences which cannot be determined by `is`. This is a known weakness.

  `assume` does not handle predicates with complex numbers. If a predicate contains a complex number `assume` returns `inconsistent` or `redunant`.

  `assume` evaluates its arguments.

  See also `is`, `facts`, `forget`, `context`, and `declare`.

  Examples:

      (%i1) assume (xx > 0, yy < -1, zz >= 0);
      (%o1)              [xx > 0, yy < - 1, zz >= 0]
      (%i2) assume (aa < bb and bb < cc);
      (%o2)                  [bb > aa, cc > bb]
      (%i3) facts ();
      (%o3)     [xx > 0, - 1 > yy, zz >= 0, bb > aa, cc > bb]
      (%i4) is (xx > yy);
      (%o4)                         true
      (%i5) is (yy < -yy);
      (%o5)                         true
      (%i6) is (sinh (bb - aa) > 0);
      (%o6)                         true
      (%i7) forget (bb > aa);
      (%o7)                       [bb > aa]
      (%i8) prederror : false;
      (%o8)                         false
      (%i9) is (sinh (bb - aa) > 0);
      (%o9)                        unknown
      (%i10) is (bb^2 < cc^2);
      (%o10)                       unknown

  ·

  Categories: Declarations and inferences

Option variable: assumescalar

  Default value: `true`

  `assumescalar` helps govern whether expressions `expr` for which `nonscalarp (expr)` is `false` are assumed to behave like scalars for certain transformations.

  Let `expr` represent any expression other than a list or a matrix, and let `[1, 2, 3]` represent any list or matrix. Then `expr . [1, 2, 3]` yields `[expr, 2 expr, 3 expr]` if `assumescalar` is `true`, or `scalarp (expr)` is `true`, or `constantp (expr)` is `true`.

  If `assumescalar` is `true`, such expressions will behave like scalars only for commutative operators, but not for noncommutative multiplication `.`.

  When `assumescalar` is `false`, such expressions will behave like non-scalars.

  When `assumescalar` is `all`, such expressions will behave like scalars for all the operators listed above.

  ·

  Categories: Declarations and inferences

Option variable: assume_pos

  Default value: `false`

  When `assume_pos` is `true` and the sign of a parameter x cannot be determined from the current context or other considerations, `sign` and `asksign (x)` return `true`. This may forestall some automatically-generated `asksign` queries, such as may arise from `integrate` or other computations.

  By default, a parameter is x such that `symbolp (x)` or `subvarp (x)`. The class of expressions considered parameters can be modified to some extent via the variable `assume_pos_pred`.

  `sign` and `asksign` attempt to deduce the sign of expressions from the sign of operands within the expression. For example, if `a` and `b` are both positive, then `a + b` is also positive.

  However, there is no way to bypass all `asksign` queries. In particular, when the `asksign` argument is a difference `x - y` or a logarithm `log(x)`, `asksign` always requests an input from the user, even when `assume_pos` is `true` and `assume_pos_pred` is a function which returns `true` for all arguments.

  ·

  Categories: Declarations and inferences

Option variable: assume_pos_pred

  Default value: `false`

  When `assume_pos_pred` is assigned the name of a function or a lambda expression of one argument x, that function is called to determine whether x is considered a parameter for the purpose of `assume_pos`. `assume_pos_pred` is ignored when `assume_pos` is `false`.

  The `assume_pos_pred` function is called by `sign` and `asksign` with an argument x which is either an atom, a subscripted variable, or a function call expression. If the `assume_pos_pred` function returns `true`, x is considered a parameter for the purpose of `assume_pos`.

  By default, a parameter is x such that `symbolp (x)` or `subvarp (x)`.

  See also `assume` and `assume_pos`.

  Examples:

      (%i1) assume_pos: true$
      (%i2) assume_pos_pred: symbolp$
      (%i3) sign (a);
      (%o3)                          pos
      (%i4) sign (a[1]);
      (%o4)                          pnz
      (%i5) assume_pos_pred: lambda ([x], display (x), true)$
      (%i6) asksign (a);
                                    x = a

      (%o6)                          pos
      (%i7) asksign (a[1]);
                                   x = a
                                        1

      (%o7)                          pos
      (%i8) asksign (foo (a));
                                 x = foo(a)

      (%o8)                          pos
      (%i9) asksign (foo (a) + bar (b));
                                 x = foo(a)

                                 x = bar(b)

      (%o9)                          pos
      (%i10) asksign (log (a));
                                    x = a

      Is  a - 1  positive, negative, or zero?

      p;
      (%o10)                         pos
      (%i11) asksign (a - b);
                                    x = a

                                    x = b

                                    x = a

                                    x = b

      Is  b - a  positive, negative, or zero?

      p;
      (%o11)                         neg

  ·

  Categories: Declarations and inferences

Option variable: context

  Default value: `initial`

  `context` names the collection of facts maintained by `assume` and `forget`. `assume` adds facts to the collection named by `context`, while `forget` removes facts.

  Binding `context` to a name foo changes the current context to foo. If the specified context foo does not yet exist, it is created automatically by a call to `newcontext`. The specified context is activated automatically.

  See `contexts` for a general description of the context mechanism.

  ·

  Categories: Declarations and inferences

Option variable: contexts

  Default value: `[initial, global]`

  `contexts` is a list of the contexts which currently exist, including the currently active context.

  The context mechanism makes it possible for an user to bind together and name a collection of facts, called a context. Once this is done, the user can have Maxima assume or forget large numbers of facts merely by activating or deactivating their context.

  Any symbolic atom can be a context, and the facts contained in that context will be retained in storage until destroyed one by one by calling `forget` or destroyed as a whole by calling `kill` to destroy the context to which they belong.

  Contexts exist in a hierarchy, with the root always being the context `global`, which contains information about Maxima that some functions need. When in a given context, all the facts in that context are "active" (meaning that they are used in deductions and retrievals) as are all the facts in any context which is a subcontext of the active context.

  When a fresh Maxima is started up, the user is in a context called `initial`, which has `global` as a subcontext.

  See also `facts`, `newcontext`, `supcontext`, `killcontext`, `activate`, `deactivate`, `assume`, and `forget`.

  ·

  Categories: Declarations and inferences

Function: deactivate (context_1, …, context_n)

  Deactivates the specified contexts context_1, …, context_n.

  ·

  Categories: Declarations and inferences

Function: facts
`facts` (item)
`facts` ()

  If item is the name of a context, `facts (item)` returns a list of the facts in the specified context.

  If item is not the name of a context, `facts (item)` returns a list of the facts known about item in the current context. Facts that are active, but in a different context, are not listed.

  `facts ()` (i.e., without an argument) lists the current context.

  ·

  Categories: Declarations and inferences

Function: forget
`forget` (pred_1, …, pred_n)
`forget` (L)

  Removes predicates established by `assume`. The predicates may be expressions equivalent to (but not necessarily identical to) those previously assumed.

  `forget (L)`, where L is a list of predicates, forgets each item on the list.

  ·

  Categories: Declarations and inferences

Function: is (expr)

  Attempts to determine whether the predicate expr is provable from the facts in the `assume` database.

  If the predicate is provably `true` or `false`, `is` returns `true` or `false`, respectively. Otherwise, the return value is governed by the global flag `prederror`. When `prederror` is `true`, `is` complains with an error message. Otherwise, `is` returns `unknown`.

  `ev(expr, pred)` (which can be written `expr, pred` at the interactive prompt) is equivalent to `is(expr)`.

  See also `assume`, `facts`, and `maybe`.

  Examples:

  `is` causes evaluation of predicates.

      (%i1) %pi > %e;
      (%o1)                       %pi > %e
      (%i2) is (%pi > %e);
      (%o2)                         true

  `is` attempts to derive predicates from the `assume` database.

      (%i1) assume (a > b);
      (%o1)                        [a > b]
      (%i2) assume (b > c);
      (%o2)                        [b > c]
      (%i3) is (a < b);
      (%o3)                         false
      (%i4) is (a > c);
      (%o4)                         true
      (%i5) is (equal (a, c));
      (%o5)                         false

  If `is` can neither prove nor disprove a predicate from the `assume` database, the global flag `prederror` governs the behavior of `is`.

      (%i1) assume (a > b);
      (%o1)                        [a > b]
      (%i2) prederror: true$
      (%i3) is (a > 0);
      Maxima was unable to evaluate the predicate:
      a > 0
       -- an error.  Quitting.  To debug this try debugmode(true);
      (%i4) prederror: false$
      (%i5) is (a > 0);
      (%o5)                        unknown

  ·

  Categories: Predicate functions ·Declarations and inferences

Function: killcontext (context_1, …, context_n)

  Kills the contexts context_1, …, context_n.

  If one of the contexts is the current context, the new current context will become the first available subcontext of the current context which has not been killed. If the first available unkilled context is `global` then `initial` is used instead. If the `initial` context is killed, a new, empty `initial` context is created.

  `killcontext` refuses to kill a context which is currently active, either because it is a subcontext of the current context, or by use of the function `activate`.

  `killcontext` evaluates its arguments. `killcontext` returns `done`.

  ·

  Categories: Declarations and inferences

Function: maybe (expr)

  Attempts to determine whether the predicate expr is provable from the facts in the `assume` database.

  If the predicate is provably `true` or `false`, `maybe` returns `true` or `false`, respectively. Otherwise, `maybe` returns `unknown`.

  `maybe` is functionally equivalent to `is` with `prederror: false`, but the result is computed without actually assigning a value to `prederror`.

  See also `assume`, `facts`, and `is`.

  Examples:

      (%i1) maybe (x > 0);
      (%o1)                        unknown
      (%i2) assume (x > 1);
      (%o2)                        [x > 1]
      (%i3) maybe (x > 0);
      (%o3)                         true

  ·

  Categories: Predicate functions ·Declarations and inferences

Function: newcontext
`newcontext` (name)
`newcontext` ()

  Creates a new, empty context, called name, which has `global` as its only subcontext. The newly-created context becomes the currently active context.

  If name is not specified, a new name is created (via `gensym`) and returned.

  `newcontext` evaluates its argument. `newcontext` returns name (if specified) or the new context name.

  ·

  Categories: Declarations and inferences

Function: sign (expr)

  Attempts to determine the sign of expr on the basis of the facts in the current data base. It returns one of the following answers: `pos` (positive), `neg` (negative), `zero`, `pz` (positive or zero), `nz` (negative or zero), `pn` (positive or negative), or `pnz` (positive, negative, or zero, i.e. nothing known).

  See also `signum`.

  ·

  Categories: Declarations and inferences

Function: supcontext
`supcontext` (name, context)
`supcontext` (name)
`supcontext` ()

  Creates a new context, called name, which has context as a subcontext. context must exist.

  If context is not specified, the current context is assumed.

  If name is not specified, a new name is created (via `gensym`) and returned.

  `supcontext` evaluates its argument. `supcontext` returns name (if specified) or the new context name.

  ·

  Categories: Declarations and inferences

Next: Functions and Variables for Predicates, Previous: Functions and Variables for Properties, Up: Maxima's Database [Contents][Index]