RIES - Find Algebraic Equations, Given Their Solution
ries is a program that takes any number (for example, 2.5063) and produces a list of equations very much like the following:
bash# ries 2.5063
Your target value: T = 2.5063 www.mrob.com/ries
2 x = 5 for X = T - 0.0063 {49} ln(x)^2 = sin(1) for X = T - 0.00373232 {60} x^2 = 2 pi for X = T + 0.000328275 {55} x^x = 1+9 for X = T - 0.000115854 {69} cos(cos(x)) = ln(2) for X = T + 8.77443e-05 {67} x^2+e = 9 for X = T + 3.56063e-05 {63} sin(1/x^2) = 1-sin(1) for X = T - 3.1577e-05 {82} x-sqrt(e) = cos(cos(1)) for X = T - 2.55135e-05 {81} x-sin(x) = 3,/7 for X = T + 2.45325e-05 {88} sin(2) x = sin(1),/2 for X = T + 2.05293e-05 {88} x/4+1 = 4,/7 for X = T + 6.24679e-06 {91} phi sin(x) = cos(6) for X = T - 5.93376e-06 {81} x-sqrt(cos(1)) = log_3(7) for X = T - 3.66369e-06 {94} ln(sqrt(x)-1) = -(phi/3) for X = T + 1.4647e-06 {97} sin(phi x) = 1-ln(6) for X = T - 1.14085e-06 {96} x-1/cos(2) = sin(2)+4 for X = T - 5.34897e-07 {99} sin(e^(x-1)) = 1/7^2-1 for X = T + 1.01363e-07 {105}
"A,/B" = Ath root of B
--LHS-- --RHS-- -Total- dead-ends: 201098 245848 446946 CPU time: 0.0 expressions: 16341 19346 35687 distinct: 10824 8763 19587 Memory: 960K
Total equations tested: 94850712
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 Inverter and 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.
Stupid Math Tricks
Here are a few cute and/or fun things you can do with ries:
Mystical Pre-Destiny
Take your phone number and a friend's phone number and insert a decimal point: 123-4567 becomes 123.4567 and 555-1212 becomes 555.1212. Then take the ratio: 555.1212/123.4567 = 4.496485. Put this into ries and pick a formula that can be solved for x (for example, I used x+9√pi=6-1/e). Solve it for x (in this case getting x=6-1/e-9√pi), and then multiply the whole thing by the phone number that you originally put in the denominator and you get the other phone number:
(6 - 1/e - 9√pi) × 123.4567 = 555.121234525
If the answer doesn't have all 7 digits, try another of the formulas that ries gave. If you don't find a nice formula, start with something else, like 5.551212+1.234567 or 5.551212-1.234567, and transform the result in the appropriate way.
Now go to your friend and announce that you have found the mystic formula that links their phone number to yours. For extra credit, write the formula in an old school notebook and claim it was given as a problem in class long before you met.
Finding Exact Solutions (Newton's Method)
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
(other answers not shown)
x^3 = 3 for X = T + 5.70307e-07 {51}
ries 1.442249570
(other answers not shown)
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 for which 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 (D=04, A=01, V=22, E=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...
See Also
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 :-)
1. Linux rules.
Robert Munafo's home pages on HostMDS (c) 1996-2010 Robert P. Munafo. about contact
This work is licensed under a Creative Commons Attribution 2.5
License. Details here
s.13