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/phrases

Phrases as the CAS's first client, each closed form a check

A phrase asks for a quantity, not an algorithm: integrate x^2 from 1 to 2 asks for , and Gauss-Legendre is one way to get it. When the CAS has the quantity in closed form, the phrase's number can be held to it. viv check --phrases prog.viv writes a program that calls the defs below, one per phrase, and runs it (lang/viv/src/cas_check.rs). Each check prints what the CAS found, the phrase's own number, the difference and the tolerance, and one __cas__ line of JSON for the tools:

  • cas_check_integral: the antiderivative (checked by differentiating it), the exact value , and the method's tolerance. For a rule with a fixed number of intervals (Simpson's, the trapezoid rule) the tolerance is the error the Euler-Maclaurin formula predicts from the CAS's own derivatives at the ends: for the trapezoid rule and for Simpson's, twice that plus rounding. The check prints the predicted error beside the observed one.
  • cas_check_root: every real root of the polynomial in closed form; the phrase's root must be one of them (inside the bracket, for a bracketing method).
  • cas_check_deriv: the exact derivative, evaluated at the point.
  • cas_check_value: a closed form the compiler wrote out (the trace of a literal matrix, the norm of a literal vector).

A phrase the CAS has no closed form for is refused, with the reason, never passed. Two warnings come from the CAS knowing the problem: a bracketing method given an interval where the function does not change sign, and Newton's method at a multiple root, where it converges linearly and stops about away; there the tolerance is relative and the warning says why.

cas_deriv_at is what differentiate F at X using the symbolic derivative lowers to: the CAS differentiates F once (the result is kept by its text) and evaluates the derivative at X with the program's values for the other names.

Used with import cas.phrases.

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 42–382