[sage-support] Re: %auto not automatically running code when upload notebook worksheet

2011-06-22 Thread Rolf
> "x is %d" % y is standard Python for having variables in strings.

Thank, that helped a lot. In Python documentation I found the
solution.

> > html('In Scientific Notation: ${%d} \cdot 10^{%d}$'%base%exponent)
>
> > doesn't work either.
>
> I didn't see that inhttp://phil4.com/public/Sci.sws.  I'm not sure
> where you saw that.

In fact it is not from that worksheet. I tried to change it. See
below.

> The *ONLY* problem is that it will not automatically run
> thanks to %auto.

I have the solution to that problem though it is not as much of a
solution as rather an idea what the reason could be.
On my system the %auto command works fine if there is no comment in
front of the cell.
Please open a new worksheet and copy the following code into the first
cell.

%auto
%hide
@interact
def _(base=(1..10),exponent=(-6..6)):
html('The Number: $%f$'%(base * 10**exponent))
html('In Scientific Notation: ${%d} \cdot 10^{%d}$'%(base,
exponent))

Works with me, and you will see my enhancement to the code. The two
variable thing.

Best regards
R.

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


[sage-support] unanticipated divison by zero

2011-06-22 Thread Ken Levasseur
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?

The full error message from evaluating  sum_of_squares(73) is

]Traceback (most recent call last):
  File "", line 1, in 
  File "_sage_input_36.py", line 10, in 
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 

  File "/private/var/folders/dV/dVqvhWPV2RWo0U+8ZQR1kTM/-Tmp-/
tmpGm6sIU/___code___.py", line 3, in 
exec compile(u'sum_of_squares(_sage_const_73 )
  File "", line 1, in 

  File "/private/var/folders/dV/dVqvhWPV2RWo0U+8ZQR1kTM/-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 sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] unanticipated divison by zero

2011-06-22 Thread Robert Bradshaw
On Wed, Jun 22, 2011 at 12:35 PM, Ken Levasseur  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 "", line 1, in 
>  File "_sage_input_36.py", line 10, in 
>    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 
>
>  File "/private/var/folders/dV/dVqvhWPV2RWo0U+8ZQR1kTM/-Tmp-/
> tmpGm6sIU/___code___.py", line 3, in 
>    exec compile(u'sum_of_squares(_sage_const_73 )
>  File "", line 1, in 
>
>  File "/private/var/folders/dV/dVqvhWPV2RWo0U+8ZQR1kTM/-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 sage-support@googlegroups.com
> To unsubscribe from this group, send email to 
> sage-support+unsubscr...@googlegroups.com
> 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 sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: unanticipated divison by zero

2011-06-22 Thread Ken Levasseur


On Jun 22, 4:06 pm, Robert Bradshaw 
wrote:

> What is startingA ? What is the parent of A?
>

The full .sws file is at http://homepage.mac.com/klevasseur/sum_of_squares.sws

Ken

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


[sage-support] Re: unanticipated divison by zero

2011-06-22 Thread kcrisman
If you take a look at the code, there is something fishy. Add the
following statements.

def sum_of_squares(p):
if p.mod(4)==1:
A=startingA(p)
print A
B=1
temp = A**2+B**2
print type(A**2+B**2)
temp
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'

For 73 you get

46

Traceback (click to the left of this block for traceback)
...
ZeroDivisionError: Inverse does not exist.

So A^2+B^2 (legitimate syntax in Sage) is a modular integer.  In fact,
you can check that its modulus is 73, and so it's no surprise that
dividing by 73 \equiv 0 will result in a zero-division error.
You'll have to find a way to get the power modulo p without actually
making the thing an integer mod p.

Hope this helps!
- kcrisman


On Jun 22, 7:43 pm, Ken Levasseur  wrote:
> On Jun 22, 4:06 pm, Robert Bradshaw 
> wrote:
>
> > What is startingA ? What is the parent of A?
>
> The full .sws file is athttp://homepage.mac.com/klevasseur/sum_of_squares.sws
>
> Ken

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


[sage-support] Re: unanticipated divison by zero

2011-06-22 Thread Ken Levasseur
Yes, it's exactly what I needed. I wasn't aware of the type
distinction between integers and integers mod m.  What I needed to use
is the lift method:

s=pow(2,11,23)
[type(s),type(s.lift())]

[,
]

Thank you!

Ken


On Jun 22, 8:28 pm, kcrisman  wrote:
> If you take a look at the code, there is something fishy. Add the
> following statements.
>
> def sum_of_squares(p):
>     if p.mod(4)==1:
>         A=startingA(p)
>         print A
>         B=1
>         temp = A**2+B**2
>         print type(A**2+B**2)
>         temp
>         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'
>
> For 73 you get
>
> 46
> 
> Traceback (click to the left of this block for traceback)
> ...
> ZeroDivisionError: Inverse does not exist.
>
> So A^2+B^2 (legitimate syntax in Sage) is a modular integer.  In fact,
> you can check that its modulus is 73, and so it's no surprise that
> dividing by 73 \equiv 0 will result in a zero-division error.
> You'll have to find a way to get the power modulo p without actually
> making the thing an integer mod p.
>
> Hope this helps!
> - kcrisman
>
> On Jun 22, 7:43 pm, Ken Levasseur  wrote:
>
>
>
> > On Jun 22, 4:06 pm, Robert Bradshaw 
> > wrote:
>
> > > What is startingA ? What is the parent of A?
>
> > The full .sws file is 
> > athttp://homepage.mac.com/klevasseur/sum_of_squares.sws
>
> > Ken

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


[sage-support] Re: %auto not automatically running code when upload notebook worksheet

2011-06-22 Thread Chris Seberino


On Jun 22, 4:26 am, Rolf  wrote:
> Works with me, and you will see my enhancement to the code. The two
> variable thing.

Rolf

Thanks.  Does your version automatically start up when you upload the
worksheet?
Your version works like mine but doesn't start automatically for me
like mine still.

cs

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


[sage-support] Re: %auto not automatically running code when upload notebook worksheet

2011-06-22 Thread Rolf
> Thanks.  Does your version automatically start up when you upload the
> worksheet?

Yes, as I said it starts automatically but it must have no descriptive
comment above the cell. That is a worksheet with only one naked cell
and no description in it.
That's why I suggested to start a new worksheet from scratch.

Your worksheet (http://phil4.com/public/Sci.sws) doesn't work with me
either.

Good luck
R.

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