This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · lib/cas/eval

Evaluating a CAS expression in doubles, mod p and in balls

Three evaluators of an expression of the store (lib/cas/store), each given the values of its symbols in a map from the symbol's id:

  • cas_eval(e, env): in doubles, with Viv's own exp, log, sin, erf and the rest, so every engine gives the same bits. pi is the double nearest . A refusal, a symbol with no value, or a power the reals do not have (a negative number to a fractional power) gives NaN.
  • cas_mod(e, env): the residue mod (lib/cas/rational), for an expression that is a rational function of its symbols: numbers, sums, products and integer powers. It gives MOD_UNLUCKY when a denominator is 0 mod at that point (the certificate draws another point) and MOD_NOT_RATIONAL for anything else (a function, , a fractional power).
  • cas_ball(e, envm, envr): a midpoint and a radius that contain the expression's value when each symbol s lies within envr[s] of envm[s]. Each operation adds two units of relative to its radius for its own rounding, and each function uses a bound on its derivative over the ball; the functions assume Viv's libm is within one unit in the last place (fdlibm's own analysis, lang/viv/src/vmath; not proved here). A radius of NaN means the ball is not known: a pole or a domain edge is inside it. This is ball arithmetic in doubles instead of Arb's multiprecision balls, so a ball can refute an equality and can only support one. cas_sign reads the sign of an expression off its ball.

Used with import cas.eval.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 30–406