Internal reference

These helpers support loading, matching and interpreting rule sets. Their interfaces may change; see the Reference for the public API.

OpenSymbolicRules._ASSOCIATIVE_SYMBOLS — Constant
_ASSOCIATIVE_SYMBOLS

OpenMath symbols denoting associative operations. An n-ary OSR expression with such a head is normalized to left-associated binary SymbolicUtils terms.

source
OpenSymbolicRules._BINDER_HEADS — Constant
_BINDER_HEADS

Canonical 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.

source
OpenSymbolicRules._CANONICAL_ARITHMETIC — Constant
_CANONICAL_ARITHMETIC

Julia 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.

source
OpenSymbolicRules._COMMUTATIVE_SYMBOLS — Constant
_COMMUTATIVE_SYMBOLS

OpenMath 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.

source
OpenSymbolicRules._CONSTRAINT_COMBINATORS — Constant
_CONSTRAINT_COMBINATORS

Constraint 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.

source
OpenSymbolicRules._DEFAULT_SEMANTICS — Constant
_DEFAULT_SEMANTICS

OpenMath 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.

source
OpenSymbolicRules._NUMERIC_CONDITIONS — Constant
_NUMERIC_CONDITIONS

Predicate 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.

source
OpenSymbolicRules._OSR_PREDICATES — Constant
_OSR_PREDICATES

Julia 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.

source
OpenSymbolicRules._PROPERTIES — Constant
_PROPERTIES

The 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.

source
OpenSymbolicRules._STRUCTURAL_HEADS — Constant
_STRUCTURAL_HEADS

Heads 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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
OpenSymbolicRules._equality_parent — Method
equality_satisfiable(constraints) -> Bool

Decide 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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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 ℚ.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source
OpenSymbolicRules._unproved — Method
_unproved(predicate)

Abandon the guard being evaluated because predicate cannot be decided, and record which predicate it was.

source
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.

source
OpenSymbolicRules._weigh — Method
_weigh(predicate, held)

Return whether a guard's predicate held, recording it when it did not and recording is on.

source
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.

spellingmeaningpattern
~xslot~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.3optional 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 ^.

source
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.

source
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.

source
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.

source
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.

source
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.

source
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.

source