Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def listeracines(a, b, delta, parentheses=False):
'''renvoie racsimple,simplifie,formule_x1,x_1,formule_x2,x2'''
'''avec x_10
simplrac est True si racine de delta se simplifie'''
a = int(a)
b = int(b)
# parenthesex1 = parenthesex2 = True # par défaut
# simplrac=True
strx1 = "\\dfrac{-%s-\\sqrt{%s}}{2\\times %s}" % (pTeX(b), TeX(delta), pTeX(a))
strx2 = "\\dfrac{-%s+\\sqrt{%s}}{2\\times %s}" % (pTeX(b), TeX(delta), pTeX(a))
# #on a strx1
P0 = "%s-%s" % (var, pTeX(racines[0]))
factorisation = [[P0, P0]] # non simplifiée
if 0 > racines[0]:
P0 = X - racines[0]
factorisation.append([P0, P0])
else: # delta>0
simplrac, strx1, x1, strx2, x2 = listeracines(P[2], P[1], delta)
if isinstance(x1, RacineDegre2):
x1 = x1.simplifie()
x2 = x2.simplifie()
racines = [x1, x2]
str_racines = [strx1, strx2]
P1 = "%s-%s" % (var, pTeX(x1))
P2 = "%s-%s" % (var, pTeX(x2))
factorisation = [[P1, P2]] # non simplifiée
# Peut-on simplifier les parenthèses ?
if x1.radicande == 0 and (x1.numerateur < 0 or x2.numerateur < 0):
P1 = (X - x1)(var)
P2 = (X - x2)(var)
factorisation.append([P1, P2])
return delta, simplrac, racines, str_racines, factorisation
def racines_degre2(P):
"""renvoie les racines d'un polynôme de degré 2"""
from pyromaths.classes.Fractions import Fraction
delta = int(P[1] ** 2 - 4 * P[2] * P[0])
if delta == 0:
x0 = eval(priorites('Fraction(-1, 2)*%r/%r' % (P[1], P[2]))[-1][0])
if isinstance(x0, (Fraction, RacineDegre2)):
liste_racines = [x0.simplifie()]
else:
liste_racines = [x0]
liste_str_racines = ["\\dfrac{-%s}{2\\times %s}" % (pTeX(P[1]), pTeX(P[2]))]
simplrac = [False]
elif delta > 0:
simplrac, strx1, x1, strx2, x2 = listeracines(P[2], P[1], delta, parentheses=False)
liste_racines = [x1, x2]
liste_str_racines = [strx1, strx2]
else:
simplrac = [False]
liste_racines = liste_str_racines = []
return delta, simplrac, liste_racines, liste_str_racines
# delta
P0 = "%s-%s" % (var, pTeX(racines[0]))
factorisation = [[P0, P0]] # non simplifiée
if 0 > racines[0]:
P0 = X - racines[0]
factorisation.append([P0, P0])
else: # delta>0
simplrac, strx1, x1, strx2, x2 = listeracines(P[2], P[1], delta)
if isinstance(x1, RacineDegre2):
x1 = x1.simplifie()
x2 = x2.simplifie()
racines = [x1, x2]
str_racines = [strx1, strx2]
P1 = "%s-%s" % (var, pTeX(x1))
P2 = "%s-%s" % (var, pTeX(x2))
factorisation = [[P1, P2]] # non simplifiée
# Peut-on simplifier les parenthèses ?
if x1.radicande == 0 and (x1.numerateur < 0 or x2.numerateur < 0):
P1 = (X - x1)(var)
P2 = (X - x2)(var)
factorisation.append([P1, P2])
return delta, simplrac, racines, str_racines, factorisation