SkillAgentSearch skills...

Ries

Robert Munafo's reverse equation solver

Install / Use

/learn @clsn/Ries
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

  • RIES

This is a repository made from Robert Munafo's fascinating [[http://mrob.com/pub/ries/index.html][ries]] program, which tries to find equations/approximations given a number. So it can find fun approximations to π, or ℯ, or your phone number with a decimal point in front of it. It was used in the making of https://xkcd.com/1047/. Seriously, go check out the page.

Munafo's official ries source is not (yet) on github, but I've been playing with it and wanted to make my tweaks available, at least. Maybe I should make a =munafo= branch to track his official code--but then I'd have to remember to update that somewhat regularly.

** Contents of Repository

So, what's available here (at first) is:

  • =ries.c= :: The source file for =ries=. This contains copious comments, comprising Munafo's Changelog (but not mine), thoughts, compilation instructions, and everything else.

  • =msal_math64.c= :: A standalone math library (also from Robert Munafo) that can optionally be used in =ries= to provide some more functionality (some transcendental functions.)

  • =ries.1= :: The manual page for =ries=. Also from Munafo. I try to update this to reflect any new features I may have added, but not necessarily promptly.

  • =latin.ries= :: Now we are into =ries= profiles, which are settings of particular sets of =ries= options, including how to display the results, etc (=--symbol-names=). This is from Munafo, supposed to display the results in Latin text.

  • =Mathematica.ries= :: Another profile, also from Munafo, for producing output that could be pasted into Mathematica (perhaps with minor changes.)

  • =constants.ries= :: Now we get into files that are from me (Mark Shoulson) and not Robert Munafo. A feature I've added is the ability to define additional constants to be used in =ries= equations. So instead of only being able to generate equations made from single digits, π, ℯ, φ, and functions of them, you can decide, for example, that [[https://en.wikipedia.org/wiki/Ap%C3%A9ry%27s_constant][Apéry's constant]], ζ(3)≈1.20205690315959, is a "base" constant that can be used in your equations. Or the [[https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant][Euler-Mascheroni constant]], γ≈0.57721566490153286, or anything else you like. This profile contains a selection of such constants:

    • [[https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant][Euler-Mascheroni constant]] :: γ = lim_{n→∞} (sum_{i=1}^n 1/i) - ln(n). Approximately 0.5772156649

    • [[https://en.wikipedia.org/wiki/Plastic_number][Plastic Number]] :: The unique real root ρ of /x³-x-1/. Approximately 1.324717957244746

    • [[https://en.wikipedia.org/wiki/Ap%C3%A9ry%27s_constant][Apéry's constant]] :: ζ(3) (Riemann Zeta function). Approximately 1.20205690315959

    • [[https://en.wikipedia.org/wiki/Khinchin%27s_constant][Khinchin's constant]] :: The geometric mean of the partial quotients in the continued fraction expansion for "almost all" real numbers. Approximately 2.6854520010653

    • [[http://mathworld.wolfram.com/ContinuedFractionConstant.html][Continued Fraction constant]] :: The value of the continued fraction [0; 1, 2, 3, 4, …]. Equal to /I₁(2)/I₀(2)/, where the /I/-s refer to Bessel I-functions. Approximately 0.697774657964

    • [[https://en.wikipedia.org/wiki/L%C3%A9vy%27s_constant][Lévy's constant]] :: The limit as n→∞ of /qₙ^(1/n)/, where /qₙ/ is the denominator of the /n/-th convergent of the continued fraction for "almost all" real numbers. Equal to exp(π²/(12·ln 2)); approximately 3.275822918721811

    • [[http://mathworld.wolfram.com/ReciprocalFibonacciConstant.html][Reciprocal Fibonacci constant]] :: The sum of the reciprocals of all the Fibonacci numbers. Approximately 3.359885666243

    • [[http://mathworld.wolfram.com/CatalansConstant.html][Catalan's Constant]] :: The alternating sum of the reciprocals of the squares of all odd integers. Approximately 0.9159655941772190

    • Γ(γ) :: The [[https://en.wikipedia.org/wiki/Gamma_function][Gamma function]] applied to the Euler-Mascheroni constant (see above). Because it's lots of gammas.

  • =funcs.ries= :: My =ries= extentions allow you to define your own functions, with =--define 'weight:name:description:formula'=. This file contains a few sample definitions, like sinh and cosh, etc.

  • =pretty.ries= :: A =ries= profile for replacing a few of the mathematical symbols with pretty unicode characters. The main non-obvious one is that =ries='s n-th root operator (represented "/ in =ries=) is shown as √, while a true square root is ²√.

  • =sympy.ries= :: A profile for use with the python symbolic math package [[http://www.sympy.org/][sympy]]. Does only a few very simple substitutions, like constant names, =**= for =^=, and =S.One= for =1=, so reciprocals (at least) won't get evaluated to floating-point numbers and sympy can keep them as rationals.

  • =infixnroot.py= :: a small Python script that uses a hack (from [[http://code.activestate.com/recipes/384122-infix-operators/][here]]) to create a Python "infix" operator that does what =ries='s ~"/~ symbol does: take the n-th root of something. This way, =sympy.ries= above doesn't choke on n-th roots. Even gotten arbitrary logarithms to work, albeit by means of some rather evil Python.

  • =rcomplete.sh= :: a little shellscript to enable tab-completion for =ries= options.

  • =Makefile= :: A simple Makefile for building =ries=, as well as =riesw=, which is a name I gave to the version of =ries= with the =msal_math64.c= extensions included (because it supports the /W/-function), other "variants" of =ries= that use different math libraries, and processing the manual page to text, cleaning, etc.

** Extensions to =ries=

*** User-defined Constants As mentioned above, one thing I've added to =ries= myself is the ability to add more constants. You do this with the =-X= option, followed by a string of the form =weight:name:description:value=. The weight is used by =ries= to decide how "expensive" it is to use this constant, i.e. how much more "complicated" it makes the resulting expression. I usually set this at 4, mostly just to pick a number.

*** User-defined Functions I've also added the ability to define your own functions, with the =--define= option, which should be followed by a string of the form =weight:name:description:formula=, where the formula is the postfix notation formula to be computed. This uses =ries='s =-F0= syntax, with one-letter symbols for the operations. Alternatively, (as another new feature) you can use the FORTH-like =-F3= format, with full names for the operators, if you separate them with spaces /and/ put an extra colon (=:=) at the very beginning. This also works for the =-O=, =-N=, =-E=, and =-S= options, etc; see the =ries.1= documentation file.

*** GSL Support You can now compile =ries= to use the [[https://www.gnu.org/software/gsl/][GNU Scientific Library]] as a math engine, which provides access to some "special" functions:

  • [[https://en.wikipedia.org/wiki/Lambert_W_function][Lambert W Function]] :: The inverse of wexp(w). That is, W(/x/) is the number /w/ such that wexp(w) = x. You can use this to build a "super square root" function, that is, to find the number /y/ such that y^y=x.

  • [[https://en.wikipedia.org/wiki/Gamma_function][Gamma]] and [[https://en.wikipedia.org/wiki/Factorial][Factorial]] Functions :: The factorial /n/! of a positive integer /n/ is the product of all the integers from 1 through /n/. The Gamma function \Gamma(x) extends this function to non-integers, and also to negative non-integers (but not to negative integers!), except that /n/!=\Gamma(n+1). The natural log of the Gamma function is also available separately, as a single function, which can accept much higher arguments without overflowing than the Gamma function can.

  • Log of the [[https://en.wikipedia.org/wiki/Pochhammer_notation][Pochhammer Symbol]] :: The Pochhammer Symbol, or Rising Factorial, is a function of /two/ arguments, x and y, and equals \Gamma(x+y)/\Gamma(x). This function makes the logarithm of that rising factorial available.

  • [[https://en.wikipedia.org/wiki/Digamma_function][Digamma or Psi Function]] :: The Digamma function is \Gamma'(x)/\Gamma(x), where \Gamma'(x) is the derivative of the Gamma function.

  • [[https://en.wikipedia.org/wiki/Exponential_integral][Exponential]] and [[https://en.wikipedia.org/wiki/Trigonometric_integral#Hyperbolic_sine_integral][Hyperbolic]] Integrals :: These are three functions based on the exp function and the sinh and cosh functions, but involving integrals of f(t)/t.

  • [[https://en.wikipedia.org/wiki/Spence%2527s_function][Dilogarithm]] or Li_2(x) :: The dilogarithm is another integral-based function, this one based on (1-t)/t.

  • [[https://en.wikipedia.org/wiki/Riemann_zeta_function][Riemann Zeta Function]] :: This is the well-known function at the center of the famed [[https://en.wikipedia.org/wiki/Riemann_hypothesis][Riemann hypothesis]]. It's an infinite sum of integers to the power of -x.

  • Super Cube Root :: This is not a built-in function of the GSL, but uses GSL's root-finding capabilities to find the number /y/ such that y^y^y=x.

*** RHS-only Operator Restrictions This feature is still a bit experimental, but I've added the ability to restrict or permit the use of a given set of symbols on the RHS of the equations separately from the permissions on the LHS. Still working out uses and ramifications of this.

*** Docs All this new stuff has been added to the already comprehensive documentation file.

Related Skills

View on GitHub
GitHub Stars22
CategoryDevelopment
Updated1mo ago
Forks2

Languages

C

Security Score

90/100

Audited on Mar 12, 2026

No findings