# Assumptions

Assumptions are statements about symbols that are assumed to be true. For example, the assumption that $$x$$ is a positive real number is used to simplify \|x|\) to $$x$$.

When declaring a symbol, it is possible to specify its domain. For example, the symbol $$x$$ can be declared to be a real number:

ce.declare("x", "RealNumbers");


However, assumptions can be used to describe more complex properties of symbols. For example, the assumption that $$x$$ is positive is used to simplify $$\sqrt{x^2}$$ to $$x$$.

ce.assume(["Greater", "x", 2]);


Assumptions can also describe the relationship between two symbols, for example that $$x$$ is greater than $$y$$:

ce.assume(["Greater", "x", "y"]);


This knowledge base is used by the Compute Engine to simplify expressions.

In general, assumptions are not used when evaluating expressions.

## Defining New Assumptions

To make an assumption about a symbol, use the ce.assume() function.

For example, to indicate $$\beta \in \R$$:

ce.assume(ce.parse("\\beta \\in \\R"));

// or:

ce.assume(["Element", "Beta", "RealNumbers"]);


In this case, this would be equivalent to declaring a domain for the symbol $$\beta$$:

ce.declare("Beta", "RealNumbers");


The head of the proposition can be one of the following:

Element
NotElement
Indicate the domain of a symbol
Less
LessEqual
Greater
GreaterEqual
Inequality. Both sides are assumed to be RealNumbers
Equal
NotEqual
Equality
And
Or
Not
Boolean expression. Using And is equivalent to using multiple assume() for each term of the boolean expression.

If the assume() function is invoked with two arguments, it is equivalent to ce.assume(["Element", <arg1>, <arg2>]).

ce.assume(["Element", "x", "RealNumbers"); // same as ce.assume(["Element", "x", "RealNumbers"])


The argument to the assume() function is a proposition. That proposition is analyzed and the fact it describes are recorded in the Compute Engine assumptions knowledge base. Some propositions can be described in several different but equivalent ways. You can use whichever form you prefer. Similarly, when querying the knowledge base later, you can use any form you’d like.

ce.assume(["Element", "x", "PositiveNumbers"]);

// Equivalent to...
ce.assume(["Greater", "x", 0]);

// ... or ...
ce.assume(["Element", "x", ["Interval", ["Open", 0], "Infinity"]]);


### Multivariate Assumptions

Assumptions frequently describe the property of a symbol. However, it is also possible to describe relationships betwen symbols.

ce.assume(ce.parse('xy + 1 = 0'))'


### Default Assumptions

When creating an instance of a Compute Engine, the following assumptions are made:

Symbol Domain
a b c d
i j k
r t
x y
RealNumbers
f g h Functions
m n
p q
Integers
w z ComplexNumbers

This list of assumptions make it possible to immediately use common symbols such as x or y without having to declare them explicitly.

To specify a different list of assumptions, use the assumptions option when creating a Compute Engine instance:

const ce = new ComputeEngine({
assumptions: [
["Element", "x", "Integers"],
["Element", "y", "Integers"],
],
});


To have no assumptions at all, set the assumptions option to null:

const ce = new ComputeEngine({ assumptions: null });


## Verifyinf Assumptions

To test if a particular assumption is valid, call the ce.verify() function.

ce.verify(["Element", "x", "RealNumbers"]);


The function ce.verify() return true if the assumption is true, false if it is not, and undefined if it cannot be determined.

While ce.verify() is appropriate to get boolean answers, more complex queries can also be made.

To query the assumptions knowledge base call the ce.ask() function.

The argument of ask() can be a pattern, and it returns an array of matches as Substitution objects.

// "x is a positive integer"
ce.assume(["Element", "x", "PositiveIntegers"]);

// "What is x greater than?"

//  -> [{"val": 0}] "It is greater than 0"


## Forgetting Assumptions

Each call to ce.assume() is additive: the previous assumptions are preserved.

To remove previous assumptions, use ce.forget().

• Calling ce.forget() with no arguments will remove all assumptions.
• Passing an array of symbol names will remove assumptions about each of the symbols.
• Passing a symbol name will only remove assumptions about that particular symbol.
ce.assume(["Element", "\\alpha", "RealNumbers"]);
ce.is(["Element", "\\alpha", "RealNumbers"]);
// ➔  true

ce.forget("\\alpha");

ce.is(["Element", "\\alpha", "RealNumbers"]);
// ➔  undefined


## Scoped Assumptions

When an assumption is made, it is applicable to the current scope and all subsequent scopes. Scopes “inherit” assumptions from their parent scopes.

When exiting a scope, with ce.popScope(), all assumptions made in that scope are forgotten.

To temporarily define a series of assumptions, create a new scope.

ce.is(["Element", "\\alpha", "RealNumbers"]);
// ➔ undefined

ce.pushScope();

ce.assume(["Element", "\\alpha", "RealNumbers"]);
ce.is(["Element", "\\alpha", "RealNumbers"]);
// ➔  true

ce.popScope(); // all assumptions made in the current scope are forgotten

ce.is(["Element", "\\alpha", "RealNumbers"]);
// ➔  undefined