← Back to team overview

aesthete-team team mailing list archive

Re: mpmath related diffs

 

Phil Weir wrote:


The mpmath library should never be preferred if functions are available
for both - it should be called as a matter of last resort. That was the aim
of the try-except - to convert to numbers any symbol that mpmath didn't
like, to allow the calculation to continue. It's a bit of a blunderbuss
right now, in that if there's only one bit out of many that mpmath doesn't
like, the whole thing is converted. Ideally we should be converting only
the symbols that mpmath functions are accessing.

I've just moved the sympy globals in reorder_globals to the end of the
globals dictionary update loop, so they'll overwrite any functions they
come across. That seems to fix it for me and, in theory, any mpmath
function that is not in sympy will appear as normal, trigger an exception,
and get handed the mpmathified version of the arguments. As you say,
ideally we could pick out the bits that need converted, though I suspect
anything that doesn't need converted will pass through unchanged anyhow
(e.g. acceptable python and sympy types)

In short, give it a whirl!
P

Yes, that seems to work.

Here's one more patch to review - this one allows me to type exciting expressions like -1 and 𝛑/2 into aesthete and not get an error.

I've also attempted uploading some defs to the downpatrick branch - let me know if that's caused any problems.

Chris.
=== modified file 'aesthete/glypher/BinaryExpression.py'
--- aesthete/glypher/BinaryExpression.py	2011-10-26 19:06:26 +0000
+++ aesthete/glypher/BinaryExpression.py	2011-11-08 02:39:41 +0000
@@ -4,6 +4,9 @@
 from ..utils import debug_print
 from PhraseGroup import *
 import sympy.functions.elementary.exponential as i_func
+from sympy import Mul as sympy_mul
+from sympy import Pow as sympy_power
+from sympy.core.numbers import NegativeOne as sympy_negone
 
 from gutils import float_cmp as fcmp
 
@@ -40,7 +43,7 @@
     def get_sympy(self) :
         # apparently how sympy renders negative numbers
         debug_print(self.get_target('expression').get_sympy())
-        return sympy.core.mul.Mul(sympy.core.numbers.NegativeOne(), self.get_target('expression').get_sympy())
+        return sympy_mul(sympy_negone(), self.get_target('expression').get_sympy())
 
 class GlypherCumulativeSuffix(GlypherPhraseGroup) :
     suffix_shape = None
@@ -606,8 +609,8 @@
         for i in range(1, self.get_op_count()) :
             if self.syms[i].to_string() == '-' :
                 signed_args.append(\
-                    sympy.core.mul.Mul(\
-                        sympy.core.numbers.NegativeOne(),\
+                    sympy_mul(\
+                        sympy_negone(),\
                         self.get_target('pos'+str(2*i)).get_sympy()))
             else :
                 signed_args.append(self.get_target('pos'+str(2*i)).get_sympy())
@@ -817,8 +820,8 @@
         self.mes.append('side_fraction')
 
     def get_sympy(self) :
-        return sympy.core.mul.Mul(self.get_target('pos0').get_sympy(),\
-            sympy.core.power.Pow(self.get_target('pos2').get_sympy(), -1))
+        return sympy_mul(self.get_target('pos0').get_sympy(),\
+            sympy_power(self.get_target('pos2').get_sympy(), -1))
 
     def _set_pos_properties(self, pos) :
         GlypherBinaryExpression._set_pos_properties(self, pos)


Follow ups

References