Simplifying log expressions

151 views
Skip to first unread message

Tom Judson

unread,
Jan 12, 2012, 5:16:55 PM1/12/12
to sage-support
I would like to simplify the difference of two log expressions to show
that I get a constant, but

simplify((1/2)*log(2*t) - (1/2)*log(t))

just returns the expression. Does anyone know of an easy fix for
this? Preferably, I would like something that Calculus II students
could easily use.

Tom Judson

Michael Orlitzky

unread,
Jan 12, 2012, 5:24:35 PM1/12/12
to sage-s...@googlegroups.com

There's no global function for it, but what you want is to call
full_simplify() on the expression.

sage: f = (1/2)*log(2*t) - (1/2)*log(t)
sage: f.full_simplify()
1/2*log(2)

JamesHDavenport

unread,
Jan 13, 2012, 7:38:06 PM1/13/12
to sage-support, Professor James Davenport, r...@cs.bath.ac.uk, d...@cs.bath.ac.uk
Unfortunately, full_simplify has its own problems, notably with branch
cuts.
sage: f = (1/2)*log(2*t) + (1/2)*log(-t)
sage: f.full_simplify()
1/2*log(2)
Unfortunately, when t=-1, we have the sum of the logarithms of two
negative numbers, and therefore the imaginary part is 2i pi, not 0

Michael Orlitzky

unread,
Jan 13, 2012, 8:47:34 PM1/13/12
to sage-s...@googlegroups.com
On 01/13/2012 07:38 PM, JamesHDavenport wrote:
> Unfortunately, full_simplify has its own problems, notably with branch
> cuts.
> sage: f = (1/2)*log(2*t) + (1/2)*log(-t)
> sage: f.full_simplify()
> 1/2*log(2)

In my session, I had the difference of two logarithms. In yours above,
you've got the sum. Is that an actual sage session? I get something
different on 4.8.alpha6:

sage: f = (1/2)*log(2*t) + (1/2)*log(-t)
sage: f.full_simplify()

1/2*I*pi + 1/2*log(2) + log(t)


In the example below, with t=-1, both logs should have imaginary part pi
and real parts log(2) and zero respectively?

JamesHDavenport

unread,
Jan 14, 2012, 1:00:17 PM1/14/12
to sage-support, Professor James Davenport, r...@cs.bath.ac.uk, dj...@bath.ac.uk
I was using sagenb,org, so the output isn't actually a SAGE session,
but pasting from sagenb.org. It says it is 4.7.2.
Glad it's fixed. I guess I ought to download a 4.8 if I'm really going
to comment in more detail, given the apparent changes.

William Stein

unread,
Jan 14, 2012, 2:22:54 PM1/14/12
to sage-s...@googlegroups.com, Professor James Davenport, r...@cs.bath.ac.uk, dj...@bath.ac.uk
On Sat, Jan 14, 2012 at 10:00 AM, JamesHDavenport
<J.H.Da...@bath.ac.uk> wrote:
> I was using sagenb,org, so the output isn't actually a SAGE session,
> but pasting from sagenb.org. It says it is 4.7.2.
> Glad it's fixed. I guess I ought to download a 4.8 if I'm really going
> to comment in more detail, given the apparent changes.

Quick hint: If you click the Text button in the upper right of the
notebook, you'll get something that looks like a normal Sage session.


>
> On Jan 14, 1:47 am, Michael Orlitzky <mich...@orlitzky.com> wrote:
>> On 01/13/2012 07:38 PM, JamesHDavenport wrote:
>>
>> > Unfortunately, full_simplify has its own problems, notably with branch
>> > cuts.
>> > sage: f = (1/2)*log(2*t) + (1/2)*log(-t)
>> > sage: f.full_simplify()
>> > 1/2*log(2)
>>
>> In my session, I had the difference of two logarithms. In yours above,
>> you've got the sum. Is that an actual sage session? I get something
>> different on 4.8.alpha6:
>>
>>    sage: f = (1/2)*log(2*t) + (1/2)*log(-t)
>>    sage: f.full_simplify()
>>    1/2*I*pi + 1/2*log(2) + log(t)
>>
>> In the example below, with t=-1, both logs should have imaginary part pi
>> and real parts log(2) and zero respectively?
>>
>> >> There's no global function for it, but what you want is to call
>> >> full_simplify() on the expression.
>>
>> >>    sage: f = (1/2)*log(2*t) - (1/2)*log(t)
>> >>    sage: f.full_simplify()
>> >>    1/2*log(2)
>

> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to sage-support...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org

--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

Screen Shot 2012-01-14 at 11.21.58 AM.png

JamesHDavenport

unread,
Jan 15, 2012, 1:18:24 PM1/15/12
to sage-support, Professor James Davenport, r...@cs.bath.ac.uk, dj...@bath.ac.uk
Thanks. Given that, here's the sagenb (4.7.2) version, showing the bug
(wrong when t is negative real):
sage: t=var('t')
sage: f=(1/2)*log(2*t)+(1/2)*log(1/t)
sage: f.full_simplify()
1/2*log(2)
[William - this is actually quite a difficult area: see Beaumont et
al.,
Testing Elementary Function Identities Using CAD.
AAECC 18(2007) pp. 513-543.
http://www.springerlink.com/content/f1357425727485r0.]
On Jan 14, 7:22 pm, William Stein <wst...@gmail.com> wrote:
> On Sat, Jan 14, 2012 at 10:00 AM, JamesHDavenport
>
> > For more options, visit this group athttp://groups.google.com/group/sage-support
> > URL:http://www.sagemath.org
>
> --
> William Stein
> Professor of Mathematics
> University of Washingtonhttp://wstein.org
>
>  Screen Shot 2012-01-14 at 11.21.58 AM.png
> 73KViewDownload

Michael Orlitzky

unread,
Jan 18, 2012, 11:28:39 AM1/18/12
to sage-s...@googlegroups.com
On 01/15/12 13:18, JamesHDavenport wrote:
> Thanks. Given that, here's the sagenb (4.7.2) version, showing the bug
> (wrong when t is negative real):
> sage: t=var('t')
> sage: f=(1/2)*log(2*t)+(1/2)*log(1/t)
> sage: f.full_simplify()
> 1/2*log(2)

I created a ticket for this here:

http://trac.sagemath.org/sage_trac/ticket/12322

Thanks for the example!

Greg Marks

unread,
Feb 28, 2012, 2:51:15 PM2/28/12
to sage-s...@googlegroups.com
Dear Sage Developers:

There seems to be a similar issue in Sage Version 4.8:

   sage: a=log(6)/(1+log(2))
   sage: (6*exp(-a)-2^a).full_simplify()
   -(2^(log(3)/(log(2) + 1) + 1/(log(2) + 1))*3^(1/(log(2) + 1))*e^(log(2)^2/(log(2) + 1)) - 6)/(2^(1/(log(2) + 1))*3^(1/(log(2) + 1)))
   sage: (6*exp(-a)/2^a).simplify_full()
   2^(log(2/3)/(log(2) + 1))*3^(log(2)/(log(2) + 1))*e^(-log(2)^2/(log(2) + 1))

Sincerely,
Greg Marks

    ------------------------------------------------
   | Greg Marks                                     |
   | Department of Mathematics and Computer Science |
   | St. Louis University                           |
   | St. Louis, MO 63103-2007                       |
   | U.S.A.                                         |
   |                                                |
   | Phone: (314)977-7206                           |
   | Fax: (314)977-1452                             |
   | Web: http://math.slu.edu/~marks                |
    ------------------------------------------------

Dima Pasechnik

unread,
Feb 28, 2012, 4:00:19 PM2/28/12
to sage-s...@googlegroups.com
In gmane.comp.mathematics.sage.support, you wrote:
>
> Dear Sage Developers:
>
> There seems to be a similar issue in Sage Version 4.8:
>
> sage: a=log(6)/(1+log(2))
> sage: (6*exp(-a)-2^a).full_simplify()
> -(2^(log(3)/(log(2) + 1) + 1/(log(2) + 1))*3^(1/(log(2) +
> 1))*e^(log(2)^2/(log(2) + 1)) - 6)/(2^(1/(log(2) + 1))*3^(1/(log(2) + 1)))
> sage: (6*exp(-a)/2^a).simplify_full()
> 2^(log(2/3)/(log(2) + 1))*3^(log(2)/(log(2) + 1))*e^(-log(2)^2/(log(2) +
> 1))

Sage calls Maxima to do such kinds of computations. If one uses Maxima
on these expressions directly, it does not come up any better than that.
(Or perhaps one needs to know more about Maxima than I do).

Best,
Dmitrii

>
> Sincerely,
> Greg Marks
>

Reply all
Reply to author
Forward
0 new messages