Re: [sympy] Problem with sqrt(-1)

2021-01-05 Thread Oscar Benjamin
SymPy users can use sympy from different contexts or interfaces. They might use it through octave or sage or mathics etc. Or they can use SymPy directly in Python. The advantage of allowing users to use sympy directly in Python is that they can use all of the tools of the Python language to

Re: [sympy] Problem with sqrt(-1)

2021-01-05 Thread David Bailey
On 04/01/2021 23:05, Aaron Meurer wrote: On Mon, Jan 4, 2021 at 3:32 PM David Bailey wrote: There's always the risk that a syntax mistake will actually be valid syntax in some unrelated way. For example, you might accidentally write x(y + z) instead of x*(y + z). x(y + z) is valid syntax (it

Re: [sympy] Problem with sqrt(-1)

2021-01-04 Thread gu...@uwosh.edu
I believe a solution would be to plug into the preparser and override the behavior. All I know is that the preparser provides a way to do this. Jonathan On Monday, January 4, 2021 at 5:05:23 PM UTC-6 asme...@gmail.com wrote: > On Mon, Jan 4, 2021 at 3:32 PM David Bailey wrote: > > > > On

Re: [sympy] Problem with sqrt(-1)

2021-01-04 Thread Aaron Meurer
On Mon, Jan 4, 2021 at 3:32 PM David Bailey wrote: > > On 04/01/2021 21:30, Thomas Ligon wrote: > > Hello David, > indeed, when I enter print(sqrt(-1)), I get I, just as you do. > However, when I enter print(4s**2), it is flagged with an error "unexpected > token 's'", so I immediately see that

Re: [sympy] Problem with sqrt(-1)

2021-01-04 Thread David Bailey
On 04/01/2021 21:30, Thomas Ligon wrote: Hello David, indeed, when I enter print(sqrt(-1)), I get I, just as you do. However, when I enter print(4s**2), it is flagged with an error "unexpected token 's'", so I immediately see that I have something wrong. But, when I  enter print(4j**2), I get

Re: [sympy] Problem with sqrt(-1)

2021-01-04 Thread Aaron Meurer
To be clear, only j where there is nothing between the number and "j" produces a complex number in Python, like 1j. j by itself is a normal variable name which isn't defined to anything by default (and x for any other letter x is a syntax error without a mathematical operation between the number

Re: [sympy] Problem with sqrt(-1)

2021-01-04 Thread Thomas Ligon
Hello David, indeed, when I enter print(sqrt(-1)), I get I, just as you do. However, when I enter print(4s**2), it is flagged with an error "unexpected token 's'", so I immediately see that I have something wrong. But, when I enter print(4j**2), I get (-16 + 0j), so python is just making a

Re: [sympy] Problem with sqrt(-1)

2021-01-04 Thread David Bailey
On 04/01/2021 10:37, Oscar Benjamin wrote: In Python 4j is the literal syntax to create an imaginary number (0 + 4*I). You need to use 4*j. I don't understand this because Thomas Lignon imported sqrt from sympy, so why didn't he get the imaginary answer he was expecting? Indeed, trying this

Re: [sympy] Problem with sqrt(-1)

2021-01-04 Thread Thomas Ligon
Thanks! So I made a stupid mistake, and forgot a *. I do that often, but usually find the mistake fast. Now I also found a remark in Stack Overflow: Python adopted the convention used by electrical engineers. In that field, i is used to represent current and use j as the square root of -1. On

Re: [sympy] Problem with sqrt(-1)

2021-01-04 Thread Oscar Benjamin
In Python 4j is the literal syntax to create an imaginary number (0 + 4*I). You need to use 4*j. On Mon, 4 Jan 2021 at 10:10, Thomas Ligon wrote: > > My understanding is that Sympy uses I as sqrt(-1), but I am running into a > problem with j. I have defined j as a symbol, but j**2 is sometimes

[sympy] Problem with sqrt(-1)

2021-01-04 Thread Thomas Ligon
My understanding is that Sympy uses I as sqrt(-1), but I am running into a problem with j. I have defined j as a symbol, but j**2 is sometimes returning -1. Here is the code: from sympy import latex from sympy import symbols, sqrt m = symbols('m') j = symbols('j') s = symbols('s')