Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
Activity
• 16:20
github-actions[bot] commented #21546
• 15:12
smichr synchronize #21546
• 14:56
sympy-bot commented #21763
• 14:56
sympy-bot commented #21763
• 14:56
akshanshbhatt edited #21763
• 14:39
stevenleeS0ht commented #21790
• 14:36
stevenleeS0ht commented #21790
• 14:31
github-actions[bot] commented #21789
• 14:29
oscarbenjamin labeled #21787
• 14:29
oscarbenjamin labeled #21787
• 14:29
oscarbenjamin commented #21787
• 14:27
oscarbenjamin commented #21790
• 14:07
smichr commented #21787
• 14:03
smichr synchronize #21546
• 14:02
stevenleeS0ht opened #21790
• 14:02
proy87 commented #21788
• 14:02
proy87 closed #21788
• 13:57
smichr synchronize #21546
• 13:55
oscarbenjamin commented #21788
• 13:54
oscarbenjamin commented #21788
Muhammed Ali
@khabdrick
Hello everyone, I am new to sympy, was going through the docs and I saw a lot of maths, can someone please tell me the basic math principles I need to know before I can be comfortable contributing to the project
Francesco
@cescofran_gitlab
Hi There, I'm studying a little the source and I have some questions ..I will ask them one at the time...
1. Why Float are called Float and not Reals? Float seam to refer rather to floating point which by definitions are approximation
but sympy Float seam to have arbitrary precision..
Isuru Fernando
@isuruf
@cescofran_gitlab, they are still floating point numbers, because they have a limited number of digits in the mantissa which is determined at instantiation time.
Francesco
@cescofran_gitlab
Thanks you very much @isuruf ! I see you cannot instantiate any real number just by value ... since that will need infinite memory.
But since still you can have arbitrary precision I felt a little confused in Float nomenclature....
Isuru Fernando
@isuruf
arbitrary precision integers and arbitrary precision floats are two entirely different beasts
with integers, you only need a finite amount of memory
with integer operations, integers can get bigger and the size grows as expected
with reals, you need infinite memory at the start
otherwise you get floats
Francesco
@cescofran_gitlab
so is common to refer to floats as arbitrary precision floats?
Isuru Fernando
@isuruf
I didn't get that part
20 replies
with sympy, instead of storing 1/3 with say 1000 digits, you can store it as a Rational number and sympy will not convert it to a float in subsequent operations which means multiplying Rational(1, 3) * 3 gives you an integer 1 instead of a float 1.0
WhiteBlackGoose
@WhiteBlackGoose
Hey! I'm working on an oss computer algebra library for .NET, those, who are "fluent" in SymPy and willing to contribute to our project - please, let me know! (Oryp4ik#0120. on Discord. The project I'm working on is here: https://github.com/asc-community/AngouriMath . There's no need to know .NET to help with the project)
Aaron Meurer
@asmeurer
@cescofran_gitlab Float refers to the specific way the numbers are represented, i.e., floating-point. Not all real numbers are represented that way. For instance, Rational(1, 3), sqrt(2) and pi are real numbers but not floating point, and in fact they can't be exactly represented as floating-point. A floating point number uses a very specific representation of $man\times 2^{exp}$ (see https://mpmath.org/doc/current/technical.html#representation-of-numbers).
Floating point numbers approximate real numbers, but they are not the same as real numbers. Even numbers that are represented exactly are not the same, because they might have a sum that isn't exactly representable. For example, Float(x) + Float(y) != Float(x + y) in general.
Francesco
@cescofran_gitlab
Thanks you @asmeurer , but for example also Rational are just one representation for rational numbers
Float could be another representation for rational numbers .. but in the case of Rational
that specific representation as been assigned the name of the set...
The fact you cannot instantiate all reals with Float does not mean you could not use it as type of real...
I'm not suggesting to do so .. that is just to say from what my question was coming from ....
An approach could be that since is a symbolic math lib... you could just abstract any internal representation
and having just Rational, Reals etc..
Aaron Meurer
@asmeurer
The mathematical sets that numbers belong to is done in SymPy via the assumptions system. For example x.is_real will tell you if x is a real number. The Python classes are based on the implementation, which is why they are named after the representation. Calling Float Real would be inaccurate because it is only one possible representation of real numbers, and one that can't even represent all possible ones at that.
2 replies
Francesco
@cescofran_gitlab
I agree that Float should not be named Real, I'm not convinced should be named Float neither because of the arbitrary precsion... and so for Rational since is conflicting with is_rational (for example I find strange that Float(1.2).is_rational is None )... anyway thanks to you and @isuruf for all the clarifications!
Benoit Martin
@metabsd
Hi, There is a way to solve this with sympy ? Thx!!
Sidharth Mundhra
@0sidharth
@metabsd
>>> from sympy import *
>>> i = Symbol('i')
>>> a = 3 * i
>>> Sum(a, (i, 1, 5))
Sum(3*i, (i, 1, 5))
>>> Sum(a, (i, 1, 5)).doit()
45
>>> b = Sum(i, (i, 1, 10)) / Sum(i + 1, (i, 1, 10))
>>> b
Sum(i, (i, 1, 10))/Sum(i + 1, (i, 1, 10))
>>> b.doit()
11/13
>>> pprint(Sum(a, (i, 1, 5)))
5
___
╲
╲
╱   3⋅i
╱
‾‾‾
i = 1

>>> pprint(b)
10
___
╲
╲
╱   i
╱
‾‾‾
i = 1
─────────────
10
___
╲
╲
╱   (i + 1)
╱
‾‾‾
i = 1
Ayush Bisht
@ayushbisht2001
hi everyone , I have been scrolling through sympy documentation and I get stuck in finding the lcm for more than 2 numbers. Is there a way to find the lcm for a set of numbers?
Sidharth Mundhra
@0sidharth
I'm not sure about sympy but python 3.9+ has math.lcm
Ayush Bisht
@ayushbisht2001
If we have a set in symbols then how can we compute LCM for that... I am seeking for sympy things... Using sympy.lcm, I compute the LCM for 2 numbers but I get errors for more numbers...
Muhammed Ali
@khabdrick
Hello everyone, to start contributing, do I clone the repo directly or fork it
almighty123789
@almighty123789
@khabdrick I think the standard procedure is to first fork and then clone from the remote on your account.
Mayank-gaur
@Mayank-gaur
HI! I am looking for some active issues for beginner so that I can start my journey with organization. I am a very hardworking guy but I am not finding any active issues and I have commented on many 'easy to fix' label issues but there also I am getting no reponse. Can someone please suggest some active and beginner friendly issues?
Ayush Bisht
@ayushbisht2001

@0sidharth , we can also do the same thing by passing a list of numbers to sympy.lcm( ) method.

import sympy
print(sympy.lcm([4,6,2]))
12

Benoit Martin
@metabsd
Hi, there a way to pprint(simplify(e)) with explanation. Or all step to simplify ?
Kartik Sethi
@ks147
hi there, is there some way to get a matrix with kth diagonal populated as input array, like Matlab's diag(A,k)
Ayush Bisht
@ayushbisht2001

from sympy import *
x,y,z = symbols("x y z")
exp = (x+z)&2
TypeError: unsupported operand type(s) for &: 'Add' and 'int'

how can we implement bitwise operation with sympy.

Sayandip Halder
@sayandip18
Currently, solve([x - 5], x) gives the dict {x: 5} as solution. However, solve([sin(x)], x) and solve([x**2-4],x) does not return a dict solution unless stated explicitly.
Shouldn't solve([x - 5], x) simply return [5]?
Benoit Martin
@metabsd
Normally when I divide I subtract exp but here it looks like the exp is being increased.
Benoit Martin
@metabsd
Benoit Martin
@metabsd
e25_4 = ((-4*a*b**2/-2*a**2*c**2) + (14*a**4*c/-2*a**2*c**2))
Result -7*a**6*c**3 + 2*a**3*b**2*c**2
Ayush Bisht
@ayushbisht2001
can someone review my PR #20919
this one also , #20923
Aaron Meurer
@asmeurer
@ayushbisht2001 ilcm accepts any number of arguments
2 replies
moiseszeleny
@moiseszeleny

Hi everyone, can someone give me some recommendation to the next problem, I have a large expression lambdified, the problem is that has Nan results when I evaluate. I have found one term which causes this behavior and given by:

from sympy import init_printing,symbols,log,sqrt
init_printing()

m = symbols('m')
f = 0.5*log(1 - 3.13400648e+22/(1.56700324e+22*sqrt(1 - 1.5976993129893e-11*m)*sqrt(1.5976993129893e-11*m + 1) + 1.56700324e+22))

Then, when I substitute in $m=1e-3$

f.subs(m,1e-3)

Which give $\tilde{\infty}$. However, if I use evalf command I obtain

f.evalf(subs={m:1e-3})
-32.4607738174251 + 1.5707963267949*I

Then, I don't know what result is correct. Is this a problem of the precision of subs command?.

Aaron Meurer
@asmeurer
evalf is more accurate. The problem is that when using subs, the expression inside of the log is not evaluated to enough precision to distinguish it from 0
evalf(subs=...) handles cases like this where naive substitution leads to loss of significance
for lambdify, you are going to run into this same problem, because you are evaluating it naively. You will need to rewrite the expression somehow to avoid the massive cancellation.
Generally, you'd want to evaluate something like this using log1p.
Aaron Meurer
@asmeurer
You can use sympy.codegen.cfunctions.log1p. But I still get issues with it, so you need to make some other changes.
Maybe log1p isn't actually applicable here, since the argument is near 0, not near 1
Aaron Meurer
@asmeurer
If you are just using SymPy, you can fix this problem by converting the floats to rationals. Then subs will be able to evaluate it more accurately. But for lambdify to numpy, you will need to figure out how to rewrite the expression to be more numerically stable.
Aaron Meurer
@asmeurer
A suggestion would be to multiply and distribute a large value inside of the log then subtract the log of that value. That way the number evaluated in the log isn't so close to 0.
Ayush Bisht
@ayushbisht2001
@asmeurer , some of the test are failing in my PR's #20923 #20919, please do review.