## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• 15:08
sympy-bot commented #21472
• 15:08
JSS95 edited #21472
• 14:08
github-actions[bot] commented #21472
• 13:26
orielmalihi commented #21687
• 13:25
orielmalihi commented #21687
• 13:20
orielmalihi synchronize #21687
• 12:59
ilayn commented #21763
• 12:43
JSS95 synchronize #21472
• 12:42
moorepants commented #21626
• 11:56
JSS95 synchronize #21472
• 11:39
jksuom commented #21626
• 11:27
namannimmo10 commented #21763
• 10:41
oscarbenjamin commented #21626
• 10:38
oscarbenjamin labeled #21771
• 10:38
oscarbenjamin labeled #21771
• 10:38
oscarbenjamin labeled #21771
• 10:38
oscarbenjamin labeled #21771
• 10:37
oscarbenjamin commented #21771
• 09:20
moorepants commented #21626
• 08:13
stevenleeS0ht edited #21771
Matthew Roos
@mattroos
I'm brand new to sympy and to computer algebra systems. I'd like to create a function that can take in an expression and return an expression in which any symbols raised to a power (integer, and >1) are placed by 1. For example, x**2 + x*y**3 becomes x + x*y. Any pointers as to what I should review/read in the repo or the sympy.org website, to get me started, would be much appreciated!
Naveen Sai
@naveensaigit
@mattroos This may not be the most efficient way to do it, but it works
In [95]: e = x**(S(3)/2) + x**2*y**3 + x + 1/y
...: e
Out[95]:
3/2    2  3       1
x    + x ⋅y  + x + ─
y

In [96]: powers = e.atoms(Pow)
...: powers
Out[96]:
⎧ 3/2   2  1   3⎫
⎨x   , x , ─, y ⎬
⎩          y    ⎭

In [97]: int_powers = list(filter(lambda x: x.exp.is_Integer and x.exp > 1, powers))
...: int_powers
Out[97]:
⎡ 3   2⎤
⎣y , x ⎦

In [98]: {k:v for k, v in zip(int_powers, list(map(lambda x: x.base, int_powers)))}
Out[98]:
⎧ 2      3   ⎫
⎨x : x, y : y⎬
⎩            ⎭

In [99]: e.subs({k:v for k, v in zip(int_powers, list(map(lambda x: x.base, int_powers)))})
Out[99]:
3/2             1
x    + x⋅y + x + ─
y
Matthew Roos
@mattroos
Thanks, @naveensaigit! I'm learning a lot about sympy from that single example!
Gaurav Dhingra
@gxyd
Hi @asmeurer , any expected date by when can we see the SymPy 1.9 coming out?
Fabio Luporini
Hi everyone! How can I enforce precedence on the Mod in a*(b%3) where a and b are plain Symbol ? SymPy will evaluate it to a*Mod(b, 3), while I'd want to keep the precedence explicit (so that ultimately generation of lower level code honours this user-enforced precedence)
Oscar Benjamin
@oscarbenjamin
You can enforce precedence with brackets as you showed.
13 replies
mostlyaman
@mostlyaman
Hi everyone! Can anyone verify that my release notes for sympy/sympy#21553 are acceptable so that I can add them manually to the wiki. The PR has been closed now. Thanks!
Aaron Meurer
@asmeurer
@mostlyaman yes they look good
mostlyaman
@mostlyaman
@asmeurer Thanks! Added them to the wiki.
Shamitha
@ShamithaReddy
Hi everyone, can anyone say why this isn't working. p=lambda x: x*2, Range(n)
p(3), this is giving error-- Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: 'tuple' object is not callable
I'm new to sympy, can anyone help
sharath sr
@Sharath-a26
Hello guys, i'm interested to work on this project, Can someone guide me?
ASUTOSH GHANTO
@asutoshgha
how to actually contribute to this repository?
Akhil (#stayhome #staysafe )
Hello everyone
Is anyone there??
Shamitha
@ShamithaReddy
hi
ASUTOSH GHANTO
@asutoshgha
I want to improve
Miguel Guthridge
@MiguelGuthridge
Is there a way for me to include sympy as a module in another project so that I can import it inside an interpreter where pip installing modules isn't accessible?
2 replies
I'm trying to make an extension to a search program that uses python so that when you type eq [some equation] it'll solve it
But since I've never included a package without having it pip installed, I'm not entirely sure where to start haha
shashankks0987
@shashankks0987
My test is returning this as the expected output Complement(Integers, ConditionSet(n, Eq((n - 1)*(n + 1), 0), Integers)). I need to convert this to 'sympy' form. Need help
oponkork
@oponkork

Why does the following latex code of the function varies from the symbol?

import sympy as sp
r = sp.symbols("r")
print(sp.latex(sp.symbols("\delta\ u_t")))
print(sp.latex(sp.Function("\delta\ u_t")(r)))

gives

\delta u_{t}
\delta\ u_{t}{\left(r \right)}

Notice that the space right after \delta is escaped for the function, but not for the symbol.

Aaron Meurer
@asmeurer
The latex printer uses different code paths for Symbol and Function. They should probably be made uniform. By the way, you should always use raw strings for latex, like r"\delta\ u_t".
oponkork
@oponkork

Okay, is there a way I can use the Symbol-like expressions for functions, or define the symbol without the space? The way it gets displayed, it appears as if \delta and u_t are two different variables. Ofcourse, sp.symbols("\deltau_t"), it won't work.

Also, why raw strings for latex?

Kalevi Suominen
@jksuom

why raw strings for latex?

Otherwise double backslash will be needed like \\delta.

oponkork
@oponkork

why raw strings for latex?

Otherwise double backslash will be needed like \\delta.

But sp.symbols("\delta\ u_t") works.

Kalevi Suominen
@jksuom
It seems to work, apparently because \d is not an escape sequence in Python. However, \b is an escape sequence:
>>> "\beta\ u_t"
'\x08eta\\ u_t'
oponkork
@oponkork
Aah okay. \theta won't work either then. Thanks a lot.

Okay, is there a way I can use the Symbol-like expressions for functions, or define the symbol without the space? The way it gets displayed, it appears as if \delta and u_t are two different variables. Ofcourse, sp.symbols("\deltau_t"), it won't work.

Also, why raw strings for latex?

Any solution for this?

Arun sanganal
@ArunSanganal
Hello! I am a freshman from IIT Kharagpur, new to sympy. Hoping to get along with this awesome community. Cheers!😄
wolfgang_302
@wolfgang-302

Maybe someone can explain the following to me:
Using sympy 1.7.1 i get the following:

from sympy import *
init_printing()

a = Symbol('a')

a0, = solveset(Eq(2*a**5,0.34),domain=S.Reals)
a0 # 0.70160032942779
0.70160032942779

print(a0.round(4)) # 0.7016
print(a0.round(4).n(10)) # 0.7015991211

Thank you for any hints.
Wolfgang

Felix
@flxai:matrix.org
[m]
Hi! 👋 I have a sympy expression and want to iterate over elements of its syntax tree. Can somebody please point me to the right direction?
Nevermind. I just found it myself: docs.sympy.org/latest/tutorial/manipulation.html#recursing-through-an-expression-tree
moiseszeleny
@moiseszeleny
@flxai:matrix.org hi you can use the args method, for example if you expression is 'expr' you can iterate on its elements by '[arg for arg in expr.args]'.
Felix
@flxai:matrix.org
[m]
moiseszeleny-5dd0d487d73408ce4fd13ecb: Thanks. That's what I'm doing. Just recursively
latot
@latot:matrix.org
[m]
Hi hi, can someone help me with a little thing plis?
I'm having a very hard time trying to get the memory usage of sympy expressions, actually for example, sys.getsizeof always return 64 bytes, even if the var have 200 bytes in the name...., just the name...., how can I get the actual memoery usage of a expression?
Felix
@flxai:matrix.org
[m]
latot: You could try something like this: ix.io/3q9z
oytis
@oytis:matrix.org
[m]

Sorry, a very general question, I'm just looking around with sympy.

I was confused by sympy having two implementations of vectors, sympy.vector an sympy.physics.vector. They seem to not be sharing code and the documentation for either doesn't mention another one and the reason to have them separate. Why is that? Is there a way to make them interoperate?

Thanks!

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