On Wed, Jun 22, 2011 at 12:35 PM, Ken Levasseur <[email protected]> wrote:
> Hello.  I'm trying to implement the algorithm for representing primes
> congruent to 1 mod 4 as a sum of squares and I know the logic of the
> algebra is right (identical equations work in Mathematica).  However,
> I get  a "ZeroDivisionError: Inverse does not exist." error when I
> evaluate the expression
>
> sum_of_squares(73).
>
> where the definition of sum_of_squares is
>
> def sum_of_squares(p):
>    if p.mod(4)==1:
>        A=startingA(p)
>        print A
>        B=1
>        M=(A**2+B**2)/p
>        while M>1:
>            [a,b,r]=iterate(A,B,M,p)
>            [A,B,M]=[a,b,r]
>        return [A,B]
>    else:
>        print 'no'
>
> The error appears to be when M is computed just before the while
> loop.   I know that A is computed correctly because the correct values
> come out randomly when I print A, but then I never get to the loop.
> I evaluate the following before the definition of the function.
>
> p=var('p')
> A=var('A')
> B=var('B')
> r=var('r')
> a=var('a')
> b=var('b')
>
> Anyone know what's going on?

What is startingA ? What is the parent of A?

> The full error message from evaluating  sum_of_squares(73) is
>
> ]Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "_sage_input_36.py", line 10, in <module>
>    exec compile(u'open("___code___.py","w").write("# -*- coding:
> utf-8 -*-\\n" +
> _support_.preparse_worksheet_cell(base64.b64decode("c3VtX29mX3NxdWFyZXMoNzMp"),globals())
> +"\\n"); execfile(os.path.abspath("___code___.py"))
>  File "", line 1, in <module>
>
>  File "/private/var/folders/dV/dVqvhWPV2RWo0U+8ZQR1k++++TM/-Tmp-/
> tmpGm6sIU/___code___.py", line 3, in <module>
>    exec compile(u'sum_of_squares(_sage_const_73 )
>  File "", line 1, in <module>
>
>  File "/private/var/folders/dV/dVqvhWPV2RWo0U+8ZQR1k++++TM/-Tmp-/
> tmpXtNmdU/___code___.py", line 8, in sum_of_squares
>    M=(A**_sage_const_2 +B**_sage_const_2 )/p
>  File "element.pyx", line 1551, in
> sage.structure.element.RingElement.__div__ (sage/structure/element.c:
> 12000)
>  File "coerce.pyx", line 713, in
> sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/
> coerce.c:6153)
>  File "element.pyx", line 1549, in
> sage.structure.element.RingElement.__div__ (sage/structure/element.c:
> 11981)
>  File "integer_mod.pyx", line 2223, in
> sage.rings.finite_rings.integer_mod.IntegerMod_int._div_ (sage/rings/
> finite_rings/integer_mod.c:19173)
> ZeroDivisionError: Inverse does not exist.
>
>
>
>
> Ken Levasseur
> UMass Lowell
>
> --
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to 
> [email protected]
> For more options, visit this group at 
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to