Skip to content
plurimathPublic

About

OpenMath 2 and 3: the XML encoding as a typed model — parse, serialize, evaluate — for the Plurimath ecosystem.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

OpenMath

OpenMath 2 (the published standard) and OpenMath 3 (the draft) as a typed Ruby model: parse the XML encoding, serialize it back, and evaluate through content dictionaries. Part of the {plurimath}[https://github.com/plurimath] ecosystem; consumed by the plurimath gem.

Status

The complete OpenMath 2 object grammar — OMOBJ, OMS, OMV, OMI, OMB, OMSTR, OMF, OMA, OMBIND, OMBVAR, OME, OMATTR, OMATP, OMFOREIGN, OMR — modeled with {LutaML Model}[https://github.com/lutaml/lutaml-model] against the authoritative schema (schemas/openmath2.rnc, vendored from OpenMath/OMSVN). Namespaced documents parse in both the unprefixed and the om:-prefixed form; round trips are byte-stable.

  • Validation ships: Openmath.valid? / validate! check any document against its version’s vendored RelaxNG schema (OpenMath 2 and the OM3 draft) through nokogiri; violations refuse with typed errors.

  • OpenMath 3: the versioned hierarchy (Openmath::V3) parses and round-trips the same object grammar under Openmath.parse(xml, version: 3).

  • Content dictionaries: the CD document model, the collection loader, symbol resolution with cdbase matching, and CD validation against omcd2.rng — CD content is data, never code.

  • Evaluation: the CD binding table (data/binding-table-1.yml) binds the working families — nums1, arith1, relation1, logic1, integer1, rounding1, set1/list1, interval1, linalg1/linalg2/linalg3 — to exact operations; Openmath.evaluate(xml, variables:) walks the tree under the exactness discipline — integers and rationals stay exact, floats contaminate to the limited class, unbound symbols refuse naming the symbol. fns1/lambda binds: OMBIND evaluates to a closure captured lexically, applied through an enclosing OMA with typed arity refusals; map/suchthat ride the lambda layer; attributed variables bind by their wrapped name; OMATTR evaluates its attributed object, attributions riding along as data; OMR references resolve within the document scope with cycle detection; shape contradictions refuse with the DimensionMismatch name. calculus1 stays symbolic — outside the evaluated surface, refused typed.

  • Foreign objects: markup inside OMFOREIGN (the schema’s notOM content) is captured verbatim at parse time (notom_value) and re-emitted at its recorded positions on serialization — MathML, SVG, any well-formed fragment round-trips byte-identically.

  • Canonical serialization: #to_canonical_xml and #canonical_sha256 on every element give one deterministic form of an object — invariant under prefix choice, attribute order and insignificant whitespace — with Openmath.canonical_equal? as the explicit equality operation.

  • Content MathML v4: Openmath::ContentMathML.parse/generate ride the same content models (the plurimath#35 re-parenting) — csymbol ↔ symbol, apply ↔ application, lambda/bvar ↔ the binding containers — with the MathML 4 operator table transforming to the strict form, exact cn constructions (rational, based integers, e-notation), and typed refusals for everything outside the semantic core.

  • Binary encoding: Openmath::Binary.encode/decode speak the standard’s compact tagged format — both framings, streaming packets, internal and external references, the shared-object optimization backed by OMR, and typed refusals for every malformed byte sequence. Every corpus object round-trips at a binary fixed point.

  • The PM register: the pmquant CD family (data/pmquant.ocd, schema- validated) carries PM 1002’s quantity/uncertainty constructors — ustd, uexp, ucov — as OpenMath data with its own signature file; quantities combine under JCGM 101’s first-order propagation, and Openmath.evaluate_stochastic runs deterministic Monte-Carlo evaluation under a declared generator and seed (same seed, same samples).

Known limitations (tracked in the issues):

  • OMFOREIGN fragments re-serialize pretty-printed by nokogiri rather than in the surrounding document’s indentation.

Usage

require "openmath"

object = Openmath.parse(<<~XML, version: 2)
  <OMOBJ xmlns="http://www.openmath.org/OpenMath">
    <OMA><OMS cd="arith1" name="plus"/><OMI>1</OMI><OMI>1</OMI></OMA>
  </OMOBJ>
XML

object.oma_value.first.omi_value.map { |i| i.value.first.strip }
# => ["1", "1"]

puts object.to_xml

# Always-available schema validation
Openmath.valid?(xml, version: 2)   # => true

# Semantic math that evaluates
Openmath.evaluate(<<~XML)
  <OMOBJ xmlns="http://www.openmath.org/OpenMath">
    <OMA><OMS cd="nums1" name="rational"/><OMI>1</OMI><OMI>4</OMI></OMA>
  </OMOBJ>
XML
# => rational 1/4 (an exact Rational — never a float)

Roadmap

The semantic program: content dictionaries bind symbols to evaluated operations (the Plurimath PM-series evaluator), the official CD collection loads as data, and the test suites of other implementations join the {plurimath-testsuite}[https://github.com/plurimath/plurimath-testsuite] under the provenance discipline. Tracked in plurimath#582 (the gem), #583 (evaluation), #584 (the testsuite stage), #585 (the wiring).

Development

bundle install
bundle exec rake

About

OpenMath 2 and 3: the XML encoding as a typed model — parse, serialize, evaluate — for the Plurimath ecosystem.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages