sympy/sympy_gamma

Subversion checkout URL

You can clone with
or
.

Implemented MathJax usage.

commit 2db482dd8623ea3152ebd1934c593024bf907f6f 1 parent e87765b
dekozo authored
32 app/logic/logic.py
 @@ -1,5 +1,5 @@ from utils import Eval -from sympy import pprint +from sympy import latex, series, sympify, solve, Derivative, Integral, Symbol, diff, integrate class SymPyGamma(object): @@ -19,7 +19,7 @@ def try_sympy(self, s): # change to True to spare the user from exceptions: if not len(s): return - r = a.eval(u'pprint(%s)' % s, use_none_for_exceptions=False) + r = a.eval(s, use_none_for_exceptions=False) if r is not None: result = [ {"title": "Input", "input": s}, @@ -33,7 +33,7 @@ def try_sympy(self, s): result = %s else: result = None -pprint(result) +result """ var = a.eval(code % (s, 'x'), use_none_for_exceptions=True) # Come up with a solution to use all variables if more than 1 @@ -41,7 +41,7 @@ def try_sympy(self, s): line = "simplify(%s)" simplified = a.eval(line % s, use_none_for_exceptions=True) r = a.eval(code % (s, line % s), use_none_for_exceptions=True) - if simplified and simplified != "None" and simplified.replace(" ", "") != s: + if simplified != "None" and simplified != s: result.append( {"title": "Simplification", "input": simplified, "output": r}) @@ -49,32 +49,34 @@ def try_sympy(self, s): var = var.replace("None", "").replace("\n", "") if len(var): line = "solve(%s, {_var})".format(_var=var) - r = a.eval(code % (s, (line % s)), use_none_for_exceptions=True) + r = sympify(a.eval(code % (s, (line % s)), use_none_for_exceptions=True)) if r and r != "None": result.append( {"title": "Roots", "input": line % simplified, - "output": r}) + "pre_output": latex(var), "output": latex(r)}) + line = "diff(%s, {_var})".format(_var=var) - r = a.eval(code % (s, line % s), use_none_for_exceptions=True) + r = sympify(a.eval(code % (s, line % s), use_none_for_exceptions=True)) if r and r != "None": result.append( {"title": "Derivative", "input": (line % simplified), - "output": r}) + "pre_output": latex(Derivative(s, Symbol(var))), + "output": latex(r)}) + line = "integrate(%s, {_var})".format(_var=var) - r = a.eval(code % (s, line % s), use_none_for_exceptions=True) + r = sympify(a.eval(code % (s, line % s), use_none_for_exceptions=True)) if r and r != "None": result.append( {"title": "Indefinite integral", "input": line % simplified, - "output": r}) + "pre_output": latex(Integral(s,Symbol(var))), + "output": latex(r)}) + line = "series(%s, {_var}, 0, 10)".format(_var=var) - r = a.eval(code % (s, line % s), use_none_for_exceptions=True) + r = sympify(a.eval(code % (s, line % s), use_none_for_exceptions=True)) if r and r != "None": result.append( {"title": "Series expansion around 0", "input": line % simplified, - "output": r}) - for item in result: - for k in item: - item[k] = item[k].replace('None', '') + "output": latex(r)}) return result else: return None
2  media/css/style.css
 @@ -151,7 +151,7 @@ div.cell_input { div.cell_output { color: black; - font-size:8pt; + font-size:20pt; margin: 10px; border: 1px solid #a8a8a8; }
23 templates/base.html
 @@ -11,6 +11,29 @@ + +
61 templates/result.html
 @@ -1,34 +1,37 @@ {% extends "base.html" %} + {% block title %} + SymPy Gamma + {% endblock %} -{% block title %} -SymPy Gamma -{% endblock %} - -{% block content %} -
-
- {{ form.i }} - - -
-
- {% for cell in result %} -
-
- {{ cell.title }}: -
-
-
{{ cell.input }}
-
- {% if cell.output %} -
-
{{ cell.output }}
+ {% block content %} +
+
+ {{ form.i }} + + +
+
+ {% for cell in result %} +
+
+ {{ cell.title }}: +
+
+
{{ cell.input }}
- {% endif %} + {% if cell.output %} +
+ {% if cell.pre_output %} + {{ cell.pre_output }} = + {% endif %} + {{ cell.output }} + +
+ {% endif %} +
+ {% endfor %} + - {% endfor %} - -
+
{% endblock %}