ries is a program that takes any number (for example, 2.5063) and produces a list of equations very much like the following:
Notice the answers are ordered by increasing closeness to your number. It should also be apparent that the simplest equations come first and the more complex ones later on. ries follows the example of continued fractions as you go to longer equations, you get a closer approximaion to your number, and each approximation is the closest approximation that is available with an equation of that complexity.
ries is highly customizable. You can have it omit symbols (like the symbol for phi, the Golden Ratio) if you don't want it to use them in solutions. You can give it an integer and specify that it limit its search to calculations that come out to be exact integers, and it will figure out the shortest way to construct your number from the digits 1 through 9. ries can find the simplest way to (for example) express the value 27 using only the digit 4 and the four basic operators plus, minus, times and divide.
ries is also very fast. The above run took less than 2 seconds on a 180-MHz P5 (586 clone) machine. You can specify a longer search to get more (and longer) equations, and it will try over 1010 equations in less than a minute. On a 733-MHz Pentium-III, ries -l4 tests over 1.4×1012 equations in 62 seconds and uses 115 megs of memory; on a 2.33-GHz Intel Core 2, the same thing finishes in only 13.5 seconds.
I wrote ries after I was frustrated by services such as Plouffe's Inverterand the Inverse Symbolic Calculator. In case you're wondering, the things that frustrated me are described here.
ries was first created for Linux1, but is is easily ported to Mac OS X, and nearly any OS with a C compiler. The source code is distributed under GPL 2.0. You can also get the manpage source. If you don't already have a copy, you should also retrieve the GNU General Public License version 2.0, which defines the terms under which this source code is made available to you, here.
Here are a few cute and/or fun things you can do with ries:
Finding Exact Solutions
Because ries uses derivatives to report how far a match deviates from exactness, you can use it to iterate Newton's Method. Suppose you know that the cube root of 3 starts with the digits 1.442, and want to find more digits. ries 1.442 yields the result:
x^3 = 3 for X = T + 0.00024957 {51}
Just add a few of the digits it gives:
ries 1.442249
x^3 = 3 for X = T + 5.70307e-07 {51}
ries 1.442249570
x^3 = 3 for X = T + 3.07408e-10 {51}
and so on. The actual value of the cube root of 3 (to 25 digits) is 1.4422495703074083823216383... Although this specific example is a case of extreme computational overkill, the same method can be used to compute quantities that cannot be computed directly, such as the value of x in xx=10.
Four Fours
At one time this type of problem was popular: How do you reach various values using four 4's and any number of symbols (for example: 44/44 = 1, 4/4+4/4 = 2, (4+4+4)/4 = 3, etc.). Solutions of a similar type of problem can be found with a command like:
ries '-S4+-*/' -Ox 17
x-4*4 = 4/4 (exact match)
which corresponds to the solution 4/4+4×4 = 17. Note that -S4+-*/ specifies the "symbols" that can be used in solutions, the quotes prevent the shell from performing filename globbing, and -Ox tells ries that x should only appear once in each equation. Also, although this example happens to have four 4's, ries cannot be told how many 4's to use. So, although its answers for 3, 5, 6, 9 and 17 yield equations with four 4's, other numbers give more or fewer.
Secret Code
Convert letters to numbers, generate an equation with ries, convert to an expression, then transmit to your friends. They use a calculator as the "secret decoder ring". Not very efficient, but pretty darn obscure. Example: Convert "D A V E" to numbers (04, 01, 22, 05). Make this to a single number (4.012205). Typing ries -l1 4.012205 generates the equation e^(1/-cos(x)) = sin(6)+5 (this is the first result with a positive error term that is less than 10-6.) Converting this to an expression gives 2*pi-arccos(-1/ln(sin(6)+5)). You can exclude certain operations with the -N option, for example, ries -l1 -NSfe 4.012205 gives sqrt(x^2-5) = 4,/pi+2. Note that 4,/pi is the 4th root of pi, so this answer converts to the formula sqrt((sqrt(sqrt(pi))+2)^2+5). The first formula gives 4.01220568...; the second gives 4.01220579...
If you like ries, you might also be amused by my web pages on numbers and large numbers. There is also Hypercalc (the calculator that doesn't overflow) and this program which computes the Riemann Zeta function and turns the real and imaginary components into left and right audio waveforms, so you can listen to the Zeta function on your stereo (it actually sounds pretty good :-)
This work is licensed under a Creative Commons Attribution 2.5
License. Details here
s.13