On Fri, Oct 21, 2011 at 3:49 PM, Chris Smith <smi...@gmail.com> wrote:
> I just noticed in Integer, too, the invert method which gives the > multiplicative inverse mode n of a number: > > >>> invert(S(3),5) > 2 > >>> (3*2)%5 == 1 > True > >>> invert(S(4),6) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "sympy\polys\polytools.py", line 4249, in invert > return f.invert(g) > File "sympy\core\numbers.py", line 1322, in invert > raise ZeroDivisionError("zero divisor") > ZeroDivisionError: zero divisor > > Before tackling this problem, we need to answer - is ``invert`` (or inverse in finite field) in its present form valid?? In [39]: FF? Docstring : Finite field based on Python's integers. In [40]: FF(4) Out[40]: ℤ₄ But FF(4) fails to be a field [0]. Multiplication is not well defined. This thing is not highlighted by sympy In [42]: FF(4)(1).invert() Out[42]: 1 mod 4 In [43]: FF(4)(2).invert() NotInvertible: zero divisor In [44]: FF(4)(3).invert() Out[44]: 3 mod 4 1st and 3rd answer doesn't make any sense as inverse doesn't exist at all. I second Aaron's suggestions of making class FiniteRing and put more constrains on FintiteField. So, the output **would** be something like - >>> FF(4) Error - Z4 is not a filed >>> FR(4) Z4 >>> FR(4)(3).invert() 1 ## Additive inverse >>> FF(5) Z5 >>> FF(5)(4).invert_mul() 4 >>> FF(5)(4).invert_add() 1 > To find an Integer given a description of it's modulus profile perhaps > a method "from_moduli" could be added so Integer.from_moduli((2, 3), > (3, 5)) would give 8. Hector, Mateusz, anyone else: does that look > like a good way to construct it? Is there a better method name? > This looks good. Even it can be extended to non linear polynomials using CRT. @smichr : Did you pull the function you once mentioned in the pull request # 390 [1] for solving system of congruence relations where CRT fails? That function can be used to do the above task. [0] http://en.wikipedia.org/wiki/Field_(mathematics) [1] https://github.com/sympy/sympy/pull/390#issuecomment-2402863 > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to sympy@googlegroups.com. > To unsubscribe from this group, send email to > sympy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > > -- -Regards Hector Whenever you think you can or you can't, in either way you are right. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.