Repository navigation
Added formula extraction and evaluation - #19
HassanAkbar wants to merge 13 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class support for extracting and evaluating embedded Content MathML formulae from DCC documents, including a CLI entrypoint to print evaluated results with optional variable overrides.
Changes:
- Introduces
Dcc::Extract::Formulawith AST construction, MathML parsing, binding extraction, and BigDecimal-based evaluation. - Adds
dcc extract formulae FILEwith repeatable-v NAME=V1,V2overrides and formatted output. - Adds comprehensive RSpec coverage for parsing, evaluation semantics, error handling, and CLI behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/dcc/extract/formula/parser_spec.rb | New specs covering MathML parsing, operand ordering, roots, and malformed input handling. |
| spec/dcc/extract/formula/evaluator_spec.rb | New specs covering numeric evaluation, precision, domain errors, broadcasting, and override validation behavior. |
| spec/dcc/extract/formula_spec.rb | New integration specs verifying end-to-end extraction, binding resolution (including nested lists), and evaluation matches reference values. |
| spec/dcc/cli/cli_spec.rb | Adds CLI specs for extract formulae output, repeatable -v, broadcasting, and clean failure modes. |
| lib/dcc/extract/formula/quantity.rb | Adds Quantity coercion/validation boundary for numeric inputs (scalars + lists) into finite BigDecimals. |
| lib/dcc/extract/formula/parser.rb | Adds MathML-to-AST parser, including operator mapping, constant handling, and structured <cn> rejection. |
| lib/dcc/extract/formula/evaluator.rb | Adds BigDecimal/BigMath-based evaluator with precision rules, finite-result checks, and list broadcasting. |
| lib/dcc/extract/formula/ast.rb | Adds AST node types and arity enforcement for operator application nodes. |
| lib/dcc/extract/formula.rb | Adds extraction pipeline wiring: locate formulae, gather quantity bindings (including nested lists), and build ASTs. |
| lib/dcc/cli/cli.rb | Extends extract command with formulae target and repeatable -v overrides parsing/validation + printing. |
| dcc.gemspec | Adds bigdecimal runtime dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lib/dcc/extract/formula.rb:3
data_blocksuses::Set.newbut this file never requires the stdlibsetlibrary. Nothing in the repo appears torequire "set", so this relies on incidental load order from dependencies and can break with Ruby/dep changes (NameError: uninitialized constant Set).
require "bigdecimal"
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lib/dcc/extract/formula.rb:4
Dcc::Extract::Formulauses::Set(walk(dcc, ::Set.new, ...)) but this file does notrequire "set".Setis not part of Ruby core, so in a minimal runtime this will raiseNameError: uninitialized constant Setwhen formula extraction is invoked. Add an explicit require so extraction doesn’t depend on transitive requires from other libraries.
# frozen_string_literal: true
require "bigdecimal"
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds
Dcc::Extract::Formulaand adcc extract formulaecommand. A certificate canembed a MathML formula plus its parameters; this reads both and evaluates them in
BigDecimal, with
-v NAME=VALUEto override a parameter.All five reference values match PTB's own dcclib test suite exactly.
Known and accepted:
fix/parse-data-loss, notmain. Formula parameters live insidedcc:list, which that branch stops dropping. Onmainthis fails 22 examples.<cn>forms it cannot read exactly rather than guessing. Abaseattribute or a
<sep/>-separated value now raises, where both previouslyreturned a plausible wrong number:
<cn base="8">17</cn>read as 17, not 15.Ast::Apply's constructor, so a hand-built AST isheld to the same contract as a parsed one.
<power/>with one operand used tocompute
x**x.bigdecimalto the gemspec, unpinned likethor. Only the long-stableBigMathsubset is used.Quantity#uncertaintyis carried through but nothing populates it yet.