On Sat, Sep 8, 2012 at 2:51 PM, Douglas Macdonald
<[email protected]> wrote:
> Hello,
>
> When multiplying
>
> In [34]: (4 - I*5) * (3 + I*2)
>
> I get the answer
>
> Out[34]: (3 + 2⋅ⅈ)⋅(4 - 5⋅ⅈ)
>
> However, I was expecting something like
>
> 22 - 7i
>
> To get this answer it required
>
>
> In [35]: simplify((4 - I*5) * (3 + I*2))
> Out[35]: 22 - 7⋅ⅈ
>
> This is okay but is there a logic, that I am missing, as to why
> multiplication for this requires 'simplify' when, for example, addition
> would not?
>
> Kind regards,
>
> Douglas

SymPy tries to do minimal automatic simplification, because any
simplification that happens automatically is impossible to not do.

The reason that this expression doesn't expand by default is that I is
implemented as an object not much different from pi or Symbol('x').
We certainly wouldn't want something like (x + 1)*(x + 2) to
automatically simplify to x**2 + 3*x + 2, or else it would be
impossible to factor x**2 + 3*x + 2 into (x + 1)*(x + 2) (the latter
would just transform right back into the former). Expressions with I
work the same way, except I**2 is automatically converted to -1.

There has been talk in the past of creating a complex number object,
which would hold both the real and imaginary parts (currently 1 + 2*I
is just implemented as Add(1, Mul(2, I))), and would automatically
combine like you want.  Unfortunately, the current core is not really
expressive enough to make this work well with other expressions.  In
fact, there would be no way to make a ComplexNumber object
consistently combine with other ComplexNumbers unless we specifically
special cased it in Mul, which we want to avoid. There is some more
extensive discussion at
https://github.com/sympy/sympy/wiki/Canonicalization.  It's definitely
a non-trivial problem.

Aaron Meurer

>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/rMsF3mc5bYkJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to