Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplify using a relation between variables in sympy

Tags:

sympy

I want to do a calculation for general matrices from SU(2), i.e. I have a

a,b=symbols('a,b')
m=Matrix([[a,b],[-conjugate(b), conjugate(a)]])

and after some calculations i want sympy to simplify my result respecting that

abs(a)**2 + abs(b)**2 == 1.

Is there anyone with an idea how to tell sympy about this relation between a and b?

like image 927
symcheat Avatar asked Apr 01 '26 15:04

symcheat


1 Answers

The easiest way to do this is to solve the equation for one expression and replace it. In this case, replace abs(a)**2 with 1 - abs(b)**2 (more generally, you can use solve to do this isolation for you).

So something like expr.subs(abs(a)**2, 1 - abs(b)**2). You may also need to replace a*conjugate(a) with abs(a)**2 (or rather, conjugate(a) with abs(a)**2/a) first to get things in terms of abs.

like image 162
asmeurer Avatar answered Apr 11 '26 13:04

asmeurer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!