Assumptions

Assumptions

Whether a step of algebra is valid often depends on what the letters stand for. An assumption says it: x is positive, n is an integer, t lies between 0 and 1. From assumptions the library proves signs, and it only uses a rule when the proof is there.

Stating them

import { assume } from "@ratmath/symbolic";

const A = assume({
  x: "positive",            // also negative, nonnegative, nonpositive, nonzero, real
  n: "integer, >= 1",       // several facts, separated by commas
  t: "in (0, 1]",           // an interval with open or closed ends
  u: "> 2",                 // a comparison with an exact number
  w: "0:!w:5",              // a Core chain: 0 < w ≤ 5
  s: [0, 10],               // a closed interval as a pair
});

A Core RationalInterval or Region is accepted as well, so the same object that describes a domain elsewhere in RatMath can be the assumption here. Every function that takes options accepts { assume: … } with either the object above or the plain description.

What follows from them

A.sign("x^2 + x + 1");        // "positive"
A.sign("log(t)");             // "nonpositive"   (t ≤ 1)
A.sign("x - u");              // "unknown"
A.range("t*(1 - t)");         // { lo: 0, hi: 1, loClosed: true, hiClosed: false }: a bound, not the exact range
A.proves("u^2 > 4");          // true
A.proves("x < 0");            // false   (proven false)
A.proves("x > u");            // null    (undecided)
A.proves("integer(n^2 + 3n)");   // true

proves has three answers and only two of them are proofs. null means the library could not decide, which is different from the statement being false.

How a sign is proven

Three methods are tried in turn.

Interval arithmetic with unbounded ends. Each variable has a range such as (0,∞)(0, \infty), and the range of an expression is bounded by combining ranges: (0,∞)+[1,2]=(1,∞)(0,\infty) + [1, 2] = (1, \infty), a square is ≥0\ge 0, eu>0e^u > 0, log⁡\log of something >1> 1 is positive. Open and closed ends are tracked, which is what separates "positive" from "nonnegative". The bounds of exp⁡\exp, log⁡\log and the others at finite ends are certified enclosures from analytic.

Factoring. Interval arithmetic sees x2−2x+1x^2 - 2x + 1 as [0,∞)−(−∞,∞)+1[0,\infty) - (-\infty,\infty) + 1, which says nothing. Factored as (x−1)2(x - 1)^2 it is plainly ≥0\ge 0.

Counting real roots. A polynomial in one variable that has no real root in the variable's range cannot change sign there. A Sturm sequence counts the roots exactly, so x2−2x+2x^2 - 2x + 2 is proven positive for all real xx, and x2−3x+2x^2 - 3x + 2 is proven positive for x>2x > 2.

None of these is complete: a true inequality can come back "unknown". What is guaranteed is the other direction: an answer other than unknown is a theorem.

Try itEdit the code and run it with @ratmath/symbolic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs