| I tried to write a little differentiatior: one my one year old macbook i need to wait more than 17 second to get the following answer why does it that long? |
| The previous answers (with the exception of Nils Bruin's) are incorrect in their assessment of the problem -- the slowdown is indeed coming from trying to decide whether "x == tan(x)" is True or False. In particular, the slowdown comes a lot from our overhead in talking to Maxima. Sage performs the following things when trying to test whether an equation is zero or not.
There are a number of areas for improvement:
I will make tickets for these and add the links to them here.
thank you!
Philipp Schneider (Aug 27 '10) |
| the problem is neither Python, nor recursion, but Sage expressions. If I replace those with lists and strings the computation time drops to 0: Now: |
| One obvious thing is that the wall time is considerably longer than the cpu-time. That can mean your process didn't get 100% of the CPU time or that Sage called out to a different process (maxima?) to get some results. Indeed, if you run: you'll find 4995 calls to indicating that there were 4995 calls to another process. There are also various calls to various "simplify" routines, so either in construction or in comparison of symbolic expressions, Sage did feel the need to simplify things. In short: If you want to do pattern matching on symbolic expressions, do not use "==". It is apparently already reserved for a fairly expensive equality test. I am surprised that this program still triggers calls out to maxima. I don't think it's "reduce", since that only receives 18 calls and takes negligible time in the profile. All the other operations, including "==" should really map to straight pynac operations. |
| This is more like a comment to Mike's answer, but it's rather long and I don't see how to add code to comments, so I'll put it here. A workaround to check if an expression is trivially equal to another is to use This is very fast: Here is the Now I get: Note that speeding up symbolic comparison is #6799 on trac. |
| Because pure python is slow. No offense but why would you want to do this? Symbolic calculations are usually done with pynac (C++ wrapped into Sage) or Maxima (40 year old optimized Lisp wrapped into Sage). If you want something about symbolic differentiation improved you should contribute to those projects. What do you need that isn't already there? For your example on my computer: gives |
| technically, apart from mhamptons comment, there are two problems: (I've just briefly looked at the code and maybe I didn't understand it)
|
| @mhampton i don't wont to write the next best differentiator in the world. I'm just trying to give an example on how to program with symbolic expressions in sage. @harald sorry, i should change the line into then no ripping apart and reconstruction occurs. (I was trying to mimic pattern matching.) Still, this doesn't help much. Does anybody know how Sage tests equality of symbolic expressions? Does it try to simplify those each time before it compares them? |
Asked: Aug 26 '10
Seen: 459 times
Last updated: Aug 28 '10
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.