[sage-support] randint - Maybe one bug !

2012-09-19 Thread Christophe BAL
Hello, I've just tried to produce randomized fractions. I've decided to use randint but I've noticed a wierd behavior shown in the following code with one output. Best regards. Christophe = PYTHON CODE = for i in range(1, 6): a_Num = (-1)^randint(1, 2)*randint(1, 20) a_Den = rand

Re: [sage-support] randint - Maybe one bug !

2012-09-19 Thread D. S. McNeil
You don't actually say what you find weird about your output, so I had to look at it for a while before coming up with something. I'm guessing it's how the division is behaving? `randint` returns a Python int: sage: randint(1, 10) 7 sage: type(randint(1, 10)) And division of Python ints is tru

Re: [sage-support] randint - Maybe one bug !

2012-09-19 Thread Christophe BAL
Hello, you're right my example is too long. Here is a better example where you can see that the use of ``1*randint(-20, 20)`` instead of ``randint(-20, 20)`` will produce fractions instead of integer divisisons. I really think that this is illogical. Don't you ? Christophe. = Python-Sage

Re: [sage-support] randint - Maybe one bug !

2012-09-19 Thread Christophe BAL
I guess that here there are some Sage-type conversions coming from ``+/- 1*...``. >From my point of view, using in Sage, ``randint`` should produce Sage integers and not Python integer. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To post

Re: [sage-support] randint - Maybe one bug !

2012-09-19 Thread D. S. McNeil
> I really think that this is illogical. Don't you ? No, because it's perfectly consistent. I can see why it's not obvious, though -- and for related reasons, in Python 3 the division of two ints produces a float (or in Python 2 if you `from __future__ import division`). That won't help us much

[sage-support] Re: randint - Maybe one bug !

2012-09-19 Thread P Purkayastha
On 09/19/2012 07:23 PM, Christophe BAL wrote: Hello, you're right my example is too long. Here is a better example where you can see that the use of ``1*randint(-20, 20)`` instead of ``randint(-20, 20)`` will produce fractions instead of integer divisisons. I really think that this is illogi

Re: [sage-support] randint - Maybe one bug !

2012-09-19 Thread Christophe BAL
What I think very confusing is that 1/4 is the Sage division and not the Python standard one, so why it would be different for randint ? I'm a teacher and the problem is not from my point of view but it will be a tricky thing to explain to my students which are in "french lycée" (sorry, I don't kn

Re: [sage-support] randint - Maybe one bug !

2012-09-19 Thread D. S. McNeil
On Wed, Sep 19, 2012 at 12:42 PM, Christophe BAL wrote: > What I think very confusing is that 1/4 is the Sage division and not the > Python standard one, so why it would be different for randint ? It's not Sage division vs. Python division, it's Sage Integers vs. Python ints. At the Sage console

Re: [sage-support] randint - Maybe one bug !

2012-09-19 Thread Robert Bradshaw
I agree that this is a surprising and unfortunate wart in the was Sage is built. I would explain it like this: Python has an integer type int that has several surprising behaviors (from a mathematicians perspective, e.g. division). For this reason we created our own time, Integer, that behaves bet

[sage-support] Re: how to factorize an expression with constant variables ?

2012-09-19 Thread mazkime
sorry for the late answer. After some investigations on the internet, I did not find any convenient solution. My concern being on polynomials, I ended up doing some copy/paste of my expressions and working in another window with a polynomial ring defined the following way : R. = QQ[] R. = Polyn