# HG changeset patch
# User Karl-Dieter Crisman <kcrisman@gmail.com>
# Date 1265299344 18000
# Node ID c07e8cdddeb47c58463a2d4f49430158ec3e4674
# Parent 513aeb51f77fe178a6aa275881e018f744e5d77a
Trac 7334 - Referee fixes to documentation and the log_expand function
diff -r 513aeb51f77f -r c07e8cdddeb4 sage/symbolic/expression.pyx
a
|
b
|
|
5404 | 5404 | |
5405 | 5405 | def simplify_trig(self,expand=True): |
5406 | 5406 | r""" |
5407 | | Optionally expands and then employs the identities |
5408 | | `\sin(x)^2 + \cos(x)^2 = 1` and `\cosh(x)^2 - \sinh(x)^2 = 1` |
| 5407 | Optionally expands and then employs identities such as |
| 5408 | `\sin(x)^2 + \cos(x)^2 = 1`, `\cosh(x)^2 - \sinh(x)^2 = 1`, |
| 5409 | `\sin(x)\csc(x) = 1`, or `\tanh(x)=\sinh(x)/\cosh(x)` |
5409 | 5410 | to simplify expressions containing tan, sec, etc., to sin, |
5410 | 5411 | cos, sinh, cosh. |
5411 | 5412 | |
… |
… |
|
5429 | 5430 | sin(x)^2 + cos(x)^2 |
5430 | 5431 | sage: f.simplify_trig() |
5431 | 5432 | 1 |
| 5433 | sage: h = sin(x)*csc(x) |
| 5434 | sage: h.simplify_trig() |
| 5435 | 1 |
| 5436 | sage: k = tanh(x)*cosh(2*x) |
| 5437 | sage: k.simplify_trig() |
| 5438 | (2*sinh(x)^3 + sinh(x))/cosh(x) |
5432 | 5439 | |
5433 | 5440 | In some cases we do not want to expand:: |
5434 | 5441 | |
… |
… |
|
5460 | 5467 | method for simplifications. Possible values are |
5461 | 5468 | |
5462 | 5469 | - 'simple' (simplify rational functions into quotient of two |
5463 | | poylnomials), |
| 5470 | polynomials), |
5464 | 5471 | |
5465 | 5472 | - 'full' (apply repeatedly, if necessary) |
5466 | 5473 | |
… |
… |
|
5469 | 5476 | - ``map`` - (default: False) if True, the result is an |
5470 | 5477 | expression whose leading operator is the same as that of the |
5471 | 5478 | expression ``self`` but whose subparts are the results of |
5472 | | applying simplifaction rules to the corresponding subparts |
| 5479 | applying simplification rules to the corresponding subparts |
5473 | 5480 | of the expressions. |
5474 | 5481 | |
5475 | 5482 | ALIAS: :meth:`rational_simplify` and :meth:`simplify_rational` |
… |
… |
|
5507 | 5514 | sage: f.simplify_rational(map=True) |
5508 | 5515 | x - log(x)/(x + 2) - 1 |
5509 | 5516 | |
| 5517 | Here is an example from the Maxima documentation of where |
| 5518 | ``method='simple'`` produces an (possibly useful) intermediate |
| 5519 | step:: |
| 5520 | |
| 5521 | sage: y = var('y') |
| 5522 | sage: g = (x^(y/2) + 1)^2*(x^(y/2) - 1)^2/(x^y - 1) |
| 5523 | sage: g.simplify_rational(method='simple') |
| 5524 | -(2*x^y - x^(2*y) - 1)/(x^y - 1) |
| 5525 | sage: g.simplify_rational() |
| 5526 | x^y - 1 |
| 5527 | |
5510 | 5528 | With option ``method='noexpand'`` we only convert to common |
5511 | 5529 | denominators and add. No expansion of products is performed:: |
5512 | 5530 | |
… |
… |
|
5676 | 5694 | ratnump(m)$ . Then logcontract(1/2*log(x)); will give |
5677 | 5695 | log(sqrt(x))." |
5678 | 5696 | |
5679 | | ALIAS: :meth:`log_simplify` and :meth:`log_simplify` are the |
| 5697 | ALIAS: :meth:`log_simplify` and :meth:`simplify_log` are the |
5680 | 5698 | same |
5681 | 5699 | |
5682 | 5700 | EXAMPLES:: |
… |
… |
|
5697 | 5715 | |
5698 | 5716 | This shows that the option ``method`` from the previous call |
5699 | 5717 | has no influence to future calls (we changed some default |
5700 | | Maxima flag and have to ensure, that this flag has been |
| 5718 | Maxima flag, and have to ensure that this flag has been |
5701 | 5719 | restored):: |
5702 | 5720 | |
5703 | 5721 | sage: f.simplify_log('one') |
… |
… |
|
5709 | 5727 | sage: f.simplify_log() |
5710 | 5728 | log(x*y^2) + 1/2*log(t) |
5711 | 5729 | |
5712 | | To contract terms with no coefficient (more preciselly, with |
| 5730 | To contract terms with no coefficient (more precisely, with |
5713 | 5731 | coefficients 1 and -1) use option ``method``:: |
5714 | 5732 | |
5715 | 5733 | sage: f = log(x)+2*log(y)-log(t) |
… |
… |
|
5778 | 5796 | Simplifies symbolic expression, which can contain logs. |
5779 | 5797 | |
5780 | 5798 | Expands logarithms of powers, logarithms of products and |
5781 | | logarithms of quotients. the option ``mehotd`` tells, which |
5782 | | expression should be expanded. |
| 5799 | logarithms of quotients. The option ``method`` specifies |
| 5800 | which expression types should be expanded. |
5783 | 5801 | |
5784 | 5802 | INPUT: |
5785 | 5803 | |
5786 | 5804 | - ``self`` - expression to be simplified |
5787 | 5805 | |
5788 | | - ``method`` - (default: 'product') optional, governs which |
| 5806 | - ``method`` - (default: 'products') optional, governs which |
5789 | 5807 | expression is expanded. Possible values are |
5790 | 5808 | |
5791 | 5809 | - 'nothing' (no expansion), |
… |
… |
|
5808 | 5826 | set to false, all of these simplifications will be turned |
5809 | 5827 | off. " |
5810 | 5828 | |
5811 | | ALIAS: :meth:`log_expand` and :meth:`expand(log)` are the same |
| 5829 | ALIAS: :meth:`log_expand` and :meth:`expand_log` are the same |
5812 | 5830 | |
5813 | 5831 | EXAMPLES:: |
5814 | 5832 | |
… |
… |
|
5835 | 5853 | sage: (log((3*x)^6)).log_expand('powers') |
5836 | 5854 | log(729*x^6) |
5837 | 5855 | |
| 5856 | This shows that the option ``method`` from the previous call |
| 5857 | has no influence to future calls (we changed some default |
| 5858 | Maxima flag, and have to ensure that this flag has been |
| 5859 | restored):: |
| 5860 | |
| 5861 | sage: (log(3/4*x^pi)).log_expand() |
| 5862 | pi*log(x) + log(3/4) |
| 5863 | |
| 5864 | sage: (log(3/4*x^pi)).log_expand('all') |
| 5865 | pi*log(x) + log(3) - log(4) |
| 5866 | |
| 5867 | sage: (log(3/4*x^pi)).log_expand() |
| 5868 | pi*log(x) + log(3/4) |
5838 | 5869 | |
5839 | 5870 | AUTHORS: |
5840 | 5871 | |
5841 | 5872 | - Robert Marik (11-2009) |
5842 | 5873 | """ |
5843 | 5874 | from sage.calculus.calculus import maxima |
5844 | | maxima.eval('domain: real$') |
| 5875 | maxima.eval('domain: real$ savelogexpand:logexpand$') |
5845 | 5876 | if method == 'nothing': |
5846 | 5877 | maxima_method='false' |
5847 | 5878 | elif method == 'powers': |
… |
… |
|
5852 | 5883 | maxima_method='super' |
5853 | 5884 | else: |
5854 | 5885 | raise NotImplementedError, "unknown method, see the help for available methods" |
5855 | | self_m = self._maxima_() |
5856 | | res = self_m.ev("logexpand:%s"%maxima_method) |
| 5886 | maxima.eval('logexpand:%s'%maxima_method) |
| 5887 | res = self._maxima_() |
5857 | 5888 | res = res.sage() |
5858 | | maxima.eval('domain: complex$') |
| 5889 | maxima.eval('domain: complex$ logexpand:savelogexpand$') |
5859 | 5890 | return res |
5860 | 5891 | |
5861 | 5892 | log_expand = expand_log |