Permalink
Browse files

Cython integration

  • Loading branch information...
1 parent 9ce1e33 commit 6a0f45ab5257b3901a0ca390f0a09a97da56a4f7 @poeschko poeschko committed Mar 18, 2011
Showing with 1,220 additions and 565 deletions.
  1. +14 −0 README.rdoc
  2. +4 −0 distribute_setup.py
  3. +22 −0 initialize.py
  4. +1 −1 mathics/Makefile
  5. +24 −16 mathics/builtin/__init__.py
  6. +9 −2 mathics/builtin/arithmetic.py
  7. +1 −0 mathics/builtin/base.py
  8. +15 −6 mathics/builtin/calculus.py
  9. +1 −1 mathics/builtin/numeric.py
  10. +74 −60 mathics/builtin/patterns.py
  11. +35 −14 mathics/builtin/plot.py
  12. +2 −1 mathics/builtin/randomnumbers.py
  13. +28 −5 mathics/builtin/structure.py
  14. +7 −1 mathics/core/convert.py
  15. +7 −3 mathics/core/evaluation.py
  16. +47 −10 mathics/core/expression.py
  17. +1 −1 mathics/core/numbers.py
  18. +3 −2 mathics/core/parser.py
  19. +377 −0 mathics/core/pattern.py
  20. +82 −0 mathics/core/pattern_nocython.py
  21. +44 −315 mathics/core/rules.py
  22. +0 −7 mathics/doc/Makefile
  23. +6 −2 mathics/doc/doc.py
  24. +9 −1 mathics/doc/documentation/1-Manual.mdoc
  25. +15 −0 mathics/doc/tex/Makefile
  26. BIN mathics/doc/tex/logo.pdf
  27. +232 −0 mathics/doc/tex/mathics.tex
  28. +11 −0 mathics/doc/tex/prepare_latex.py
  29. +2 −4 mathics/optional/__init__.py
  30. +17 −15 mathics/optional/calculus.py
  31. +1 −1 mathics/server.py
  32. +12 −6 mathics/settings.py
  33. +36 −22 mathics/web/media/css/styles.css
  34. BIN mathics/web/media/img/menu_default.gif
  35. BIN mathics/web/media/img/menu_hover.gif
  36. BIN mathics/web/media/img/menu_inverted.gif
  37. BIN mathics/web/media/img/menu_inverted_hover.gif
  38. +2 −2 mathics/web/media/js/authentication.js
  39. +1 −1 mathics/web/media/js/doc.js
  40. +4 −23 mathics/web/media/js/inout.js
  41. +1 −0 mathics/web/media/js/mathics.js
  42. +1 −1 mathics/web/models.py
  43. +16 −9 mathics/web/templates/base.html
  44. +38 −26 mathics/web/views.py
  45. +5 −0 release.sh
  46. +13 −7 setup.py
View
@@ -0,0 +1,14 @@
+== Welcome to Mathics!
+
+Mathics is a general-purpose computer algebra system (CAS). It is meant to be a free, light-weight alternative to Mathematica with support for Sage.
+
+The homepage of Mathics is at http://www.mathics.org, where you can find installation instructions.
+There is also a server to use Mathics online at http://www.mathics.net.
+
+== Contributing
+
+Please feel encouraged to contribute to Mathics! Create your own fork, make the desired changes, commit, and make a pull request.
+
+== License
+
+Mathics is released under the GNU General Public License (GPL).
View
@@ -161,6 +161,10 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
return _do_download(version, download_base, to_dir,
download_delay)
except pkg_resources.DistributionNotFound:
+ # ADDED
+ # according to http://code.activestate.com/lists/python-distutils-sig/16213/
+ # (problem in Ubuntu 10.04)
+ del pkg_resources, sys.modules['pkg_resources']
return _do_download(version, download_base, to_dir,
download_delay)
finally:
View
@@ -0,0 +1,22 @@
+"""
+Creates the database used by Django
+"""
+
+import os
+from os import path
+import subprocess
+
+from mathics import settings
+
+def setup():
+ print "Creating data directory %s" % settings.DATA_DIR
+ if not path.exists(settings.DATA_DIR):
+ os.makedirs(settings.DATA_DIR)
+ print "Creating database %s" % settings.DATABASE_NAME
+ subprocess.call(['python', 'mathics/manage.py', 'syncdb', '--noinput'])
+ os.chmod(settings.DATABASE_NAME, 0766)
+ print ""
+ print "Mathics initialized successfully."
+
+if __name__ == '__main__':
+ setup()
View
@@ -1,5 +1,5 @@
put:
- rsync -av builtin core doc optional web __init__.py main.py manage.py profile.py server.py test.py tests.py urls.py --exclude "*.pyc" --exclude ".DS_Store" --exclude "web/db" --exclude "doc/tex" jan@mathics.net:/home/jan/mathics
+ rsync -av builtin core doc optional web __init__.py main.py manage.py profile.py server.py test.py tests.py urls.py --exclude "*.pyc" --exclude ".DS_Store" --exclude ".*" --exclude "web/db" --exclude "doc/tex" jan@mathics.net:/home/jan/mathics
restart:
ssh -t mathics.net "sudo siteadmin jan mathics restart"
@@ -52,7 +52,7 @@ def is_builtin(var):
builtins.append((instance.get_name(), instance))
builtins_by_module[module.__name__].append(instance)
-builtins = dict(builtins)
+#builtins = dict(builtins)
mathics_to_sage = {}
sage_to_mathics = {}
@@ -63,21 +63,29 @@ def is_builtin(var):
pattern_objects = {}
builtins_precedence = {}
-for builtin in builtins.values():
- name = builtin.get_name()
- if isinstance(builtin, SageObject):
- mathics_to_sage[name] = builtin
- if builtin.sage_name:
- sage_to_mathics[builtin.sage_name] = builtin
- mathics_to_sympy[name] = builtin
- if builtin.sympy_name:
- sympy_to_mathics[builtin.sympy_name] = builtin
- if isinstance(builtin, BoxConstruct):
- box_constructs[name] = builtin
- if isinstance(builtin, Operator):
- builtins_precedence[name] = builtin.precedence
- if isinstance(builtin, PatternObject):
- pattern_objects[name] = builtin.__class__
+def add_builtins(new_builtins):
+ for var_name, builtin in new_builtins:
+ name = builtin.get_name()
+ if isinstance(builtin, SageObject):
+ mathics_to_sage[name] = builtin
+ if builtin.sage_name:
+ sage_to_mathics[builtin.sage_name] = builtin
+ for sage_name in builtin.sage_names_alt:
+ sage_to_mathics[sage_name] = builtin
+ mathics_to_sympy[name] = builtin
+ if builtin.sympy_name:
+ sympy_to_mathics[builtin.sympy_name] = builtin
+ if isinstance(builtin, BoxConstruct):
+ box_constructs[name] = builtin
+ if isinstance(builtin, Operator):
+ builtins_precedence[name] = builtin.precedence
+ if isinstance(builtin, PatternObject):
+ pattern_objects[name] = builtin.__class__
+ builtins.update(dict(new_builtins))
+
+new_builtins = builtins
+builtins = {}
+add_builtins(new_builtins)
def get_module_doc(module):
doc = module.__doc__
@@ -571,7 +571,7 @@ def apply(self, items, evaluation):
elif x.has_form('Power', 2) and isinstance(y, Integer):
return Expression('Power', x.leaves[0], Expression('Times', x.leaves[1], y))
elif x.has_form('Times', None) and isinstance(y, Integer):
- return Expression('Times', *(Expression('Power', leaf, y) for leaf in x.leaves))
+ return Expression('Times', *[Expression('Power', leaf, y) for leaf in x.leaves])
elif isinstance(x, (Rational, Integer)) and isinstance(y, Integer):
if y.value >= 0:
@@ -596,7 +596,7 @@ def apply(self, items, evaluation):
return result
else:
if x.value == 0:
- evluation.message('Power', 'infy')
+ evaluation.message('Power', 'infy')
return Symbol('ComplexInfinity')
else:
return Number.from_mp(mpz(1).qdiv(x.value ** (-y.value)))
@@ -797,6 +797,10 @@ class Abs(SageFunction):
= -Graphics-
"""
+ sage_name = 'abs_symbolic'
+ sage_names_alt = ['abs']
+ sympy_name = 'abs'
+
def apply_real(self, x, evaluation):
'Abs[x_?RealNumberQ]'
@@ -1013,6 +1017,9 @@ class Sum(_IterationFunction):
>> Sum[k, {k, I, I + 1}]
: Iterator does not have appropriate bounds.
= Sum[k, {k, I, I + 1, 1}]
+
+ #> a=Sum[x^k*Sum[y^l,{l,0,4}],{k,0,4}]]
+ : Parse error at or near token ].
"""
def get_result(self, items):
View
@@ -348,6 +348,7 @@ def apply(self, expr, evaluation):
class SageObject(Builtin):
sage_name = None
+ sage_names_alt = []
sympy_name = None
def __init__(self, *args, **kwargs):
@@ -223,24 +223,19 @@ class Derivative(PostfixOperator, SageFunction):
'Derivative[n__Integer][Derivative[m__Integer][f_]] /; Length[{m}] == Length[{n}]':
'Derivative[Sequence @@ ({n} + {m})][f]',
"""Derivative[n__Integer][f_Symbol] /; Module[{t=Sequence@@Slot/@Range[Length[{n}]], result, nothing, ft=f[t]},
- (*Print["Check symbol ", f];*)
- (*If[f[t] === Flatten[Unevaluated[f[t]], Sequence]*)
- (*If[f[t] === Unevaluated[f[t]]*)
If[Head[ft] === f
&& FreeQ[Join[UpValues[f], DownValues[f], SubValues[f]], Derivative|D]
&& Context[f] != "System`",
False,
(* else *)
ft = f[t];
- (*Print["Try D of ", ft];*)
Block[{f},
Unprotect[f];
(*Derivative[1][f] ^= nothing;*)
Derivative[n][f] ^= nothing;
Derivative[n][nothing] ^= nothing;
result = D[ft, Sequence@@Table[{Slot[i], {n}[[i]]}, {i, Length[{n}]}]];
];
- (*Print[result, ", ", nothing];*)
FreeQ[result, nothing]
]
]""":
@@ -351,6 +346,9 @@ class Integrate(SageFunction):
#> Integrate[x ^ 3.5 + x, x]
= x ^ 2 / 2 + 0.222222222222222 x ^ 4.5
+
+ #> Integrate[Abs[Sin[phi]],{phi,0,2Pi}]//N
+ = 3.99998451720248
"""
"""
@@ -364,6 +362,7 @@ class Integrate(SageFunction):
attributes = ('ReadProtected',)
+ sage_name = ''
sympy_name = 'Integral'
messages = {
@@ -416,13 +415,21 @@ def apply(self, f, xs, evaluation):
f_sympy = f.to_sympy()
xs = xs.get_sequence()
vars = []
+ prec = None
for x in xs:
if x.has_form('List', 3):
x, a, b = x.leaves
+ prec_a = a.get_precision()
+ prec_b = b.get_precision()
+ if prec_a is not None and prec_b is not None:
+ prec_new = min(prec_a, prec_b)
+ if prec is None or prec_new < prec:
+ prec = prec_new
a = a.to_sympy()
b = b.to_sympy()
else:
a = b = None
+ a_mathics, b_mathics = a, b
if not x.get_name():
evaluation.message('Integrate', 'ilim')
return
@@ -431,11 +438,13 @@ def apply(self, f, xs, evaluation):
vars.append(x)
else:
vars.append((x, a, b))
- #print f_sympy
try:
result = sympy.integrate(f_sympy, *vars)
except sympy.PolynomialError:
return
+
+ if prec is not None:
+ result = sympy.N(result)
result = from_sympy(result)
return result
@@ -109,7 +109,7 @@ def apply_other(self, expr, prec, evaluation):
if valid_prec is not None:
if expr.get_head_name() in ('List', 'Rule'):
- return Expression(expr.head, *(self.apply_other(leaf, prec, evaluation) for leaf in expr.leaves))
+ return Expression(expr.head, *[self.apply_other(leaf, prec, evaluation) for leaf in expr.leaves])
if isinstance(expr, Number):
return expr.round(valid_prec)
Oops, something went wrong.

0 comments on commit 6a0f45a

Please sign in to comment.