1 """SympyCore - An efficient pure Python Computer Algebra System.
3 See http://sympycore.googlecode.com/ for more information.
5 __docformat__
= "restructuredtext"
7 __author__
= 'Pearu Peterson, Fredrik Johansson'
8 __license__
= 'New BSD License'
10 from .version
import version
as __version__
12 from .core
import classes
, defined_functions
, DefinedFunction
, Expr
, Pair
, IntegerList
13 from .core
import init_module
19 from arithmetic
import *
23 from basealgebra
import *
24 from algebras
import *
27 from calculus
import *
28 from polynomials
import *
29 from matrices
import *
31 from functions
import *
33 CollectingField
= CommutativeRing
35 ### Initialize sympycore subpackage namespaces
38 def profile_expr(expr
):
39 """ Printout the profiler information for executing ``expr``.
42 import hotshot
, hotshot
.stats
43 prof
= hotshot
.Profile("/tmp/sympycore_stones.prof")
44 frame
= sys
._getframe
(1)
51 stats
= hotshot
.stats
.load("/tmp/sympycore_stones.prof")
53 stats
.sort_stats('time','calls','time')
57 # This function is taken from sympy (and originally sage?)
60 var('x y z') creates symbols x, y, z
63 frame
= inspect
.currentframe().f_back
65 if not isinstance(s
, list):
73 frame
.f_globals
[t
] = sym
76 if len(res
) == 0: # var('')
78 elif len(res
) == 1: # var('x')
80 # otherwise var('a b ...')
83 # we should explicitly break cyclic dependencies as stated in inspect
87 FD
= FDFactory(CalculusDifferentialRing
)
88 D
= DFactory(CalculusDifferentialRing
)
90 sin
= CalculusFunctionRing(heads
.CALLABLE
, Sin
)
91 arcsin
= CalculusFunctionRing(heads
.CALLABLE
, ArcSin
)
92 cos
= CalculusFunctionRing(heads
.CALLABLE
, Cos
)
93 tan
= CalculusFunctionRing(heads
.CALLABLE
, Tan
)
94 cot
= CalculusFunctionRing(heads
.CALLABLE
, Cot
)
95 ln
= CalculusFunctionRing(heads
.CALLABLE
, Ln
)
96 log
= CalculusFunctionRing(heads
.CALLABLE
, Log
)
97 exp
= CalculusFunctionRing(heads
.CALLABLE
, Exp
)
104 def test(self
, nose_args
=''):
105 """ Run sympycore tests using nose.
110 #mpmath = sys.modules['sympycore.arithmetic.mpmath']
111 d
= os
.path
.dirname(os
.path
.abspath(__file__
))
112 cmd
= '%s %s %s %s' % (sys
.executable
, nose
.core
.__file
__, d
, nose_args
)
113 print >>sys
.stderr
, 'Running %r' % cmd
116 print >>sys
.stderr
, "TESTS FAILED"
118 def check_testing(self
):
124 if sys
.platform
=='win32':
125 m
= lambda s
: s
.lower()
128 argv2
= [nose
.core
.__file
__, os
.path
.dirname(os
.path
.abspath(__file__
))]
129 if map(m
, sys
.argv
[:2]) == map(m
, argv2
):
132 def show_config(self
):
135 print >>sys
.stderr
, 'Python version: %s' % (sys
.version
.replace('\n',''))
138 minimum_nose_version
= (0,10,0)
141 if nose
.__versioninfo
__ < minimum_nose_version
:
146 msg
= 'Need nose >= %d.%d.%d for tests - see ' \
147 'http://somethingaboutorange.com/mrl/projects/nose' % \
149 raise ImportError(msg
)
151 print >>sys
.stderr
, 'nose version: %d.%d.%d' % nose
.__versioninfo
__
152 print >>sys
.stderr
, 'nose is installed in %s' % (os
.path
.dirname(nose
.__file
__))
154 if 'sympycore.expr_ext' in sys
.modules
:
158 print >>sys
.stderr
, 'sympycore version: %s (%s)' % (__version__
, s
)
159 print >>sys
.stderr
, 'sympycore is installed in %s' % (os
.path
.dirname(__file__
))
161 mpmath
= sys
.modules
['sympycore.arithmetic.mpmath']
162 fn
= os
.path
.join(os
.path
.dirname(mpmath
.__file
__), 'REVISION')
164 backend
= mpmath
.libmp
.backend
.BACKEND
165 l
.append ('backend=%s' % (backend
))
166 if os
.path
.isfile(fn
):
168 l
.append('revision=%s' % (f
.read().strip()))
172 print >>sys
.stderr
, 'mpmath version: %s (%s)' % (mpmath
.__version
__, ', '.join(l
))
173 print >>sys
.stderr
, 'mpmath is installed in %s' % (os
.path
.dirname(mpmath
.__file
__))
177 gmpy
= mpmath
.libmp
.backend
.gmpy
178 print >>sys
.stderr
, 'gmpy version: %s' % (gmpy
.version())
179 print >>sys
.stderr
, 'gmpy is installed in %s' % (os
.path
.dirname(gmpy
.__file
__))
182 test
= _Tester().test