Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pol.append([[a ** 2, 2], [-b ** 2, 0]])
a, b = valeur_alea(-9, 9), valeur_alea(-9, 9)
while a * b == -64:
# sqrt{8} est trop long à décomposer en une demi-ligne
a, b = valeur_alea(-9, 9), valeur_alea(-9, 9)
pol.append([[a, 2], [b, 0]])
a, b = valeur_alea(-9, 9), valeur_alea(-9, 9)
pol.append([[a, 2], [b, 1]])
pol.pop(randrange(1, len(pol)))
pol.pop(randrange(1, len(pol)))
shuffle(pol)
for i in range(3):
m = list(pol[i])
shuffle(m)
pol[i] = m
print(str(Polynome(pol[i], "x")))
self.exercice = pol
def __init__(self):
val = [valeur_alea(-9, 9), valeur_alea(-9, 9) , valeur_alea(-9, 9)]
pol = Polynome([[val[0], 2], [(-val[0] * (val[1] + val[2])), 1], [(val[0] * val[1] * val[2]), 0]])
while val[2] == val[1] or abs(val[0] * val[1] * val[2]) > 10 or abs(eval(pol((val[1] + val[2]) / 2.))) > 10:
val = [valeur_alea(-9, 9), valeur_alea(-9, 9) , valeur_alea(-9, 9)]
pol = Polynome([[val[0], 2], [(-val[0] * (val[1] + val[2])), 1], [(val[0] * val[1] * val[2]), 0]])
val = [[val[0], 2], [(-val[0] * (val[1] + val[2])), 1], [(val[0] * val[1] * val[2]), 0]]
shuffle(val)
lp = [Polynome(val)]
val = [[valeur_alea(-9, 9), 2 - dummy] for dummy in range(3)]
val[1][0] = valeur_alea(-9, 9) * val[0][0]
pol = Polynome(val)
while val[1][0] ** 2 - 4 * val[0][0] * val[2][0] >= 0 or abs(eval(pol(-val[1][0] / 2. / val[0][0]))) > 10:
val = [[valeur_alea(-9, 9), 2 - dummy] for dummy in range(3)]
val[1][0] = valeur_alea(-9, 9) * val[0][0]
pol = Polynome(val)
shuffle(val)
pol = Polynome(val)
lp.append(pol)
shuffle(lp)
self.exercice = lp
beta = Fraction(beta, den)
b = -2 * alpha * a
c = a * (alpha ** 2 - gamma * beta ** 2)
if abs(c) <= 10 and c != 0 and not factoriser(repr(Polynome([[a, 2], [b, 1], [c, 0]]))): redo = False
if c.denominator != 1:
c = 'Fraction(%s, %s)' % (c.numerator, c.denominator)
else:
c = c.numerator
if b.denominator != 1:
b = 'Fraction(%s, %s)' % (b.numerator, b.denominator)
else:
b = b.numerator
return Polynome([[a, 2], [b, 1], [c, 0]])
elif nb_racines == 1:
a, b = valeur_alea(-9, 9), valeur_alea(-9, 9)
return Polynome([[a ** 2, 2], [2 * a * b, 1], [b ** 2, 0]])
else:
pol = [[valeur_alea(-9, 9), 2 - dummy] for dummy in range(3)]
while pol[1][0] ** 2 - 4 * pol[0][0] * pol[2][0] >= 0:
pol = [[valeur_alea(-9, 9), 2 - dummy] for dummy in range(3)]
return Polynome(pol)
if nb_racines == 2:
redo = True
while redo:
a = randrange(1, 4) * (-1) ** randrange(2)
alpha = randrange(1, 10) * (-1) ** randrange(2)
beta = randrange(1, 10)
gamma = [1, randrange(1, 6)][rac_radical]
if rac_quotient:
den = randrange(2, 6)
while pgcd(alpha, den) != 1 or pgcd(beta, den) != 1:
den = randrange(2, 6)
alpha = Fraction(alpha, den)
beta = Fraction(beta, den)
b = -2 * alpha * a
c = a * (alpha ** 2 - gamma * beta ** 2)
if abs(c) <= 10 and c != 0 and not factoriser(repr(Polynome([[a, 2], [b, 1], [c, 0]]))): redo = False
if c.denominator != 1:
c = 'Fraction(%s, %s)' % (c.numerator, c.denominator)
else:
c = c.numerator
if b.denominator != 1:
b = 'Fraction(%s, %s)' % (b.numerator, b.denominator)
else:
b = b.numerator
return Polynome([[a, 2], [b, 1], [c, 0]])
elif nb_racines == 1:
a, b = valeur_alea(-9, 9), valeur_alea(-9, 9)
return Polynome([[a ** 2, 2], [2 * a * b, 1], [b ** 2, 0]])
else:
pol = [[valeur_alea(-9, 9), 2 - dummy] for dummy in range(3)]
while pol[1][0] ** 2 - 4 * pol[0][0] * pol[2][0] >= 0:
pol = [[valeur_alea(-9, 9), 2 - dummy] for dummy in range(3)]
:rtype: list
"""
from pyromaths.classes.PolynomesCollege import Polynome
from pyromaths.classes.Fractions import Fraction
from pyromaths.classes.SquareRoot import SquareRoot
classe = cherche_classe(value, 0)
if classe:
if classe != value: return False
else: return True
#===========================================================================
# if cherche_operateur(value, 1):
# return False
#===========================================================================
try:
return isinstance(eval(value), (float, int, Polynome, Fraction, SquareRoot))
except:
return False
c = 'Fraction(%s, %s)' % (c.numerator, c.denominator)
else:
c = c.numerator
if b.denominator != 1:
b = 'Fraction(%s, %s)' % (b.numerator, b.denominator)
else:
b = b.numerator
return Polynome([[a, 2], [b, 1], [c, 0]])
elif nb_racines == 1:
a, b = valeur_alea(-9, 9), valeur_alea(-9, 9)
return Polynome([[a ** 2, 2], [2 * a * b, 1], [b ** 2, 0]])
else:
pol = [[valeur_alea(-9, 9), 2 - dummy] for dummy in range(3)]
while pol[1][0] ** 2 - 4 * pol[0][0] * pol[2][0] >= 0:
pol = [[valeur_alea(-9, 9), 2 - dummy] for dummy in range(3)]
return Polynome(pol)
# Suppression des parenthèses autour de ((9.0-80.0)*Polynome("x")) devenu (Polynome("-71.0x"))
if post and result and post[0] == ")" and result[-1] == "(" :
result, post = result[:-1], post[1:]
else:
if recherche == recherche_somme:
# Permet les cas 1 + Fraction(1, 2) + 1
# ou 3 + Polynome("5x") + 4
frac, poly, nombres = False, False, []
for i in range(0, len(calc), 2):
nombres.append(eval(calc[i]))
if isinstance(nombres[-1], Fraction): frac = True
elif isinstance(nombres[-1], Polynome): poly, var, details = True, nombres[-1].var, nombres[-1].details
if poly: nombres = [(Polynome([[i, 0]], var, details) , i)[isinstance(i, Polynome)] for i in nombres]
elif frac: nombres = [(Fraction(i, 1), i)[isinstance(i, Fraction)] for i in nombres]
if poly: classe = Polynome
elif frac: classe = Fraction
if poly or frac:
if calc[1] == '+': operation = classe.__add__
else: operation = classe.__sub__
if isinstance(nombres[0], (int, float)):
sol = operation(classe(nombres[0]), *nombres[1:])
else:
sol = operation(nombres[0], *nombres[1:])
else: sol = eval("".join(calc))
elif recherche == recherche_produit and calc[1] == "*":
frac, poly, nombres = False, False, []
for i in range(0, len(calc), 2):
nombres.append(eval(calc[i]))
if isinstance(nombres[-1], Fraction): frac = True
elif isinstance(nombres[-1], Polynome): poly, var, details = True, nombres[-1].var, nombres[-1].details
if poly: nombres = [(Polynome([[i, 0]], var, details) , i)[isinstance(i, Polynome)] for i in nombres]
2=-4-2=-6', '\\psdot [dotsize=4.5pt,dotstyle=x](0, -2)', '\\psdot [dotsize=4.5pt
,dotstyle=x](-3, -6.0)']
:rtype: list of string
"""
u = coefdir(A, B)
if isinstance(u, int) or u.d == 1:
x1 = decimaux(B[0])
else:
B = (u.d, u.n + float(A[1]))
if not dansrep(B, xmin, xmax, ymin, ymax):
B = (-u.d, -u.n + float(A[1]))
x1 = decimaux(str(B[0]))
l = Priorites3.texify([Polynome([[u, 1], [A[1], 0]], "x")(B[0])])
l.extend(Priorites3.texify(Priorites3.priorites(Polynome([[u, 1], [A[1], 0]], "x")(B[0]))))
l = [u'Tracer la droite représentative ($d_' + str(i) + '$) de la fonction $' + f + ':x\\longmapsto ' + str(Polynome([[u, 1], [A[1], 0]], "x")) + '$.',
'On sait que $' + f + '(0)=' + decimaux(str(A[1])) + '$ et $' + f + '(' + x1 + ')=' + "=".join(l) + "$.",
'\\psdot [dotsize=4.5pt,dotstyle=x]' + str(A),
'\\psdot [dotsize=4.5pt,dotstyle=x]' + str(B),
]
return l
def exprfonc(f, i, A, B):
# Génère la 3e question.
# A est sur l'axe des ordonnées, f est le nom de la fonction
u = coefdir(A, B)
if isinstance(u, int): u = Fraction(u, 1)
Polynome([[u, 1], [A[1], 0]], "x")(B[0])
#===========================================================================
# if A[1] >= 0:
# b = '+' + decimaux(str(A[1]))
# else:
# b = decimaux(str(A[1]))
# if u.d == 1:
# coef = decimaux(str(u.n))
# if u.n == -1:
# coef = '-' # utilisé dans l'expression de la fonction
# if u.n == 1:
# coef = ''
# coefres = decimaux(str(u.n)) # résultat utilisé pour a
# else:
# if u.n > 0:
# coef = '\\dfrac{' + decimaux(str(u.n)) + '}{' + decimaux(str(u.d)) + '}'
# else: