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.Thu, 04 Aug 2022 18:32:40 +0200Solve fails to identify the maximum of the entropy functionhttps://ask.sagemath.org/question/63517/solve-fails-to-identify-the-maximum-of-the-entropy-function/
The entropy function has its maximum at x=1/2
Yet when one uses solve:
x=var('x')
assume(x>0)
solve(derivative(-x*log(x) -(1-x)*log(1-x),x)==0,x)
sage returns something that is correct, but curiously non-specific
[log(x) == log(-x + 1)]
It almost seems like sage can't figure out that x=1/2 solves the above even after the assumption on x.
Thu, 04 Aug 2022 12:25:34 +0200https://ask.sagemath.org/question/63517/solve-fails-to-identify-the-maximum-of-the-entropy-function/Answer by cav_rt for <p>The entropy function has its maximum at x=1/2</p>
<p>Yet when one uses solve:</p>
<pre><code>x=var('x')
assume(x>0)
solve(derivative(-x*log(x) -(1-x)*log(1-x),x)==0,x)
</code></pre>
<p>sage returns something that is correct, but curiously non-specific</p>
<pre><code>[log(x) == log(-x + 1)]
</code></pre>
<p>It almost seems like sage can't figure out that x=1/2 solves the above even after the assumption on x.</p>
https://ask.sagemath.org/question/63517/solve-fails-to-identify-the-maximum-of-the-entropy-function/?answer=63521#post-id-63521Instead,
solve(e^derivative(-x*log(x) -(1-x)*log(1-x),x)==1,x)
gives
[x == (1/2)]Thu, 04 Aug 2022 15:10:15 +0200https://ask.sagemath.org/question/63517/solve-fails-to-identify-the-maximum-of-the-entropy-function/?answer=63521#post-id-63521Comment by Emmanuel Charpentier for <p>Instead,</p>
<pre><code>solve(e^derivative(-x*log(x) -(1-x)*log(1-x),x)==1,x)
</code></pre>
<p>gives</p>
<pre><code>[x == (1/2)]
</code></pre>
https://ask.sagemath.org/question/63517/solve-fails-to-identify-the-maximum-of-the-entropy-function/?comment=63523#post-id-63523Alternatives :
sage: Ex=-(x*log(x)+(1-x)*log(1-x))
sage: solve(Ex.diff(x),x)
[log(x) == log(-x + 1)]
Fails indeed. but :
sage: solve(Ex.diff(x),x, algorithm="sympy")
[x == (1/2)]
sage: solve(Ex.diff(x),x, algorithm="giac")
Warning, argument is not an equation, solving -ln(sageVARx)+ln(-sageVARx+1)=0
[1/2]
sage: solve(Ex.diff(x),x, algorithm="fricas")
[log(x) == log(-x + 1)]
Not directly translatable as of 9.7.beta6 :
sage: mathematica.Solve(Ex.diff(x)==0,x)
{{x -> 1/2}}
Somewhat trichodynamic :
sage: foo=solve(Ex.diff(x),x)[0]
sage: foo.operator()(*map(exp, foo.operands())).solve(x)
[x == (1/2)]
HTH,Thu, 04 Aug 2022 18:32:40 +0200https://ask.sagemath.org/question/63517/solve-fails-to-identify-the-maximum-of-the-entropy-function/?comment=63523#post-id-63523