# Contexts

## Definitions for Contexts

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.

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.

Function: assume (pred_1, ..., pred_n)
Adds predicates pred_1, ..., pred_n to the current database, after checking for redundancy and inconsistency. If the predicates are consistent and non-redundant, they are added to the data base; if inconsistent or redundant, no action is taken.

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

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.

Option variable: assume_pos
Default value: `false`

When `assume_pos` is `true` and the sign of a parameter x cannot be determined from the `assume` database 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.

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)\$
x = a

(%o6)                          pos
x = a
1

(%o7)                          pos
x = foo(a)

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

x = bar(b)

(%o9)                          pos
x = a

Is  a - 1  positive, negative, or zero?

p;
(%o10)                         pos
x = a

x = b

x = a

x = b

Is  b - a  positive, negative, or zero?

p;
(%o11)                         neg
```

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 `context` for a general description of the context mechanism.

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 a user to bind together and name a selected portion of his database, 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`.

Function: deactivate (context_1, ..., context_n)
Deactivates the specified contexts context_1, ..., context_n.

Function: facts (item)
Function: 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.

Declaration: features
Maxima recognizes certain mathematical properties of functions and variables. These are called "features".

`declare (x, foo)` gives the property foo to the function or variable `x`.

`declare (foo, feature)` declares a new feature foo. For example, `declare ([red, green, blue], feature)` declares three new features, `red`, `green`, and `blue`.

The predicate `featurep (x, foo)` returns `true` if x has the foo property, and `false` otherwise.

The infolist `features` is a list of known features. These are `integer`, `noninteger`, `even`, `odd`, `rational`, `irrational`, `real`, `imaginary`, `complex`, `analytic`, `increasing`, `decreasing`, `oddfun`, `evenfun`, `posfun`, `commutative`, `lassociative`, `rassociative`, `symmetric`, and `antisymmetric`, plus any user-defined features.

`features` is a list of mathematical features. There is also a list of non-mathematical, system-dependent features. See `status`.

Function: forget (pred_1, ..., pred_n)
Function: 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.

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`.

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

`newcontext` evaluates its argument. `newcontext` returns name.

Function: supcontext (name, context)
Function: supcontext (name)
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.