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">
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 <pearu.peterson AT gmail DOT com> 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: */
26 background-color: #ccc;
27 font-size:
13px; font-family: arial, sans-serif;
34 background-color: #fff;
36 border:
5px solid #ddd;
41 border: medium outset ;
43 background-color: #ffffee ;
48 div.sidebar p.rubric {
49 font-family: sans-serif ;
53 font-family: sans-serif ;
58 font-family: sans-serif ;
62 font-family: consolas, lucida console, courier new, monospace;
66 pre.literal-block, pre.doctest-block {
68 border-top:
1px solid #ccc;
69 border-bottom:
1px solid #ccc;
70 background-color:#f0f0f0;
74 div.admonition, div.attention, div.caution, div.danger, div.error,
75 div.hint, div.important, div.note, div.tip, div.warning {
77 border: medium outset ;
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 {
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 {
93 font-family: sans-serif }
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" />
104 <tr><th class=
"docinfo-name">Authors:
</th>
105 <td>Pearu Peterson
<pearu.peterson AT gmail DOT com
>
106 <br />Fredrik Johansson
</td></tr>
107 <tr class=
"field"><th class=
"docinfo-name">Created:
</th><td class=
"field-body">February
2008</td>
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 Introduction
</a></li>
117 <li><a class=
"reference" href=
"#commutative-ring-operations" id=
"id5" name=
"id5">2 Commutative ring operations
</a><ul class=
"auto-toc">
118 <li><a class=
"reference" href=
"#operands" id=
"id6" name=
"id6">2.1 Operands
</a></li>
119 <li><a class=
"reference" href=
"#operations" id=
"id7" name=
"id7">2.2 Operations
</a></li>
122 <li><a class=
"reference" href=
"#extended-numbers" id=
"id8" name=
"id8">3 Extended numbers
</a></li>
123 <li><a class=
"reference" href=
"#function-evaluations" id=
"id9" name=
"id9">4 Function evaluations
</a><ul class=
"auto-toc">
124 <li><a class=
"reference" href=
"#general-rules" id=
"id10" name=
"id10">4.1 General rules
</a></li>
125 <li><a class=
"reference" href=
"#exponentials" id=
"id11" name=
"id11">4.2 Exponentials
</a></li>
126 <li><a class=
"reference" href=
"#logarithms" id=
"id12" name=
"id12">4.3 Logarithms
</a></li>
127 <li><a class=
"reference" href=
"#trigonometric-functions" id=
"id13" name=
"id13">4.4 Trigonometric functions
</a></li>
130 <li><a class=
"reference" href=
"#references" id=
"id14" name=
"id14">5 References
</a></li>
134 <div class=
"section">
135 <h1><a class=
"toc-backref" href=
"#id4" id=
"introduction" name=
"introduction">1 Introduction
</a></h1>
136 <p>This document gathers rules that are applied automatically when
137 performing operations with symbolic expressions.
</p>
139 <div class=
"section">
140 <h1><a class=
"toc-backref" href=
"#id5" id=
"commutative-ring-operations" name=
"commutative-ring-operations">2 Commutative ring operations
</a></h1>
141 <div class=
"section">
142 <h2><a class=
"toc-backref" href=
"#id6" id=
"operands" name=
"operands">2.1 Operands
</a></h2>
143 <p>In commutative ring operations, four types of operands are possible:
</p>
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>
152 <p>Depending on a particular ring, numbers can be
</p>
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>
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>
169 <div class=
"section">
170 <h3><a id=
"notes-on-extended-numbers" name=
"notes-on-extended-numbers">2.1.1 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>
177 <div class=
"section">
178 <h3><a id=
"notes-on-floating-point-numbers" name=
"notes-on-floating-point-numbers">2.1.2 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>
184 <div class=
"section">
185 <h2><a class=
"toc-backref" href=
"#id7" id=
"operations" name=
"operations">2.2 Operations
</a></h2>
186 <p>In the following we consider three kinds of operations with operands:
</p>
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>
194 <p>These operations can be used to define other operations
</p>
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>
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>
209 <pre class=
"last literal-block">
210 x + (y + z) -
> x + y + z
211 (x + y) + z -
> x + y + z
212 x * (y * z) -
> x * y * z
213 (x * y) * z -
> x * y * z
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>
221 <pre class=
"last literal-block">
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>
232 <pre class=
"last literal-block">
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>
242 <pre class=
"literal-block">
245 <p>Division a non-zero number by zero is infinity with undefined direction:
</p>
246 <pre class=
"literal-block">
250 <p>Exponentiation by zero results one.
</p>
252 <pre class=
"last literal-block">
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
263 <pre class=
"last literal-block">
264 3*(x + y) -
> 3*x +
3*y
265 (
3 + x)/
2 -
> 3/
2 +
1/
2*x
266 oo*(
2 + x) -
> oo*(
2 + x)
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
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">
283 8**(
1/
2) -
> 2*
2**(
1/
2)
285 <div class=
"section">
286 <h3><a id=
"integer-powers" name=
"integer-powers">2.2.1 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>
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>
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>
306 <div class=
"section">
307 <h3><a id=
"fraction-powers" name=
"fraction-powers">2.2.2 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
>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>
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
>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>
320 <div class=
"section">
321 <h1><a class=
"toc-backref" href=
"#id8" id=
"extended-numbers" name=
"extended-numbers">3 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>
327 <pre class=
"literal-block">
328 oo*(
2 + x) -
> oo*
1 -
> oo
331 <pre class=
"literal-block">
332 oo*(
2 + x) -
> oo + oo*x -
> oo + oo*(-
1) -
> oo - oo -
> undefined
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
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
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
345 <p class=
"last">where
<tt class=
"docutils literal"><span class=
"pre">direction
</span></tt> is a complex number.
</p>
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>
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>
355 <p>The following notation is used:
</p>
356 <pre class=
"literal-block">
361 <p>An operation
<tt class=
"docutils literal"><span class=
"pre"><op
></span></tt> with an infinity and a finite number is defined
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)
<op
> number = lim r * direction
<op
> number
370 <p>An operation
<tt class=
"docutils literal"><span class=
"pre"><op
></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)
<op
> oo(dir2) = lim r1 * dir1
<op
> r2 * dir2
378 <p>where the limit processes
<tt class=
"docutils literal"><span class=
"pre">r1-
>oo
</span></tt> and
<tt class=
"docutils literal"><span class=
"pre">r2-
>oo
</span></tt> are independent.
</p>
379 <p class=
"last">If
<tt class=
"docutils literal"><span class=
"pre">lim(r1-
>oo,
</span> <span class=
"pre">r2-
>oo)
</span></tt> is different from
<tt class=
"docutils literal"><span class=
"pre">lim(r2-
>oo,
</span> <span class=
"pre">r1-
>oo)
</span></tt>
380 then the result is defined as
<tt class=
"docutils literal"><span class=
"pre">undefined
</span></tt>.
</p>
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) -
> oo(EqualArg(x,y)*x)
386 oo(x) + z -
> oo((
1+IsUnbounded(z)*(EqualArg(x,y)-
1))*x)
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) -
> oo(x*y)
393 oo(x) * z -
> oo(x*z)
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) -
> 0 for nonzero x
402 <div class=
"admonition-exponentiation-with-infinities admonition">
403 <p class=
"first admonition-title">Exponentiation with infinities
</p>
404 <pre class=
"last literal-block">
407 oo(x) ** oo(y) -
> 0 if y
< 0
408 oo(x) ** oo(y) -
> oo(IsPositive(x)) if y
> 0
409 oo(x) ** z -
> 0 if z
< 0
410 oo(x) ** z -
> oo(x**z) if z
>0
411 z ** oo(x) -
> (z**x) ** oo(
1)
414 <p>TODO: define more rules for defined results.
</p>
416 <div class=
"section">
417 <h1><a class=
"toc-backref" href=
"#id9" id=
"function-evaluations" name=
"function-evaluations">4 Function evaluations
</a></h1>
418 <div class=
"section">
419 <h2><a class=
"toc-backref" href=
"#id10" id=
"general-rules" name=
"general-rules">4.1 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
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>
434 <div class=
"section">
435 <h2><a class=
"toc-backref" href=
"#id11" id=
"exponentials" name=
"exponentials">4.2 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>
440 <div class=
"section">
441 <h2><a class=
"toc-backref" href=
"#id12" id=
"logarithms" name=
"logarithms">4.3 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
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>
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>
470 <p>TODO: log(-x), log(I*x), log(-I*x), ...
</p>
472 <div class=
"section">
473 <h2><a class=
"toc-backref" href=
"#id13" id=
"trigonometric-functions" name=
"trigonometric-functions">4.4 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">-
></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
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>
493 <div class=
"section">
494 <h1><a class=
"toc-backref" href=
"#id14" id=
"references" name=
"references">5 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>