R/MRatCalcpowered by RiX

RiX walkthrough 14 d

Exact continued-fraction reals in RiX

Explore finite values, lazy coefficient rules, convergent cylinders, and bounded refinement.

This plugin is written entirely in RiX. The same coefficient rules and exact refinement code run in the CLI, RiX Web, and RiX Notebook without a JavaScript plugin permission boundary.

Finite continued fractions

A finite coefficient sequence is an exact Rational presentation. RiX's native continued-fraction literals interoperate through the callable plugin root:

Runnable RiX

Both rows end at 355/113. Coefficients are indexed from zero in the usual mathematical notation, while Convergent(n) consumes n coefficients.

Evaluate a nonregular generalized form

A generalized continued fraction stores separate partial numerators and denominators. Finite forms may use signed exact coefficients, so their convergents come from the continuant recurrence rather than the regular positive-tail cylinder rule:

Runnable RiX

The value is 1/4, and its canonical regular form is [0,4]. If a continuant denominator becomes zero, ConvergentResult records that exact witness and ZeroStatus stays :unknown; the plugin does not invent an infinite value or reuse the positive-tail proof from simple continued fractions.

A lazy quadratic irrational

The familiar expansion sqrt(2) = [1; overline{2}] never terminates. Its successive exact Rational convergents alternate around the real value:

Runnable RiX

Each cylinder is the ordered interval between two consecutive convergents. The exact determinant identity makes its width shrink rapidly without using a floating-point estimate.

Define a coefficient rule

Lazy accepts any RiX callable. The constructor validates the first cylinder, then validates each later coefficient when refinement requests it:

Runnable RiX

For an arbitrary rule, the claim that every future tail coefficient stays positive remains an explicit constructor guarantee. Observed violations are rejected rather than silently producing an invalid enclosure.

Bounded refinement and Halo comparisons

The shared Numerics protocol advances at most one coefficient per call and keeps the narrowest certified cylinder reached within the budget:

Runnable RiX

Try changing maxWork to 0, 1, and 2. The comparison remains undecided until the available convergent cylinder separates the two neighborhoods.

Extract a certified function stream

Any certified arbitrarily refinable singleton real can be exposed as a native regular-CF stream. The source continues to provide enclosing evidence; the extractor decides permanent coefficients with exact RationalInterval floors:

Runnable RiX

CoefficientResult(index,{=trace=1}) shows each requested source enclosure, its image under the accumulated Möbius form, the two endpoint floors, and each accepted output. maxRefinements, sourceMaxWork, and initialSourceWidth bound the transaction.

The method is also an accelerated Farey walk. Repeated moves toward one Farey parent form a run; the run length is the next continued-fraction coefficient. Testing individual mediants exposes intermediate brackets, while a stable floor determines the complete run length at once. Both schedules stall at the same exact rational boundaries unless equality can be proved.

Roots choose the strongest available representation

Runnable RiX

Perfect powers are finite, nonsquare rational square roots are periodic, and other roots use certified function extraction. Calling FromRefinable(.numerics.Sqrt(4)) deliberately bypasses the exact shortcut and illustrates why an interval-only provider can remain stuck around the Integer boundary 2; .cf.Sqrt(4) proves the finite result immediately.

Arithmetic of continued-fraction reals

Native continued-fraction operands use exact Gosper homographic and bihomographic coefficient transducers by default. The certified recipe remains attached as the numerical enclosure witness:

Runnable RiX

Every emitted term follows from agreeing exact corner floors of Gosper's bihomographic form. CoefficientResult(n,{=maxInputTerms=...,trace=1}) exposes the bounded decision and its input/output transactions. It may report budgetExhausted when a coefficient is not yet forced; Coefficient(n) never substitutes a guess.

Finite arithmetic is folded exactly. Identity-aware shortcuts prove x-x=0 and nonzero x/x=1, while separately constructed equal streams retain bounded uncertainty because matching prefixes do not prove correlation. Use ZeroStatus() to distinguish exact zero, certified nonzero, and unknown. Combining a continued fraction with a Cauchy or algebraic real still chooses their common certified Oracle target.

For a transaction-by-transaction explanation and all four demonstrations, see the [Gosper arithmetic exploration](../../explorations/continued-fractions/gosper-arithmetic.md).

Recognize the periodic quadratic equation

An explicitly periodic stream determines an exact Möbius fixed point. The plugin eliminates that repeating tail and returns a primitive quadratic form without using floating-point recognition:

Runnable RiX

The three equations are x^2-2=0, x^2-6x+7=0, and 2x^2-1=0. The returned source cylinder still encloses the represented root; no decimal root choice is guessed.

Query a denominator-bounded best approximation

The second-kind query minimizes the exact scaled error |q*x-p| through the requested denominator bound. It reads one further convergent to certify that the next denominator is outside the search range:

Runnable RiX

The first row certifies 7/5 because the next convergent has denominator 12. The second row keeps 3/2, but reports budget exhaustion instead of claiming that two observed coefficients settle every denominator through 100.