Internal reference
These helpers support loading, matching and interpreting rule sets. Their interfaces may change; see the Reference for the public API.
OpenSymbolicRules._ASSOCIATIVE_SYMBOLSOpenSymbolicRules._BINDER_HEADSOpenSymbolicRules._CANONICAL_ARITHMETICOpenSymbolicRules._COMMUTATIVE_SYMBOLSOpenSymbolicRules._CONSTRAINT_COMBINATORSOpenSymbolicRules._DECLARED_HEADSOpenSymbolicRules._DEFAULT_SEMANTICSOpenSymbolicRules._NUMERIC_CONDITIONSOpenSymbolicRules._OPTIONAL_WILDCARDOpenSymbolicRules._OSR_PREDICATESOpenSymbolicRules._PERFECT_SQUARE_TRIAL_LIMITOpenSymbolicRules._PROPERTIESOpenSymbolicRules._STRUCTURAL_HEADSOpenSymbolicRules._WILDCARD_DOMAINSOpenSymbolicRules.UnprovedConstraintOpenSymbolicRules._active_assumptionsOpenSymbolicRules._alpha_renameOpenSymbolicRules._apply_lambdaOpenSymbolicRules._binder_variableOpenSymbolicRules._binomial_exponentOpenSymbolicRules._canonical_keyOpenSymbolicRules._canonical_numberOpenSymbolicRules._collect_constraint_operators!OpenSymbolicRules._compile_constraintOpenSymbolicRules._constant_termOpenSymbolicRules._domain_entailsOpenSymbolicRules._drop_identityOpenSymbolicRules._equality_parentOpenSymbolicRules._exact_powerOpenSymbolicRules._fact_entailsOpenSymbolicRules._fresh_nameOpenSymbolicRules._guard_or_unprovedOpenSymbolicRules._has_optional_slotOpenSymbolicRules._head_is_operationOpenSymbolicRules._head_nameOpenSymbolicRules._interval_entailsOpenSymbolicRules._lambda_bodyOpenSymbolicRules._literalOpenSymbolicRules._monomial_exponentOpenSymbolicRules._nonempty_matchOpenSymbolicRules._openmath_symbolOpenSymbolicRules._operand_headOpenSymbolicRules._operation_resultOpenSymbolicRules._optional_defaultOpenSymbolicRules._over_collectionOpenSymbolicRules._pattern_bindingsOpenSymbolicRules._polynomial_differenceOpenSymbolicRules._polynomial_symbols!OpenSymbolicRules._power_exponentsOpenSymbolicRules._predicate_calleeOpenSymbolicRules._rational_assumption_problemOpenSymbolicRules._rational_square_rootOpenSymbolicRules._read_asOpenSymbolicRules._relation_entailsOpenSymbolicRules._resolve_headsOpenSymbolicRules._rewrite_and_reduceOpenSymbolicRules._rule_macroOpenSymbolicRules._rule_operatorsOpenSymbolicRules._sum_operandsOpenSymbolicRules._term_keyOpenSymbolicRules._trinomial_orderingsOpenSymbolicRules._type_entailsOpenSymbolicRules._unprovedOpenSymbolicRules._variable_nameOpenSymbolicRules._weighOpenSymbolicRules._wildcard_to_exprOpenSymbolicRules.candidate_positionsOpenSymbolicRules.check_assumptionOpenSymbolicRules.dispatch_keyOpenSymbolicRules.osr_to_exprOpenSymbolicRules.record_withheld!OpenSymbolicRules.reset_unproved!OpenSymbolicRules.reset_withheld!OpenSymbolicRules.rule_headOpenSymbolicRules.unproved_predicates_seenOpenSymbolicRules.withheld_predicates_seen
OpenSymbolicRules._ASSOCIATIVE_SYMBOLS — Constant
_ASSOCIATIVE_SYMBOLSOpenMath symbols denoting associative operations. An n-ary OSR expression with such a head is normalized to left-associated binary SymbolicUtils terms.
OpenSymbolicRules._BINDER_HEADS — Constant
_BINDER_HEADSCanonical OSR heads that introduce a lexical scope. Lambda binds one variable, Forall and Exists bind a vector of variable names. Every other binding construct — an integral, a sum, a product, a derivative — carries its bound variable inside a Lambda, as the OpenMath fns1#lambda symbol prescribes, so it needs no separate entry.
OpenSymbolicRules._CANONICAL_ARITHMETIC — Constant
_CANONICAL_ARITHMETICJulia operation behind every canonical OSR arithmetic head. A rule file that renames those heads keeps working, but its expressions are then opaque to numeric folding and every guarded rewrite stays conservative.
OpenSymbolicRules._COMMUTATIVE_SYMBOLS — Constant
_COMMUTATIVE_SYMBOLSOpenMath symbols denoting operations whose operands may be reordered. Patterns headed by one of these compile to a SymbolicUtils.ACRule, so a single rule matches every operand order instead of requiring a mirrored copy per order.
openmath:arith1#times is deliberately absent. An OSR expression carries no shape information, so a times operand may be a matrix or a tensor and reordering it would be unsound. The same applies to tensor products, contractions, and axis permutations, which must use dedicated heads.
OpenSymbolicRules._CONSTRAINT_COMBINATORS — Constant
_CONSTRAINT_COMBINATORSConstraint heads whose operands are themselves constraints. They are rule language rather than domain vocabulary: each compiles to Julia control flow over booleans, never to a symbolic term, and none needs an OpenMath binding.
OpenSymbolicRules._DECLARED_HEADS — Constant
_DECLARED_HEADSNames already declared in UninterpretedHeads.
isdefined cannot answer this: that module imports Base, so Int and every other Base name reads as defined there before anything is declared.
OpenSymbolicRules._DEFAULT_SEMANTICS — Constant
_DEFAULT_SEMANTICSOpenMath Content Dictionary symbol of every canonical OSR head. A rule file declares its own semantics block, and that declaration always wins; this map only resolves heads used outside a rule file, for example when osr_to_expr is called directly.
OpenSymbolicRules._NUMERIC_CONDITIONS — Constant
_NUMERIC_CONDITIONSPredicate deciding a relation head, used only when every operand is a closed arithmetic expression. For a symbolic operand these predicates answer "not proved", which is not the same as "false", so they may not decide a condition.
OpenSymbolicRules._OPTIONAL_WILDCARD — Constant
_OPTIONAL_WILDCARDSpelling of an OSR optional operand: a name, a dot, and an optional explicit default such as m.3 or n.-1. Per OSR-W-002 and OSR-W-002a.
OpenSymbolicRules._OSR_PREDICATES — Constant
_OSR_PREDICATESJulia function implementing each OSR constraint predicate. A predicate that is not listed here is resolved in the module that loads the rule file, so a host can supply its own without changing this library.
OpenSymbolicRules._PERFECT_SQUARE_TRIAL_LIMIT — Constant
Bounded trial-division limit for exact square-root normalization.
OpenSymbolicRules._PROPERTIES — Constant
_PROPERTIESThe properties a hypothesis can establish about a term. check_assumption answers each one by entailment, so a hypothesis proves every property its domain implies rather than only the one it was written as.
OpenSymbolicRules._STRUCTURAL_HEADS — Constant
_STRUCTURAL_HEADSHeads the OSR expression language defines for itself rather than borrowing from a mathematical domain. They compile to a host collection instead of a term, so a rule file binds no domain meaning by redeclaring one and is not required to.
OpenSymbolicRules._WILDCARD_DOMAINS — Constant
_WILDCARD_DOMAINSPredicate guarding a typed blank such as m_integer.
OpenSymbolicRules.UnprovedConstraint — Type
UnprovedConstraint(predicate)Raised while evaluating a guard that names a predicate no implementation can be found for, in this package or in the module that loaded the rule file.
A predicate answers true only when the property is established, so one that cannot be evaluated establishes nothing. Raising rather than answering false is what keeps Not honest: answering false would make Not answer true and license a rewrite on a property nobody decided.
OpenSymbolicRules._active_assumptions — Method
_active_assumptions()Return the hypotheses in force, which is what makes a result conditional rather than proved.
OpenSymbolicRules._alpha_rename — Method
_alpha_rename(expr, renamings)Rename the variables of a binder term according to renamings, a map from the current name to the new one.
OpenSymbolicRules._apply_lambda — Method
_apply_lambda(expression)Return the body of the lambda expression applies, with the argument put for its variable, or nothing when expression is not such an application.
OpenSymbolicRules._binder_variable — Method
_binder_variable(variable)Return the symbol a binder should bind for variable, accepting either a SymbolicUtils variable or its name.
OpenSymbolicRules._binomial_exponent — Method
_binomial_exponent(u, x)Return the exponent n for which u is written a + b*x^n, with a, b, and n free of x, or nothing when u has no such shape.
OpenSymbolicRules._canonical_key — Method
_canonical_key(operand)A deterministic sort key for the summands of a sum. It orders by printed form, which settles a sum's shape without claiming any mathematical meaning for the order itself.
OpenSymbolicRules._canonical_number — Method
_canonical_number(value)Write an exact number in its settled form: a rational whose denominator is one is that integer.
OpenSymbolicRules._collect_constraint_operators! — Method
_collect_constraint_operators!(operators, constraint)Collect the mathematical operators a constraint applies its predicates to. A predicate name is not a mathematical operator and needs no OpenMath binding, and a combinator nests constraints rather than expressions.
OpenSymbolicRules._compile_constraint — Method
_compile_constraint(constraint, semantics)Compile one OSR constraint into a Julia expression that evaluates to a Bool. Not, And, and Or are constraint combinators: they nest constraints and compile to Julia control flow, never to a symbolic logic term.
OpenSymbolicRules._constant_term — Method
_constant_term(polynomial)Return the value of polynomial when it is constant, or nothing when it still mentions a variable.
OpenSymbolicRules._domain_entails — Method
_domain_entails(domain, property)Return whether membership of domain proves property.
OpenSymbolicRules._drop_identity — Method
_drop_identity(operands, identity)Return the operands that are not the identity element of their operation.
OpenSymbolicRules._equality_parent — Method
equality_satisfiable(constraints) -> BoolDecide conjunctions of ground equality and disequality constraints over uninterpreted symbols. Equalities are closed transitively with a pure-Julia union-find structure before all disequalities are checked.
OpenSymbolicRules._exact_power — Method
_exact_power(base, exponent)Raise base to exponent without losing exactness. Julia refuses to raise an integer to a negative integer power, yet Power(u, -1) is how OSR spells a reciprocal, so the base is widened to a rational first.
OpenSymbolicRules._fact_entails — Method
_fact_entails(fact, subject, property)Return whether one hypothesis proves property of subject.
OpenSymbolicRules._fresh_name — Method
_fresh_name(base, taken)Return a variant of base that is not in taken.
OpenSymbolicRules._guard_or_unproved — Method
_guard_or_unproved(condition)Wrap a compiled guard so that an undecidable predicate leaves it unestablished instead of propagating.
&& and || short-circuit, which gives the guard exactly the three-valued reading it needs at no cost: Or(p, undecidable) still holds when p does, because the undecidable branch is never reached, while Not(undecidable) and And(p, undecidable) reach it and establish nothing.
OpenSymbolicRules._has_optional_slot — Method
_has_optional_slot(pattern)Return whether pattern may match a term that lacks its own operation.
SymbolicUtils builds a default-valued matcher only where a DefSlot is a direct argument: such a term also matches its remaining operand alone, so it requires no particular head. An optional operand nested deeper does not relax the root — Int((a. + b.*x)^m., x) still needs an Int — which is what keeps head dispatch selective across a rule set as large as RUBI's.
OpenSymbolicRules._head_is_operation — Method
_head_is_operation(value)Return whether value can stand in operator position.
A Julia type cannot: Int names an indefinite integral in the RUBI corpus and a machine integer in Base, and building a term whose operation is Base.Int raises the moment the rule fires — while no integral-aware code recognises it in the meantime. Anything callable that is not a type is left alone, so a host can still supply its own implementation of a head.
OpenSymbolicRules._head_name — Method
_head_name(u)Return the name of u's head, or of u itself when it is a bare symbol.
RUBI applies a classifying predicate to a head a pattern bound, as in TrigQ[F] where F_ matched one of the six circular functions, so a bare head has to count as much as an application of it.
OpenSymbolicRules._interval_entails — Method
_interval_entails(domain, property)Entailment of an ordered domain, read from its bounds. A bound at zero only excludes zero when it is open, so [0, ∞) is not a proof of positivity while (0, ∞) is.
OpenSymbolicRules._lambda_body — Method
_lambda_body(expression, bound)Return the body of expression when it is the lambda bound was bound in, and expression itself otherwise — which is what an unevaluated derivative looks like.
OpenSymbolicRules._literal — Method
_literal(expr)Unwrap a symbolic numeric literal. SymbolicUtils wraps the arguments of a term, so arguments(Add(1, 2)) yields symbolic constants rather than Ints.
OpenSymbolicRules._monomial_exponent — Method
_monomial_exponent(u, x)Return the exponent of x in u when u is a product of factors free of x with exactly one power of x, or nothing otherwise. A bare x has exponent one.
OpenSymbolicRules._nonempty_match — Method
_nonempty_match(matched)Return whether a sequence wildcard bound at least one expression. OSR's __ spelling requires a non-empty match, whereas ___ accepts an empty one.
OpenSymbolicRules._openmath_symbol — Method
_openmath_symbol(head, semantics)Return the OpenMath symbol bound to head, or nothing when the head has no declared and no canonical binding.
OpenSymbolicRules._operand_head — Method
_operand_head(rule)Return the operation rule requires at the first operand of its pattern, or nothing when it requires none.
An associative-commutative rule requires none: its matcher tries every operand order, so the operation at the term's first operand does not decide whether the rule can match.
OpenSymbolicRules._operation_result — Method
_operation_result(operation, expression, unevaluated)Read expression as the result of operation, which unevaluated says is still standing.
OpenSymbolicRules._optional_default — Method
_optional_default(symbol, index)Return the value an absent operand takes at argument position index of the operation denoted by the OpenMath symbol, or nothing when the operation supplies no such value.
An optional operand only means something where the operation has an identity element to fall back on: plus contributes zero and times contributes one. power is deliberately asymmetric — an absent exponent is one, whereas an absent base has no meaning, so only its second argument defaults.
OpenSymbolicRules._over_collection — Method
_over_collection(predicate, u)Apply predicate to u, or to every element of u when it is a collection.
RUBI writes LinearQ[{u, v}, x] to ask about every element at once, the same spelling FreeQ[{a, b}, x] uses. Reading such a list as one expression makes the guard decline a rule that plainly applies.
OpenSymbolicRules._pattern_bindings — Method
_pattern_bindings(pattern)Return the names a pattern binds, whatever spelling each wildcard uses.
A rule's pattern declares its wildcards; its result and its constraints refer to the bindings it made. RUBI spells the declaration m_ and the reference m, so resolving a reference needs the set of names the pattern established.
OpenSymbolicRules._polynomial_difference — Method
_polynomial_difference(u, v)Return u - v as an exact polynomial over the symbols they mention, or nothing when either side is not a polynomial with exact rational coefficients.
A RUBI guard is overwhelmingly a polynomial identity over its parameters, and the exact sparse core decides those without ever leaving ℚ.
OpenSymbolicRules._polynomial_symbols! — Method
_polynomial_symbols!(names, expression)Collect the symbols an expression mentions, which name the ring a comparison is decided over.
OpenSymbolicRules._power_exponents — Method
_power_exponents(u, x)Return the exponents of x in u read as a sum of monomials, or nothing when some summand is not a monomial with a coefficient free of x.
A summand free of x contributes the exponent 0.
OpenSymbolicRules._predicate_callee — Method
_predicate_callee(name, caller)Return what a constraint predicate named name compiles to: this package's implementation, one the caller supplies, or a call that abandons the guard.
OpenSymbolicRules._rational_assumption_problem — Method
rational_assumptions_satisfiable(facts) -> Union{Bool, Nothing}Check a supported collection of CAS hypotheses with the exact rational linear theory. true means the converted hypotheses have a rational model, false means they are contradictory, and nothing means at least one hypothesis is outside this deliberately conservative fragment. Supported facts are IsPositive(x), IsNegative(x), IsNonzero(x), GreaterThan(x, c), and LessThan(x, c) for a named symbolic variable x and an exact rational constant c.
OpenSymbolicRules._rational_square_root — Method
_rational_square_root(value)Return the exact rational square root of value, or nothing when it has none.
OpenSymbolicRules._read_as — Method
_read_as(operation, reached, evaluated, mode)Return what the caller asked for: the expression, or the expression beside the reading it should be given.
mode follows simplify: :fast hands back the value alone, and :status hands back an OperationResult, which is what keeps an unevaluated operation from being read as a proved equality.
OpenSymbolicRules._relation_entails — Method
_relation_entails(head, operands, property)Entailment of a hypothesis written as a relation, such as GreaterThan(x, 0). A comparison also orders its subject, so it proves that the subject is real.
OpenSymbolicRules._resolve_heads — Method
_resolve_heads(documents, caller)Return, for every operator the given rule files apply, the expression to place in operator position.
A head the caller resolves to something that can act as an operation is used as it stands, which is how a host supplies its own implementation. Every other head is registered in UninterpretedHeads and referred to there, so it denotes the declared operation and nothing else.
OpenSymbolicRules._rewrite_and_reduce — Method
_rewrite_and_reduce(expression, rules, steps)Rewrite expression and reduce the applications the rewriting leaves, until neither changes it.
The two need each other. A structural rule returns a lambda whose body applies the lambdas the base rules return, so reduction cannot run until the rewriting has produced them; and the rewriting cannot continue past an application until reduction has collapsed it. Alternating is what lets a rule set differentiate a sum term by term.
OpenSymbolicRules._rule_macro — Method
_rule_macro(pattern, semantics)Return the SymbolicUtils rule macro a pattern must be compiled with. A pattern headed by a commutative operation becomes an @acrule, which matches every operand order with a single rule instead of one rule per order.
OpenSymbolicRules._rule_operators — Method
_rule_operators(documents)Return every mathematical operator the given rule files apply.
OpenSymbolicRules._sum_operands — Method
_sum_operands(u)Return the summands of u, flattening the nested binary Add terms an n-ary OSR sum compiles to.
OpenSymbolicRules._term_key — Method
_term_key(expr)Return the pair of operations expr actually has at its root and first operand.
OpenSymbolicRules._trinomial_orderings — Method
_trinomial_orderings(exponents)Return the ways three exponents can play the roles q, n, and 2n - q.
OpenSymbolicRules._type_entails — Method
_type_entails(type, property)Entailment of a hypothesis written as a Julia type, as in x ∈ Int.
OpenSymbolicRules._unproved — Method
_unproved(predicate)Abandon the guard being evaluated because predicate cannot be decided, and record which predicate it was.
OpenSymbolicRules._variable_name — Method
_variable_name(value)Return the name of a variable, whether it is written as a Julia Symbol — the form quantifier binders use — or as a SymbolicUtils symbol. Anything else has no name.
OpenSymbolicRules._weigh — Method
_weigh(predicate, held)Return whether a guard's predicate held, recording it when it did not and recording is on.
OpenSymbolicRules._wildcard_to_expr — Method
_wildcard_to_expr(node; reference=false, optional_default=nothing)Compile an OSR v0.1 wildcard spelling into a SymbolicUtils matcher pattern, or return nothing when node names an ordinary symbol. A reference wildcard stands for a binding the pattern already made — as in a rule's result or in a constraint argument — so it carries no predicate of its own.
| spelling | meaning | pattern |
|---|---|---|
~x | slot | ~x |
x_ | blank | ~x |
x_<domain> | typed blank | ~x::<predicate> |
xs__ | sequence, at least one | ~~xs::_nonempty_match |
xs___ | sequence, possibly empty | ~~xs |
a. | optional operand | ~!a |
m.3 | optional operand, explicit default | ~!m |
Matching an optional operand needs the identity element of the enclosing operation, which osr_to_expr supplies as optional_default; an explicit default in the spelling itself wins over it. With neither there is nothing for an absent operand to bind, so the wildcard is rejected rather than compiled into a rule that could never fire.
The default-valued slot is emitted as an interpolation, which SymbolicUtils splices into the pattern verbatim. The ~!a spelling of @rule cannot be used instead: it resolves the default from the Julia operator it sits under, and OSR heads are uninterpreted symbols rather than +, *, and ^.
OpenSymbolicRules.candidate_positions — Method
candidate_positions(dispatch, expr)Return the positions, in the original rule order, of the rules that can match expr.
OpenSymbolicRules.check_assumption — Method
check_assumption(predicate)Checks whether predicate is one of the hypotheses in scope, comparing it literally. The domain predicates use entailed instead, which also accepts a hypothesis that merely implies the property.
OpenSymbolicRules.dispatch_key — Method
dispatch_key(rule)Return the pair of operations a term must have at its root and at its first operand for rule to have any chance of matching, with nothing in either position that the pattern leaves open.
The root head alone stops discriminating as soon as a rule set is about one operation: every RUBI integration rule is headed by Int, so indexing on the root selects the whole set for every integral. What distinguishes those rules is the integrand, which is the first operand.
OpenSymbolicRules.osr_to_expr — Function
osr_to_expr(node, semantics=_DEFAULT_SEMANTICS; reference=false, optional_default=nothing, bindings=nothing, heads=nothing)Recursively parse an OSR JSON node into a Julia expression for SymbolicUtils. semantics is the rule file's head-to-OpenMath-symbol map; it decides which n-ary expressions are normalized to left-associated binary terms. Set reference when compiling a rule's result or a constraint argument, where a wildcard refers to a binding the pattern already made.
optional_default is the value an absent operand takes at this position, which the enclosing operation supplies as the recursion descends. A top-level node has no enclosing operation and therefore no default.
bindings names what the rule's pattern bound. Under reference, a bare name in that set is a reference to its binding rather than a free symbol, which is how RUBI spells a wildcard m_ in a pattern and m in the result.
heads says what each operator resolves to, as _resolve_heads determined. Without it a head resolves to a bare symbol of its own name, which is what direct callers of this function expect.
OpenSymbolicRules.record_withheld! — Method
record_withheld!(on)Turn on, or off, the recording of predicates that decide a guard against its rule.
This is diagnostic and off by default. An unproved predicate is always worth recording, because it names something missing; a predicate that answers false is doing its job, and only a measurement asking which rule was held back, and by what, needs to know. Rewriting should not pay for that.
OpenSymbolicRules.reset_unproved! — Method
reset_unproved!()Forget the predicates recorded so far, so the next attempt is measured alone.
OpenSymbolicRules.reset_withheld! — Method
reset_withheld!()Forget the predicates recorded so far, so the next attempt is measured alone.
OpenSymbolicRules.rule_head — Method
rule_head(rule)Return the operation a rule's pattern requires at the root of a term, or nothing when the rule may match a term of any head.
A rewrite whose pattern is headed by a concrete operation cannot match a term with a different one, so its matcher never has to run. Three kinds of pattern have no such requirement and must always be tried: a bare slot, a slot in head position, and a pattern containing an optional slot, which SymbolicUtils lets match a term that lacks the operation entirely.
OpenSymbolicRules.unproved_predicates_seen — Method
unproved_predicates_seen()Return the predicates that have abandoned a guard in this task since the last reset_unproved!.
A rule that does not fire says nothing about why on its own: a guard that is false and a guard that could not be decided both leave the term alone. Knowing which is which is what makes "implementing this predicate would unblock these rules" a measurement rather than a guess.
OpenSymbolicRules.withheld_predicates_seen — Method
withheld_predicates_seen()Return the predicates that have decided a guard against its rule in this task since the last reset_withheld!, when recording is on.