Refine module

August 17, 2009
By

(This article was originally published at I say things, and syndicated at StatsBlogs.)

This commit introduced a new module in sympy: the refine module. The purpose of this module is to simplify expressions when they are bound to assumptions. For example, if you know that x>0, then you can simplify abs(x) to x. This code was traditionally embedded into the core, but now this will be part of an external module (sympy.refine) upon which the core has no dependencies. In a not very original move, I named the main function in this module refine(). It's syntax is very straightforward: first argument is an expression and second argument are assumptions. Some examples (from isympy): In [1]: refine(1+abs(x), Assume(x, Q.positive)) Out[1]: 1 + x In [2]: refine(exp(I*x*pi), Assume(x, Q.odd)) Out[2]: -1 In [3]: refine(exp(I*x*pi), Assume(x, Q.even)) Out[3]: 1 Right now the module lacks some rules, but the design (very similar to the query module) will make adding these rules an easy task.



Please comment on the article here: I say things


Subscribe

Email:

  Subscribe