Skip to content

Commit

Permalink
Trac #17556: Move simplify_log() from simplify_full() to simplify_real()
Browse files Browse the repository at this point in the history
The `simplify_log` function assumes that its argument is real; otherwise
the log contraction operation is invalid. For example,

{{{
sage: x,y = SR.var('x,y')
sage: assume(y, 'complex')
sage: f = log(x*y) - (log(x) + log(y))
sage: f(x=-1, y=i)
-2*I*pi
sage: f.simplify_log()
0
}}}

Now that we have a `simplify_real()` method, why not move
`simplify_log()` there instead?

In the process, the newer `simplify_rectform()` can be added to
`simplify_full()`.

I'm working on a patch for this.

URL: http://trac.sagemath.org/17556
Reported by: mjo
Ticket author(s): Michael Orlitzky
Reviewer(s): Ralf Stephan
  • Loading branch information
Release Manager authored and vbraun committed Jan 23, 2015
2 parents 1b7b171 + 3616d00 commit 101ad18
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/doc/de/thematische_anleitungen/sage_gymnasium.rst
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,22 @@ wir dies mit der ``simplify_full()`` Funktion::
sage: (sin(x)^2 + cos(x)^2).simplify_full()
1

Dabei werden auch Additionstheoreme für trigonometrische Funktionen und manche
Logarithmengesetze eingesetzt::
Dabei werden auch Additionstheoreme für trigonometrische Funktionen eingesetzt::

sage: var('x, y, z')
(x, y, z)
sage: (sin(x + y)/(log(x) + log(y))).simplify_full()
(cos(y)*sin(x) + cos(x)*sin(y))/log(x*y)
sage: sin(x + y).simplify_full()
cos(y)*sin(x) + cos(x)*sin(y)
sage: (sin(x)^2 + cos(x)^2).simplify_full()
1

Mit der verwandten Funktion ``simplify_real()`` werden auch Additionstheoreme
bei Logarithmen angewandt, die nur mit reellen Werten erlaubt sind::

sage: x, y = var('x, y')
sage: (log(x) + log(y)).simplify_real()
log(x*y)

Faktorisieren und ausmultiplizieren
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/vector_symbolic_dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
sage: type(u)
<class 'sage.modules.vector_symbolic_dense.Vector_symbolic_dense'>
sage: u.simplify_full()
(1, log(6*y^2))
(1, log(3*y) + log(2*y))
TESTS:
Expand Down
35 changes: 29 additions & 6 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8239,13 +8239,28 @@ cdef class Expression(CommutativeRingElement):
1/2*log(2*t) - 1/2*log(t)
sage: forget()
Complex logs are not contracted, :trac:`17556`::
sage: x,y = SR.var('x,y')
sage: assume(y, 'complex')
sage: f = log(x*y) - (log(x) + log(y))
sage: f.simplify_full()
log(x*y) - log(x) - log(y)
sage: forget()
The simplifications from :meth:`simplify_rectform` are
performed, :trac:`17556`::
sage: f = ( e^(I*x) - e^(-I*x) ) / ( I*e^(I*x) + I*e^(-I*x) )
sage: f.simplify_full()
sin(x)/cos(x)
"""
x = self
x = x.simplify_factorial()
x = x.simplify_rectform()
x = x.simplify_trig()
x = x.simplify_rational()
x = x.simplify_log('one')
x = x.simplify_rational()
return x

full_simplify = simplify_full
Expand Down Expand Up @@ -8395,7 +8410,8 @@ cdef class Expression(CommutativeRingElement):
def simplify_real(self):
r"""
Simplify the given expression over the real numbers. This allows
the simplification of `\sqrt{x^{2}}` into `\left|x\right|`.
the simplification of `\sqrt{x^{2}}` into `\left|x\right|` and
the contraction of `\log(x) + \log(y)` into `\log(xy)`.
INPUT:
Expand All @@ -8412,6 +8428,13 @@ cdef class Expression(CommutativeRingElement):
sage: f.simplify_real()
abs(x)
::
sage: y = SR.var('y')
sage: f = log(x) + 2*log(y)
sage: f.simplify_real()
log(x*y^2)
TESTS:
We set the Maxima ``domain`` variable to 'real' before we call
Expand Down Expand Up @@ -8477,7 +8500,9 @@ cdef class Expression(CommutativeRingElement):
for v in self.variables():
assume(v, 'real');

result = self.simplify();
# This will round trip through Maxima, essentially performing
# self.simplify() in the process.
result = self.simplify_log()

# Set the domain back to what it was before we were called.
maxima.eval('domain: %s$' % original_domain)
Expand Down Expand Up @@ -9021,8 +9046,6 @@ cdef class Expression(CommutativeRingElement):
log((sqrt(2) + 1)*(sqrt(2) - 1))
sage: _.simplify_rational()
0
sage: log_expr.simplify_full() # applies both simplify_log and simplify_rational
0
We should use the current simplification domain rather than
set it to 'real' explicitly (:trac:`12780`)::
Expand Down

0 comments on commit 101ad18

Please sign in to comment.