long arithmetic

1 view
Skip to first unread message

Bob Wonderly

unread,
Sep 22, 2008, 8:23:20 PM9/22/08
to sage-s...@googlegroups.com
Using Sage I solved a long list of equations and put the solutions (s)
in a list; e.g.:

sage: for j in range(52,54,1):
q = slst[j]
j=q[0]; k=(q[1]); s=(q[2])
(q,j,k,s)
....:
([52, 30, 2081203288L], 52, 30, 2081203288L)
([53, 53, 17903198518682712L], 53, 53, 17903198518682712L)

Now I want to plug j and s into the list of y equations so that I can do
further calculations involving i. But Sage appears to be getting hung on
the s being long:

sage: for j in range(52,54,1):
q = slst[j]
j=q[0]; k=(q[1]); s=(q[2])
y = 2*(2**k)*i + s
(j,k,s,y)
....:
...
...
TypeError: unsupported operand parent(s) for '+': 'Symbolic Ring' and
'<type 'long'>'

When I take the s out of the equation for y it's OK:

sage: for j in range(52,54,1):
q = slst[j]
j=q[0]; k=(q[1]); s=(q[2])
y = 2*(2**k)*i
(j,k,s,y)
....:
(52, 30, 2081203288L, 2147483648*i)
(53, 53, 17903198518682712L, 18014398509481984*i)

FWIW:

sage: type(j), type(k), type(s), type(y), type(i)


(<type 'int'>,
<type 'int'>,
<type 'long'>,
<class 'sage.calculus.calculus.SymbolicArithmetic'>,
<class 'sage.calculus.calculus.SymbolicVariable'>)

None of the tricks I tried have convinced Sage and y that s is OK.

Jason Grout

unread,
Sep 22, 2008, 9:04:08 PM9/22/08
to sage-s...@googlegroups.com
Bob Wonderly wrote:
> Using Sage I solved a long list of equations and put the solutions (s)
> in a list; e.g.:
>
> sage: for j in range(52,54,1):
> q = slst[j]
> j=q[0]; k=(q[1]); s=(q[2])
> (q,j,k,s)
> .....:

> ([52, 30, 2081203288L], 52, 30, 2081203288L)
> ([53, 53, 17903198518682712L], 53, 53, 17903198518682712L)
>
> Now I want to plug j and s into the list of y equations so that I can do
> further calculations involving i. But Sage appears to be getting hung on
> the s being long:
>
> sage: for j in range(52,54,1):
> q = slst[j]
> j=q[0]; k=(q[1]); s=(q[2])
> y = 2*(2**k)*i + s
> (j,k,s,y)
> .....:
> ....
> ....

> TypeError: unsupported operand parent(s) for '+': 'Symbolic Ring' and
> '<type 'long'>'
>
> When I take the s out of the equation for y it's OK:
>
> sage: for j in range(52,54,1):
> q = slst[j]
> j=q[0]; k=(q[1]); s=(q[2])
> y = 2*(2**k)*i
> (j,k,s,y)
> .....:

> (52, 30, 2081203288L, 2147483648*i)
> (53, 53, 17903198518682712L, 18014398509481984*i)
>
> FWIW:
>
> sage: type(j), type(k), type(s), type(y), type(i)
>
>
> (<type 'int'>,
> <type 'int'>,
> <type 'long'>,
> <class 'sage.calculus.calculus.SymbolicArithmetic'>,
> <class 'sage.calculus.calculus.SymbolicVariable'>)
>
> None of the tricks I tried have convinced Sage and y that s is OK.


Can you try converting s to an element that Sage knows by saying:

y = 2*(2**k)*i + Integer(s)

That said, I reproduced your error with just:

sage: var("b")+long(2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

/home/grout/sage/devel/sage-main/sage/plot/<ipython console> in <module>()

/home/grout/sage/devel/sage-main/sage/plot/element.pyx in
sage.structure.element.ModuleElement.__add__
(sage/structure/element.c:5748)()

/home/grout/sage/devel/sage-main/sage/plot/coerce.pyx in
sage.structure.coerce.CoercionModel_cache_maps.bin_op
(sage/structure/coerce.c:6364)()

TypeError: unsupported operand parent(s) for '+': 'Symbolic Ring' and
'<type 'long'>'


Jason

William Stein

unread,
Sep 22, 2008, 9:09:56 PM9/22/08
to sage-s...@googlegroups.com

This is a bug, so I've added it to trac:

http://trac.sagemath.org/sage_trac/ticket/4171

William

Robert Bradshaw

unread,
Sep 22, 2008, 9:12:11 PM9/22/08
to sage-s...@googlegroups.com

... just after I added the ticket here: http://trac.sagemath.org/
sage_trac/ticket/4170

- Robert

William Stein

unread,
Sep 22, 2008, 9:17:23 PM9/22/08
to sage-s...@googlegroups.com

What's the rule about whose is a dupe then? I posted on sage-support
first, but you hit "new ticket" first. I'll let you have the ticket; please
mark mine a dupe.

William

mabshoff

unread,
Sep 22, 2008, 9:19:55 PM9/22/08
to sage-support


On Sep 22, 6:17 pm, "William Stein" <wst...@gmail.com> wrote:
> On Mon, Sep 22, 2008 at 6:12 PM, Robert Bradshaw

<SNIP>

> >> This is a bug, so I've added it to trac:
>
> >>http://trac.sagemath.org/sage_trac/ticket/4171
>
> > ... just after I added the ticket here:http://trac.sagemath.org/
> > sage_trac/ticket/4170
>
> What's the rule about whose is a dupe then?  I posted on sage-support
> first, but you hit "new ticket" first.    I'll let you have the ticket; please
> mark mine a dupe.
>
> William

Well, my personal rule is this:

* ticket with a patch closes other tickets as dupe
* no patches: earlier ticket stays open *unless* the later ticket has
a much better description

In this case Robert's ticket with patch (that I am currently
doctesting and likely to merge in 10 minutes) wins :)

Cheers,

Michael

Jason Grout

unread,
Sep 22, 2008, 9:15:42 PM9/22/08
to sage-s...@googlegroups.com
> .... just after I added the ticket here: http://trac.sagemath.org/
> sage_trac/ticket/4170


Gee, Bob, we're falling all over ourselves trying to rush to help you!

Welcome again to the community.

Jason


Robert Bradshaw

unread,
Sep 22, 2008, 9:25:41 PM9/22/08
to sage-s...@googlegroups.com

Yeah, I paused long enough to write a patch. I guess this is a good
kind of problem to have :).

- Robert

Jason Grout

unread,
Sep 22, 2008, 9:20:24 PM9/22/08
to sage-s...@googlegroups.com
William Stein wrote:

>
> What's the rule about whose is a dupe then? I posted on sage-support
> first, but you hit "new ticket" first. I'll let you have the ticket; please
> mark mine a dupe.


Hehe...I believe it's the "Code talks" rule. Robert has a patch up
already :).

Jason

Reply all
Reply to author
Forward
0 new messages