Implemented crisscross algorithm for solving LP problems.
[sympycore.git] / sympycore / __init__.py
blob18c22b5f85688b6aac90b0007291fab07a6e5c71
1 """SympyCore - An efficient pure Python Computer Algebra System.
3 See http://sympycore.googlecode.com/ for more information.
4 """
5 __docformat__ = "restructuredtext"
6 __date__ = '2008'
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
15 import heads
17 init_module.execute()
19 from arithmetic import *
21 from ring import *
23 from basealgebra import *
24 from algebras import *
25 from logic import *
26 from sets import *
27 from calculus import *
28 from polynomials import *
29 from matrices import *
30 from physics import *
31 from functions import *
33 CollectingField = CommutativeRing
35 ### Initialize sympycore subpackage namespaces
36 init_module.execute()
38 def profile_expr(expr):
39 """ Printout the profiler information for executing ``expr``.
40 """
41 import sys
42 import hotshot, hotshot.stats
43 prof = hotshot.Profile("/tmp/sympycore_stones.prof")
44 frame = sys._getframe(1)
45 g = frame.f_globals
46 l = frame.f_locals
47 def foo():
48 exec expr in g,l
49 prof.runcall(foo)
50 prof.close()
51 stats = hotshot.stats.load("/tmp/sympycore_stones.prof")
52 #stats.strip_dirs()
53 stats.sort_stats('time','calls','time')
54 stats.print_stats(40)
55 return stats
57 # This function is taken from sympy (and originally sage?)
58 def var(s):
59 """
60 var('x y z') creates symbols x, y, z
61 """
62 import inspect
63 frame = inspect.currentframe().f_back
64 try:
65 if not isinstance(s, list):
66 s = s.split(" ")
67 res = []
68 for t in s:
69 # skip empty strings
70 if not t:
71 continue
72 sym = Symbol(t)
73 frame.f_globals[t] = sym
74 res.append(sym)
75 res = tuple(res)
76 if len(res) == 0: # var('')
77 res = None
78 elif len(res) == 1: # var('x')
79 res = res[0]
80 # otherwise var('a b ...')
81 return res
82 finally:
83 # we should explicitly break cyclic dependencies as stated in inspect
84 # doc
85 del frame
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)
99 class _Tester:
101 def __init__(self):
102 self.check_testing()
104 def test(self, nose_args=''):
105 """ Run sympycore tests using nose.
107 import os
108 import sys
109 import 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
114 s = os.system(cmd)
115 if s:
116 print >>sys.stderr, "TESTS FAILED"
118 def check_testing(self):
119 import os, sys
120 try:
121 import nose
122 except ImportError:
123 return
124 if sys.platform=='win32':
125 m = lambda s: s.lower()
126 else:
127 m = lambda s: s
128 argv2 = [nose.core.__file__, os.path.dirname(os.path.abspath(__file__))]
129 if map(m, sys.argv[:2]) == map(m, argv2):
130 self.show_config()
132 def show_config(self):
133 import os, sys
135 print >>sys.stderr, 'Python version: %s' % (sys.version.replace('\n',''))
137 nose = None
138 minimum_nose_version = (0,10,0)
139 try:
140 import nose
141 if nose.__versioninfo__ < minimum_nose_version:
142 nose = None
143 except:
144 pass
145 if nose is None:
146 msg = 'Need nose >= %d.%d.%d for tests - see ' \
147 'http://somethingaboutorange.com/mrl/projects/nose' % \
148 minimum_nose_version
149 raise ImportError(msg)
150 else:
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:
155 s = 'compiled'
156 else:
157 s = 'pure'
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')
163 l = []
164 backend = mpmath.libmp.backend.BACKEND
165 l.append ('backend=%s' % (backend))
166 if os.path.isfile(fn):
167 f = open(fn, 'r')
168 l.append('revision=%s' % (f.read().strip()))
169 f.close()
170 else:
171 rev = ''
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__))
176 if backend=='gmpy':
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
183 del _Tester