Project

rh_math

0.0
The project is in a healthy, maintained state
A research-oriented pure-Ruby math layer for bounded analytic number theory evaluation workflows.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 5.0
~> 13.0
 Project Readme

rh_math

DOI

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::NumericParser for conservative decimal/scientific parsing to BigDecimal
  • RhMath::Comparators::ExactText
  • RhMath::Comparators::AbsoluteTolerance
  • arithmetic helpers:
    • RhMath::PrimeSupport.primes_up_to
    • RhMath::ArithmeticFunctions.prime_pi
    • RhMath::ArithmeticFunctions.theta
    • RhMath::ArithmeticFunctions.psi
  • Schoenfeld 1976 RHS bound helpers:
    • RhMath::Bounds::Schoenfeld1976.psi_rh_upper_bound
    • RhMath::Bounds::Schoenfeld1976.theta_rh_upper_bound
    • RhMath::Bounds::Schoenfeld1976.pi_li_rh_upper_bound
  • pointwise evaluators:
    • RhMath::Evaluators::SchoenfeldPointwise.evaluate_psi_bound
    • RhMath::Evaluators::SchoenfeldPointwise.evaluate_theta_bound
    • RhMath::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 real s > 1 via 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 -v

Run tests file-by-file:

for f in test/*_test.rb; do ruby -Ilib:test "$f" || exit 1; done

Reproducibility

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::NumericParser
  • RhMath::Comparators::ExactText
  • RhMath::Comparators::AbsoluteTolerance
  • RhMath::PrimeSupport
  • RhMath::ArithmeticFunctions
  • RhMath::SpecialFunctions
  • RhMath::Zeta
  • RhMath::Bounds::Schoenfeld1976
  • RhMath::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")
# => nil

Exact 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, 20000

Limitations and Caveats

  • This is research software under active development.
  • Mathematical coverage is partial and intentionally narrow.
  • zeta_real(s, terms:) and zeta_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 bound N^(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.