Manipulating Eq expressions

57 views
Skip to first unread message

bsdz

unread,
Dec 16, 2016, 3:18:13 AM12/16/16
to sympy
Hi

Given an expression like Eq(a/b,c), how can I manipulate both lhs and rhs together? It would be useful if something like b*Eq(a/b,c) can become Eq(a,b*c).

Thanks 
Blair

Shekhar Prasad Rajak

unread,
Dec 16, 2016, 9:09:39 AM12/16/16
to sympy
You can do this : 

```


In [7]:  cancel(y*(x/y)-z)

Out[7]: x - z

```

--
Shekhar

bsdz

unread,
Dec 16, 2016, 9:36:36 AM12/16/16
to sympy
But that doesn't work with Eq. Also how would that work if I wish to do ln(Eq(a*b,c))? Converting the expression to form lhs-rhs wouldn't work.

Shekhar Prasad Rajak

unread,
Dec 18, 2016, 5:01:07 AM12/18/16
to sympy
Convert that into lhs - rhs form and try : 


In [39]: eq = Eq(x/y,z).lhs - Eq(x/y, z).rhs


In [40]: eq

Out[40]: 

x    

─ - z

y    

bsdz

unread,
Dec 18, 2016, 5:29:49 AM12/18/16
to sympy
Not quite what I'm asking but thanks anyhow :)

Chris Smith

unread,
Dec 22, 2016, 2:48:02 PM12/22/16
to sympy
This has been discussed from time to time. Basically you have to roll your own:

```
>>> e=Eq(x,y)
>>> e
Eq(x, y)
>>> do=lambda e,g: e.func(g(e.lhs),g(e.rhs))
>>> do(e,lambda _:_*3)
Eq(3*x, 3*y)
>>> do(_,lambda _:_/3)
Eq(x, y)
```

Aaron Meurer

unread,
Dec 22, 2016, 2:49:43 PM12/22/16
to sy...@googlegroups.com
See this issue https://github.com/sympy/sympy/issues/5031

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/96bd8167-f083-4e7d-a86b-7c1683368885%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages