Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
Activity
• 08:03
oscargus converted_to_draft #22150
• 08:03
oscargus commented #22150
• 07:25
oscargus synchronize #22150
• 07:21
oscargus synchronize #22150
• 07:12
sympy-bot commented #22150
• 07:11
oscargus review_requested #22150
• 07:11
oscargus opened #22150
• 07:11
oscargus labeled #22150
• 06:38
anutosh491 commented #22149
• 06:34
anutosh491 opened #22149
• 06:31
Nabhag8848 starred sympy/sympy
• 05:58
anutosh491 commented #14103
• 05:42
smichr commented #22148
• 04:46
shelldoom starred sympy/sympy
• 03:54
fauzank339 commented #13881
• 03:01

smichr on master

Modified coeff() to give correc… Coding style fixes Added test for issue 17917 and … and 3 more (compare)

• 03:01
sympy-bot updated the wiki
• 03:01
sympy-bot commented #22140
• 03:01
smichr closed #22140
• 03:01
smichr closed #16752
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.
moiseszeleny
@moiseszeleny

@asmeurer Thanks for the suggestions and the explanation. My expression is too large because I obtained after some SymPy calculations and I do not how to rewrite the log function following your suggestions of multiply for a big number inside of log. I have tried to create a new log function like log_rewrite(x) = log(x*y) - log(y) with y a big number and after using lambdify command to the f function

from numpy import log as nplog
def log_rewritted(x):
y = 1e30
return nplog(x*y)-nplog(y)

fnp = lambdify([m],f,modules=[{'log':log_rewritted}])

However, I obtained the same result when I evaluate f,

fnp(1e-3)
-inf.
Bilsteen
@Bilsteen
hey guys i am new to open source and an aspirant for gsoc 2021. i want to contribute towards sympy . can anyone guide me and help me towards what issue should be the best to start with
Aaron Meurer
@asmeurer
@moiseszeleny I think you are going to have to rewrite what is inside of the log too. It already rounds down to 0, so simply multiplying it by a larger number won't do anything.
Ayush Bisht
@ayushbisht2001
hello everyone , does use_unicode is False by default in pprint( )
Ayush Bisht
@ayushbisht2001
I have tried to correct something in doc .Refer : #20919
Craig Russell
@ctr26
Can one use the integral transforms on numeric data?
Francesco
@cescofran_gitlab

Why

from sympy.abc import  x, k
from sympy import Sum

print(Sum(1/2**x, (x, 0, k)).evalf())

give 2.00000000000000 like it was an infinte series?

5 replies
Aaron Meurer
@asmeurer
Looks like a bug. Can you open an issue?
Francesco
@cescofran_gitlab
@asmeurer new to the project I will try to look at the reccomanded way to write a issue ..
but if someone already familiar with process do it before ...I will learn directly from it ..
Aaron Meurer
@asmeurer
It's not that complicated. Just go to https://github.com/sympy/sympy/issues/new and note the example that is wrong.
Ayush Bisht
@ayushbisht2001
#4886 I want to work on this issue , can someone suggest me how to start?? where the test file should be added . I am unable to figure out it.
Ayush Bisht
@ayushbisht2001
I have found some conflict with my PR #20935 , can someone help me ??
Francesco
@cescofran_gitlab
Sum(x**2, (x, 1, k)).evalf() and expression which derivative is not a constant raise TypeError
this should come from the euler_maclaurin when it compare a symbolic expression to a float...
why the code does not take in consideration the symbolic case?
Janmay Bhatt
@JANMAY007
Hi everyone, I am Janmay from Nirma University, India and I want to contribute into sympy library. I am CSE student, second year. I have done a research in mathematics related to prime numbers which is prime conjecture(here https://www.ijmttjournal.org/archive/ijmtt-v60p505).
This research have function for series of prime numbers and you can generate the any prime with a reference. I have read about the contribution in sympy so may someone please guide me about gsoc
This will make the prime generation faster and precise, which I want to contribute into sympy as well as for issue #19118 in sympy repository
Ayush Bisht
@ayushbisht2001

I found some unusual behaviour in randprime and I try to fix it.

from sympy import randprime
print(randprime(-2,0))
ValueError: no preceding primes

Can someone please review this PR : #20949

laolux
@laolux:wolkendienst.dynv6.net
[m]
@ayushbisht2001 Wouldn't it make sense to go all the way to 2?
for example
print(randprime(0,2)) should also print "no primes exist in the specified range"
Ayush Bisht
@ayushbisht2001
@laolux:wolkendienst.dynv6.net , Now , Is it good to go ?? #20949 .
Aaron Stiff
@AaronStiff
How would I analyze a sympy object to see whether it matches a certain structure? For instance, I want to see if an object/expression matches the structure I*im(z), where z is some complex symbol.
Aaron Meurer
@asmeurer
You can use Wild and match
Aaron Stiff
@AaronStiff
Thanks.
Vishesh Mangla
@Teut2711
class Data:
def __init__(self, string,symbol, value):
self.string = string
self.symbol = sm.Symbol(symbol)
self.value = value

return self.value + other.value if isinstance(other, Data) else other

def __str__(self):
return self.string
def _repr_latex_(self):
return display(Latex(' '.join([self.string, f'({self.symbol})' ,r'\equals', self.value] )))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
c:\users\dell\onedrive\desktop\courses sem8\venv\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
343             method = get_real_method(obj, self.print_method)
344             if method is not None:
--> 345                 return method()
346             return None
347         else:

<ipython-input-49-83e3f780e89d> in _repr_latex_(self)
11         return self.string
12     def _repr_latex_(self):
---> 13         return display(Latex(' '.join([self.string, f'({self.symbol})' ,r'\equals', self.value] )))
14 # area_each_plate = Data("Area of each plate", 15.8*15.8*SI.cm**2)
15 # inlet_pressure = Data("Area of each plate", 15.8*15.8*SI.cm**2)

TypeError: sequence item 3: expected str instance, Quantity found
how to get the latex out of sympy's Symbol?
neither does f'({latex(self.symbol)})' work
Aaron Meurer
@asmeurer
"TypeError: sequence item 3: expected str instance, Quantity found"
"item 3" is the item at index 3, which is self.value. join requires that every item is converted to a string, so use latex(self.value).
Also I'm not sure, but I think _repr_latex should return a string, not call display().
Ayush Bisht
@ayushbisht2001

With this command python3 -m doctest -v frame.py , I found these error , can anyone help me , why they are failing??

Sidharth Mundhra
@0sidharth
@ayushbisht2001 It looks like you do not have the development version setup properly. I think it is something like you are using sympy 1.7.1 version to run sympy 1.8-dev files
Ayush Bisht
@ayushbisht2001
@0sidharth , how can I update sympy 1.7.1 ?
because, It's not updating further from 1.7.1
! pip install sympy --upgrade
Sidharth Mundhra
@0sidharth
I think you have to go into sympy directory and do pip install -e . in the virtual environment