Function reference · Assumptions and sets

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)
// → x
Open in Playground

With x>=3, the root needs no absolute value.

assume(x>=3); sqrt((x-3)^2)
// → -3+x
Open in Playground

Both positive, so the logarithms combine.

assume(x>0); assume(y>0); simplify(log(x)+log(y))
// → log(x*y)
Open in Playground

An exact irrational bound.

assume(x>sqrt(2)); x>1
// → 1
Open in Playground

A bound passed on through another variable.

assume(x<y+1); assume(y<=3); x<4
// → 1
Open in Playground

Two ranges prove the sign of a sum.

assume(a>5); assume(b<3); a-b-2>0
// → 1
Open in Playground

A bound on a square root.

assume(x>4); sqrt(x)-2>0
// → 1
Open in Playground

Good to know

  • Assumptions last until you remove them. forget(x) removes those about x, and with them any relation x is part of; forget(all) removes all of them. In JavaScript, use forgetAssumptionFor(x) and clearAssumptions().
  • Reciprocal bounds need a range that excludes zero, and square-root bounds need a range of nonnegative values.
  • An even power such as x^2 is 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 for x, not one derived from relations.
  • From JavaScript, nerdamer.assume takes a variable, a comparison and a number. Notation also accepts expressions such as 1/3 or sqrt(2) as the bound.

← Back to Function reference