Implemented crisscross algorithm for solving LP problems.
[sympycore.git] / doc / html / evaluation_rules.html
blobb2501c828619df613de98a21c3498f6388a9b2a6
1 <?xml version="1.0" encoding="utf-8" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" />
7 <title>Automatic evaluation rules of symbolic expressions</title>
8 <meta name="authors" content="Pearu Peterson &lt;pearu.peterson AT gmail DOT com&gt; Fredrik Johansson" />
9 <style type="text/css">
12 :Author: Pearu Peterson
13 :Contact: pearu.peterson AT gmail DOT com
14 :Copyright: This stylesheet has been placed in the public domain.
16 Stylesheet for use with Docutils.
19 @import url(html4css1.css);
21 /* Your customizations go here. For example: */
23 body {
24 margin:0px;
25 padding:25px;
26 background-color: #ccc;
27 font-size: 13px; font-family: arial, sans-serif;
28 line-height:1.5em;
31 div.document {
32 max-width: 700px;
33 color: #000;
34 background-color: #fff;
35 padding:25px;
36 border:5px solid #ddd;
39 div.sidebar {
40 margin-left: 1em ;
41 border: medium outset ;
42 padding: 1em ;
43 background-color: #ffffee ;
44 width: 40% ;
45 float: right ;
46 clear: right }
48 div.sidebar p.rubric {
49 font-family: sans-serif ;
50 font-size: medium }
52 p.sidebar-title {
53 font-family: sans-serif ;
54 font-weight: bold ;
55 font-size: larger }
57 p.sidebar-subtitle {
58 font-family: sans-serif ;
59 font-weight: bold }
61 pre, tt {
62 font-family: consolas, lucida console, courier new, monospace;
63 color: #000080 ;
66 pre.literal-block, pre.doctest-block {
67 line-height:1.3em;
68 border-top:1px solid #ccc;
69 border-bottom:1px solid #ccc;
70 background-color:#f0f0f0;
71 color: #000080 ;
74 div.admonition, div.attention, div.caution, div.danger, div.error,
75 div.hint, div.important, div.note, div.tip, div.warning {
76 margin: 2em ;
77 border: medium outset ;
78 padding: 0.5em;
79 background-color: #fffacd;
82 div.admonition p.admonition-title, div.hint p.admonition-title,
83 div.important p.admonition-title, div.note p.admonition-title,
84 div.tip p.admonition-title {
85 font-weight: bold ;
86 font-family: sans-serif }
88 div.attention p.admonition-title, div.caution p.admonition-title,
89 div.danger p.admonition-title, div.error p.admonition-title,
90 div.warning p.admonition-title {
91 color: red ;
92 font-weight: bold ;
93 font-family: sans-serif }
95 </style>
96 </head>
97 <body>
98 <div class="document" id="automatic-evaluation-rules-of-symbolic-expressions">
99 <h1 class="title">Automatic evaluation rules of symbolic expressions</h1>
100 <table class="docinfo" frame="void" rules="none">
101 <col class="docinfo-name" />
102 <col class="docinfo-content" />
103 <tbody valign="top">
104 <tr><th class="docinfo-name">Authors:</th>
105 <td>Pearu Peterson &lt;pearu.peterson AT gmail DOT com&gt;
106 <br />Fredrik Johansson</td></tr>
107 <tr class="field"><th class="docinfo-name">Created:</th><td class="field-body">February 2008</td>
108 </tr>
109 </tbody>
110 </table>
111 <!-- -*- rest -*- -->
112 <div class="sidebar">
113 <p class="first sidebar-title">Table of contents</p>
114 <div class="contents local last topic">
115 <ul class="auto-toc simple">
116 <li><a class="reference" href="#introduction" id="id4" name="id4">1&nbsp;&nbsp;&nbsp;Introduction</a></li>
117 <li><a class="reference" href="#commutative-ring-operations" id="id5" name="id5">2&nbsp;&nbsp;&nbsp;Commutative ring operations</a><ul class="auto-toc">
118 <li><a class="reference" href="#operands" id="id6" name="id6">2.1&nbsp;&nbsp;&nbsp;Operands</a></li>
119 <li><a class="reference" href="#operations" id="id7" name="id7">2.2&nbsp;&nbsp;&nbsp;Operations</a></li>
120 </ul>
121 </li>
122 <li><a class="reference" href="#extended-numbers" id="id8" name="id8">3&nbsp;&nbsp;&nbsp;Extended numbers</a></li>
123 <li><a class="reference" href="#function-evaluations" id="id9" name="id9">4&nbsp;&nbsp;&nbsp;Function evaluations</a><ul class="auto-toc">
124 <li><a class="reference" href="#general-rules" id="id10" name="id10">4.1&nbsp;&nbsp;&nbsp;General rules</a></li>
125 <li><a class="reference" href="#exponentials" id="id11" name="id11">4.2&nbsp;&nbsp;&nbsp;Exponentials</a></li>
126 <li><a class="reference" href="#logarithms" id="id12" name="id12">4.3&nbsp;&nbsp;&nbsp;Logarithms</a></li>
127 <li><a class="reference" href="#trigonometric-functions" id="id13" name="id13">4.4&nbsp;&nbsp;&nbsp;Trigonometric functions</a></li>
128 </ul>
129 </li>
130 <li><a class="reference" href="#references" id="id14" name="id14">5&nbsp;&nbsp;&nbsp;References</a></li>
131 </ul>
132 </div>
133 </div>
134 <div class="section">
135 <h1><a class="toc-backref" href="#id4" id="introduction" name="introduction">1&nbsp;&nbsp;&nbsp;Introduction</a></h1>
136 <p>This document gathers rules that are applied automatically when
137 performing operations with symbolic expressions.</p>
138 </div>
139 <div class="section">
140 <h1><a class="toc-backref" href="#id5" id="commutative-ring-operations" name="commutative-ring-operations">2&nbsp;&nbsp;&nbsp;Commutative ring operations</a></h1>
141 <div class="section">
142 <h2><a class="toc-backref" href="#id6" id="operands" name="operands">2.1&nbsp;&nbsp;&nbsp;Operands</a></h2>
143 <p>In commutative ring operations, four types of operands are possible:</p>
144 <blockquote>
145 <ul class="simple">
146 <li>numbers, see examples below;</li>
147 <li>sums, e.g. <tt class="docutils literal"><span class="pre">3+x</span></tt>, <tt class="docutils literal"><span class="pre">-1/2+x+y</span></tt>;</li>
148 <li>products, e.g. <tt class="docutils literal"><span class="pre">3*x</span></tt>, <tt class="docutils literal"><span class="pre">x**2</span> <span class="pre">*</span> <span class="pre">z</span></tt>;</li>
149 <li>symbols, e.g. <tt class="docutils literal"><span class="pre">x</span></tt>, <tt class="docutils literal"><span class="pre">sin(x+z**2)</span></tt>.</li>
150 </ul>
151 </blockquote>
152 <p>Depending on a particular ring, numbers can be</p>
153 <blockquote>
154 <ul class="simple">
155 <li>integers, e.g. <tt class="docutils literal"><span class="pre">-4</span></tt>, <tt class="docutils literal"><span class="pre">0</span></tt>, <tt class="docutils literal"><span class="pre">1</span></tt>;</li>
156 <li>fractions, e.g. <tt class="docutils literal"><span class="pre">1/2</span></tt>, <tt class="docutils literal"><span class="pre">-3/4</span></tt>;</li>
157 <li>complex numbers, e.g. <tt class="docutils literal"><span class="pre">2+3/4*I</span></tt>, <tt class="docutils literal"><span class="pre">-4*I</span></tt>;</li>
158 <li>floating point numbers, e.g. <tt class="docutils literal"><span class="pre">1.2</span></tt>, <tt class="docutils literal"><span class="pre">-3.14</span></tt>;</li>
159 <li>extended numbers, e.g. <tt class="docutils literal"><span class="pre">+oo</span></tt>, <tt class="docutils literal"><span class="pre">-oo</span></tt>, <tt class="docutils literal"><span class="pre">zoo</span></tt>, <tt class="docutils literal"><span class="pre">undefined</span></tt>;</li>
160 </ul>
161 </blockquote>
162 <p>where real and imaginary parts of complex numbers can be integers,
163 fractions, or floating point numbers.</p>
164 <div class="admonition-metarule-1 admonition">
165 <p class="first admonition-title">Metarule 1</p>
166 <p class="last">Any rule containing symbols, should remain valid when the symbols
167 are replaced by numbers.</p>
168 </div>
169 <div class="section">
170 <h3><a id="notes-on-extended-numbers" name="notes-on-extended-numbers">2.1.1&nbsp;&nbsp;&nbsp;Notes on extended numbers</a></h3>
171 <p>Expressions containing extended numbers require special rules as
172 distributivity laws are not valid for extended numbers. An extended
173 number is defined as a quantity that has infinite or undefined
174 magnitude and has specified or undefined direction in the complex
175 plane. See below for detailed information.</p>
176 </div>
177 <div class="section">
178 <h3><a id="notes-on-floating-point-numbers" name="notes-on-floating-point-numbers">2.1.2&nbsp;&nbsp;&nbsp;Notes on floating point numbers</a></h3>
179 <p>Note that the distributivity law is not strictly valid also for
180 operations with floating point numbers but in the following we assume
181 it to hold for simplicity.</p>
182 </div>
183 </div>
184 <div class="section">
185 <h2><a class="toc-backref" href="#id7" id="operations" name="operations">2.2&nbsp;&nbsp;&nbsp;Operations</a></h2>
186 <p>In the following we consider three kinds of operations with operands:</p>
187 <blockquote>
188 <ul class="simple">
189 <li>addition: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">y</span></tt></li>
190 <li>multiplication: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">*</span> <span class="pre">y</span></tt></li>
191 <li>exponentiation: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">**</span> <span class="pre">y</span></tt></li>
192 </ul>
193 </blockquote>
194 <p>These operations can be used to define other operations</p>
195 <blockquote>
196 <ul class="simple">
197 <li>negation: <tt class="docutils literal"><span class="pre">-x</span> <span class="pre">==</span> <span class="pre">x</span> <span class="pre">*</span> <span class="pre">(-1)</span></tt></li>
198 <li>subtraction: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">-</span> <span class="pre">y</span> <span class="pre">==</span> <span class="pre">x</span> <span class="pre">+</span> <span class="pre">(-y)</span></tt></li>
199 <li>division: <tt class="docutils literal"><span class="pre">x</span> <span class="pre">/</span> <span class="pre">y</span> <span class="pre">==</span> <span class="pre">x</span> <span class="pre">*</span> <span class="pre">y**(-1)</span></tt></li>
200 </ul>
201 </blockquote>
202 <p>and hence there is no need to write rules for these operations.</p>
203 <div class="admonition-rule-1-associativity admonition">
204 <p class="first admonition-title">Rule 1: associativity</p>
205 <p>In <a class="reference" href="http://en.wikipedia.org/wiki/Associative">associative</a> operations all parenthesis are eliminated
206 (expressions are <em>flattened</em> and suboperands of operands are stored
207 in the same set-like data structure).</p>
208 <p>For example:</p>
209 <pre class="last literal-block">
210 x + (y + z) -&gt; x + y + z
211 (x + y) + z -&gt; x + y + z
212 x * (y * z) -&gt; x * y * z
213 (x * y) * z -&gt; x * y * z
214 </pre>
215 </div>
216 <div class="admonition-rule-2-commutativity admonition">
217 <p class="first admonition-title">Rule 2: commutativity</p>
218 <p>In <a class="reference" href="http://en.wikipedia.org/wiki/Commutativity">commutative</a> operations the order of operands is insignificant
219 (operands are stored in an unordered set-like data structure).</p>
220 <p>For example:</p>
221 <pre class="last literal-block">
222 x + y == y + x
223 x * y == y * x
224 </pre>
225 </div>
226 <div class="admonition-rule-3-collecting-equal-expressions admonition">
227 <p class="first admonition-title">Rule 3: collecting equal expressions</p>
228 <p>In commutative operations <em>equal</em> expressions are collected. The
229 equality is defined as an <em>equality between data structures</em> which
230 may not be equivalent to the notion of <em>mathematical equality</em>.</p>
231 <p>For example:</p>
232 <pre class="last literal-block">
233 x + x -&gt; 2*x
234 x * x -&gt; x**2
235 </pre>
236 </div>
237 <div class="admonition-rule-4-operations-with-zero admonition">
238 <p class="first admonition-title">Rule 4: operations with zero.</p>
239 <p>Multiplication by zero is zero only when a non-zero operand does not
240 contain extended numbers explicitly.</p>
241 <p>For example:</p>
242 <pre class="literal-block">
243 0 * x -&gt; 0
244 </pre>
245 <p>Division a non-zero number by zero is infinity with undefined direction:</p>
246 <pre class="literal-block">
247 1/0 -&gt; zoo
248 0/0 -&gt; undefined
249 </pre>
250 <p>Exponentiation by zero results one.</p>
251 <p>For example:</p>
252 <pre class="last literal-block">
253 x**0 -&gt; 1
254 oo**0 -&gt; 1
255 </pre>
256 </div>
257 <div class="admonition-rule-5-distributivity admonition">
258 <p class="first admonition-title">Rule 5: distributivity</p>
259 <p><a class="reference" href="http://en.wikipedia.org/wiki/Distributivity">Distributivity</a> law of multiplication over addition is applied
260 only when a sum is multiplied by a number that is not an extended
261 number.</p>
262 <p>For example:</p>
263 <pre class="last literal-block">
264 3*(x + y) -&gt; 3*x + 3*y
265 (3 + x)/2 -&gt; 3/2 + 1/2*x
266 oo*(2 + x) -&gt; oo*(2 + x)
267 </pre>
268 </div>
269 <p>All number sets (integers, rationals, complex numbers) are closed with
270 respect to addition and multiplication operations. Hence:</p>
271 <div class="admonition-rule-6-additing-and-multiplying-numbers admonition">
272 <p class="first admonition-title">Rule 6: additing and multiplying numbers</p>
273 <p class="last">Addition and multiplication operations with numbers always result in
274 a number.</p>
275 </div>
276 <p>Exponentiation operation with numbers are evaluated to a number when
277 possible. In case of algebraic numbers, suppresed evaluation may be
278 carried out. For example:</p>
279 <pre class="literal-block">
280 2**3 -&gt; 8
281 2**(-3) -&gt; 1/8
282 4**(1/2) -&gt; 2
283 8**(1/2) -&gt; 2*2**(1/2)
284 </pre>
285 <div class="section">
286 <h3><a id="integer-powers" name="integer-powers">2.2.1&nbsp;&nbsp;&nbsp;Integer powers</a></h3>
287 <div class="admonition-rule-7-m-n-for-a-number-m-and-integer-n admonition">
288 <p class="first admonition-title">Rule 7: <tt class="docutils literal"><span class="pre">m</span> <span class="pre">**</span> <span class="pre">n</span></tt> for a number <tt class="docutils literal"><span class="pre">m</span></tt> and integer <tt class="docutils literal"><span class="pre">n</span></tt>.</p>
289 <p>If <tt class="docutils literal"><span class="pre">n</span></tt> is <tt class="docutils literal"><span class="pre">0</span></tt> then the result is <tt class="docutils literal"><span class="pre">1</span></tt>.</p>
290 <p>If <tt class="docutils literal"><span class="pre">n</span></tt> is positive then the result is a number. Different
291 algorithms are possible for cases where <tt class="docutils literal"><span class="pre">m</span></tt> is integer, or
292 fraction, or floating point number, or complex number, or purely
293 imaginary complex number.</p>
294 <p class="last">If <tt class="docutils literal"><span class="pre">n</span></tt> is negative then the result is <tt class="docutils literal"><span class="pre">1/(m**(-n))</span></tt> (or
295 <tt class="docutils literal"><span class="pre">(1/m)**(-n)</span></tt>).</p>
296 </div>
297 <div class="admonition-rule-8-w-z-n-for-symbols-w-z-and-integer-n admonition">
298 <p class="first admonition-title">Rule 8: <tt class="docutils literal"><span class="pre">(w*z)</span> <span class="pre">**</span> <span class="pre">n</span></tt> for symbols <tt class="docutils literal"><span class="pre">w</span></tt>, <tt class="docutils literal"><span class="pre">z</span></tt>, and integer <tt class="docutils literal"><span class="pre">n</span></tt>.</p>
299 <p class="last">The result is <tt class="docutils literal"><span class="pre">w**n</span> <span class="pre">*</span> <span class="pre">z**n</span></tt>.</p>
300 </div>
301 <div class="admonition-rule-9-w-z-n-for-symbols-w-z-and-integer-n admonition">
302 <p class="first admonition-title">Rule 9: <tt class="docutils literal"><span class="pre">(w**z)</span> <span class="pre">**</span> <span class="pre">n</span></tt> for symbols <tt class="docutils literal"><span class="pre">w</span></tt>, <tt class="docutils literal"><span class="pre">z</span></tt>, and integer <tt class="docutils literal"><span class="pre">n</span></tt>.</p>
303 <p class="last">The result is <tt class="docutils literal"><span class="pre">w**(n*z)</span></tt>.</p>
304 </div>
305 </div>
306 <div class="section">
307 <h3><a id="fraction-powers" name="fraction-powers">2.2.2&nbsp;&nbsp;&nbsp;Fraction powers</a></h3>
308 <div class="admonition-rule-11-m-1-q-for-integers-m-q-0 admonition">
309 <p class="first admonition-title">Rule 11: <tt class="docutils literal"><span class="pre">m</span> <span class="pre">**</span> <span class="pre">(1/q)</span></tt> for integers <tt class="docutils literal"><span class="pre">m</span></tt>, <tt class="docutils literal"><span class="pre">q&gt;0</span></tt>.</p>
310 <p>If <tt class="docutils literal"><span class="pre">m</span></tt> is positive then the result is a product of algebraic numbers.</p>
311 <p class="last">If <tt class="docutils literal"><span class="pre">m</span></tt> is negative then the result is <tt class="docutils literal"><span class="pre">(-1)**(1/q)</span> <span class="pre">*</span> <span class="pre">(-m)**(1/q)</span></tt></p>
312 </div>
313 <div class="admonition-rule-12-m-p-q-for-integers-m-p-1-q-0 admonition">
314 <p class="first admonition-title">Rule 12: <tt class="docutils literal"><span class="pre">m</span> <span class="pre">**</span> <span class="pre">(p/q)</span></tt> for integers <tt class="docutils literal"><span class="pre">m</span></tt>, <tt class="docutils literal"><span class="pre">p!=1</span></tt>, <tt class="docutils literal"><span class="pre">q&gt;0</span></tt>.</p>
315 <p class="last">The result is evaluated result of <tt class="docutils literal"><span class="pre">(m</span> <span class="pre">**</span> <span class="pre">(1/q))**p</span></tt>.</p>
316 </div>
317 </div>
318 </div>
319 </div>
320 <div class="section">
321 <h1><a class="toc-backref" href="#id8" id="extended-numbers" name="extended-numbers">3&nbsp;&nbsp;&nbsp;Extended numbers</a></h1>
322 <p>See also <a class="reference" href="http://code.google.com/p/sympycore/wiki/ExtendedNumbers">http://code.google.com/p/sympycore/wiki/ExtendedNumbers</a>.</p>
323 <p>The reason why distributivity law is not used in case of extended
324 numbers, such as infinities, is that it might lead to undefined
325 results that otherwise would be defined. For example, if <tt class="docutils literal"><span class="pre">x=-1</span></tt>
326 then:</p>
327 <pre class="literal-block">
328 oo*(2 + x) -&gt; oo*1 -&gt; oo
329 </pre>
330 <p>but</p>
331 <pre class="literal-block">
332 oo*(2 + x) -&gt; oo + oo*x -&gt; oo + oo*(-1) -&gt; oo - oo -&gt; undefined
333 </pre>
334 <p>An extended number is defined as a quantity that has infinite or
335 undefined magnitude and has specified or undefined direction in the
336 complex plane.</p>
337 <p>Infinity with direction <tt class="docutils literal"><span class="pre">theta</span> <span class="pre">=</span> <span class="pre">Arg(direction)</span></tt> can be defined as
338 follows:</p>
339 <div class="admonition-definition-infinity-with-direction admonition">
340 <p class="first admonition-title">Definition: infinity with direction</p>
341 <pre class="literal-block">
342 oo(direction) = lim r * direction
343 r -&gt; oo
344 </pre>
345 <p class="last">where <tt class="docutils literal"><span class="pre">direction</span></tt> is a complex number.</p>
346 </div>
347 <div class="admonition-definition-quantity-with-undefined-magnitude admonition">
348 <p class="first admonition-title">Definition: quantity with undefined magnitude.</p>
349 <p class="last">A quantity with undefined magnitude and undefined direction is defined as <tt class="docutils literal"><span class="pre">oo(0)</span></tt>.</p>
350 </div>
351 <div class="admonition-definition-projective-infinity admonition">
352 <p class="first admonition-title">Definition: projective infinity.</p>
353 <p class="last">Infinity with undefined direction is defined as <tt class="docutils literal"><span class="pre">oo(undefined)</span></tt>.</p>
354 </div>
355 <p>The following notation is used:</p>
356 <pre class="literal-block">
357 +oo = oo(1)
358 -oo = oo(-1)
359 zoo = oo(oo(0))
360 </pre>
361 <p>An operation <tt class="docutils literal"><span class="pre">&lt;op&gt;</span></tt> with an infinity and a finite number is defined
362 as follows:</p>
363 <div class="admonition-definition-operations-with-finite-numbers admonition">
364 <p class="first admonition-title">Definition: operations with finite numbers</p>
365 <pre class="last literal-block">
366 oo(direction) &lt;op&gt; number = lim r * direction &lt;op&gt; number
367 r -&gt; oo
368 </pre>
369 </div>
370 <p>An operation <tt class="docutils literal"><span class="pre">&lt;op&gt;</span></tt> with two infinities with different directions is
371 defined as follows:</p>
372 <div class="admonition-definition-operations-with-infinite-numbers admonition">
373 <p class="first admonition-title">Definition: operations with infinite numbers</p>
374 <pre class="literal-block">
375 oo(dir1) &lt;op&gt; oo(dir2) = lim r1 * dir1 &lt;op&gt; r2 * dir2
376 r1, r2 -&gt; oo
377 </pre>
378 <p>where the limit processes <tt class="docutils literal"><span class="pre">r1-&gt;oo</span></tt> and <tt class="docutils literal"><span class="pre">r2-&gt;oo</span></tt> are independent.</p>
379 <p class="last">If <tt class="docutils literal"><span class="pre">lim(r1-&gt;oo,</span> <span class="pre">r2-&gt;oo)</span></tt> is different from <tt class="docutils literal"><span class="pre">lim(r2-&gt;oo,</span> <span class="pre">r1-&gt;oo)</span></tt>
380 then the result is defined as <tt class="docutils literal"><span class="pre">undefined</span></tt>.</p>
381 </div>
382 <div class="admonition-addition-with-infinities admonition">
383 <p class="first admonition-title">Addition with infinities</p>
384 <pre class="last literal-block">
385 oo(x) + oo(y) -&gt; oo(EqualArg(x,y)*x)
386 oo(x) + z -&gt; oo((1+IsUnbounded(z)*(EqualArg(x,y)-1))*x)
387 </pre>
388 </div>
389 <div class="admonition-multiplication-with-infinities admonition">
390 <p class="first admonition-title">Multiplication with infinities</p>
391 <pre class="last literal-block">
392 oo(x) * oo(y) -&gt; oo(x*y)
393 oo(x) * z -&gt; oo(x*z)
394 </pre>
395 </div>
396 <div class="admonition-dividing-by-infinity admonition">
397 <p class="first admonition-title">Dividing by infinity</p>
398 <pre class="last literal-block">
399 1/oo(x) -&gt; 0 for nonzero x
400 </pre>
401 </div>
402 <div class="admonition-exponentiation-with-infinities admonition">
403 <p class="first admonition-title">Exponentiation with infinities</p>
404 <pre class="last literal-block">
405 oo(x) ** 0 -&gt; 1
406 1 ** oo(x) -&gt; 1
407 oo(x) ** oo(y) -&gt; 0 if y &lt; 0
408 oo(x) ** oo(y) -&gt; oo(IsPositive(x)) if y &gt; 0
409 oo(x) ** z -&gt; 0 if z &lt; 0
410 oo(x) ** z -&gt; oo(x**z) if z&gt;0
411 z ** oo(x) -&gt; (z**x) ** oo(1)
412 </pre>
413 </div>
414 <p>TODO: define more rules for defined results.</p>
415 </div>
416 <div class="section">
417 <h1><a class="toc-backref" href="#id9" id="function-evaluations" name="function-evaluations">4&nbsp;&nbsp;&nbsp;Function evaluations</a></h1>
418 <div class="section">
419 <h2><a class="toc-backref" href="#id10" id="general-rules" name="general-rules">4.1&nbsp;&nbsp;&nbsp;General rules</a></h2>
420 <div class="admonition-function-evaluation admonition">
421 <p class="first admonition-title">Function evaluation.</p>
422 <p class="last">A function should automatically evaluate back to a number when given
423 an input for which it assumes a rational or complex rational
424 value.</p>
425 </div>
426 <p>An exception to this rule can be made if the computation required to
427 produce the number is extremely time-consuming.</p>
428 <div class="admonition-floating-point-function-evaluation admonition">
429 <p class="first admonition-title">Floating-point function evaluation.</p>
430 <p class="last">Given a floating-point number <tt class="docutils literal"><span class="pre">x</span></tt>, <tt class="docutils literal"><span class="pre">f(x)</span></tt> should return a
431 floating-point approximation.</p>
432 </div>
433 </div>
434 <div class="section">
435 <h2><a class="toc-backref" href="#id11" id="exponentials" name="exponentials">4.2&nbsp;&nbsp;&nbsp;Exponentials</a></h2>
436 <p><tt class="docutils literal"><span class="pre">exp(x)</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">E**x</span></tt>, and implemented as a simple
437 wrapper for this operation.</p>
438 <p>Likewise, <tt class="docutils literal"><span class="pre">sqrt(x)</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">x**(1/2)</span></tt>.</p>
439 </div>
440 <div class="section">
441 <h2><a class="toc-backref" href="#id12" id="logarithms" name="logarithms">4.3&nbsp;&nbsp;&nbsp;Logarithms</a></h2>
442 <p><tt class="docutils literal"><span class="pre">log(x,b)</span></tt> is defined as <tt class="docutils literal"><span class="pre">log(x)/log(b)</span></tt>. <tt class="docutils literal"><span class="pre">log(x)</span></tt> denotes the
443 natural logarithm with base <tt class="docutils literal"><span class="pre">b</span></tt> = <tt class="docutils literal"><span class="pre">E</span></tt>. In general <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">b</span></tt>
444 are assumed to be complex numbers (meaning that some transformations
445 familiar for positive real numbers cannot be performed automatically
446 with symbolic arguments). If no simplifications can be found,
447 <tt class="docutils literal"><span class="pre">log(x,b)</span></tt> is expanded automatically to <tt class="docutils literal"><span class="pre">log(x)/log(b)</span></tt>.</p>
448 <div class="admonition-evaluating-log-integer-input admonition">
449 <p class="first admonition-title">Evaluating <tt class="docutils literal"><span class="pre">log</span></tt>: integer input.</p>
450 <p class="last">If <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">b</span></tt> are both positive integers, <tt class="docutils literal"><span class="pre">log(x,</span> <span class="pre">b)</span></tt>
451 evaluates to an integer when exact (note that <tt class="docutils literal"><span class="pre">log(x)/log(b)</span></tt> does
452 not).</p>
453 </div>
454 <div class="admonition-evaluating-log-complex-input admonition">
455 <p class="first admonition-title">Evaluating <tt class="docutils literal"><span class="pre">log</span></tt>: complex input.</p>
456 <p class="last">For complex arguments, <tt class="docutils literal"><span class="pre">log(x)</span></tt> is taken to be the principal
457 branch of the natural logarithm, with the branch cut placed
458 infinitesimally below the negative real half axis.</p>
459 </div>
460 <p><tt class="docutils literal"><span class="pre">log(x)</span></tt> evaluates to an explicit value at <tt class="docutils literal"><span class="pre">x</span></tt> = <tt class="docutils literal"><span class="pre">1</span></tt>, <tt class="docutils literal"><span class="pre">E</span></tt>,
461 <tt class="docutils literal"><span class="pre">I</span></tt> and <tt class="docutils literal"><span class="pre">-I</span></tt>. <tt class="docutils literal"><span class="pre">log(0)</span></tt> evaluates to <tt class="docutils literal"><span class="pre">-oo</span></tt> and <tt class="docutils literal"><span class="pre">log(oo)</span></tt>
462 evaluates to <tt class="docutils literal"><span class="pre">oo</span></tt>.</p>
463 <div class="admonition-evaluating-log-power-input admonition">
464 <p class="first admonition-title">Evaluating <tt class="docutils literal"><span class="pre">log</span></tt>: power input.</p>
465 <p class="last"><tt class="docutils literal"><span class="pre">log(b**x,</span> <span class="pre">b)</span></tt> evaluates to <tt class="docutils literal"><span class="pre">x</span></tt> if <tt class="docutils literal"><span class="pre">b</span></tt> is positive and <tt class="docutils literal"><span class="pre">x</span></tt>
466 is real (in particular, if <tt class="docutils literal"><span class="pre">b</span></tt> is <tt class="docutils literal"><span class="pre">E</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt> is rational).
467 By extension, <tt class="docutils literal"><span class="pre">log(b**x,</span> <span class="pre">b**y)</span></tt> evaluates to <tt class="docutils literal"><span class="pre">x/y</span></tt> if <tt class="docutils literal"><span class="pre">b</span></tt> is
468 positive and <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt> are both real.</p>
469 </div>
470 <p>TODO: log(-x), log(I*x), log(-I*x), ...</p>
471 </div>
472 <div class="section">
473 <h2><a class="toc-backref" href="#id13" id="trigonometric-functions" name="trigonometric-functions">4.4&nbsp;&nbsp;&nbsp;Trigonometric functions</a></h2>
474 <p>Trigonometric functions are automatically evaluated to algebraic
475 values if the argument is an integral multiple of <tt class="docutils literal"><span class="pre">pi/6</span></tt>. (Direct
476 evaluation is currently also performed at all multiples of <tt class="docutils literal"><span class="pre">pi/12</span></tt>;
477 this behavior could be adjusted.) The poles in <tt class="docutils literal"><span class="pre">tan</span></tt> and <tt class="docutils literal"><span class="pre">cot</span></tt>
478 evaluate to <tt class="docutils literal"><span class="pre">zoo</span></tt>. Trigonometric functions are kept unevaluated at
479 <tt class="docutils literal"><span class="pre">-oo</span></tt> and <tt class="docutils literal"><span class="pre">oo</span></tt> (this can be useful when computing limits).</p>
480 <p>If the argument to a trigonometric function contains an explicit
481 rational multiple of <tt class="docutils literal"><span class="pre">pi</span></tt> as a term, this term is replaced by
482 a multiple of pi in the interval <tt class="docutils literal"><span class="pre">[0,</span> <span class="pre">pi/2)</span></tt> using
483 trigonometric identities. This may involve replacing a sine
484 by a cosine, etc.</p>
485 <p>Explicit signs are moved out of the function, e.g.
486 <tt class="docutils literal"><span class="pre">sin(-x)</span> <span class="pre">-&gt;</span> <span class="pre">-sin(x)</span></tt>. If the argument is a sum of several terms,
487 a sign is moved out if and only if all terms have an explicit
488 minus sign.</p>
489 <p>Trigonometric functions of products containing an explicit
490 imaginary factor <tt class="docutils literal"><span class="pre">I</span></tt> evaluate to hyperbolic functions and vice versa.</p>
491 </div>
492 </div>
493 <div class="section">
494 <h1><a class="toc-backref" href="#id14" id="references" name="references">5&nbsp;&nbsp;&nbsp;References</a></h1>
495 <p><a class="reference" href="http://code.google.com/p/sympycore/wiki/ExtendedNumbers">http://code.google.com/p/sympycore/wiki/ExtendedNumbers</a></p>
496 </div>
497 </div>
498 </body>
499 </html>