aesthete-team team mailing list archive
-
aesthete-team team
-
Mailing list archive
-
Message #00026
Making Downpatrick work in Fedora
Hi all,
Please find attached a largish patch, which should allow basic Aesthete
functionality on an computer running Fedora 15 with the latest sympy
(0.7.1). Also included is work towards getting sec() and the like working.
Summary of changes:
* Work around the fact that the thirdparty module no longer seems to
work for importing pyglet
* Many sympy.*.*.<function> calls no longer seem to work, so do imports
of these functions - some of these (sympify, Basic for instance) are
repeated across several files, so maybe something could be done about
that...
* Include mpmath in Dynamic.py to allow calls to mpmath.sec and the
like. I've only included a sec defs file at this stage.
The main problem with sec currently is it doesn't like sec(𝛑) - it produces
TypeError: cannot create mpf from pi
It seems to work otherwise, and it will evaluate sec(pi) when run in
isympy (after `from mpmath import *' of course).
Some of these changes may break 0.6.7 sympy, so take care.
Chris.
=== modified file 'aesthete/glypher/Dynamic.py'
--- aesthete/glypher/Dynamic.py 2011-10-30 23:57:07 +0000
+++ aesthete/glypher/Dynamic.py 2011-10-31 21:53:34 +0000
@@ -1,5 +1,6 @@
from sympy import *
import sympy
+from mpmath import *
from sympy.series import limits
import glypher as g
from ..utils import *
=== modified file 'aesthete/glypher/Fraction.py'
--- aesthete/glypher/Fraction.py 2011-10-26 05:24:37 +0000
+++ aesthete/glypher/Fraction.py 2011-10-31 21:34:32 +0000
@@ -6,6 +6,7 @@
from Function import *
import BinaryExpression
import sympy
+from sympy.core import sympify
class GlypherFraction(GlypherPhraseGroup) :
bodmas_level = 0
@@ -125,7 +126,7 @@
GlypherPhraseGroup.child_change(self)
self.make_simplifications()
-a_half = sympy.core.sympify("1/2")
+a_half = sympify("1/2")
class GlypherSqrt(GlypherCompoundPhrase) :
bodmas_level = 0
degree = None
=== modified file 'aesthete/glypher/Function.py'
--- aesthete/glypher/Function.py 2011-10-30 23:57:07 +0000
+++ aesthete/glypher/Function.py 2011-10-31 21:48:47 +0000
@@ -3,6 +3,7 @@
from Word import *
from BinaryExpression import *
from Decoration import *
+from sympy.core.function import *
auto_bracket_funcs = \
[ 'cos', 'sin', 'tan',
@@ -135,7 +136,7 @@
return self.get_sympy_func()(*args)
else :
debug_print('x')
- f = sympy.core.function.Function(str(self.get_target('name').to_string()))
+ f = Function(str(self.get_target('name').to_string()))
return f(*args)
except RuntimeError as e :
debug_print(e)
@@ -155,7 +156,7 @@
name_sympy = None
if name_sympy is not None and \
- isinstance(name_sympy, sympy.core.function.Lambda) :
+ isinstance(name_sympy, Lambda) :
self.set_sympy_func(name_sympy)
else :
if name_sympy in function_translation :
=== modified file 'aesthete/glypher/InterpretBackend.py'
--- aesthete/glypher/InterpretBackend.py 2011-10-26 04:39:00 +0000
+++ aesthete/glypher/InterpretBackend.py 2011-10-31 21:45:27 +0000
@@ -1,6 +1,9 @@
import time
from sympy.printing.mathml import mathml
from sympy.matrices import matrices
+from sympy.core.basic import Basic
+from sympy.core.relational import Equality
+from sympy.core import sympify
from ..utils import debug_print
import xml.etree.ElementTree as ET
from ComplexPlane import *
@@ -96,9 +99,9 @@
def _generic_to_entity(parent, node) :
debug_print(str(node))
- if isinstance(node, sympy.core.basic.Basic) or \
+ if isinstance(node, Basic) or \
isinstance(node, matrices.Matrix) or \
- isinstance(node, sympy.core.relational.Equality) :
+ isinstance(node, Equality) :
try :
content = mathml(node)
except :
@@ -342,7 +345,7 @@
return frac
else :
try :
- syop = sympy.core.sympify(operation)
+ syop = sympify(operation)
except :
syop = sympy.core.basic.Symbol(str(operation))
args_match = syop in g.define_functions
@@ -351,7 +354,7 @@
args_match = args_match and \
arguments[i].tag == 'ci' and \
g.define_functions[syop][i] == \
- sympy.core.sympify(arguments[i].text)
+ sympify(arguments[i].text)
if args_match :
return make_word(operation, parent)
@@ -411,7 +414,7 @@
# 'Sigma')
# return p
elif node.tag == 'cn' :
- num = sympy.core.sympify(node.text)
+ num = sympify(node.text)
word = make_word(unicode(abs(num)), parent)
if num < 0 :
neg = GlypherNegative(parent)
@@ -508,7 +511,7 @@
return neg
elif isinstance(ex, sympy.core.numbers.Infinity) :
return make_word(u'\u221e', parent)
- elif isinstance(ex, sympy.core.relational.Equality) :
+ elif isinstance(ex, Equality) :
return GlypherEquality(parent,
lhs=_sympy_to_entity(parent, ex.args[0]),
rhs=_sympy_to_entity(parent, ex.args[1]))
=== modified file 'aesthete/glypher/Plot.py'
--- aesthete/glypher/Plot.py 2011-10-31 04:56:29 +0000
+++ aesthete/glypher/Plot.py 2011-10-31 21:54:50 +0000
@@ -2,11 +2,14 @@
import gtk
import threading
import gobject
-from sympy.thirdparty import import_thirdparty
try :
- import pyglet
+ from sympy.thirdparty import import_thirdparty
+ pyglet = import_thirdparty("pyglet")
except :
- pyglet = import_thirdparty("pyglet")
+ try :
+ import pyglet
+ except :
+ sys.exit("Aesthete currently requires pyglet")
import pyglet.app as pyga
from sympy.plotting import plot, managed_window
from ..sims import FunctionSource
=== modified file 'aesthete/glypher/Word.py'
--- aesthete/glypher/Word.py 2011-10-30 23:57:07 +0000
+++ aesthete/glypher/Word.py 2011-10-31 21:49:55 +0000
@@ -5,6 +5,9 @@
from Phrase import *
from Symbol import *
from sympy import physics
+from sympy.core.symbol import Symbol as sySymbol
+from sympy.core.basic import Basic
+from sympy.core.numbers import *
import Decoration
class GlypherWord (GlypherPhrase) :
@@ -94,7 +97,7 @@
if me_str is None :
sym = sympy.sympify(self.to_string())
else :
- sym = sympy.core.symbol.Symbol(str(me_str))
+ sym = sySymbol(str(me_str))
if sub and sym in g.var_table :
sym = g.var_table[sym]
@@ -102,7 +105,7 @@
sym = g.define_symbols[sym]
return sym
- #return sympy.core.symbol.Symbol(self.to_string("sympy"))
+ #return sySymbol(self.to_string("sympy"))
def draw(self, cr) :
try :
@@ -153,26 +156,26 @@
symp = None
# If we have a Let function, show it up
- if symp and isinstance(symp, sympy.core.basic.Basic) and \
+ if symp and isinstance(symp, Basic) and \
symp in g.let_functions :
if not self.let_function :
self.let_function = True
self.set_bold(True)
self.set_rgb_colour((0.5, 0.2, 0.5))
# If we have a Define function, show it up
- elif symp and isinstance(symp, sympy.core.basic.Basic) and \
+ elif symp and isinstance(symp, Basic) and \
symp in g.define_functions :
if not self.defined_function :
self.defined_function = True
self.set_bold(True)
self.set_rgb_colour((0.2, 0.4, 0.4))
- elif symp and isinstance(symp, sympy.core.basic.Basic) and \
+ elif symp and isinstance(symp, Basic) and \
symp in g.define_symbols and \
isinstance(g.define_symbols[symp], sympy.core.symbol.Wild) :
if not self.wildcard :
self.wildcard = True
self.set_rgb_colour((0.8, 0.6, 0.0))
- elif symp and isinstance(symp, sympy.core.basic.Basic) and \
+ elif symp and isinstance(symp, Basic) and \
symp in g.define_symbols :
if not self.defined_symbol :
self.defined_symbol = True
@@ -334,7 +337,7 @@
constants['pi'] = lambda p : GlypherConstant.new_from_symbol(p, 'pi',
u'\u03c0',
- sympy.core.numbers.Pi(),
+ Pi(),
italicize=False)
constants['infinity'] = lambda p : GlypherConstant.new_from_symbol(p,
'infinity',
=== modified file 'aesthete/glypher/glypher.py'
--- aesthete/glypher/glypher.py 2011-10-26 21:54:34 +0000
+++ aesthete/glypher/glypher.py 2011-10-31 21:37:28 +0000
@@ -1,5 +1,11 @@
import re
import sympy
+from sympy.core.numbers import Infinity
+from sympy.core.numbers import ImaginaryUnit
+try:
+ from sympy.polys.factortools import factor # 0.6.7
+except:
+ from sympy.polys.polytools import factor # 0.7.1
import os
import codecs
@@ -93,8 +99,8 @@
is_floating_point_num_regex = '[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?'
sympy_specials = {
- u'\u221e' : sympy.core.numbers.Infinity(),
- 'i' : sympy.core.numbers.ImaginaryUnit()
+ u'\u221e' : Infinity(),
+ 'i' : ImaginaryUnit()
}
suggested_target_phrased_to = None
@@ -162,7 +168,7 @@
import Commands as C
operation_commands = {
- 'Factor' : sympy.polys.factortools.factor,
+ 'Factor' : factor,
}
commands = { 'Set' : C.set_equal, 'Differentiate' : C.diff, 'Substitute' : C.sub, 'Expand' : C.series, 'Evaluate' : C.evalf, 'Limit' : C.limit,
'S' : C.set_equal, 'Di' : C.diff, 'Sub' : C.sub,
=== added file 'defs/sec.xml'
--- defs/sec.xml 1970-01-01 00:00:00 +0000
+++ defs/sec.xml 2011-10-31 22:04:24 +0000
@@ -0,0 +1,9 @@
+<sec type="trig_function" name="sec" auto_bracket="True" title="sec(ð)" mathml='sec'>
+ <info>Secant of an angle</info>
+ <wiki>Secant</wiki>
+ <latex>"\sec "+self["args"].to_latex()</latex>
+ <sympy>sec(*args)</sympy>
+ <sympy_inverse>asec(*args)</sympy_inverse>
+ <symbol>sec(ð)</symbol>
+ <category>Trigonometry</category>
+</sec>
Follow ups