.TH RIES 1L \" -*- nroff -*- .SH NAME ries \- find algebraic equations, given their solution .SH SYNOPSIS .B ries [-\fBl\fIn\fR] [-\fBi[e]\fR] [-\fBx\fR] [-\fBF\fR] [-\fBS\fIsss\fR] [-\fBN\fIsss\fR] [-\fBO\fIsss\fR] [-\fBD\fIxxx\fR] \fIvalue\fP .SH DESCRIPTION .B ries searches for algebraic equations in one variable that have the given number as a solution. It avoids trivial or reducible solutions like "x = x". If .I value is an integer, .B ries will find an exact solution expressed in terms of single-digit integers. For example, if you supply the value 2.5063, the first part of \fBries\fP's output will resemble the following: Your target: T = 2.5063 2 X = 5 for X = T - 0.0063 {49} ln(x)^2 = sin(1) for X = T - 0.00373232 {64} X^2 = 2 pi for X = T + 0.000328275 {55} X^X = 1 + 9 for X = T - 0.000115854 {69} X^2 + e = 9 for X = T + 3.56063e-05 {63} The output gives progressively "more complex" solutions (as described below) that come progressively closer to matching your number. There are four columns: equations in symbolic form (two columns of symbolic expressions with '=' in the middle), solution of equation (value of \fIX\fR in terms of \fIT\fR), and total complexity score (described below). Options allow complete control over what symbols, constants and functions are used in solutions, or to limit solutions to all-integer values. .SH OPTIONS Options must be separate: `\fBries -l1 -i -Ox 27\fP', not `\fBries -l1iOx 27\fP'. .IP \fB-l\fIn\fR Specifies the level of the search (default 0). .B \-l1 will search about 10 times as many equations and take at least 4 times as long (depending on memory limits) as \fB-l0\fP. Use higher levels to add more factors of 10. Here are typical figures, measured on a 733-MHz Pentium-III with the sample command \fBries -l\fP\fIn\fR\fB 2.5063141592653589\fP for different values of searchlevel \fIn\fR: memory equations digits runtime usage tested matched (733MHz P3) -l0 960K 95,000,000 6+ 0.1 sec -l1 3.1M 1,030,000,000 7+ 0.7 sec -l2 11 M 12,800,000,000 8+ 3.3 sec -l3 33 M 120,000,000,000 9+ 12 sec -l4 115M 1,470,000,000,000 11+ 63 sec (for a 180-MHz 586, the times are 10 times longer and the rest of the figures are the same.) When free memory is exhausted; performance depends on your operating system. Under Linux, .B ries keeps running but the system slows to a crawl. Other operating systems might experience similar effects, or simply not allow .B ries to get more memory (at which point .B ries terminates its search and quits immediately). If you don't know what your OS will do, be careful before running .B ries with higher levels. In extreme cases your computer's response might slow down so much that you are unable to save files in other programs. The memory limits are not reached nearly as quickly when the symbolset is greatly limited with \fB-S\fP, \fB-O\fP and \fB-N\fP or when \fB-i\fP is specified. \fB-i\fP in particular should allow about two more levels in any given amount of memory. .IP \fB-N\fIsss\fR .B \-N followed by one or more characters specifies symbols (constants and operators) that .B ries should not use in its equations. The symbols are as follows: .RS 0.7i .IP 1-9 The integers 1 through 9. (\fBries\fP constructs all larger integers from combinations of these.) .IP p pi = 3.14159... .IP e e = 2.71828... .IP f phi = (1+sqrt(5))/2 = 1.61803... .IP n Negative .IP r Reciprocal .IP s Squared .IP q Square root .IP "S C" Sine, cosine .IP "T A" Tangent, arctangent .IP l ln (natural logarithm) .IP "+ -" Plus and minus .IP "* /" Times, divide .IP ^ Power: 2 ^ 3 = 8 .IP v Root: 3 v 27 = cube root of 27 .IP L Log-base-N .RE There are lots of potential uses for \fB\-N\fP. For example, if you invoke .B ries on a small irrational number, you might get several solutions that involve the unary and binary logarithm operators 'l' and 'L'. If you decide you aren't interested in such solutions you can just add .B \-NlL to your command line, and all such solutions will be skipped. If you are checking an unknown number that you found in the context of some larger problem, you probably have some idea what constants and operators may be involved, or not involved, in the phenomenon that produced your number. Use \fB-N\fR to rule out functions you don't think are relevant. Note that .B ries will often run considerably slower when you limit it to a very small set of symbols, mainly because it cannot use its optimization rules (this is described below under ALGORITHM). Also, with fewer symbols the average length of expressions is longer, and that makes the search slower. .IP \fB-S\fIsss\fR Specifies a symbol set, as with \fB\-N\fP, but has the opposite effect: .I only these symbols will be used. If .B \-S and .B \-N are used together, the .B \-N is ignored. .B \-S can be used to solve those old problems of the sort "How can the number 27 be expressed using only the four basic operators and the digit 4?" The answer is given by: ries '-S4+-*/' 27 -Ox (The .B \-Ox option is described next). To solve the same problem using the .B \-N option, you'd have to type: ries -Npef12356789rsqlL^v 27 -Ox .IP \fB-O\fIsss\fR Specifies symbols which should appear no more than once on each side of the equation. This option can be combined with .B \-S or \fB\-N\fP, in which case they augment each other. Any conflicts are resolved on a symbol-by-symbol basis: \fB-S\fP overrules \fB-O\fP, \fB-O\fP overrules \fB-N\fP. One additional symbol is available with \fB-O\fP: x The variable on the left-hand-side Thus, you can use \fB-Ox\fP to limit \fBries\fP's output to equations that have only one 'X' in them and are therefore easy to solve for X using only the most basic algebra techniques. This also makes \fBries\fP's output more like that of traditional expression-finders, which search for expressions equal to X rather than equations in X. Here's an example: \fBries -i 16\fP gives lots of answers like "X + 3^X = 9^8" with X very, very close to T. \fBries -i 16 -Ox\fP eliminates all these, and prints more interesting answers like "(X+7)^4 = 6^7". .IP \fB-i\fR Require that all expressions, and all subexpressions, must have integer values. This is primarily useful if you are searching for an exact solution for a large integer. Note that inexact solutions will still be given, but both sides will be integers. An example of such a solution is "X * 9 = 8^2" where X=7. \fB-i\fP is ignored if the supplied target value is not an integer. .IP \fB-x\fR Print actual values of \fIX\fR (the roots of the equations found) rather than expressing \fIX\fR as \fIT\fR plus/minus a small number. .IP \fB-F\fR Print solutions in postfix format, similar to that used in FORTH and on certain old pocket calculators. This is the format used internally by \fBries\fP. \fB-F\fP is intended mainly for use by scripts that use \fBries\fP as an engine to generate equations and then perform further manipulation on them. However, this option will also help you distinguish what symbols were actually used internally to generate an answer. For example, the symbols 's' and '^2' both show up as '^2' in the normal output, but in postfix they appear as "dup*" and "2 **" respectively. Most of the symbols used by \fB-F\fP are self-explanatory. The nonobvious ones are: \fBneg\fR for negate, \fBrecip\fR for reciprocal, \fBdup*\fR for square, \fBsqrt\fR for square root, \fB**\fR for power (A^B), \fBroot\fR for Bth root of A, \fBlogn\fR for logarithm (to base B) of A. For these last three, \fIA\fR is the first operand pushed on the stack and \fIB\fR is the second. .IP \fB-D\fIxx\fR Display debugging messages. \fI-D\fR is followed by one or more letters specifying the messages you want to see. The options listed first create less output and are generally more useful: .RS 0.7i .IP a Debug option a .IP b Debug option b .RE .IP (Description of debugging has not been written -- if you need it, email me to let me know.) .SH ALGORITHM .B ries begins its search with small, simple equations and proceeds to longer, more complex ones. To determine the order to search, .B ries uses many \fIcomplexity rules\fP, including the following: .IP 1. If you add a symbol to an equation, the result is more complex: X + 1 = 3 is more complex than X = 3 X + 1 = ln(3) is more complex than X + 1 = 3 X - 7 = 4^2 is more complex than X - 7 = 4 .IP 2. If two equations are the same except for one number, the equation with the higher number is more complex: X + 1 = 5 is more complex than X + 1 = 3 X^3 + 1 = 3 is more complex than X^2 + 1 = 3 .IP 3. If two equations are the same except for one symbol, the equation with the "more exotic" symbol is more complex: X ^ 5 = 3 is more complex than X + 5 = 3 .P As .B ries searches it finds solutions -- these are equations for which X is close to being an exact answer. Each time it finds a solution it prints it out. Then .B ries raises its standard for the next answer: The next answer .B ries prints must be a closer match to your supplied value than all the answers it has given so far. (The only exception to this rule is an exact match: .B ries will print the simplest exact solution but will then continue to print more inexact solutions. This is important if you only know a few digits of your number but don't care about the fact that it can be expressed as an integer divided by a power of 10.) Instead of trying complete equations, .B ries actually constructs half-equations, called \fIleft-hand-side expressions\fP and \fIright-hand-side expressions\fP, abbreviated LHS's and RHS's. It keeps a list of LHS's and a list of RHS's, and it keeps these lists in numerical order at all times. This enables .B ries to find matches much faster. All LHS's contain \fIX\fR and all RHS's do not. Thus, 1000 LHS's and 1000 RHS's make a total of 1000000 possible equations, and all 1000000 combinations can be quickly checked just by scanning through the two lists in numerical order. This is why .B ries is able to check billions of equations in less than a minute. The closeness of an LHS match depends on the value of \fIX\fR, and also on the derivative with respect to \fIX\fR of the LHS expression. Because of this, .B ries calculates derivatives of LHS's as well as their values. There are dozens of optimization rules .B ries uses, like the following: .IP \fBa+\fP Don't try "K + K" for any constant \fBK\fP because "K * 2" is equivalent. .IP \fBb+\fP Don't try "3 + 4" (or any two unequal integers from 1 to 5) because another single integer (in this case "7") is shorter. .IP \fBa*\fP Don't try "1 * K" for any constant \fBK\fP because "K" is shorter. .IP \fBb*\fP Don't try both "2 * 4" and "4 * 2" because they are equivalent. .IP \fBc*\fP Don't try "K * K" because "K ^ 2" is shorter. .IP \fBar\fP Don't try "1 / (1 / expr))" for any expression \fBexpr\fP because "expr" is shorter. .IP \fBa^\fP Don't try "2 ^ 2" or "2 squared" because "4" is shorter. .IP \fBb^\fP Don't try "expr ^ 2" for any expression \fBexpr\fP because "expr squared" is shorter. .RE These rules are important -- they make the search about 10 times faster. However, if the symbol set is limited via \fB-N\fP, \fB-O\fP or \fB-S\fP, some of these rules cannot be used. For each optimization rule there are one or more symbolset exclude rules like the following: Don't use rule \fBa+\fP if either of the symbols '*' or '2' is disabled. In order to maintain maximum efficiency, .B ries checks each rule individually against the symbolset, and uses as many rules as it can. You can see this process in action by trying a command like \fBries 1.4142\fP, which gives the answer "X^2 = 2". If you disable the 's' (squared) and '^' (power) symbols with \fBries 1.4142 -Ns^\fP, rules \fBc*\fP and \fBb^\fP go away, and the answer becomes "X = sqrt(2)". If you also disable 'q' (square root) the answer becomes "X * X = 2". .SH UNEXPECTED BEHAVIOR Adding or changing the symbolset with the \fB-S\fP, \fB-O\fP and \fB-N\fP options often causes unexpected changes in the output. For example, \fBries 2.5063\fP yields the solution \fIX\fP^2 = \fIpi\fR * 2 but \fBries 2.5063 -N+-\fP gives the same solution as \fIX\fR / sqrt(2) = sqrt(\fIpi\fR). This seems counterintuitive -- there was no + or - in the first answer, so why did .B ries decide it had to give the answer in a different form? In fact, both solutions are generated, but .B ries will only print the first one it encounters during its search. Note that the second version has a simpler RHS and a more complex LHS. The mysterious behavior results from the fact that .B ries always tries to keep the number of LHS and RHS expressions equal as it performs its search. Eliminating operators with the \fB-N\fP option means that more complex expressions must be generated to reach the "quota". In this particular case, the symbolset restriction has a greater effect on the LHS than on the RHS, so as the search is progressing, LHS complexity grows a little more quickly than RHS complexity. In this particular case, \fIpi\fR * 2 is a more complex expression than sqrt(\fIpi\fR) because it has more symbols. Conversely, \fIX\fR^2 is \fIless\fP complex than \fIX\fR / sqrt(2). So, one of the solutions has more complexity on its left and the other has more complexity on its right. \fIX\fR^2 = \fIpi\fR * 2 and \fIX\fR / sqrt(2) = sqrt(\fIpi\fR) are equivalent solutions, but only one can be found first. The \fB-l\fP option is meant to give control over the number of solutions searched, but it actually controls the number of LHS and RHS expressions generated. Because two RHS's often have the same value, and only one (the first) gets kept, the number of solutions checked (which is the RHS count times the LHS count) depends on how often you get two LHS's or RHS's with the same value. This happens particularly often when the symbol set is severely restricted. If \fBries\fP tried to compensate for this, the result would be that severely limited symbolsets would take a very long time to run and would generate really long equations. The current implementation is considered to be a good tradeoff. .SH BUGS Performance does not degrade gracefully when the physical memory limit is hit, because expression nodes are allocated in sequential order in memory, without regard to where they will end up in the tree. Although it tries to avoid it, \fBries\fR will often print more than one equivalent solution. It misses the fact that the multiple solutions are equivalent because of roundoff error. It still occasionally prints "answers" that are actually tautologies empty in meaning (a simple example would be \fIX\fR/\fIX\fR = 1, but .B ries handles that case and most other simple cases. When this bug happens it's always something much more complex). Due to roundoff error, .B ries sometimes prints completely wrong answers. An example is 1/(1/(1/\fIX\fR)-\fIX\fR)=8^(7*2). For certain values of \fIX\fR, 1/(1/\fIX\fR) comes out slightly different from \fIX\fR (because of roundoff error), and therefore the LHS ends up being a really big number, like 8^14. Make sure to double-check \fBries\fR's answers before using them. .SH ACRONYM .B ries (pronounced "reese" or "reeze") is an acronym for "RILYBOT Inverse Equation Solver". The expansion of .I RILYBOT includes two more acronyms whose combined length is greater than 11. The full expansion of .B ries grows without limit and is well-defined but not primitive-recursive. Contact the author for more information. .SH AUTHOR Robert P. Munafo, .