Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: sympy Date: Thu, 31 Mar 2016 16:55:58 +0200 Organization: None Lines: 71 Message-ID: References: <733f5f0d-9b4e-4023-897b-e1f2730c39cb@googlegroups.com> <56fbcd01$0$1599$c3e8da3$5496439d@news.astraweb.com> <99b7cf43-50ff-4de7-8de0-e324658682bf@googlegroups.com> <56fbf7e7$0$1591$c3e8da3$5496439d@news.astraweb.com> <244e1277-e105-4419-a449-7f2012c6d78e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de Di78Q2ZKOV2F+737ugxEsQLPb9QgiAbj3ryMS+wkXEPw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'below).': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'def': 0.13; 'thu,': 0.15; '2016': 0.16; 'evaluations': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'value:': 0.16; 'wrote:': 0.16; 'numerical': 0.18; 'foundation': 0.19; '>>>': 0.20; 'am,': 0.23; 'seems': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X -Complaints-To:1': 0.26; 'define': 0.27; 'function': 0.28; 'values': 0.28; 'calculated': 0.29; 'way?': 0.29; "i'm": 0.30; 'guess': 0.31; 'point': 0.33; 'steven': 0.33; 'skip:- 10': 0.34; 'next': 0.35; 'done': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'wanted': 0.37; 'skip:x 10': 0.40; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'some': 0.40; 'more': 0.63; 'times': 0.63; 'mar': 0.65; '10000': 0.66; 'evaluate': 0.72; "d'aprano:": 0.84; 'wanted,': 0.84; 'glad': 0.87 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd993c.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:106164 Poul Riis wrote: > Den onsdag den 30. marts 2016 kl. 17.59.49 UTC+2 skrev Steven D'Aprano: >> On Thu, 31 Mar 2016 02:23 am, Poul Riis wrote: >> >> > What I intend to do is to let sympy find the derivative of some >> > welldefined function and next define the foundation derivative as a >> > normal function so that I can calculate numerical values or even make a >> > graph. >> >> >> I'm glad you explained what you *actually* wanted, because I was going to >> guess that you wanted to evaluate the derivative at x = 3: >> >> >> py> ftext.evalf(subs={x:3}) >> -0.0600000000000000 >> >> >> >> -- >> Steven > > ... However, the sympy way seems to be about 70 times slower than using > the derivative calculated 'by hand' (try the example below). Can it be > done in a more efficient way? Hm, the two functions fmsympy() and fm() do not return the same value: $ python -i sympy_diff.py 10000 evaluations with sympy : dt1 = 0.7178411483764648 10000 evaluations without sympy: dt2 = 0.10177111625671387 >>> fm(42) cos(42) >>> fmsympy(42) -0.399985314988351 What's the point of that benchmark? > Poul Riis > > > > from sympy import * > from time import * > x=Symbol('x') > ftext=diff(sin(x),x) > > def fmsympy(t): > return ftext.evalf(subs={x:t}) > > def fm(t): > return cos(t) > > nloop=10000 > tstart=time() > # nloop evaluations with sympy > for i in range(0,nloop): > a=fmsympy(1) > dt1=time()-tstart > > # nloop evaluations without sympy > tstart=time() > for i in range(0,nloop): > a=fm(1) > dt2=time()-tstart > > print(nloop,' evaluations with sympy : dt1 =',dt1) > print(nloop,' evaluations without sympy: dt2 =',dt2)