## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• 11:22
oscarbenjamin commented #21945
• 11:05
jksuom commented #21945
• 10:41
sympy-bot commented #22111
• 10:41
oscargus milestoned #22111
• 10:41
oscargus opened #22111
• 10:01
jksuom commented #21945
• 09:38
oscargus commented #21973
• 06:56
asmeurer commented #18960
• 06:50
asmeurer commented #22070
• 05:09
anutosh491 commented #21888
• 01:34
eagleoflqj review_requested #22098
• 00:30
oscarbenjamin commented #18960
• 00:28
smichr commented #22094
• 00:25
oscarbenjamin commented #18960
• 00:19
• 00:10
smichr commented #18960
• Sep 17 23:56
oscarbenjamin commented #21945
• Sep 17 23:56
oscarbenjamin commented #21945
• Sep 17 23:50
oscarbenjamin labeled #22110
• Sep 17 23:21
oscarbenjamin commented #22110
Miguel Guthridge
@MiguelGuthridge
I've been making a maths interpreter using sympy, and I'm trying to implement simultaneous equations, but I'm getting a cannot determine truth value of Relational error when I try to solve them
It's parsing the equations as being semicolon seperated, then recursively generating a sympy expression for them
For the = I'm using sym.Eq(a, b)
And then once I've got everything simplified as much as possible, it uses sym.solve() with a list of the expressions
Which is where the error occurs
Miguel Guthridge
@MiguelGuthridge
Ok nevermind it turns out that sympy doesn't work well with prettyprinting so I just had to stringify it first
AlphaVictorDelta
@AlphaVictorDelta
Hey guys,
My name is Adarsh V. Desai. I am an aspiring software developer. I would like to be a part of sympy and take my skills to the next level by learning new technologies while being an active contributor. I have already installed sympy (developer version) on my local system. Could you guys please point me towards what I should do next to become an active contributor and also understand the code base?
Thank you.
flxai
@flxai:matrix.org
[m]
You could help solving issues, prioritizing bugs: https://github.com/sympy/sympy/issues
Priyanshu Agarwal
@priyanshuone6
When I try sympy.vector.operators.Divergence('x') it gives me AttributeError: module 'sympy' has no attribute 'vector' but when I try from sympy.vector.operators import Divergence and Divergence('x') it works, could you please help me
Aaron Meurer
@asmeurer
The vector module is not imported by default so you have to import sympy.vector before you can access it.
nkr0
@nkr0
nkr0
@nkr0
I'm a bit confused with the Fr and Frstar outputs of Kane's method. Here I've printed them. Fr, shows Tx, which is the load/torque. Cool. Frstar has 3 terms. First one is Ixx ddeta; inertia x angular acceleration. ok. But the next 2 terms are Ixx Omega^2; inertia x angular velocity^2. why is it like that? Fr has the unit Nm, term 1 of Frstar has Nm.rad, others have Nm.rad^2. Is it because rad is an SI derived unit?
Gerardo Jose Suarez
@mcditoos
Hi. why is xconjugate(x)==abs(x)*2 false?
Kalevi Suominen
@jksuom

They are not structurally equal:

In [11]: srepr(x*conjugate(x))
Out[11]: "Mul(Symbol('x'), conjugate(Symbol('x')))"

In [12]: srepr(abs(x)**2)
Out[12]: "Pow(Abs(Symbol('x')), Integer(2))"

== denotes structural equality.

Gerardo Jose Suarez
@mcditoos
got it, is there other equality I can use for this kind of stuff?
Kalevi Suominen
@jksuom
You can use (abs(x)**2).rewrite(conjugate).
Sebastian Helm
@SebastianHelm
Just a quick question|remark: Under The Power of Symbolic Computation, where output is spread over several lines, it misaligns with most fonts. Which font is recommended for viewing this nicely? I only found it to work with Unifont, which isn't very pretty, though. Anyway, maybe the page can be rewritten to suggest such a font?
4 replies
Pieter Barendrecht
@pjbarendrecht

Hi guys, question about root finding with symbolic coefficients. Is it possible to get symbolic results for something like the following:

import sympy as sp
t = sp.Symbol('t')
P = sp.Poly(t**2 + 2*t + sp.log(2))
P.all_roots()

This does not work, as I get sympy.polys.polyerrors.PolynomialError: only univariate polynomials are allowed

Replacing the 3rd line with P = sp.Poly(t**2 + 2*t + sp.log(2), t, domain='RR') works for numerical values. Looking at the docs, I thought something like P = sp.Poly(t**2 + 2*t + sp.log(2), t, domain='QQ<log(2)>') might work, but this triggers a sympy.polys.polyerrors.NotAlgebraic: log(2) doesn't seem to be an algebraic element
Kalevi Suominen
@jksuom
QQ<log(2)> does not work because log(2) is not algebraic. One must use something like QQ(log(2))instead. Or, simply give t as the sole generator; then log(2) will automatically become a constant.
In [26]: p = Poly(t**2 + 2*t + log(2), t)

In [27]: roots(p)
Out[27]:
⎧       ____________            ____________   ⎫
⎨-1 - ╲╱ 1 - log(2) : 1, -1 + ╲╱ 1 - log(2) : 1⎬
⎩                                              ⎭
Pieter Barendrecht
@pjbarendrecht
Thanks! Using P.all_roots() still produces an error when doing so (NotImplementedError: sorted roots not supported over ZZ[log(2)]), but roots(P) works just fine
Kunal Mahatha
@kunal-mahatha
Hey everyone,
I am Kunal. I want to contribute to sympy, but I am a beginner and I know basic to intermediate Python. Could someone please guide me on how the contribution procedure works here, and suggest to me some good beginner-friendly issues to start working on?
Taven
@daegontaven
hi, i'm an amateur at logic, and was wondering if it was possible to generate latex semantic tableaux trees using sympy?
Joao Aguirre
@aguirreeng
Hello everyone, just a simple question (I hope), is it possible to do nested summations with dependent indexes using the Concrete class Sum, replicating in a "single command" things like
$f \left ( {x} \right ) = \sum_{i = 0}^{3} {\left ( {\sum_{j = i + 1}^{4} {\frac{a}{x_{i} - y_{j}}}} \right )}$
Brandon Feder
@brandon-feder
Hey guys. I was just wondering if anyone knows what algorithm is being used in the GeneralSumOfSquaresclass used here. Is there a paper I can reference/explanation, etc?
Aaron Meurer
@asmeurer
@brandon-feder there are some links in the source, e.g., in the power_representation function. Otherwise you might find some references in some of the old 2013 posts in this blog https://thilinaatsympy.wordpress.com/
Jason Ross
@Jason-S-Ross

I'm having trouble learning the diffgeom module. I'm trying to compute covariant derivatives in spherical coordinates and I feel like I'm missing something.

Here's what I'm working with:

from sympy import *
from sympy.abc import x, y, z, r, theta, phi
from sympy.diffgeom import CoordSystem, Manifold, Patch, TensorProduct as TP

R3 = Manifold("R3", 3)
S = Patch("S", R3)
relations = {
("Car3D", "Sph") : Lambda(
(x, y, z),
Matrix([
sqrt(x**2 + y**2 + z**2),
acos(z / sqrt(x**2 + y**2 + z**2)),
atan2(y, x),
])
),
("Sph", "Car3D"): Lambda(
(r, theta, phi),
Matrix([r * sin(theta) * cos(phi), r * sin(theta) * sin(phi), r * cos(theta)])
)
}
Car3D = CoordSystem("Car3D", S, [x, y, z], relations)
Sph = CoordSystem("Sph", S, [r, theta, phi], relations)

I can compute the metric tensor in spherical coordinates by doing the following:

g = (Car3D.jacobian(Sph) @ Car3D.jacobian(Sph).T).simplify()

However, this computes the metric tensor with respect to $x, y, z$, while I'd like to write the metric tensor with respect to $r, \theta, \phi$:
$\left[\begin{matrix}1 & 0 & 0\\0 & \frac{1}{x^{2} + y^{2} + z^{2}} & 0\\0 & 0 & \frac{1}{x^{2} + y^{2}}\end{matrix}\right]$
I can do a substitution, but it's kind of awkward:

x, y, z = Car3D.symbols
r, theta, phi = Sph.symbols
forward_subs = {
x: r * sin(theta) * cos(phi),
y: r * sin(theta) * sin(phi),
z: r * cos(theta)
}
g_sph = g.subs(forward_subs).simplify()

$\left[\begin{matrix}1 & 0 & 0\\0 & \frac{1}{r^{2}} & 0\\0 & 0 & \frac{1}{r^{2} \sin^{2}{\left(\theta \right)}}\end{matrix}\right]$
This gives me the expected metric tensor as a matrix but there's a lot of extra effort:

• I have to define the forward and backward transformations BEFORE I declare forward_subs since the CoordinateSymbol "x" does not exist until I create Car3D, and I have to provide the forward and backward transformations to create Car3D.
• Converting from one coordinate system to another uses a dictionary that duplicates all the information already defined in the coordinate systems
• Computing a metric tensor by taking the Jacobian times its transpose seems like extra effort
• I still haven't got a tensor expression for the metric tensor

I can convert the metric tensor Matrix to a tensor expression as follows:

g_sph_tens = 0
for i, e_i in enumerate(Car3D.base_oneforms()):
for j, e_j in enumerate(Car3D.base_oneforms()):
g_sph_tens += g_sph[i, j] * TP(e_i, e_j)

However, computing the Christoffel symbol for g_sph_tens using metric_to_Christoffel_2nd gives all zeros, which is incorrect.

Can somebody help me out with this? It seems like I'm missing some fundamentals.

Matías Senger
@SengerM

Hi, I want to learn SymPy to do some calculations. I am practicing with the electromagnetic Lagrangian term $F_{\mu\nu}F^{\mu\nu}$. I have defined $F$ in the way that is explained in the documentation but cannot figure out how to go from there to $E^2 + B^2$. How am I supposed to do this?

Up to now I have this:

Ex, Ey, Ez, Bx, By, Bz = sp.symbols('E_x E_y E_z B_x B_y B_z')
c = sp.symbols('c', positive=True)

F = spT.TensorHead('F', [Lorentz, Lorentz], spT.TensorSymmetry.fully_symmetric(-2))

repl = {Lorentz: sp.diag(1, -1, -1, -1)}
repl.update({F(-mu,-nu): [
[0, Ex/c, Ey/c, Ez/c],
[-Ex/c, 0, -Bz, By],
[-Ey/c, Bz, 0, -Bx],
[-Ez/c, -By, Bx, 0]]}
)

and I have tried (F(mu,nu)*F(-mu,-nu)).replace_with_arrays(repl, [mu,nu]) and also F(mu,nu).replace_with_arrays(repl, [mu,nu])*F(-mu,-nu).replace_with_arrays(repl, [mu,nu]).

6 replies
Priyanshu Agarwal
@priyanshuone6
Hey, I have some huge equations but they are getting printed incomplete and half when I use sympy preview for pdf (see the pdf here) , could you please help me with this
sympy.preview(expr, output="pdf", viewer="file", filename="DFN_equations.pdf", dvioptions=['-D', '1100'], euler=False)
Jason Ross
@Jason-S-Ross

I wanted to expand on my question from earlier since it may be too specific.
I am working through some equations from the theory of elasticity.

The differential equation I am trying to work with is the equation
for compatibility of small displacements in a strained isotropic elastic body.
This is written as
$(1 - 2\eta) v^i|^j_j + v^j|^i_j = 0$
where
$f^i|_j$
represents the covariant derivative of f with respect to j, and
$f^i|^j$
represents the covariant derivative of f with respect to j
with the j index raised (this convention is from Green and Zerna -
I don't know if this is a standard notation).

We can use solutions of the above differential equation to compute
the stress tensor as follows:

$\frac{\tau^{ij}}{\mu} = g^{js} v^i|_s + g^{ir} v^j|_r + \frac{2 \eta}{1 - 2 \eta} g^{ij} v^r|_r$

One of the solutions to the displacement equation is as follows:

$v_i = F|_i$

where F is a harmonic function.

What's a good way to

1. Verify that this satisfies the displacement equation
2. Plug this into the stress tensor equation and display the result in Cartesian
and spherical coordinates?
Megan Ly
@meganly
Is there a way to get Sympy to pull a constant inside of an integral without evaluating it? For example, rewriting c*Integral(f(x), (x,a,b)) as Integral(c*f(x), (x,a,b)). I'm struggling to get replace to work.
4 replies
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