On 05/06/2016 09:50 PM, Marc Tardif wrote:
> Hi folks,
> 
> When comparing the product of two square roots to the square root of
> the product using two scalars, I get True:
> 
>     sage: bool(sqrt(pi)*sqrt(2) == sqrt(pi*2))
>     True
> 
> But when using a variable instead of one of the scalars, I get False:
> 
>     sage: n = var('n')
>     sage: assume(n>=0)
>     sage: bool(sqrt(pi)*sqrt(n) == sqrt(pi*n))
>     False
> 

The identity isn't true in general. Take,

  i * i = sqrt(-1) * sqrt(-1) = -1

and apply the identity:

  sqrt(-1 * -1) = sqrt(1) = 1.

In Sage, variables are complex by default, so we can't use that
identity. In a perfect world, your assumption that n >= 0 would fix
that, but the "safe" simplification routines involved with
bool(<expression>) aren't smart enough to use it.

Instead, you can try,

  sage: (sqrt(pi)*sqrt(n) - sqrt(pi*n)).simplify_real()
  0

The simplify_real() method can be a little more extreme since you're
making it clear that you want to treat the expression as real.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to