Skip to content

Missing Parentheses in Complex Number Operations with SymPy #224

@limka1200

Description

@limka1200

I noticed a potential issue when using SymPy in combination with handcalcs. When performing operations involving complex numbers, parentheses are not added around terms during subtraction or multiplication. This could lead to confusion, especially when negative parts of complex numbers are involved, as the expressions might appear mathematically incorrect.
Here’s an example to illustrate:

from sympy import I
import handcalcs.render
%%render
z1 = 3 + I*4
z2 = -4 + I*3

z01 = z1*z2
z02 = z1-z2

The rendered output in LaTeX might look like this
image

Expected Behavior

Parentheses should be automatically placed around subtracted or multiplied terms to clarify the operations:
z01 = (3 + 4i)(-4 + 3i) = -24 - 7i
z02 = 3 + 4i - (-4 + 3i) = 7 + i

Version: 1.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions