ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 16 Aug 2020 05:43:38 +0200Law of logs false for symbols but true for numbershttps://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/Why do I get False for the additive law of logs for symbols, but True for numbers?
var('a b')
print(bool(log(a)+log(b)==log(a*b)))
print(bool(log(5)+log(10)==log(5*10)))
False
TrueSat, 15 Aug 2020 07:15:55 +0200https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/Comment by cybervigilante for <p>Why do I get False for the additive law of logs for symbols, but True for numbers?</p>
<pre><code>var('a b')
print(bool(log(a)+log(b)==log(a*b)))
print(bool(log(5)+log(10)==log(5*10)))
False
True
</code></pre>
https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?comment=53025#post-id-53025And how do I delete a comment?Sat, 15 Aug 2020 07:23:24 +0200https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?comment=53025#post-id-53025Answer by tmonteil for <p>Why do I get False for the additive law of logs for symbols, but True for numbers?</p>
<pre><code>var('a b')
print(bool(log(a)+log(b)==log(a*b)))
print(bool(log(5)+log(10)==log(5*10)))
False
True
</code></pre>
https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?answer=53032#post-id-53032As you can see with its source code (by typing `log??`), the `log` function first tries to call the `.log` method, which is different from symbolic expressions and for Sage integers, so there is no contradiction here.
What you are pointing here is the fact that when the symbolic ring is not able to prove something, it considers it as `False`. Here, `False` means `False or Unknown`. I admit that such a trivial case should be dealt with.
As a workaround, you can help the symbolic ring to prove the equality by expanding the logs:
sage: print(bool((log(a)+log(b)==log(a*b)).simplify_log()))
True
Sat, 15 Aug 2020 12:48:46 +0200https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?answer=53032#post-id-53032Comment by nbruin for <p>As you can see with its source code (by typing <code>log??</code>), the <code>log</code> function first tries to call the <code>.log</code> method, which is different from symbolic expressions and for Sage integers, so there is no contradiction here.</p>
<p>What you are pointing here is the fact that when the symbolic ring is not able to prove something, it considers it as <code>False</code>. Here, <code>False</code> means <code>False or Unknown</code>. I admit that such a trivial case should be dealt with.</p>
<p>As a workaround, you can help the symbolic ring to prove the equality by expanding the logs:</p>
<pre><code>sage: print(bool((log(a)+log(b)==log(a*b)).simplify_log()))
True
</code></pre>
https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?comment=53035#post-id-53035The problem here, once again, is that most functions we consider are actually *multivalued* complex functions, which really aren't function on $\mathbb{C}$ at all in the normal sense. This usually gets solved by picking a "principal branch", but that sacrifices analyticity along the branch cut. For log, you can see what happens:
sage: log(-1)
I*pi
sage: log(-1)+log(-1)
2*I*pi
sage: log( (-1)*(-1))
0
These two values are not equal: they differ by an integer multiple of $2\pi I$. Since complex logs are "only defined up to multiples of $2\pi I$, they are "essentially" equal (as values taken by logs), but not as elements of $\mathbb{C}$.Sat, 15 Aug 2020 18:40:50 +0200https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?comment=53035#post-id-53035Comment by cybervigilante for <p>As you can see with its source code (by typing <code>log??</code>), the <code>log</code> function first tries to call the <code>.log</code> method, which is different from symbolic expressions and for Sage integers, so there is no contradiction here.</p>
<p>What you are pointing here is the fact that when the symbolic ring is not able to prove something, it considers it as <code>False</code>. Here, <code>False</code> means <code>False or Unknown</code>. I admit that such a trivial case should be dealt with.</p>
<p>As a workaround, you can help the symbolic ring to prove the equality by expanding the logs:</p>
<pre><code>sage: print(bool((log(a)+log(b)==log(a*b)).simplify_log()))
True
</code></pre>
https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?comment=53046#post-id-53046I couldn't find a description of simplify_log anywhere, or in Help. Can you point me to one? So far it doesn't seem to do anything. It returned the same log of products as the same that was input, and as the same symbolic type. I'm curious what it actually does.
I think what bothers me is bool(log(a)+log(b)==log(a*b) was working Entirely in symbolic values, so I'm wondering just where I can trust Sagemath for symbolic results without checking type for every single step.Sun, 16 Aug 2020 01:16:52 +0200https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?comment=53046#post-id-53046Comment by nbruin for <p>As you can see with its source code (by typing <code>log??</code>), the <code>log</code> function first tries to call the <code>.log</code> method, which is different from symbolic expressions and for Sage integers, so there is no contradiction here.</p>
<p>What you are pointing here is the fact that when the symbolic ring is not able to prove something, it considers it as <code>False</code>. Here, <code>False</code> means <code>False or Unknown</code>. I admit that such a trivial case should be dealt with.</p>
<p>As a workaround, you can help the symbolic ring to prove the equality by expanding the logs:</p>
<pre><code>sage: print(bool((log(a)+log(b)==log(a*b)).simplify_log()))
True
</code></pre>
https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?comment=53049#post-id-53049It still works:
sage: var('a,b')
sage: bool(log(a)+log(b) == log(a*b))
False
In general you cannot expect that a symbolic engine will be able to prove all symbolic identities, so it's important that `False` can mean `Don't know`. In this case, however, it's really the case that there are numerical inputs for which the identity doesn't hold, so the `False` really is `False` in this case.Sun, 16 Aug 2020 05:43:38 +0200https://ask.sagemath.org/question/53024/law-of-logs-false-for-symbols-but-true-for-numbers/?comment=53049#post-id-53049