A computer algebra system written in pure Python http://sympy.org/ . To get started to with contributing https://github.com/sympy/sympy/wiki/Introduction-to-contributing
I am working in a simple QFT calculation and would like to do it using Sympy to learn (and also check my result). I have found the Quantum Mechanics module but cannot see how to start using it for my purpose. I have defined these quantities:
import sympy.physics.quantum as Q
vacuum = Q.OrthogonalKet(0)
annihilation_op = Q.Operator('a')
creation_op = Q.Dagger(annihilation_op)
and now I want to tell Sympy that $a |n\rangle = \sqrt{n} | n-1 \rangle$ if $n>0$ else $0$ and $a^\dagger | n \rangle = \sqrt{n+1} | n+1 \rangle$. How would I do this? Also, how do I impose the commutation relations between $a$ and $a^\dagger$?
Hi all,
I am just a new user for SymPy. I am self learning this library for my undergrauate research. But in the middle of the process I am stucked with one code.
So I have defined a function with a subscript.
U_n= x^n + 1/x^n
When I consider (U_1)^3 I get (substitute n=1)
(U_1)^3 = (x+1/x)^3
Then after simplifying this I get
(U_1)^3 = (x^3 + 1/x^3) + 3(x+ 1/x)
But one can see this answer as
(U_1)^3 = U_3 + 3U_1
How to get the output in terms of U_n 's ?
Can someone please give an idea how to build this code using SymPy. It would be a very big help for my research.
Thank you very much.
Gayanath Chandrasena.
dr*(k-1) < dr*(k+1)
, which is obviously true, since dr = symbols('Delta',real=True,positive=True,nonzero=True)
and k = symbols('k',integer=True,real=True)
, yet sympy doesn't seem to thing this is the case. Am I doing something wrong?
Also I get
In [54]: print(ask(dr*(k-1) < dr*(k+1)))
None
but
In [55]: print(ask(dr*k-dr < dr*k+dr))
True
@ThePauliPrinciple
My function is
U_n= x^n + 1/x^n.
As an example when I compute (U_1)^3 I get (x^3 + 1/x^3) + 3(x+ 1/x).---------(i)
And if I compute (U_2)^2 I get x^4 + 1/x^4 + 2---------(ii)
But since in (i), (x^3 + 1/x^3)= U_3 and 3(x+ 1/x)=3U_1 I want to get the answer U_3+3U_1.
In (ii) I want to get the answer U_4 +2 since x^4 + 1/x^4 = U_4.
aman@amanUBUNTU:~/Desktop$ python3 Un.py
Enter Value of n and k as in (U_n)^k
n = 1
k = 3
3*U_1 + U_3
aman@amanUBUNTU:~/Desktop$ python3 Un.py
Enter Value of n and k as in (U_n)^k
n = 1
k = 2
U_2 + 2
aman@amanUBUNTU:~/Desktop$ python3 Un.py
Enter Value of n and k as in (U_n)^k
n = 2
k = 10
45*U_12 + 10*U_16 + U_20 + 210*U_4 + 120*U_8 + 252
@mostlyaman Yes.This is kind of same what I want.But in my case it is bit advanced.
U(n)=x^n + 1/x^n
V(n)=x^n - 1/x^n
So if I ask for any expression I should get the answer in U(n)'s and V(n)'s.I have buil it for U(n) and V(n) separately but cannot combine them.
ex: u(1)v(1)=v(2)
v(2)u(1)-v(1)=v(3)
v(1)^2 - u(1)^2 =2*u(2)
This is the program which I want.
@mostlyaman is your program executable in jupyter notebook?. If you have an idea please let me know.
dr = symbols('Delta',real=True,positive=True,nonzero=True)
and k = symbols('k',integer=True,real=True)
@AbhJ Welcome! Please have a look at https://github.com/sympy/sympy/wiki/Introduction-to-contributing and the Easy-to-fix issues https://github.com/sympy/sympy/issues?q=is%3Aopen+is%3Aissue+label%3A%22Easy+to+Fix%22
Note that there are many issues that have some PR already proposed. It makes sense to have a look at those (or pick one without any solution proposed) and see why they didn't get merged yet (maybe because a test is missing or the documentation not updated or something else). If you decide to use a solution attempt from any of them, please make sure that you build on that PR and do not just copy and paste the code.