5 Mathematical API
| (require animate/math) | package: animate |
This module exports held model values, deterministic local checking, explicit rewrites, and presentation descriptions. It does not import rendering or external CAS-execution modules. All accessors and ordinary constructors here are pure when used with the default local prover. An explicitly installed custom prover must honor its documented callback contract.
5.1 Held states and occurrence identity
procedure
datum : math-datum? id : symbol? = 'math ctx : math-context? = (math-context)
The expression remains held: term order, repeated occurrences, explicit units, zeroes, and unevaluated arithmetic are retained. The default namespace is 'math; supply different #:id values for independent roots. Occurrence paths exclude the operator and are zero-based. Initial domain requirements are retained in the context; a refuted definedness condition raises exn:fail:math?. No CAS or typesetter is loaded by this constructor.
procedure
(math-datum record) → math-datum?
record : math?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
Identity is deterministic and scoped to the mathematical root and derivation, not allocated by a process-global counter.
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-context-of state) → math-context?
state : math?
procedure
(math-occurrences record) → (and/c hash? immutable?)
record : math?
Keys are operand paths. Hash enumeration has no semantic order; use datum-paths or the ordered selector results when order matters.
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-revision record) → any/c
record : math?
Identity is deterministic and scoped to the mathematical root and derivation, not allocated by a process-global counter.
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-with-context state requested-context [ #:scope scope]) → math? state : math? requested-context : math-context? scope : (or/c symbol? #f) = #f
Existing domain restrictions survive this update. An inconsistent context is rejected. Scope must be a symbol or false. A supplied scope changes the revision tag but does not silently allocate a new global identity namespace.
procedure
(math-occurrence-at state path) → occurrence?
state : math? path : (listof exact-nonnegative-integer?)
procedure
(math-inspect state path) → (and/c hash? immutable?)
state : math? path : (listof exact-nonnegative-integer?)
procedure
(math-datum? x) → boolean?
x : any/c
Recognizes finite real atoms, booleans, symbols, and proper symbol-headed application lists. The constructor additionally validates known operator arities. This predicate does not establish mathematical validity or real-valuedness.
procedure
(held-substitute x replacements) → math-datum?
x : math-datum? replacements : (or/c hash? list?)
Substitution is simultaneous: replacement results are not substituted again. It does not rebuild ancestors through simplifying CAS constructors. Traversal under binders is rejected rather than risking variable capture. The operation returns ordinary data and retains no replacement map.
procedure
x : math-datum? target : math-datum?
Tests structural absence, not algebraic independence. Equivalent but differently written expressions are not treated as equal.
procedure
(datum-ref x p) → math-datum?
x : math-datum? p : (listof exact-nonnegative-integer?)
An empty path denotes the root. Each nonnegative index selects an operand, not a list element including the operator. Invalid paths raise a diagnostic.
procedure
(datum-paths x [p]) → (listof (listof exact-nonnegative-integer?))
x : math-datum? p : (listof exact-nonnegative-integer?) = '()
Returns the root first, followed by operands recursively in their stored order. The optional prefix is prepended to every returned path.
procedure
(occurrence? value) → boolean?
value : any/c
procedure
(occurrence-id record) → symbol?
record : occurrence?
Identity is deterministic and scoped to the mathematical root and derivation, not allocated by a process-global counter.
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(occurrence-path record) → (listof exact-nonnegative-integer?)
record : occurrence?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(occurrence-datum record) → math-datum?
record : occurrence?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(exn:fail:math? value) → boolean?
value : any/c
procedure
(exn:fail:math-code record) → symbol?
record : exn:fail:math?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(exn:fail:math-details record) → list?
record : exn:fail:math?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
parameter
(current-math-validation) → (or/c 'strict 'draft)
(current-math-validation mode) → void? mode : (or/c 'strict 'draft)
parameter
(current-math-prover prover) → void? prover : procedure?
5.2 Contexts and evidence
procedure
(math-context [ #:real real #:assuming assumptions #:definitions definitions]) → math-context? real : (listof symbol?) = '() assumptions : (listof math-datum?) = '() definitions : (or/c hash? list?) = '()
Only declared symbols are assumed real. Assumptions retain declaration order. Definitions may be a hash or a list of two-element name/expression lists; names must be symbols, duplicates in list input are rejected, and cycles are rejected. The stored definition hash is immutable. A definition is an abbreviation, not a new unconstrained variable.
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-context? value) → boolean?
value : any/c
procedure
(math-context-real record) → (listof symbol?)
record : math-context?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-context-assumptions record) → (listof math-datum?)
record : math-context?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-context-definitions record) → (and/c hash? immutable?)
record : math-context?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-context-restrictions record) → (listof math-datum?)
record : math-context?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(context-assume c guard) → math-context?
c : math-context? guard : math-datum?
procedure
(context-add-restrictions c rs) → math-context?
c : math-context? rs : (listof math-datum?)
procedure
(context-expand c x) → math-datum?
c : math-context? x : math-datum?
procedure
(context-prove c p) → verification?
c : math-context? p : math-datum?
Returns established, refuted, or unknown evidence. Definedness is checked before algebraic identity reasoning, so simplifying a quotient cannot erase its excluded points. This is a bounded elementary checker, not a complete prover.
procedure
(context-signs c expr [fuel]) → (listof exact-integer?)
c : math-context? expr : math-datum? fuel : exact-nonnegative-integer? = 24
The result is a conservative subset of '(-1 0 1). Its entries mean negative, zero, and positive. The default recursion budget is 24. Exhaustion returns uncertainty; it never silently assumes positivity.
procedure
(context-real? c x [fuel]) → boolean?
c : math-context? x : math-datum? fuel : exact-nonnegative-integer? = 40
The default recursion budget is 40. Failure to establish real-valuedness returns false, which does not prove non-real-valuedness.
procedure
c : math-context?
procedure
(context-facts c) → (listof math-datum?)
c : math-context?
procedure
(check-case-coverage c guards) → verification?
c : math-context? guards : (listof math-datum?)
Checks both exhaustiveness and pairwise disjointness using at most seven propositional sign atoms. Unsupported guards or a larger problem return unknown evidence. Branch declaration order is preserved separately by the derivation.
procedure
(verification? value) → boolean?
value : any/c
procedure
(verification-status record)
→ (or/c 'established 'refuted 'unknown) record : verification?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(verification-method record) → symbol?
record : verification?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(verification-proposition record) → any/c
record : verification?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(verification-obligations record) → list?
record : verification?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(verification-message record) → (and/c string? immutable?)
record : verification?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(verification-details record) → any/c
record : verification?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(established method proposition [details]) → verification?
method : symbol? proposition : math-datum? details : any/c = '()
This constructs evidence metadata; it does not itself prove the proposition. Custom provers and service adapters are trusted to supply truthful reports. Acyclic metadata containers, including strings, vectors, boxes, and hashes, are copied immutably; already validated verification records may be nested. Cyclic metadata, procedures, and opaque native resources are rejected. This prevents external result handles from changing previously recorded evidence.
procedure
(unknown method proposition [ obligations message details]) → verification? method : symbol? proposition : math-datum? obligations : list? = (list proposition) message : string? = "Not established." details : any/c = '()
Records explicit unresolved obligations. Unknown is never interpreted as true. Empty obligation lists still leave the report status unknown.
procedure
(refuted method proposition [message details]) → verification?
method : symbol? proposition : math-datum? message : string? = "Refuted." details : any/c = '()
Constructs a refutation report rather than throwing an exception. Application of a refuted rewrite is rejected even in draft mode.
procedure
(merge-verifications checks [proposition]) → verification?
checks : (listof verification?) proposition : math-datum? = 'derivation
Refutation takes precedence over unknown, and unknown takes precedence over established. Report order is retained in the combined details.
5.3 Selectors
Selects the complete root. Selectors refer to the input snapshot of the operation, not a location remembered from a different revision.
The containing selection must resolve to a binary relation. It is not a text search for the material left of the first rendered equals sign.
The containing selection must resolve to a binary relation. The selector returns its second mathematical operand.
Requires a held quotient '(/ numerator denominator). It does not invent a quotient view of a product with a negative exponent.
procedure
(denominator [within]) → selector?
within : selector? = (whole)
Requires explicit quotient syntax. No implicit CAS normalization is used when resolving this selector.
procedure
p : (listof exact-nonnegative-integer?)
Validates the path shape immediately. Range validation occurs against a specific held expression when the selector is resolved.
procedure
(matching datum [ #:occurrence ordinal #:within within]) → selector? datum : math-datum? ordinal : (or/c exact-positive-integer? #f) = #f within : selector? = (whole)
Matches structural data within the selected subtree in preorder. #:occurrence is one-based. Without it, all matches are returned; an operation requiring one match diagnoses ambiguity instead of selecting the first.
procedure
(all-matching datum [#:within within]) → selector?
datum : math-datum? within : selector? = (whole)
Returns all structural matches in preorder. Repeated equal values retain their distinct occurrence identities.
procedure
(operator-of [within]) → selector?
within : selector? = (whole)
Selects the owning mathematical expression. The visual adapter may then address its operator role; this selector does not create a separate AST operand.
procedure
(resolve-selector state s)
→ (listof (listof exact-nonnegative-integer?)) state : (or/c math? math-datum?) s : selector?
procedure
(resolve-one state s) → (listof exact-nonnegative-integer?)
state : (or/c math? math-datum?) s : selector?
procedure
(math-select state s) → (listof occurrence?)
state : math? s : selector?
5.4 Operations and template rules
procedure
(math-operation? value) → boolean?
value : any/c
procedure
(math-operation-name record) → symbol?
record : math-operation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-operation-selector record) → selector?
record : math-operation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(apply-math-operation state op [#:name name]) → rewrite-step?
state : math? op : math-operation? name : symbol? = (math-operation-name op)
The focus must resolve uniquely. The operation constructs a held edit, checks its obligations, retains the original domain restrictions, and commits a new immutable state. No animation or typesetting is performed.
procedure
(both-sides op operand [ #:at focus #:relationship relationship]) → math-operation? op : symbol? operand : math-datum? focus : selector? = (whole) relationship : symbol? = 'equivalence
Accepts 'add, 'subtract, 'multiply, 'divide, or 'power. Equivalence is the default. Multiplication and division require the appropriate nonzero conditions. Multiplying an inequality by a known negative value reverses its direction; an undecided sign is not guessed. Squaring is available as an explicit 'implication, not as an automatic solution-preserving equivalence.
procedure
(cancel-addends [#:at focus #:pair pair]) → math-operation?
focus : selector? = (whole) pair : (or/c list? #f) = #f
Cancels one additive-inverse pair in the selected sum. A supplied pair is a two-element list of zero-based signed-addend indices. With no pair, cancellation requires a unique match. More than one eligible pair is an ambiguity error.
procedure
(cancel-factor [ #:at focus] #:factor factor [ #:keep-one? keep-one?]) → math-operation? focus : selector? = (whole) factor : math-datum? keep-one? : boolean? = #f
Requires an explicitly held quotient and the specified common factor. The factor must be nonzero in the current context. Retained domain exclusions survive cancellation. With #:keep-one? #t, a visible unit is retained for a subsequent remove-unit step.
procedure
(remove-unit [#:at focus]) → math-operation?
focus : selector? = (whole)
Removes an explicitly displayed multiplicative unit. This is separate from cancellation so its disappearance can receive its own animation phase.
procedure
(reduce-identities [#:at focus]) → math-operation?
focus : selector? = (whole)
Applies the implemented zero, unit, and sign identities within the selected focus. Unrelated portions of the held expression are not normalized.
procedure
(evaluate [#:at focus #:mode mode]) → math-operation?
focus : selector? = (whole) mode : symbol? = 'all
The mode is 'all or 'deepest. Arithmetic is exact; non-perfect radicals and unsupported operations remain held. Equations remain visible equations instead of collapsing to booleans.
procedure
(rewrite-to target [#:at focus #:using rule]) → math-operation?
target : math-datum? focus : selector? = (whole) rule : symbol? = 'rational-identity
The target is explicit held data. The implemented policy checks rational or polynomial identity and records a focused replacement. A rule name labels the step; it does not manufacture a fine-grained derivation that a CAS never supplied. Target equivalence does not authorize discarding domain restrictions.
procedure
(reorder-addends [#:at focus] #:order order) → math-operation?
focus : selector? = (whole) order : (listof exact-nonnegative-integer?)
The order must be a permutation of all zero-based signed-addend indices. Signs travel with the terms. Missing, repeated, or out-of-range indices are rejected.
procedure
(zero-product [#:at focus]) → math-operation?
focus : selector? = (whole)
Requires a product equation equal to zero over real scalars. The result is an explicit disjunction of factor equations, retaining all alternatives.
procedure
(square-solutions [#:at focus]) → math-operation?
focus : selector? = (whole)
Requires a square equation. A positive right side produces positive- and negative-root alternatives; zero produces one alternative; a negative right side has no real solutions. An unknown sign is an unresolved obligation rather than an implicit choice of the positive branch.
procedure
(abbreviate name [#:at focus]) → math-operation?
name : symbol? focus : selector? = (whole)
The name must have a scoped definition, and the selected expression must match the defined value under the available checks. The definition remains in the context for subsequent reasoning and display.
procedure
(each-branch op) → math-operation?
op : math-operation?
Applies the supplied operation to each direct disjunction alternative. It does not recursively search arbitrary nested case trees.
procedure
(substitute replacements [#:at focus]) → math-operation?
replacements : (or/c hash? list?) focus : selector? = (whole)
Accepts a hash or an association list of replacement pairs. Captures an immutable copy of the caller’s replacement map when this operation is constructed. Subsequent caller mutation cannot change its result. The recorded relationship is specialization, not equation equivalence.
procedure
(conclude classification #:for variable) → math-operation?
classification : symbol? variable : symbol?
Accepts 'all-real or 'no-solutions. These are checked classifications, not arbitrary labels. Original-domain restrictions prevent an incorrect claim that every real value is allowed.
procedure
(assert-step target [ #:at focus #:reason reason]) → math-operation? target : math-datum? focus : selector? = (whole) reason : string? = "Author-supplied target."
Creates an explicitly unverified author-supplied target. Strict mode rejects unresolved application. Draft presentation requires an explicit opt-in and displays an unverified warning.
syntax
(define-math-rule name #:metavariables (variable ...) #:from before-template #:to after-template)
(define-math-rule distribute-left #:metavariables (u v w) #:from (* u (+ v w)) #:to (+ (* u v) (* u w)) #:check polynomial-identity)
procedure
(make-math-rule name variables before after [ #:requires requires #:merge merge #:version version #:check check]) → math-rule? name : symbol? variables : (listof symbol?) before : math-datum? after : math-datum? requires : (listof math-datum?) = '() merge : (or/c symbol? #f) = #f version : exact-positive-integer? = 1 check : symbol? = 'polynomial-identity
Metavariables are unique symbols in declaration order. Templates stay held. Checks are 'polynomial-identity or 'author-assertion. A repeated source metavariable requires an explicit #:merge 'merge policy before several source occurrences can contribute to a destination. Rule versions are positive exact integers.
procedure
(math-rule? value) → boolean?
value : any/c
procedure
(math-rule-name record) → symbol?
record : math-rule?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(use-rule rule [#:at focus]) → math-operation?
rule : math-rule? focus : selector? = (whole)
Creates an operation descriptor. The selector is resolved and the rule is checked only when the operation is applied to a mathematical state.
procedure
(apply-rule rule [#:at focus]) → math-operation?
rule : math-rule? focus : selector? = (whole)
An alias of use-rule. It creates an operation, not an applied rewrite step. Use apply-rewrite for immediate application.
procedure
(apply-rewrite rule state [ #:name name #:at focus]) → rewrite-step? rule : math-rule? state : math? name : symbol? = (math-rule-name rule) focus : selector? = (whole)
Combines use-rule with apply-math-operation. The requested step name is independent of the reusable rule name.
procedure
(template-bindings template value variables)
→
(and/c hash? immutable?) (and/c hash? immutable?) template : math-datum? value : math-datum? variables : (listof symbol?)
Returns two values: an immutable binding hash and an immutable hash of ordered source witness paths. Matching is structural; it does not silently commute or reassociate terms. Conflicting repeated metavariables raise an error.
5.5 Derivations and branches
syntax
(steps [name operation] ...)
(define (subtract-and-cancel amount) (steps [subtract (both-sides 'subtract amount)] [cancel (cancel-addends #:at (lhs))])) (derive problem [isolate-term (subtract-and-cancel 5)])
procedure
(steps/proc entries) → step-sequence?
entries : list?
procedure
(step-sequence? value) → boolean?
value : any/c
procedure
(derivation-tree record) → (listof derivation-node?)
record : derivation?
procedure
(derivation-node? value) → boolean?
value : any/c
procedure
(derivation-node-path record) → (listof symbol?)
record : derivation-node?
procedure
(derivation-node-before record) → math?
record : derivation-node?
procedure
(derivation-node-after record) → math?
record : derivation-node?
procedure
(derivation-node-children record) → (listof derivation-node?)
record : derivation-node?
procedure
(derivation-node-step record) → (or/c rewrite-step? #f)
record : derivation-node?
procedure
(derivation-node-at source address) → derivation-node?
source : (or/c derivation? case-derivation? solution-check?) address : (or/c symbol? (listof symbol?))
(derivation-node-at solution '(isolate-term cancel-five)) (derivation-node-at general-solution '(ordinary isolate-x))
procedure
(derivation-node-relation record) → symbol?
record : derivation-node?
procedure
(derivation-node-verification record) → verification?
record : derivation-node?
procedure
(derivation-step-paths record) → (listof (listof symbol?))
record : derivation?
syntax
(derive initial [name operation] ...)
(derive (math '(= (+ (* 3 x) 5) 17) #:context (math-context #:real '(x))) [subtract-five (both-sides 'subtract 5)] [cancel-five (cancel-addends #:at (lhs))] [compute-right (evaluate #:at (rhs))])
procedure
(derive/proc initial named-operations) → derivation?
initial : (or/c math? derivation?) named-operations : list?
The second argument is an ordered list of pairs whose car is a symbol step name and whose cdr is an elementary operation or recipe. Top-level names must be unique in the extended derivation; child names are sibling-local. No partial derivation is returned on failure, and an existing derivation is never mutated.
syntax
(derive-cases initial [name guard [step operation] ...] ...)
procedure
(make-case-derivation initial branch-specs) → case-derivation?
initial : (or/c math? derivation?) branch-specs : list?
Requires a nonempty list of three-element branch specifications, (list name guard factory). Names are symbols and guards are validated mathematical data. The factory accepts the scoped input state, requires no keyword arguments, and returns a derivation or case tree. Factories run during construction, must honor the held-state contract, and are not retained in scenes. Duplicate sibling names and unsupported strict-mode coverage are rejected.
procedure
(derivation? value) → boolean?
value : any/c
procedure
(derivation-initial record) → math?
record : derivation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(derivation-steps record) → (listof rewrite-step?)
record : derivation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(derivation-final record) → math?
record : derivation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(case-branch? value) → boolean?
value : any/c
procedure
(case-branch-name record) → symbol?
record : case-branch?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(case-branch-guard record) → math-datum?
record : case-branch?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(case-branch-derivation record) → any/c
record : case-branch?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(case-derivation? value) → boolean?
value : any/c
procedure
(case-derivation-prefix record) → derivation?
record : case-derivation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(case-derivation-branches record) → (listof case-branch?)
record : case-derivation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(case-derivation-coverage record) → verification?
record : case-derivation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(solution-check? value) → boolean?
value : any/c
procedure
(solution-check-problem record) → math?
record : solution-check?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(solution-check-variable record) → symbol?
record : solution-check?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(solution-check-value record) → math-datum?
record : solution-check?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(solution-check-derivation record) → (or/c derivation? #f)
record : solution-check?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(solution-check-verification record) → verification?
record : solution-check?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
d : (or/c math? derivation? case-derivation? solution-check?) label : (or/c symbol? (listof symbol?) #f) = #f
Without a label, a linear derivation returns its final state. A case tree has no unique final state: select a branch path or inspect its branches explicitly. A named path uses any required branch symbols followed by a move/leaf path. Both composite and elementary addresses are accepted; a composite returns its final child’s state. Unqualified symbols must be unambiguous in the requested scope.
procedure
(derivation-step d label) → rewrite-step?
d : (or/c derivation? case-derivation?) label : (or/c symbol? (listof symbol?))
procedure
(derivation-states d) → (listof math?)
d : (or/c derivation? case-derivation?)
procedure
d : (or/c derivation? case-derivation?)
procedure
(check-solution problem #:for variable #:value value) → solution-check? problem : math? variable : symbol? value : math-datum?
Checks the candidate against the original problem and its original context. A successful substitution check establishes membership, not completeness of the solution set. An undefined or unestablished-domain candidate has no visible checking derivation.
procedure
(rewrite-step? value) → boolean?
value : any/c
procedure
(rewrite-step-name record) → symbol?
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-before record) → math?
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-after record) → math?
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-rule record) → symbol?
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-focus record)
→ (listof exact-nonnegative-integer?) record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-bindings record) → (and/c hash? immutable?)
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-links record) → (listof path-link?)
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-trace record) → (listof trace-relation?)
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-relation record) → symbol?
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-verification record) → verification?
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-details record) → any/c
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(rewrite-step-version record) → exact-positive-integer?
record : rewrite-step?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(trace-descendants step item) → (listof occurrence?)
step : rewrite-step? item : (or/c occurrence? symbol?)
procedure
(path-link? value) → boolean?
value : any/c
procedure
(path-link-source record) → (listof exact-nonnegative-integer?)
record : path-link?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(path-link-target record) → (listof exact-nonnegative-integer?)
record : path-link?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(path-link-kind record) → symbol?
record : path-link?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(path-link-subtree? record) → boolean?
record : path-link?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(trace-relation? value) → boolean?
value : any/c
procedure
(trace-relation-kind record) → symbol?
record : trace-relation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(trace-relation-sources record) → (listof symbol?)
record : trace-relation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(trace-relation-targets record) → (listof symbol?)
record : trace-relation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(trace-relation-details record) → any/c
record : trace-relation?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
5.6 Complete mathematical notation
procedure
d : (or/c math? math-datum?) m : symbol? = 'school
An alias of datum->tex. Both held data and mathematical states are accepted, and neither is normalized for display.
procedure
(datum->tex d [#:multiplication m]) → string?
d : (or/c math? math-datum?) m : symbol? = 'school
procedure
(format-math-source datum [ #:multiplication multiplication]) → math-source? datum : (or/c math? math-datum?) multiplication : symbol? = 'school
Returns a complete TeX source string plus semantic half-open source ranges, measured in Racket string character indices, not UTF-8 bytes. Expression ranges may contain subordinate leaf or operator ranges. No TeX process is run.
procedure
(math->string x) → string?
x : (or/c math? math-datum?)
Produces the readable diagnostic notation used by –steps and context captions. It is not a parser round-trip format.
procedure
(math-source? value) → boolean?
value : any/c
procedure
(math-source-text record) → (and/c string? immutable?)
record : math-source?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-source-spans record) → (listof math-source-span?)
record : math-source?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-source-span? value) → boolean?
value : any/c
procedure
(math-source-span-start record) → exact-nonnegative-integer?
record : math-source-span?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-source-span-end record) → exact-positive-integer?
record : math-source-span?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-source-span-path record)
→ (listof exact-nonnegative-integer?) record : math-source-span?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-source-span-role record) → symbol?
record : math-source-span?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
5.7 Presentation policy and schedules
procedure
(math-presentation [ #:anchor anchor #:history history #:start-group start-group #:new-parts new-parts #:removed-parts removed-parts #:reflow reflow #:multiplication multiplication #:pause-between-groups pause #:duration step-duration #:font-size font-size #:row-gap row-gap #:max-visible-rows max-rows]) → math-presentation? anchor : symbol? = 'relation history : symbol? = 'keep-completed-groups start-group : symbol? = 'copy new-parts : symbol? = 'fade removed-parts : symbol? = 'fade reflow : symbol? = 'staged multiplication : symbol? = 'school pause : (and/c real? (>=/c 0)) = 3/5 step-duration : (and/c real? positive?) = 4/5 font-size : (and/c real? positive?) = 11/20 row-gap : (and/c real? positive?) = 21/20 max-rows : (and/c exact-integer? (>=/c 2)) = 5
The anchor is 'relation or 'center. History is 'keep-completed-groups, 'keep-all-checkpoints, or 'replace. Start-group is 'copy or 'replace. The supported appearance effect is 'fade; unsupported effects are rejected. Reflow is 'staged or 'simultaneous, and multiplication is 'school or 'explicit. Durations and pauses are seconds; font size and row gap are world units. Values must be finite. Pauses may be zero, other sizes and durations are positive, and at least two visible rows are required. Defaults use exact rational numbers.
procedure
(math-presentation? value) → boolean?
value : any/c
value
procedure
(present source [ #:style style #:groups groups #:case case-path #:case-layout case-layout #:allow-unverified? allow?]) → presentation-plan? source : (or/c derivation? case-derivation? solution-check?) style : math-presentation? = classroom groups : (or/c 'top-level 'steps list? hash? #f) = #f case-path : (or/c symbol? (listof symbol?) #f) = #f
case-layout : (or/c 'complete-paths 'shared-prefix) = 'complete-paths allow? : boolean? = #f
Groups partition elementary steps exactly once in order. 'top-level (and the default #f) uses one group per top-level move or elementary root; 'steps uses one per elementary rewrite. Explicit groups may name moves or leaves; move references expand before partition validation. For several cases, either symbolic mode applies to every case, or a hash maps case paths to modes or group lists. Missing hash entries use the top-level default. The case selector is a symbol or a list of branch symbols. Strict presentation rejects unverified derivations unless #:allow-unverified? #t is supplied; that flag must be a boolean and causes a visible warning.
The default 'complete-paths plays a complete derivation for every leaf. With 'shared-prefix, each nonempty common mathematical prefix is played once before its descendant branch suffixes. Group declarations still describe complete leaf paths; they are validated first, then projected onto the emitted segments. Incompatible partitions of a shared prefix are rejected. Selecting a single #:case always restores its full prefix, irrespective of layout.
syntax
(choreograph plan [step-key phase ...] ...)
(choreograph plan [cancel-five (retire-cancelled #:duration 2/5) (hold 1/2) (compact #:duration 2/5)])
procedure
(presentation-style? value) → boolean?
value : any/c
procedure
(presentation-style-anchor record) → symbol?
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-history record) → symbol?
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-start-group record) → symbol?
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-new-parts record) → symbol?
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-removed-parts record) → symbol?
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-reflow record) → symbol?
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-multiplication record) → symbol?
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
→ (and/c real? (>=/c 0)) record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-duration record) → (and/c real? positive?)
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-font-size record) → (and/c real? positive?)
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-row-gap record) → (and/c real? positive?)
record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-style-max-visible-rows record)
→ exact-positive-integer? record : presentation-style?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-plan? value) → boolean?
value : any/c
procedure
(presentation-plan-source record) → any/c
record : presentation-plan?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-plan-style record) → math-presentation?
record : presentation-plan?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-plan-segments record) → (listof plan-segment?)
record : presentation-plan?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-plan-choreography record)
→ (and/c hash? immutable?) record : presentation-plan?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-plan-allow-unverified? record) → boolean?
record : presentation-plan?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(plan-segment? value) → boolean?
value : any/c
procedure
(plan-segment-path record) → (listof symbol?)
record : plan-segment?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(plan-segment-derivation record) → derivation?
record : plan-segment?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(plan-segment-groups record) → list?
record : plan-segment?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(plan-segment-context record) → math-context?
record : plan-segment?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(plan-segment-verdict record) → (or/c verification? #f)
record : plan-segment?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(plan-segment-shared? record) → boolean?
record : plan-segment?
procedure
(presentation-phase? value) → boolean?
value : any/c
procedure
(presentation-phase-kind record) → symbol?
record : presentation-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-phase-duration record) → (and/c real? (>=/c 0))
record : presentation-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-phase-effect record) → symbol?
record : presentation-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-phase-layout record) → symbol?
record : presentation-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(presentation-phase-annotation record)
→ (or/c #f (list/c math? string?)) record : presentation-phase?
procedure
(scheduled-phase? value) → boolean?
value : any/c
procedure
(scheduled-phase-segment record) → exact-nonnegative-integer?
record : scheduled-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(scheduled-phase-step record)
→ (or/c symbol? (listof symbol?) #f) record : scheduled-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(scheduled-phase-kind record) → symbol?
record : scheduled-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(scheduled-phase-start record) → (and/c real? (>=/c 0))
record : scheduled-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(scheduled-phase-duration record) → (and/c real? (>=/c 0))
record : scheduled-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(scheduled-phase-group record) → exact-integer?
record : scheduled-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(scheduled-phase-phase record) → (or/c presentation-phase? #f)
record : scheduled-phase?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-checkpoint? value) → boolean?
value : any/c
procedure
(math-checkpoint-index record) → exact-nonnegative-integer?
record : math-checkpoint?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-checkpoint-segment record) → exact-nonnegative-integer?
record : math-checkpoint?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-checkpoint-step record)
→ (or/c symbol? (listof symbol?) #f) record : math-checkpoint?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-checkpoint-time record) → (and/c real? (>=/c 0))
record : math-checkpoint?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-checkpoint-state record) → math?
record : math-checkpoint?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(math-checkpoint-case-path record) → (listof symbol?)
record : math-checkpoint?
This accessor is pure. It does not copy, reorder, render, or mutate the record.
procedure
(plan-checkpoints plan) → immutable-vector?
plan : presentation-plan?
procedure
(checkpoint-at plan time) → math-checkpoint?
plan : presentation-plan? time : (and/c real? (>=/c 0))
Returns the latest mathematical checkpoint at or before the requested time. Animation interiors do not invent partial mathematical assertions.
procedure
(plan-schedule plan) → (listof scheduled-phase?)
plan : presentation-plan?
Entries are in chronological order, with zero-duration mathematical checkpoint records included. These data describe presentation; they are not a second frame-sampling engine. Native compilation uses ordinary animate scenes.
procedure
(plan-duration plan) → (and/c real? (>=/c 0))
plan : presentation-plan?
procedure
(plan-inspect plan t) → scheduled-phase?
plan : presentation-plan? t : (and/c real? (>=/c 0))
Time lies in the closed interval from zero to plan-duration. Active phase intervals are half-open. The total endpoint returns the final phase.
procedure
(prepare-space [#:duration d]) → presentation-phase?
d : (and/c real? positive?) = 1/2
Moves surviving parts to prepared positions before new material appears. The duration is measured in seconds and must be positive and finite.
procedure
(reveal-created [ #:effect effect #:duration d]) → presentation-phase? effect : symbol? = 'fade d : (and/c real? positive?) = 2/5
Fades newly created material in while the established layout is held. Only 'fade is supported in this release.
procedure
(retire-cancelled [ #:effect effect #:layout layout #:duration d]) → presentation-phase? effect : symbol? = 'fade layout : symbol? = 'hold d : (and/c real? positive?) = 2/5
Fades cancelled material out without moving surviving parts. Only 'fade and 'hold layout are supported. Follow with a hold and compact to separate cancellation from closing the resulting gap.
procedure
(retire-removed [ #:effect effect #:layout layout #:duration d]) → presentation-phase? effect : symbol? = 'fade layout : symbol? = 'hold d : (and/c real? positive?) = 2/5
Uses the same held-layout retirement mechanism as cancellation but names a general removal event. It does not implicitly compact the expression.
procedure
(compact [#:duration d]) → presentation-phase?
d : (and/c real? positive?) = 2/5
Moves surviving parts to their complete destination layout after retirement. The duration is positive and finite seconds. Reordered signed terms move in rigid units along two separated native-motion legs. Cancellation that creates a unit coefficient introduces that coefficient only after compaction; an explicit reveal-created phase can separate those actions further.
procedure
(hold d) → presentation-phase?
d : (and/c real? (>=/c 0))
The duration may be zero. A hold adds no mathematical checkpoint or scene-state mutation.
procedure
(explain-math state [ #:caption caption #:duration duration]) → presentation-phase? state : (or/c math? math-datum?) caption : string? = "" duration : (and/c real? positive?) = 2
(choreograph plan [add-nine (explain-math '(= (expt (/ 6 2) 2) 9) #:caption "Half the coefficient of x, then square it") (prepare-space) (reveal-created)])
procedure
(transition [#:duration d]) → presentation-phase?
d : (and/c real? positive?) = 4/5
procedure
(plan-with-choreography plan overrides) → presentation-plan?
plan : presentation-plan? overrides : list?
Overrides are an ordered list of (cons step-key phases). A key is a step name or a list of branch symbols followed by the step name. Each phase list is nonempty. Unknown keys, duplicate keys within one call, and invalid phase values are rejected. A case-specific override takes precedence over an unqualified step-name override.