assume
Tells Nerdamer that a variable lies in a range of real numbers.
Other operations use the range: comparisons, max and min, square roots and logarithm rules that depend on sign.
Repeated assumptions about one variable combine. An assumption that contradicts the current ones is an error, and the earlier ones stay.
Bounds stay exact: fractions and roots such as sqrt(2) aren't rounded. You can also relate two variables by a constant, as in assume(x<y+1) or assume(2*x+3<2*y+5), and the bound carries over from one variable to the other.
Nerdamer only concludes what the ranges prove. It can prove the sign of sums of assumed variables, products of positive values, some integer and reciprocal powers, and square roots of nonnegative values. A result can be true, false or unknown; comparisons give 1 only for true.
Notation
assume(expr)
Write it in an expression: nerdamer('assume(x>0); assume(y<0); max(x,y)'), or in the Playground.
nerdamer.assume
nerdamer.assume(expr: string): Assumption
A method on the default import. Arguments can be strings, as in Notation.
import { assume }
import { assume } from 'nerdamer/assumptions';
assume(expr: string): Assumption
Import only this function, from nerdamer/assumptions.
Examples
x is positive and y negative, so x is larger.
assume(x>0); assume(y<0); max(x,y)
// → xOpen in PlaygroundBoth positive, so the logarithms combine.
assume(x>0); assume(y>0); simplify(log(x)+log(y))
// → log(x*y)Open in PlaygroundA bound passed on through another variable.
assume(x<y+1); assume(y<=3); x<4
// → 1Open in PlaygroundGood to know
- Assumptions last until you remove them.
forget(x)removes those aboutx, and with them any relationxis part of;forget(all)removes all of them. In JavaScript, useforgetAssumptionFor(x)andclearAssumptions(). - Reciprocal bounds need a range that excludes zero, and square-root bounds need a range of nonnegative values.
- An even power such as
x^2is never negative, but that doesn't make it positive: it can be zero. - Relations other than a constant difference, such as
assume(x<y^2), are errors. getAssumptionFor(x)returns only the range you stated forx, not one derived from relations.- From JavaScript,
nerdamer.assumetakes a variable, a comparison and a number. Notation also accepts expressions such as1/3orsqrt(2)as the bound.
