.TH RIES 1L "Manual version: 2012 Jan 22" \" -*- nroff -*- .SH NAME ries \- find algebraic equations, given their solution .SH SYNOPSIS \fBries\fP [\fB-l\fIn\fR] [\fB-i[e]\fR] [\fB-x\fR] [\fB-F\fIn\fR] [\fB-S\fIsss\fR] [\fB-N\fIsss\fR] [\fB-O\fIsss\fR] [\fB-D\fIxxx\fR] [\fB-p\fIfilename\fP] [\fB--extended-options\fR [...]] \fIvalue\fP .B ries --find-expression \fR[\fIexpression\fR [...]] .B ries --eval-expression \fR[\fIexpression\fR [...]] .SH DESCRIPTION \fBries\fP searches for algebraic equations in one variable that have the given number as a solution. It avoids trivial or reducible solutions like ``\fIx\fR/\fIx\fR = 1''. If \fIvalue\fR is an integer, \fBries\fR can 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: .fam C Your target value: T = 2.5063 www.mrob.com/ries 2 x = 5 for x = T - 0.0063 {49} 8 x = e^3 for x = T + 0.00439212 {66} x^2 = 2 pi for x = T + 0.000328275 {55} x^x = 1+9 for x = T - 0.000115854 {69} (x-1)^2 = tanpi(1/e) for x = T + 0.000108368 {75} x^2+e = 9 for x = T + 3.56063e-05 {63} ln(6) x = sqrt(pi)+e for x = T + 2.73037e-05 {93} .fam T 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 expressions with '=' in the middle), solution of equation (value of \fIx\fR expressed as \fIT\fR plus a small error term), and total complexity score (described below). Each match is checked by solving for \fIx\fR using the Newton-Raphson method, and the closeness of the match is judged by the difference between the root (the value of \fIx\fR for which the two sides are equal) and your target value \fIT\fR. 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: `\FCries -l1 -i -Ox 27\FT', not `\FCries -l1iOx 27\FT'. .IP \fB-p\fIname\fR Profile (or Parameters): Load one or more options from file \fIname\fR. Equivalent to \fB--include\fP \fIname\fR, which is described in the EXTENDED OPTIONS section below. .IP \fB-l\fIn\fR Level: Specifies the level of the search (default 2). With each increment of \fB-l\fP, \fBries\fP will search about 10 times as many equations, use 3.5 times as much memory and take at least 4 times as long. Use higher levels to add more factors of 10. The level can be fractional or negative. Here are typical figures, measured on a Core i7 at 3.2 GHz (using only one thread) invoked by the command \fBries -l\fP\fIn\fR\fB 2.5063141592653589\fP for different values of searchlevel \fIn\fR: .fam C memory equations tested digits run time -l0 1.2M 89,400,000 6+ 0.025 sec -l1 4.0M 932,000,000 7+ 0.08 sec -l2 14 M 11,400,000,000 8+ 0.33 sec -l3 45 M 134,000,000,000 9+ 1.8 sec -l4 158M 1,600,000,000,000 11+ 8.8 sec -l5 490M 15,000,000,000,000 12+ 37.1 sec -l6 1.7G 184,000,000,000,000 13+ 190 sec .fam T (these times are a little quicker than a 2.33-GHz Core 2 Duo; on a 733-MHz Pentium 3, the times were about 5 times longer. If compiled for an environment with 32-bit pointers, memory usage figures are about 20% lower. \fBries\fP also works on much older and smaller systems, and can test billions of equations in less than a minute on 1990's hardware) Use a fractional argument (like \fB-l5.5\fR) for more precise control of how much memory \fBries\fP will use before stopping its search. When free memory is exhausted; performance will degrade significantly and \fBries\fP might exit, depending on your operating system. Under Linux and Mac OS, \fBries\fP keeps running but the system slows to a crawl. If you don't know what your OS will do, be careful before running \fBries\fP with higher levels. In extreme cases your computer's response might slow down so much that you are unable to save your work in other applications. 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. Large arguments tend to lengthen runtime: for example, \FCries -l4 1058073667\FT takes about three times as long as \FCries -l4 1.058073667\FT. .IP \fB-N\fIsss\fR Never use these: \fB-N\fP followed by one or more characters specifies symbols (constants and operators) that \fBries\fP 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 Tangent .IP l ln (natural logarithm, also called log) .IP "+ -" Add, Subtract .IP "* /" Multiply, Divide .IP ^ Power: 2 ^ 3 = 8 .IP v Root (the ``v'' resembles a radical symbol): 3 v 27 = cube root of 27 .IP L Logarithm to base A of B .RE .IP There are lots of potential uses for \fB\-N\fP. For example, if you invoke \fBries\fP on a small irrational number, you might get several solutions that involve the unary and binary logarithm operators 'ln' (natural logarithm) and 'log_' (log to base A of B). If you decide you aren't interested in such solutions you can just add \fB-NlL\fP 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 \fBries\fP will often run considerably slower when you limit it to a very small set of symbols, mainly because it cannot use its optimization rules (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 permitted Symbol Set: Specifies a symbol set, as with \fB\-N\fP, but has the opposite effect: \fIonly\fR these symbols will be used. If \fB-S\fP and \fB\-N\fP are used with the same symbol, the \fB\-N\fP is ignored. \fB\-S\fP 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: \FCries '-S4+-*/' 27 -Ox\FT (The \fB-Ox\fP option is described next). To solve the same problem using the \fB-N\fP option, you'd have to type: \FCries -Npef12356789rsqlL^v 27 -Ox\FT If you give the \fB\-S\fP option with no symbols, \fBries\fP will display a table of all available symbols (as modified by any \fB-N\fP, \fB-O\fP and \fB-S\fP options) with their definition and weights. This lone \fB\-S\fP can be given along with a normal \fB\-S\fP option, but in any case \fBries\fP will exit after showing the table. .IP \fB-O\fIsss\fR Only One: Specifies symbols which should appear no more than once on \fIeach side\fR of the equation. This option can be combined with \fB-S\fP 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: .RS 1.2i .IP x The variable on the left-hand-side .RE .IP Thus, you can use \fB-Ox\fP to limit \fBries\fP's output to equations that have only one '\fIx\fR' in them and are therefore easy to solve for \fIx\fR 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 \fIx\fR rather than equations in \fIx\fR. Here's an example: \FCries -i 16\FT gives lots of answers like ``\fIx\fR + 3^\fIx\fR = 9^8'' with \fIx\fR very, very close to T, because 3^16 is close to 9^8. \FCries -i 16 -Ox\FT eliminates all these, and prints more interesting answers like ``(\fIx\fR+7)^4 = 6^7''. .IP \fB-i\fR Integer: 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 an inexact integer solution is ``2 \fIx\fR = 7^3'' where \fIx\fR=173. \fB-i\fP is ignored if the supplied target value is not an integer. .IP \fB-ie\fR Integer, Exact. Like \fB-i\fR, but only reports a single exact match, then exits. .IP \fB-x\fR X Values: 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\fIn\fR Format: Controls the way expressions are formatted in the main output. If \fIn\fR is omitted it is 3 (``-F'' for ``FORTH Format''); if \fB-F\fR is not specified at all, the format will be 2. The following formats are available; each shows the output of \FCries 1.506591651 -F\FT\fIn\fR: Format 0: Compressed FORTH-like postfix format: Each operator and constant is just a single symbol. The symbols are as listed above under the \fB-N\fR option. .fam C x1- = 2r for x = T - 0.00659165 {50} xlr = 6q for x = T - 0.00241106 {62} x4^ = p2+ for x = T - 0.000766951 {68} x1+s = p2* for x = T + 3.66236e-05 {69} .fam T Format 1: Infix format, but with single-letter symbols. If this format is specified, a table of symbols will be printed after the main table of results. The rest of the expression syntax is the same as the normal format. For example, "q(l(\fIx\fR)) = p-1" means "sqrt(ln(\fIx\fR)) = pi - 1". .fam C x-1 = 1/2 for x = T - 0.00659165 {50} 1/l(x) = q(6) for x = T - 0.00241106 {62} x^4 = 2+p for x = T - 0.000766951 {68} (x+1)^2 = 2.p for x = T + 3.66236e-05 {69} .fam T Format 2: Standard infix expression format (this is the default). .fam C x-1 = 1/2 for x = T - 0.00659165 {50} 1/ln(x) = sqrt(6) for x = T - 0.00241106 {62} x^4 = 2+pi for x = T - 0.000766951 {68} (x+1)^2 = 2 pi for x = T + 3.66236e-05 {69} .fam T Format 3: Print solutions in postfix format, similar to that used in FORTH and on certain old pocket calculators. This is close to the format used internally by \fBries\fP (to get the exact, condensed format, use \fI-F0\fR). This 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, 'squared' and 'to the power of 2' both show up as '^2' in the normal output, but in postfix they appear as "dup*" and "2 **" respectively. .fam C x 1 - = 2 recip for x = T - 0.00659165 {50} x ln recip = 6 sqrt for x = T - 0.00241106 {62} x 4 ** = pi 2 + for x = T - 0.000766951 {68} x 1 + dup* = pi 2 * for x = T + 3.66236e-05 {69} .fam T Most of the symbols used by \fB-F3\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. The setting of \fB-F\fP does not affect expressions displayed by the various \fB-D\fP diagnostic options. .IP \fB-D\fIxx\fR Display Diagnostic Data: A detailed understanding of the \fBries\fP algorithms (described below) is assumed. \fB-D\fP is followed by one or more letters specifying the messages you want to see. Options \fBA\fP through \fBL\fP and \fBa\fP through \fBl\fP (except \fBe\fP and \fBf\fP) apply to the LHS and RHS respectively. For each option, the number of lines of output that you can expect from a command like \FCries -l2 -D\FT\fIx\fR\FC 2.506314159\FT is shown: .RS 0.7i .IP A,a \fB[64895; 107077]\fP partial expression error (e.g. divide by zero); pruned .IP B,b \fB[55; 50]\fP partial expression is zero; pruned .IP C,c \fB[197613; 1299137]\fP partial expression is non-integer (and -i option given); pruned .IP D,d \fB[2081; 3324]\fP partial expression overflowed; pruned .IP E \fB[1132]\fP partial expression derivative nearly zero; pruned .IP F \fB[1912]\fP full expression derivative nearly zero; pruned .IP G,g \fB[346110; 547466]\fP expression added to database .IP H,h \fB[418208; 623315]\fP show attributes of each expression tested .IP I,i \fB[3984718; 5925992]\fP show each new symbol to be added before complexity pruning .IP J,j \fB[2595423; 3831907]\fP show symbols skipped by complexity pruning .IP K,k \fB[250769; 416908]\fP show symbols skipped by redundancy and tautology rules .IP L,l \fB[34; 34]\fP show symbols skipped to obey -O option .IP m \fB[9150548]\fP show all metastack operations .IP M \fB[46]\fP show memory allocation benchmarks, and enable automatic exit when memory gets slow (see \fB--memory-abort-threshold\fP option) .IP n \fB[174]\fP show Newton iteration values and errors if any .IP o \fB[588]\fP show work in detail: operator/symbol, x and dx at each step .IP p \fB[418874]\fP show match checks .IP q \fB[88]\fP show close matches dispatched to Newton and results of test .IP r \fB[1597798]\fP show results (value and derivative of operands and result) for each opcode executed .IP s \fB[275]\fP show your work: displays values of each subexpression for every reported answer. Subexpressions are shown in normal (infix) syntax, which is useful in combination with \fB-F0\fP to see the postfix format used with options like \fB--eval-expression\fP. .IP t \fB[10438]\fP show all abc-forms passed to expression generation .IP u \fB[36096]\fP show steps of min/max complexity ranging for each abc-form .IP v \fB[5236]\fP show number of expressions generated by each abc-form .IP w \fB[31662]\fP show details of abc-form generation (pruning, weights, etc.) .IP x \fB[89]\fP show all rules used (varies with the -N -O and -S options) .IP y \fB[354]\fP statistics and decisions made in main loop .IP z \fB[38]\fP initialization and other uncategorized messages .IP 0 \fB[1743837]\fP list the entire expression database after every pass through the main loop .RE .IP Of these, \fB-Ds\fP is probably the most useful and fun to look at. \fB-Dy\fP gives a nice top-level view of the statistics of the search. Most of the options that generate lots of output are useful if filtered through \FCgrep\FT; this can tell you why a certain subexpression is or is not appearing in results. (Note that subexpressions are shown in the \fB-F0\fP terse postfix format.) .SH EXTENDED OPTIONS Longer names are used for options that are thought to be less commonly wanted, or are more likely to be used only within \fB--include\fP files. .IP \fB--include\fP\ \fIfilename\fR .IP \fB-p\fIfilename\fR Load one or more options from file \fIfilename\fR. The options ``\fB--include\fP \fIfilename\fR'' and ``\fB-p\fIfilename\fR'' are equivalent; note that one requires a space before \fIfilename\fR and the other cannot have a space. \fBries\fP will attempt to open the named file, or the given name with ``\FC.ries\FT'' appended. If either is found, \fBries\fP will scan it for parameters and arguments separated by whitespace. Any control characters count as whitespace. Any '#' character that comes immediately after blank space denotes a comment and the rest of the line will be ignored. For example, if there is a file ``hst.ries'' containing the following: .fam C # hst.ries: High School Trigonometry settings --trig-argument-scale 1.74532925199433e-2 # pi/180 -NLleEv # No log, ln, e, e^x or arbitrary roots -Ox # Only allow one 'x' on the left-hand-side -x # Show equation roots as "x = 123.456" # rather than "x = T + 1.23e-4" .fam T then giving the option ``\fB-phst\fR'' is equivalent to giving the options ``\fB--trig-argument-scale 1.74532925199433e-2 -Ox -x\fP'', in that order. A parameter file may additionally invoke another parameter file with the \fB--include\fP option. When it encounters this option, \fBries\fP will apply the options in the included file, then continue with the rest of the first file. These may be nested up to 25 levels deep. If a file includes itself recursively (either directly or indirectly) \fBries\fP will exit with an error. It is an error for \fB--include\fP or the end of an included file to come between an option and its arguments. For example, ``\fBries 1.2345 --eval-expression --include expressions.txt\fP'' will produce an error regardless of the contents of ``\FCexpressions.txt\FT''. .IP \fB--canon-reduction\fP\ \fIsymbols\fR Apply simple transformations in an effort to make all expression values fall in the range [1 ... 2). This option improves the efficiency of the \fBries\fP algorithm (described in the ``ALGORITHM'' section below) by fitting the expressions into a smaller range, thereby increasing the odds of a close match. This option should be followed by one or more symbols which represent the operations \fBries\fP will try to apply to expressions: .RS 0.7i .IP n Negate expressions when possible to make all values positive. .IP r Take the reciprocal when possible to make all expressions fall outside the range (-1 ... 1). .IP 2 Multiply by 2 when possible to increase the magnitude of expressions in the range (-1 ... 1). .IP 5 Divide by 2 (i.e. multiply by 0.5) when possible to decrease the magnitude of expressions that fall outside the range (-2 ... 2). .RE .IP In these descriptions, the words \fIwhen possible\fR refer to the fact that \fB--canon-reduction\fP will respect any limits imposed by the symbolset options \fB-N\fP, \fB-O\fP and \fB-S\fP. So if you use the option \fB-n\fP together with \fB--canon-reduction n\fP, the negation operator will still be used only once per expression. Although it makes \fBries\fP more efficient, this option also causes the printed results to have greater complexity scores, and complexity scores will increase somewhat more erratically. Also, you will find that many printed results can be simplified by undoing the \fB--canon-reduction\fP transformations. For example, \FCries 2.50618 --canon-reduction nr25\FT might yield the result ``\FCx^x/2 = (1+9)/2\FT'', which you would simplify to ``\FCx^x = 1+9\FT''. .IP \fB--max-memory\fP\ \fIsize\fR This option tells \fBries\fP not to use more than the given amount of memory. This is an important option for users who frequently use a high \fB-l\fP (search level) option. For example, if you typically have about 2 gigabytes of free memory on your machine, you could invoke \fBries\fP with the option \fB--max-memory\fP \fB1.0e9\fP, to ensure that it never uses more than 1 gigabyte of memory regardless of the search level. \fBries\fP also has an (experimental) feature that can automatically detect when your system is slowing down; see the \fB--memory-abort-threshold\fP option for details. .IP \fB--memory-abort-threshold\fP\ \fIN\fR This option is used with the \fB-DM\fP option, and overrides the default slowness measurement after which \fBries\fP will automatically exit. With the \fB-DM\fP option, \fBries\fP measures how fast it is running, as compared to an estimate of how fast it ``should'' be running. If this ratio is greater than the \fI--memory-abort-threshold\fR for more than 3 of the past 10 measurements, \fBries\fP will exit. The default \fI--memory-abort-threshold\fR is 2.0. The value must be at least 1.0, and values less than about 1.5 are unlikely to be of much use. \fINOTE\fR: \fB--memory-abort-threshold\fP is an experimental \fBries\fP feature and is likely to change in future versions of \fBries\fP. .IP \fB--min-match-distance\fP\ \fIvalue\fR Specify the minimum distance between your given target value \fIT\fR and the roots \fIx\fR of any reported equations. This is useful for finding approximate formulas for constants that have a known, simple formula. For example, using the command \FCries 3.141592653589 -x --min-match-distance 1e-10\FT one can discover the following approximate formulas for \fIpi\fR : .fam C x-3 = 1/6 for x = 3.16666666666667 x-3 = 1/7 for x = 3.14285714285714 ln(ln(x)) = 1/e^2 for x = 3.14219183392327 x^2+1 = 4 e for x = 3.14215329254258 e^x+2 = 8 pi for x = 3.14124898321672 x/phi^2 = 1/5+1 for x = 3.14164078649987 e^x-pi = 4*5 for x = 3.14163154625921 ln(x)-3 = -(e^(1/phi)) for x = 3.14157115114649 x^2-8 = pi-sqrt(phi) for x = 3.1415876565959 x-(sqrt(2)+1) = 1/pi,/e for x = 3.14159091166831 sqrt(1+pi) x = e^3/pi for x = 3.14159272240341 x^2/e^3 = 1/sqrt(1+pi) for x = 3.1415926879966 .fam T Among these results (after solving for \fIx\fR) are the ancient approximations 19/6 and 22/7, and the more modern curiosity \fIe\fR^\fIpi\fR \o"~=" 20 + \fIpi\fR (which is called ``\fIGelfond's constant\fR''). Other interesting results can be found by omitting symbols with \fB-N\fP, for example \fBries 3.1415926 -NSCTlLfEevp\fP (excluding most of the scientific functions) gives the fraction approximation 355/113 in the form \FC1/(x-3)-1 = 1/4^2+6\FT. You will often get multiple equivalent results. For example, the last two equations above correspond to the approximate relation: .RS 1.2i \fIpi\fR \o"~=" sqrt(sqrt(\fIe\fR^6/(\fIpi\fR+1))) .RE .IP (which does \fInot\fR converge on the true value of \fIpi\fR if iterated). .IP \fB--min-memory\fP\ \fIsize\fR If \fBries\fP is given the debug option \fB-DM\fP, it will try to measure the responsiveness of the system and automatically exit if it gets very slow. This is intended as an automatic safeguard against virtual memory ``thrashing'' that will happen if \fBries\fP is allowed to use all of your system's memory. (This feature is only active with the \fB-DM\fP option because it is still being tested). When \fB--min-memory\fP is given in combination with \fB-DM\fP, it will ensure that \fBries\fP does not exit because of slow memory response until at least \fIsize\fR bytes of memory have been used. For example, if you know that you always have about 1 gigabyte of free memory on your machine, and your machine often gets slow for other compute-intensive tasks, you could invoke \fBries\fP with the options \fB-DM\fP \fB--min-memory\fP \fB1.0e9\fP, and slow system detection would be enabled but would not trigger (if at all) until a gigabyte of memory has been used. For more direct control over \fBries\fP' memory usage, use the \fB--max-memory\fP option or use a suitably small \fB-l\fP search level. .IP \fB--significance-loss-margin\fP\ \fIdigits\fR Specify the number of significant digits that may be lost in a calculation. By default, \fBries\fP tolerates a loss of 2 digits in any calculation. For example, if \fIx\fR is 0.906402477... (the value of Gamma[5/4]), \fBries\fP would not use \FCx+e^5\FT in any of its expressions, because \fIe\fR^5 is more than 100 times as large as \fIx\fR. Due to round-off, more than 2 digits of the value of \fIx\fR would be lost in the addition. This restriction applies to constant expressions too, so \fBries\fP also avoids \FC1+e^5\FT and \FC1+e^-5\FT. Similar restrictions apply to any function that can cause precision to be lost (if evaluated at a point where the function's derivative is very low). The normal \fBries\fP behavior corresponds to a \fB--significance-loss-margin\fP option with an argument of 2.0. Give a higher value to allow more digits to be lost in calculations. Conversely, if you suspect \fBries\fP is generating meaningless results due to round-off error, you can look at its calculations in detail with the options \fB-Ds\fP and \fB-F0\fP, then evaluate specific expressions with \fB--eval-expression\fP (described below). If it seems appropriate, make \fBries\fP more strict by giving \fB--significance-loss-margin\fP with a lesser argument. .IP \fB--trig-argument-scale\fP\ \fIvalue\fR Specify a constant by which the argument of the sine, cosine and tangent functions should be multiplied. By default this value is \fIpi\fR and the trig functions are called \FCsinpi\FT, \FCcospi\FT and \FCtanpi\FT. sinpi(\fIx\fR) is the sine of \fIpi\fR times \fIx\fR; so for example sinpi(1/3) is the sine of \fIpi\fR/3, which is half the square root of 3. A full circle is 2 in these units: sinpi(\fIx\fR) = -sinpi(\fIx\fR+1) = sinpi(\fIx\fR+2) for all \fIx\fR. If you give this option, arguments will be multiplied by the number you give instead of by \fIpi\fR. Useful values to give are: .RS 0.7i .IP A,a \fB--trig-argument-scale 1\fP for "natural" units (radians): sin(1/3) = 0.327194... .IP B,b \fB--trig-argument-scale 1.74532925199433e-2\fP for degrees: sin(22.5) = 0.382683... .IP B,b \fB--trig-argument-scale 1.570796326794897e-2\fP for grads: sin(25) = 0.382683... .RE .IP If you use this option, \fBries\fP will call the functions \FCsin\FT, \FCcos\FT and \FCtan\FT in its output, and the scale will be displayed after the function definitions at the end. .SH SPECIAL COMMANDS \fBries\fP provides some functions that supplement its main purpose. Commands and their parameters must be separate: `\FCries 1.23 --find-expression xxS+\FT', not `\FCries 1.23 --find-expressionxxS+\FT'. Because the parameters are given separately, your target value might be interpreted as a parameter if you give it right after a special command. To avoid this, put your target value first or put it after a simple option. .IP \fB--eval-expression\fP\ \fIforth-expr\fR\ [\fIforth-expr\fR\ ...] Evaluate one or more expressions, showing intermediate values, derivatives, and the complexity score of the full expression. The expression(s) should be given in the FORTH-like postfix syntax that is displayed when you use the -F0 option. The symbols are as listed above under the \fB-N\fR option. For example, \FCxxq-\FT is the syntax for \fIx\fR-sqrt(\fIx\fR). Syntax errors and computation errors such as overflow are reported; however successful execution by \fB--eval-expression\fP does not guarantee that the expression will be found in an actial \fBries\fP search. For example, an expression containing \fIx\fR only appears as the left-hand-side of an equation if the \fIx\fR is the first symbol in the postfix form: \fBries\fP will use \FCx2+\FT (\fIx\fR+2) but will not use \FC2x+\FT (2+\fIx\fR). .IP \fB--find-expression\fP\ \fIforth-expr\fR\ [\fIforth-expr\fR\ ...] Perform the normal equation-finding search algorithm, and report specific expressions when they are found, along with their value, derivative, and complexity. The expression(s) should be given in the FORTH-like postfix syntax that is displayed when you use the -F0 option. The symbols are as listed above under the \fB-N\fP option. For example, \FCxxq-\FT is the syntax for \fIx\fR-sqrt(\fIx\fR). .SH ALGORITHM \fBries\fP begins its search with small, simple equations and proceeds to longer, more complex ones. To determine the order to search, \fBries\fP uses many \fIcomplexity rules\fP, including the following: .IP 1. If you add a symbol to an equation, the result is more complex: \fIx\fR + 1 = 3 is more complex than \fIx\fR = 3 \fIx\fR + 1 = ln(3) is more complex than \fIx\fR + 1 = 3 \fIx\fR - 7 = 4^2 is more complex than \fIx\fR - 7 = 4 .IP 2. If two equations are the same except for one number, the equation with the higher number is more complex: \fIx\fR + 1 = 5 is more complex than \fIx\fR + 1 = 3 \fIx\fR^3 + 1 = 3 is more complex than \fIx\fR^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: \fIx\fR ^ 5 = 3 is more complex than \fIx\fR + 5 = 3 .P As \fBries\fP searches it finds solutions -- these are equations for which \fIx\fR is close to being an exact answer. Each time it finds a solution it prints it out. Then \fBries\fP raises its standard for the next answer: The next answer \fBries\fP 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: \fBries\fP 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, \fBries\fP 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 \fBries\fP 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 \fBries\fP is able to check billions of equations in such a short time. 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, \fBries\fP calculates derivatives of LHS's as well as their values. There are dozens of optimization rules \fBries\fP 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, \fBries\fP 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 \FCries 1.4142135\FT, which gives the answer "\fIx\fR^2 = 2". If you disable the 's' (squared) and '^' (power) symbols with \FCries 1.4142135 -Ns^\FT, rules \fBc*\fP and \fBb^\fP go away, and the answer becomes ``\fIx\fR = sqrt(2)''. If you also disable 'q' (square root) the answer becomes ``\fIx x\fR = 2''. Disable '*' and you get ``log_2(\fIx\fR) = 1/2'' (the logarithm to base 2 of \fIx\fR is 1/2). Disable 'L' and it becomes ``\fIx\fR = 2,/2'' (square root of 2, this time using the generalized root function). Disable 'v' and you get ``\fIx\fR/(1/\fIx\fR) = 2''. Disabling '/', we get a trignometric identity involving \fIpi\fR/4; disabling the trig functions as well, the command becomes \FCries 1.4142135 '-Ns^q*Lv/SCT'\FT and we finally get an answer that most people probably would not guess: \fIx\fR-1/(\fIx\fR+1) = 1 (note that the '/' in this answer is actually part of '1/', which is the reciprocal operator 'r'). Throughout this progression the complexity score of the equation increases as the solution becomes more and more obscure, and simpler but poorly matching ``solutions'' like 1/cos(\fIx\fR) = 6 begin to appear. .SH UNEXPECTED BEHAVIOR Sometimes a more complex equation will be given before the (simpler) equation that you expect. For example, tan(4) = sin(4)/cos(4) is 1.1578212823..., so you might expect the command \FCries 1.1578212823 --trig-argument-scale 1 -NT\FT to report something close to cos(4) \fIx\fR = sin(4). Instead, \fBries\fP gives 1/(\fIx\fR^2+1) = cos(4)^2 (equivalent by trigonometric identity) because it considers this equation to be ``more balanced'' (complexity score 45+38) than the other (which has a score of 48+29). Please read the preceding section ``ALGORITHM'' for more details. 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, \FCries 2.50618\FT yields the solution \fIx\fR^2 = 2 \fIpi\fR but \FCries 2.50618 -N+-/\FT does not give this solution in any form. This seems counterintuitive: there was no +, -, or / in the `\fIx\fR^2 = 2 \fIpi\fR' solution, so why did \fBries\fP decide not to report it? In fact, the solution is still generated internally, but because you have told it to exclude some common operators, \fBries\fP has to try other, more exotic expressions sooner than it otherwise would. As it happens, one of these solutions is `cos(cos(\fIx\fR)) = ln(2)' which matches the target value 2.50618 a lot more closely than \fIx\fR^2 = 2 \fIpi\fR. The mysterious behavior results from the fact that \fBries\fP 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. The complexity of \fIx\fR^2 is only 28, while the complexity of cos(cos(\fIx\fR)) is 41. In addition, the right-hand-side ln(2) is considered a little less complex than 2 \fIpi\fR. In the case of two equivalent solutions (like the 1.157 and 2.50618 examples earlier in this section), both equations come equally close to the supplied value, but only one can be found first. Once the first one is reported, the other is not, because \fBries\fP only reports solutions that are at least a 0.1% closer match than the previously-reported solution. 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. This is an important issue for those using \fBries\fP to solve special problems, like the ``four fours problem'' exemplified by the command \FCries '-S4+-*/' -Ox 17\FT. The current implementation represents the author's attempt at a reasonable 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. This could be improved in the future with percentile demographics and a sort performed one time only, after the tree reaches a healthy (but not excessive) size. 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. For example, \FCries '-S4+-*/' -Ox 17\FT gives ``x-4*4 = 4/4'' and ``(x+4)/(4/4+4+4) = 4/(4-4/4)+4/4'', only recognizing the first as an exact match (the more complex one involves divisions by 3 and by 9, which require rounding). Related to this, \fBries\fR sometimes gives an overly-complex answer, again because of roundoff error. For example, \fBries\fR gets slightly different values for ``2/3'' and ``1-1/3'', and stores both of these in its database of RHS values. When reporting a solution in which both sides of the equation equal 2/3, it might give ``1-1/3'' for the right-hand side if it is closer to the (rounded) value of the left-hand side. In deeper searches \fBries\fR might occasionally report ``solutions'' that are actually tautologies empty in meaning. A typical example is ``\fIx\fR^(4/ln(sqrt(\fIx\fR))) = sqrt(e)^(4^2)'' (which is true for any value of \fIx\fR), but \fBries\fP handles that case and most others like it. If you suspect the solutions it gives, use the \fB-Ds\fP option to show all calculations behind each proposed solution. The \fB--significance-loss-margin\fP and \fB--min-match-distance\fP options may also help avoid meaningless results. .SH ACRONYM \fBries\fP (pronounced ``reese'' or ``reeze'') is an acronym for ``RILYBOT Inverse Equation Solver''. The expansion of \fIRILYBOT\fR includes two more acronyms whose combined length is greater than 11. The full expansion of \fBries\fP grows without limit and is well-defined but not primitive-recursive. Contact the author for more information. .SH AUTHOR Robert P. Munafo (contact information on mrob.com)