## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• 13:29
smichr synchronize #22144
• 12:55
smichr synchronize #22152
• 12:54
smichr synchronize #22144
• 12:53
smichr synchronize #22144
• 12:39
PandaxCloud starred sympy/sympy
• 12:32
smichr synchronize #22152
• 11:20
anutosh491 edited #22149
• 07:15
proy87 commented #22134
• 07:01
smichr converted_to_draft #19907
• 06:59
smichr commented #22148
• 06:59
smichr closed #22148
• 06:59
smichr commented #21360
• 06:54
smichr converted_to_draft #22152
• 06:53
smichr synchronize #22152
• 06:53
smichr synchronize #22144
• 06:52
smichr reopened #22144
• 06:30
smichr synchronize #22152
• 06:24
sympy-bot commented #22152
• 06:24
smichr opened #22152
• 06:23
smichr commented #14933
s3k
@s3k:matrix.org
[m]
Hi Folks! Is it possible to use sympy to obtain the probability density function of a transformed random variable?
kdsch
@kdsch:matrix.org
[m]
I am not expecting the results given by https://tinyurl.com/y2vzw6dp
Matías Senger
@SengerM

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$?

GayanathSamuditha
@GayanathSamuditha

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.

ThePauliPrinciple
@ThePauliPrinciple
You can use .subs to substitute x+1/x with U_1
But, you need a better definition of what you want
since U_1^3 is already in terms of U_n's?
treffenl
@treffenl:matrix.org
[m]
Cheers! I'm having an issue with an integration where sympy outputs a piecewise with the condition 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
So sympy seems to think that it can't multiply out the brackets for some reason?
treffenl
@treffenl:matrix.org
[m]
I'm on sympy 1.8, btw.
GayanathSamuditha
@GayanathSamuditha
@ThePauliPrinciple If I simplify U_1^3 I will be getting the answers in X terms.But if you further inspect that term can be converted again to U_n terms(ex: U_1^3=U_3+3U_1). Simple substitution does not work here. There should be a method to back-substitute.
ThePauliPrinciple
@ThePauliPrinciple
But you still have not defined what it is you actually want, you only gave a single example, do you want an arbitrary expression to be expressed in terms of a sum_i a_i*U_i? with in the above case a_3=1 and a_1=3?
GayanathSamuditha
@GayanathSamuditha

@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.

mostlyaman
@mostlyaman
@GayanathSamuditha Although I dont know how you are going to interface with this, but I have created something which can do what you explained.
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 Please tell me if this is what you are hoping for. It asks for the value of n and k and returns the expression in the format you described. GayanathSamuditha @GayanathSamuditha @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. ThePauliPrinciple @ThePauliPrinciple Well, if you have both U(n) and V(n) that actually simplifies it a bit, since it turns into solving a system of linear equations You have an expression in terms of a_ix^[-n...n] and you want to express that in terms of b_i(U(n) or V(n)), now if for example you have n=3, you have 6 terms of x and 3 U(n) +3 V(n) ThePauliPrinciple @ThePauliPrinciple I suppose you could allow for n=0 too, just note that V(0)=0 so that would not be useful for anything GayanathSamuditha @GayanathSamuditha @ThePauliPrinciple yes. right now I have created a computer code which runs these 2 functions separately.I will try to combine it. Thank you for your idea. I will try that too. Raphael Seidel @Arque94_twitter One question regarding the use with Spyder. I activated that sympy rendering is initiated at the creation of a new console. This is very helpful as I work with sympy alot. However one thing that very much annoys me is that standalone integers are rendered too (and this always takes some time). Is there a way of turning of rendering for integers? s3k @s3k:matrix.org [m] Hi folks! Sympy produced this expression: how should i interpret$\sign^2(x)\$?
treffenl
@treffenl:matrix.org
[m]
why is sympy having problems evaluating the first expression, but not the second one
With dr = symbols('Delta',real=True,positive=True,nonzero=True) and k = symbols('k',integer=True,real=True)
mostlyaman
@mostlyaman
@s3k:matrix.org Could you please share the expression in code? It could be this sign function.
syn09001
@syn09001
Hi. Question: If I am in interactive session, and I type F, the symbolic representation of defined expression is outputted. But if I write a program which includes print(F), then the output of F is standards, non symbolic. Is there a way to preserve symbolic expressional form after the program is run? Thanks.
treffenl
@treffenl:matrix.org
[m]
@syn09001: there's a pprint function that does this
Abhijay Mitra
@AbhJ
Hello everyone, I am Abhijay, an Electrical engineering student from IIT Kharagpur, India. I would love to contribute as much as I can to Sympy. I have experience with C++, Java, Javascript and Python and know a bit of Kotlin. I would love to get to know you and get started on contribution!
Oscar Gustafsson
@oscargus

@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.

Zhang
@Naville
Hi:
I'm very new to mathematics or SymPy / SymEngine and is looking for ways to reimplement my simple SymPy code in C++. What's the relationship between SymEngine(which linked SymPy as its homepage) and can I except invoking the same API from SymEngine to work for my SymPy code?
ThePauliPrinciple
@ThePauliPrinciple
You can always run any python code from your c++ program
Zhang
@Naville
Thanks. I'm aware, but I'd prefer avoiding the whole Python GIL and extra dependency with my code, if possible
It seems all SolveSet() related SymPy APIs wont see their existence in SymEngine?
If I'm not mistaken
Meghna Tripathi
@meghna0tripathi
Hello everyone , I am Meghna Tripathi , a computer science student from Delhi Technological University. I have a keen interest in mathematics and also have prior knowledge of C++, python and Javascript . I would love to know more about the project and want to contribute to the project
Shashvat Gupta
@Shashvat6264
Hi everyone, I am Shashvat Gupta, a computer science student from IIT Kharagpur. I have a keen interest in maths and vast knowledge of C++, Python, JS and Java. I would like to know more about the project and get in pace so as to contribute to the project as soon as possible.
Daniel Sears
@highpost
Hi, I have a variable x_i that I've declared as a constant. But when I render it with display(), pprint() or print() it shows only x.
import sympy as sp

x_i  = sp.symbols('x', constant = True)
display(x)
Daniel Sears
@highpost
Thanks!
Peter Li
@lh6210
Hi everyone, I cannot see the matrix square brackets in the output. And idea?
Peter Li
@lh6210
The cmd used to render ? with a square around where the matrix brackets should be.
Kalevi Suominen
@jksuom
@lh6210 Maybe some font set should be installed.
Miguel Guthridge
@MiguelGuthridge
Hi all!, I'm having an issue with adding the result of two substitutions if a substitution doesn't take place (since there's no instance of the symbol in expression to substitute into).
Here's a simple replication in the issue:
>>> import sympy
>>> n = sympy.symbols("n")
>>> x = sympy.Subs(1.0, n, 1)
>>> y = sympy.Subs(1.0, n, 2)
>>> x + y
Traceback (most recent call last):
# Shortened for clarity
File "/mnt/c/Users/migue/Source/Equator/.venv_linux/lib/python3.8/site-packages/sympy/logic/boolalg.py", line 211, in _noop
raise TypeError('BooleanAtom not allowed in this context.')
TypeError: BooleanAtom not allowed in this context.

During handling of the above exception, another exception occurred:
# Shortened for clarity
Traceback (most recent call last):
File "/mnt/c/Users/migue/Source/Equator/.venv_linux/lib/python3.8/site-packages/sympy/logic/boolalg.py", line 211, in _noop
raise TypeError('BooleanAtom not allowed in this context.')
TypeError: BooleanAtom not allowed in this context.
Any ideas why I'm getting that issue? It isn't a problem usually
Like if I make them use the value of n in the substitution then it works completely fine
>>> x = sympy.Subs(n, n, 1)
>>> y = sympy.Subs(n, n, 2)
>>> x + y
Subs(n, n, 1) + Subs(n, n, 2)
Miguel Guthridge
@MiguelGuthridge
The only loosely related thing I can find is this issue, but it doesn't really explain why I'm getting this issue... it's not like I'm working with booleans
sympy/sympy#13427