Ask Your Question

ryss's profile - activity

2023-06-30 19:25:37 +0200 received badge  Popular Question (source)
2022-07-20 21:00:18 +0200 answered a question how to write an expression in latex without it being transformed by sage/sagetex

With all the answers I received before, I was able to build this code, with a small improvement. def signe(valeur):

2022-07-20 14:55:15 +0200 commented answer how to write an expression in latex without it being transformed by sage/sagetex

Thanks a lot. I had started to write something (with if then else), but longer and less elegant. I didn't think to build

2022-07-20 14:51:34 +0200 commented answer how to write an expression in latex without it being transformed by sage/sagetex

Thanks a lot. I had started to write something (with if then else), but longer and less elegant. I didn't think to build

2022-07-20 11:52:13 +0200 commented answer how to write an expression in latex without it being transformed by sage/sagetex

Yes I think I have to code it with Python. The problem with this answer is that with a, b, c = -2, 3, -4 (I changed the

2022-07-20 11:35:33 +0200 commented answer how to write an expression in latex without it being transformed by sage/sagetex

Yes I think I have to code it with Python. The problem with this answer is that with a, b, c = -2, 3, -4 (I changed the

2022-07-20 09:49:23 +0200 commented answer how to write an expression in latex without it being transformed by sage/sagetex

Yes I think I have to code it with Python. The problem with this answer is that with a, b, c = -2, 3, -4 (I changed the

2022-07-20 00:28:39 +0200 commented answer how to write an expression in latex without it being transformed by sage/sagetex

I changed format(latex(fcanonique(x)) to format(latex(fcanonique(x).subs(subs_dict))), but, the problem still remain : I

2022-07-19 22:35:39 +0200 commented question how to write an expression in latex without it being transformed by sage/sagetex

The problem with strings are signs : I can retrieve a, b, c, alpha and beta values to make a string, but I have to manag

2022-07-19 20:53:44 +0200 asked a question how to write an expression in latex without it being transformed by sage/sagetex

how to write an expression in latex without it being transformed by sage/sagetex For my lesson that I am trying to write

2022-07-08 15:25:20 +0200 marked best answer Generate a list of integer excluding -1, 1 and 0.

In python, I made this code to pick numbers from a list of numbers, excluding -1, 0 and 1. I can't find the equivalent in sage.

def alea(n, max):
    complete_list = [i for i in range(-max, max+1, 1) if i != 0 and i != -1 and i != 1]
    list = random.sample(complete_list, n)
    return(list)

With Sage, I've done this :

sage: def alea(n, max):
....:     list = [randrange(-max, max+1) for i in range(n)]
....:     return list
....: 
sage: a = alea(5,10)
sage: a
[1, 3, 8, -9, 7]

and as you can see, 1 is in the list of course.

My goal will then be to take for example 4 random numbers a, b, c and d, to make a sum of fractions a/b+c/d, and to generate the answer automatically to make a series of exercises in a document written with latex/sagetex. That's why I need to exclude -1, 0 and 1.

Thanks in advance for your help .

edit :

under sage (jupyter) I have this error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-8b055ece5ba6> in <module>
      3     list = random.sample(complete_list, n)
      4     return(list)
----> 5 a = alea(Integer(5), Integer(10))
      6 a

<ipython-input-17-8b055ece5ba6> in alea(n, max)
      1 def alea(n, max):
      2     complete_list = [i for i in range(-max, max+Integer(1), Integer(1)) if i != Integer(0) and i != -Integer(1) and i != Integer(1)]
----> 3     list = random.sample(complete_list, n)
      4     return(list)
      5 a = alea(Integer(5), Integer(10))

AttributeError: 'function' object has no attribute 'sample'
2022-07-08 15:25:19 +0200 commented answer Generate a list of integer excluding -1, 1 and 0.

thx for this answer.

2022-07-08 15:24:06 +0200 answered a question Generate a list of integer excluding -1, 1 and 0.

As Max Alekseyev said, need to add : import random before.

2022-07-08 15:22:10 +0200 commented question Generate a list of integer excluding -1, 1 and 0.

Of course ... thanks ... it was so simple. I forgot this.

2022-07-08 14:57:26 +0200 commented question Generate a list of integer excluding -1, 1 and 0.

I have an error under Sage, as I show in the "edit" part, and I have some difficulties to understand.

2022-07-08 14:56:53 +0200 commented question Generate a list of integer excluding -1, 1 and 0.

I have an error under Sage, as I show in the "edit" part.

2022-07-08 14:56:19 +0200 edited question Generate a list of integer excluding -1, 1 and 0.

Generate a list of integer excluding -1, 1 and 0. In python, I made this code to pick numbers from a list of numbers, ex

2022-07-08 14:55:58 +0200 received badge  Editor (source)
2022-07-08 14:55:58 +0200 edited question Generate a list of integer excluding -1, 1 and 0.

Generate a list of integer excluding -1, 1 and 0. In python, I made this code to pick numbers from a list of numbers, ex

2022-07-08 12:17:38 +0200 asked a question Generate a list of integer excluding -1, 1 and 0.

Generate a list of integer excluding -1, 1 and 0. In python, I made this code to pick numbers from a list of numbers, ex

2022-07-07 13:56:27 +0200 commented answer why there is no exact result with this fractions sum ?

Thank you for the answer.

2022-07-07 13:55:30 +0200 marked best answer why there is no exact result with this fractions sum ?

Hi, here is my code, in order to use it with sagetex (I'm new with sage). I want to make a sum with two fractions.

L = random.sample([n for n in range(-15, 15) if n != -1 and n != 1 and n != 0], 4)
print(L)
print(type(L[0]))
L[0]/L[1]+L[2]/L[3]

and the result is :

[-11, 12, 7, -7]
<class 'int'>
-1.9166666666666665

so, no exact value.

I've made an other test :

L = random.sample([n for n in range(-15, 15) if n != -1 and n != 1 and n != 0],4)
print(L)
print(type(L[0]))
print(L[0]/L[1]+L[2]/L[3])
QQ(L[0]/L[1]+L[2]/L[3])

and the output is :

[-6, -8, -4, 5]
<class 'int'>
-0.050000000000000044
-52215647853572/1044312957071439

instead of -1/20. I would like to understand how to achieve the exact and simplified fraction.

Thank you


Edit :

I tried with this 1 min ago :

L = random.sample([n for n in range(-15, 15) if n != -1 and n != 1 and n != 0],4)
print(L)
print(type(L[0]))
print(L[0]/L[1]+L[2]/L[3])
print(Integer(L[0])/Integer(L[1])+Integer(L[2])/Integer(L[3]))
QQ(L[0]/L[1]+L[2]/L[3])

and the output is :

[5, -8, -6, -13]
<class 'int'>
-0.16346153846153844
-17/104

-39792720200266/243437817695745

so ... i have to do this with "Integer" ?

2022-07-07 13:55:30 +0200 received badge  Scholar (source)
2022-07-06 21:15:35 +0200 received badge  Student (source)
2022-07-06 17:28:28 +0200 asked a question why there is no exact result with this fractions sum ?

why there is no exact result with this fractions sum ? Hi, here is my code, in order to use it with sagetex (I'm new wit