## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• 12:48
hanspi42 commented #17098
• 12:46
hanspi42 commented #7219
• 12:41
oscargus edited #22568
• 12:40
oscargus labeled #22568
• 12:40
oscargus opened #22568
• 12:35
cheginit starred sympy/sympy
• 12:35
anutosh491 review_requested #22463
• 12:33
anutosh491 commented #22463
• 12:32
anutosh491 commented #22463
• 12:31
anutosh491 commented #22463
• 12:31
oscargus labeled #22567
• 12:31
oscargus opened #22567
• 12:30
hanspi42 synchronize #22376
• 12:28
hanspi42 commented #22376
• 12:27
hanspi42 commented #22376
• 12:22
oscarbenjamin unlabeled #17945
• 12:14
hanspi42 commented #22376
• 12:10
hanspi42 review_requested #22376
• 12:10
hanspi42 review_requested #22376
• 12:10
Ruturaj57
@Ruturaj57
Hello everyone!
Am Ruturaj, computer science student.
I want to contribute to this open source, so can anyone guide me please?
Cherish Sachdeva
@csachdeva83
Hello Everyone!
Hope you all are having a nice day.I want to integrate(cos(3theta)/(5-4cos(theta)),(theta,0,2pi)) this expression whose
answer is pi/12 but sympy does not executes the integral. So,I replaced cos(3
theta) with
4cos(theta)*3-3cos(theta) then I am obtaining -21pi/8.Also when I replaced cos(3theta) with
cos(theta) sympy executed the integral and gave -pi/2.Can anyone please elaborate why sympy is not executing
cos(3*theta) in integral?
Kalevi Suominen
@jksuom
Integrals of that type should be handled by the risch integrator but that part of the algorithm has not been implemented (yet). Currently, heurisch will be used as a fall-back integrator but it looks like there is a bug that leads to a wrong result.
Megan Ly
@meganly
Is there a way to get the Latex printer to print Integral(x**2,(x,1,2)) as the string '\\int_{1}^{2} x^{2}\\, dx' instead of '\\int\\limits_{1}^{2} x^{2}\\, dx'?
Aaron Meurer
@asmeurer
@meganly apparently latex(mode='inline') does that.
I wonder what the point of \limits is.
$\int_1^2 x^2\, dx$ vs. $\int\limits_1^2 x^2\, dx$
I guess \limits puts them directly above or below the integral sign. That does seem better for non-inline mode, especially if the limits can be long.
then again the non-limits version does look better even for equation mode when the limits are small. Maybe there should be some heuristics here.
Aaron Meurer
@asmeurer
I opened sympy/sympy#21851 for this.
Megan Ly
@meganly
Thanks. My reason for not wanting \limits is that the \limits command is not supported by MathQuill which causes issues for rendering Latex in a web browser.
ThePauliPrinciple
@ThePauliPrinciple
hey hey, I saw in the release notes that ArraySymbol was added, however, I couldn't find the documentation on it, does anyone have any hints where to find more information?
Aaron Meurer
@asmeurer
It looks like it isn't documented very much yet. You may have to take a look at the PR that added it for now to get some more information.
ThePauliPrinciple
@ThePauliPrinciple
Thanks, I looked into the source and it basically is a way to conveniently get symbols with labes that make sense for arrays and array elements, but there is not other functionality that really requires documentation
Aaron Meurer
@asmeurer
I think it should be roughly the same idea as MatrixSymbol
Het
@hetp111
Any docs to build sympy from source?
2 replies
ThePauliPrinciple
@ThePauliPrinciple
Lambdify uses _EvaluatorPrinter and I want it to behave slightly differently. Is there any option other than a lot of code duplication/modifying the source? Specifically, I don't want it to use return, but instead I want to use ASTs return (so that I can e.g. go for multiple lines in one go or use control flow logic from AST)
ThePauliPrinciple
@ThePauliPrinciple
In particular, my solution would be to replace '''funcbody.append('return ({})'.format(self._exprrepr(expr)))''' with '''funcbody+=self._exprrepr(expr).splitlines()''' if expr is a CodeBlock on line 1092 of utilities/lambdify.py
also, gratz on the 1.9 release :D
pratham-saxena
@pratham-saxena
Heyy devs, i am new to open source and i would certainly love to help in whichever way possible. Is there anything i could help you guys with?
ThePauliPrinciple
@ThePauliPrinciple
ThePauliPrinciple
@ThePauliPrinciple
When I want to copy some file from sympy and modify it slightly for my own library, can I do that? I would guess I need to add the Sympy license to my own project? If so, do I need to add all the "external" licenses of the sympy project too, or only the main sympy license?
Jason Ross
@Jason-S-Ross
Is there a generalized Kronecker Delta in sympy?
https://en.wikipedia.org/wiki/Kronecker_delta#Generalizations
pratham-saxena
@pratham-saxena
@ThePauliPrinciple thanks for answering sir .
ThePauliPrinciple
@ThePauliPrinciple
There is a levi-civita symbol, which you may be able to use @Jason-S-Ross
alternatively, you could explicitly write the pxp determinant https://docs.sympy.org/latest/tutorial/matrices.html#determinant
Jason Ross
@Jason-S-Ross
@ThePauliPrinciple I think the levi-civita symbol would work. Good thinking
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