pearu / sympycore

Automatically exported from code.google.com/p/sympycore
Other
10 stars 1 forks source link

Parsing %/mod in Calculus and mod vs Mod conventions. #60

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Currently when one inputs:

    Calculus('x%2')

one gets the exception:

.../sympycore/basealgebra/algebra.py in
handle_get_operand_algebra_failure(cls, head, index)
    146     @classmethod
    147     def handle_get_operand_algebra_failure(cls, head, index):
--> 148         raise TypeError('Cannot convert %s-th %s operand to %s
algebra' % (index, head_to_string.get(head, head), cls.__name__))
    149 
    150     @classmethod

TypeError: Cannot convert 0-th MOD operand to Calculus algebra

Based on the stacktrace I tried changing basealgebra/pairs.py:

-        if head in [ADD, SUB, DIV, MUL, NEG, POS]:
+        if head in [ADD, SUB, DIV, MUL, NEG, POS, MOD]:

After this change the exception turns to:

.../sympycore/calculus/algebra.py in Mod(cls, x, y)
    128     @classmethod
    129     def Mod(cls, x, y):
--> 130         return defined_functions.mod(x, y)
    131 
    132     def evalf(self, n=None):

AttributeError: Holder instance has no attribute 'mod'

Inspection with pdb.pm() shows that defined_functions
has an attribute 'Mod', but not 'mod', and that most
attributes are capitalized. Since I see a number of
uses of defined_function.foo where foo is not
capitalized, I think there may be a more general
issue to do with capitalization conventions.

I am happy to try to increase the unittest coverage
for simple things like this, but I am still unsure
whether this would have been appropriate as a test
under e.g. basealgebra/tests/test_pairs.py or
calculus/tests/ instead.

Original issue reported on code.google.com by dai...@gmail.com on 15 Apr 2008 at 8:47

GoogleCodeExporter commented 8 years ago
I was working with cleaning up parsing/converting code, it is
not fully completed. However, the working idea is settled down,
see

http://sympycore.googlecode.com/svn/trunk/doc/html/structure.html#how-does-it-wo
rk-in-sympycore

Another general note, we will have to type of callables for functions.
For example, Sin implements basic evaluation and sin is instance of
FunctionRing. Users can either use sin(x) or Sin(x) that will return
exactly the same instance, but at the moment printing/parsing sin(x)
may be inconsistent.

At the moment I cannot work on it because my computer stopped working and
is being repaired..

Tests of parsing Mod should go under basealgebr/tests, tests for checking
Mod validity should go under calculus/tests.

Original comment by pearu.peterson on 16 Apr 2008 at 9:33