rh_math
Status and Scope
This is a research-oriented, partial implementation focused on bounded evaluation of selected analytic number theory results (for example, Schoenfeld 1976 bounds and real zeta(s) for s > 1).
It is not a general-purpose number theory library.
The implementation is intentionally limited, explicit, and designed to support reproducible evaluation of LLM-generated code against peer-reviewed mathematical results.
rh_math is a pure-Ruby research gem for the rh_llm_benchmark project.
Current gem version: v0.1.0
It provides small, explicit numeric parsing and comparison utilities, plus early arithmetic/bound routines used by executable pointwise benchmark checks.
Purpose
- keep computation/comparison logic outside Rails orchestration and persistence
- provide a testable pure-Ruby layer for benchmark evaluation logic
- support incremental, auditable growth of RH-related routines
Current Scope
Implemented today:
-
RhMath::NumericParserfor conservative decimal/scientific parsing toBigDecimal RhMath::Comparators::ExactTextRhMath::Comparators::AbsoluteTolerance- arithmetic helpers:
RhMath::PrimeSupport.primes_up_toRhMath::ArithmeticFunctions.prime_piRhMath::ArithmeticFunctions.thetaRhMath::ArithmeticFunctions.psi
- Schoenfeld 1976 RHS bound helpers:
RhMath::Bounds::Schoenfeld1976.psi_rh_upper_boundRhMath::Bounds::Schoenfeld1976.theta_rh_upper_boundRhMath::Bounds::Schoenfeld1976.pi_li_rh_upper_bound
- pointwise evaluators:
RhMath::Evaluators::SchoenfeldPointwise.evaluate_psi_boundRhMath::Evaluators::SchoenfeldPointwise.evaluate_theta_boundRhMath::Evaluators::SchoenfeldPointwise.evaluate_pi_li_bound- validated across representative moderate-x ranges used by the harness seed corpus
- special function:
RhMath::SpecialFunctions.li(x)
- bounded zeta routines:
-
RhMath::Zeta.zeta_real(s, terms: N)for reals > 1via truncated Dirichlet series -
RhMath::Zeta.zeta_real_with_error(s, terms: N)returning value plus a rigorous truncation tail bound
-
Intended Use
- evaluation of LLM-generated code against known mathematical bounds
- reproducible research workflows
- small-scale numeric validation of analytic results
Not intended for:
- production numerical computing
- high-precision analytic number theory
- large-scale prime computations
Current Non-Goals
- proving or disproving RH
- full zeta-function evaluation (complex inputs, analytic continuation, or critical-strip work)
- zero-finding
- symbolic theorem parsing
- complex arithmetic support
- production-grade high-precision analytic number theory engine
Local Development Setup
From the gem repo:
cd ../rh_math
ruby -vRun tests file-by-file:
for f in test/*_test.rb; do ruby -Ilib:test "$f" || exit 1; doneReproducibility
This gem is consumed by rh_llm_benchmark via local path dependency:
gem "rh_math", path: "../rh_math"Key commands:
- gem tests:
for f in test/*_test.rb; do ruby -Ilib:test "$f" || exit 1; done - zeta reporting via Rails harness:
bin/rails "demo:report_zeta_real"
Rails Integration (Local Path)
rh_llm_benchmark consumes this gem by local path in its Gemfile:
gem "rh_math", path: "../rh_math"After gem changes, run in Rails repo:
cd ../rh_llm_benchmark
bundle install
bin/rails runner "puts RhMath::VERSION"Public Modules and Classes
RhMath::NumericParserRhMath::Comparators::ExactTextRhMath::Comparators::AbsoluteToleranceRhMath::PrimeSupportRhMath::ArithmeticFunctionsRhMath::SpecialFunctionsRhMath::ZetaRhMath::Bounds::Schoenfeld1976RhMath::Evaluators::SchoenfeldPointwise-
RhMath::ComparisonResult(struct) -
RhMath::PointwiseResult(struct)
Usage Examples
Numeric parsing
require "rh_math"
value = RhMath::NumericParser.parse_decimal("1.25e-3")
# => #<BigDecimal:...,'0.125E-2',...>
RhMath::NumericParser.parse_decimal("not-a-number")
# => nilExact text comparison
require "rh_math"
result = RhMath::Comparators::ExactText.compare(
reference_text: " alpha ",
observed_text: "alpha"
)
result.verdict
# => "pass"
result.difference_text
# => "exact match"Absolute tolerance comparison
require "rh_math"
result = RhMath::Comparators::AbsoluteTolerance.compare(
reference_text: "10.0",
observed_text: "10.12",
tolerance_text: "0.2"
)
result.verdict
# => "pass"
result.difference_text
# => "0.12"Arithmetic functions (prime_pi, theta, psi)
require "rh_math"
RhMath::ArithmeticFunctions.prime_pi(10)
# => 4
RhMath::ArithmeticFunctions.theta(10)
# => sum(log p) for p <= 10
RhMath::ArithmeticFunctions.psi(10)
# => sum(log p) over prime powers p^k <= 10
li(x) usage
require "rh_math"
RhMath::SpecialFunctions.li(3000)
# => Float approximation of offset logarithmic integral li(3000)
zeta_real(s, terms:) usage (real s > 1)
require "rh_math"
approx = RhMath::Zeta.zeta_real(2.0, terms: 10_000)
# => ~1.644834 (approaches pi^2 / 6 as terms increase)
zeta_real_with_error(s, terms:) usage (rigorous truncation bound)
require "rh_math"
bounded = RhMath::Zeta.zeta_real_with_error(2.0, terms: 10_000)
# => {
# value: 1.644834..., # partial sum
# error_bound: 0.000099995...,# rigorous upper bound on tail truncation error
# lower_bound: value,
# upper_bound: value + error_bound
# }Schoenfeld pointwise evaluators
require "rh_math"
psi_eval = RhMath::Evaluators::SchoenfeldPointwise.evaluate_psi_bound(1000)
psi_eval.verdict
# => "pass" (expected for seeded benchmark path)
theta_eval = RhMath::Evaluators::SchoenfeldPointwise.evaluate_theta_bound(1000)
pi_li_eval = RhMath::Evaluators::SchoenfeldPointwise.evaluate_pi_li_bound(5000)
pi_li_eval.theorem_key
# => "schoenfeld_1976_corollary_1_eq_6_18"
# Typical seeded ranges in rh_llm_benchmark:
# psi: 100, 1000, 5000
# theta: 700, 1000, 5000
# pi-li: 3000, 5000, 10000, 20000Limitations and Caveats
- This is research software under active development.
- Mathematical coverage is partial and intentionally narrow.
-
zeta_real(s, terms:)andzeta_real_with_error(s, terms:)are real-domain only (s > 1). - No analytic continuation is implemented.
- No complex arithmetic is implemented.
-
li(x)is a moderate-x, Float-based numerical routine. -
zeta_real_with_error(s, terms:)provides a rigorous truncation-tail boundN^(1-s)/(s-1)for the partial sum; it does not bound floating-point roundoff error. - Arithmetic routines are straightforward and not optimized for large-scale computation.
Research Status Note
This gem currently supports benchmark architecture validation and early executable pointwise checks. It does not yet implement full RH computation workflows.