Re: [sage-support] Re: please explain casting in this example

2019-02-16 Thread John Cremona
1. You can use srange which works like range but gives a list of Sage integers. 2. To coerce an int to a Sage Integer just use ZZ(): sage: srange(1,4) [1, 2, 3] sage: [type(i) for i in srange(1,4)] [, , ] sage: range(1,4) [1, 2, 3] sage: [type(i) for i in range(1,4)] [, , ] sage: [type(ZZ(i))

[sage-support] Re: please explain casting in this example

2019-02-15 Thread Michael Beeson
Well, the real cure is to use IntegerRange instead of range. Sorry to bother those of you who actually can read a manual. On Friday, February 15, 2019 at 2:56:14 PM UTC-8, Michael Beeson wrote: > > def test(p,q): > t = p/q; > print(p,q,p/q,t) > def test2(): > for p in range(1,4): > for q in

[sage-support] Re: please explain casting in this example

2019-02-15 Thread Michael Beeson
And it can be fixed by inserting p = sage.rings.integer.Integer(p) after p is generated by range. Comments on this still welcome. This may be a dumb question but now I'm worried that perhaps this problem exists silently elsewhere in my code. On Friday, February 15, 2019 at 2:56:14 PM

[sage-support] Re: please explain casting in this example

2019-02-15 Thread Michael Beeson
I see by inserting print(type(p)) that range produces objects of type int, while when it's called from top-level the types of p and q are sage.rings.integer.Integer. So that answers "why" but not "how to prevent". On Friday, February 15, 2019 at 2:56:14 PM UTC-8, Michael Beeson wrote: > >