Skip to content

clsn/ries

Repository files navigation

RIES

This is a repository made from Robert Munafo’s fascinating 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 Apéry’s constant, ζ(3)≈1.20205690315959, is a “base” constant that can be used in your equations. Or the Euler-Mascheroni constant, γ≈0.57721566490153286, or anything else you like. This profile contains a selection of such constants:
Euler-Mascheroni constant
γ = limn→∞ (sumi=1^n 1/i) - ln(n). Approximately 0.5772156649
Plastic Number
The unique real root ρ of x³-x-1. Approximately 1.324717957244746
Apéry’s constant
ζ(3) (Riemann Zeta function). Approximately 1.20205690315959
Khinchin’s constant
The geometric mean of the partial quotients in the continued fraction expansion for “almost all” real numbers. Approximately 2.6854520010653
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
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
Reciprocal Fibonacci constant
The sum of the reciprocals of all the Fibonacci numbers. Approximately 3.359885666243
Catalan’s Constant
The alternating sum of the reciprocals of the squares of all odd integers. Approximately 0.9159655941772190
Γ(γ)
The 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 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 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 GNU Scientific Library as a math engine, which provides access to some “special” functions:

Lambert W Function
The inverse of w*exp(w). That is, W(x) is the number w such that w*exp(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.
Gamma and Factorial Functions
The factorial n! of a positive integer n is the product of all the integers from 1 through n. The Gamma function Γ(x) extends this function to non-integers, and also to negative non-integers (but not to negative integers!), except that n!=Γ(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 Pochhammer Symbol
The Pochhammer Symbol, or Rising Factorial, is a function of two arguments, x and y, and equals Γ(x+y)/Γ(x). This function makes the logarithm of that rising factorial available.
Digamma or Psi Function
The Digamma function is Γ’(x)/Γ(x), where Γ’(x) is the derivative of the Gamma function.
Exponential and Hyperbolic Integrals
These are three functions based on the exp function and the sinh and cosh functions, but involving integrals of f(t)/t.
Dilogarithm or Li_2(x)
The dilogarithm is another integral-based function, this one based on (1-t)/t.
Riemann Zeta Function
This is the well-known function at the center of the famed 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.

About

Robert Munafo's reverse equation solver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages