def creerPolydegre2(nb_racines=2, rac_radical=True, rac_quotient=False): 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)] return Polynome(pol)
def __init__(self): pol = creerPolydegre2(nb_racines=2, rac_radical=False, rac_quotient=False).monomes pol2 = [[valeur_alea(-9, 9), 1], [valeur_alea(-9, 9), 0]] shuffle(pol) shuffle(pol2) p = [pol, pol2] shuffle(p) p.append(['<', '>', '\\le', '\\ge'][randrange(4)]) self.exercice = p
def valeurs_somme_prod(): # cree 3 fractions et un tuple de signes (+,*) while True: (base1, base2) = (valeur_alea(-13, 13), valeur_alea(-13, 13)) lepgcd = pgcd(base1, base2) (base1, base2) = (base1 // lepgcd, base2 // lepgcd) if base1 != 1 and base2 != 1: break (n2, d2) = (base1 * valeur_alea(-10, 10), abs(base2 * valeur_alea(2, 10))) lepgcd = pgcd(n2, d2) (n2, d2) = (n2 // lepgcd, d2 // lepgcd) (n3, d3) = (base2 * valeur_alea(-10, 10), abs(base1 * valeur_alea(2, 10))) lepgcd = pgcd(n3, d3) (n3, d3) = (n3 // lepgcd, d3 // lepgcd) (n1, d1) = (base1 * valeur_alea(-10, 10), abs(pgcd(d2, base2 * valeur_alea(2, 10)))) lepgcd = pgcd(n1, d1) (n1, d1) = (n1 // lepgcd, d1 // lepgcd) if randrange(2) == 0: s1 = '+' else: s1 = '-' if randrange(2) == 0: s2 = '*' else: s2 = ':' if s2 == '*': return ((n1, d1), (n2, d2), (n3, d3), (s1, s2)) else: return ((n1, d1), (n2, d2), (d3, n3), (s1, s2))
def valeurs_reciproque_thales(): while True: (a, b, c, d) = (random.randrange(2, 50), random.randrange(2, 50), random.randrange(2, 20), random.randrange(2, 20)) p1 = pgcd(a, b) (a, b) = (a / p1, b / p1) if c < d: (c, d) = (d, c) if a != b and int(c / d) != (c * 1.0) / d and 10 < a * c < 200 and \ 10 < a * d < 200 and 10 < b * c < 200 and 10 < b * d < 200 and \ .3 < (d * 1.0) / c < .7: break t = valeur_alea(-1, 1) # -1 si papillon, 1 si triangle r = random.randrange(5) while r == 2: r = random.randrange(5) angle = random.randrange(15, 105) valeurs = ( (a * c) / 10.0, (b * c) / 10.0, 0, (a * d) / 10.0, (b * d) / 10.0, 0, (a * c - (t * a) * d) / 10.0, (b * c - (t * b) * d) / 10.0, angle, t, r, ) return valeurs
def PointsCourbes(sens_var=(-1, -1, 0, 1, 1), nb_var=(3, 5), absc=(-5, 5), ordo=(-4, 4), cstes=(0, 1)): """Définit les ordonnées entières dans [-5 ; 5] de points d'abscisses entières dans [-5 ; 5] de telle sorte que la fonction sur chaque intervalle comporte entre 3 et 5 variations différentes, une seule section pouvant être constante. La fonction doit avoir des images positives et négatives. variations= [[-1, -6, -2], [1, -2, 1], [-1, 1, 2], [0, 2, 4]] """ while True: lY, sens, variations = [valeur_alea(ordo[0], ordo[1])], [], [] nb_cste = 0 for dummy in range(absc[1] - absc[0]): while True: lg = valeur_alea(1, 4) # pente maximale entre deux points consécutifs sens.append(sens_var[randrange(len(sens_var))]) nY = lY[-1] + lg * sens[-1] if ordo[0] <= nY <= ordo[1]: if nY * lY[-1] < 0: lY.append(0) else: lY.append(nY) if not variations or sens[-1] != variations[-1][0]: variations.append([sens[-1], dummy + absc[0], dummy + absc[0] + 1]) else: variations[-1][2] = dummy + absc[0] + 1 break else: sens.pop(-1) if nb_var[0] <= len(variations) <= nb_var[1]: extremums = [] gextr = [100, -100] # extrema sur l'esnble de définition for i in range(len(variations)): if lY[variations[i][1] - absc[0]] > gextr[1]: gextr[1] = lY[variations[i][1] - absc[0]] elif lY[variations[i][1] - absc[0]] < gextr[0]: gextr[0] = lY[variations[i][1] - absc[0]] if extremums.count(lY[variations[i][1] - absc[0]]) > 0 and variations[i - 1][0] != 0: nb_cste = cstes[1] + 1 else: extremums.append(lY[variations[i][1] - absc[0]]) if variations[i][0] == 0:nb_cste += 1 if extremums.count(lY[-1]): nb_cste = cstes[1] + 1 if lY[-1] > gextr[1]: gextr[1] = lY[-1] elif lY[-1] < gextr[0]: gextr[0] = lY[-1] if gextr[0] * gextr[1] >= 0: nb_cste = cstes[1] + 1 if cstes[0] <= nb_cste <= cstes[1]: break variations[-1][2] = absc[1] return lY, variations
def __init__(self): pol = [creerPolydegre2(nb_racines=2, rac_radical=False, rac_quotient=False)] pol.append(creerPolydegre2(nb_racines=1)) a, b = valeur_alea(-9, 9), valeur_alea(-9, 9) pol.append([[a ** 2, 2], [-b ** 2, 0]]) a, b = valeur_alea(-9, 9), valeur_alea(-9, 9) pol.append([[a, 2], [b, 1]]) a, b = valeur_alea(-9, 9), valeur_alea(-9, 9) pol.append([[a, 2], [b, 0]]) pol.pop(randrange(1, len(pol))) pol.pop(randrange(1, len(pol))) pol.pop(randrange(1, len(pol))) shuffle(pol) exercice = [pol] lval = [[[randrange(2, 10) * (-1) ** randrange(2), 1], [randrange(2, 10) * (-1) ** randrange(2), 0]] for dummy in range(3)] a, b, c = -lval[2][0][0] * lval[1][0][0], lval[0][0][0] - lval[2][0][0] * lval[1][1][0] - lval[2][1][0] * lval[1][0][0], lval[0][1][0] - lval[2][1][0] * lval[1][1][0] delta = b ** 2 - 4 * a * c while delta < 0 or carrerise(delta) != 1: lval = [[[randrange(2, 10) * (-1) ** randrange(2), 1], [randrange(2, 10) * (-1) ** randrange(2), 0]] for dummy in range(3)] a, b, c = -lval[2][0][0] * lval[1][0][0], lval[0][0][0] - lval[2][0][0] * lval[1][1][0] - lval[2][1][0] * lval[1][0][0], lval[0][1][0] - lval[2][1][0] * lval[1][1][0] delta = b ** 2 - 4 * a * c # print delta, Polynome([[a, 2], [b, 1], [c, 0]]), '\cfrac{%s}{%s}' % (-b - sqrt(delta), 2 * a), '\cfrac{%s}{%s}' % (-b + sqrt(delta), 2 * a) exercice.append(lval) shuffle(exercice) self.exercice = exercice
def valeurs_prod_parenth(): # cree 3 fractions et un tuple de signes (*,+) while True: (base1, base2) = (valeur_alea(2, 13), valeur_alea(2, 13)) lepgcd = pgcd(base1, base2) (base1, base2) = (base1 // lepgcd, base2 // lepgcd) if base1 != 1 and base2 != 1: break while True: n2 = valeur_alea(-13, 13) lepgcd = pgcd(n2, base1) if lepgcd == 1: break while True: n3 = valeur_alea(-13, 13) lepgcd = pgcd(n3, base2) if lepgcd == 1: break while True: (n1, d1) = (valeur_alea(-10, 10), valeur_alea(2, 10)) lepgcd = pgcd(n1, d1) if lepgcd != n1 and lepgcd != d1: break (n1, d1) = (n1 // lepgcd, d1 // lepgcd) if randrange(2) == 0: s1 = '*' else: s1 = ':' if randrange(2) == 0: s2 = '+' else: s2 = '-' return ((n1, d1), (n2, base1), (n3, base2), (s1, s2))
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
def __init__(self): pol = [creerPolydegre2(nb_racines=2, rac_radical=True, rac_quotient=False)] pol.append(creerPolydegre2(nb_racines=1)) a, b = valeur_alea(-9, 9), valeur_alea(-9, 9) 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 self.exercice = pol
def __init__(self): pol = [creerPolydegre2(nb_racines=2, rac_radical=True, rac_quotient=False)] pol.append(creerPolydegre2(nb_racines=1)) a, b = valeur_alea(-9, 9), valeur_alea(-9, 9) 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 valeurs_quotient_frac(): # cree 4 fractions et un tuple de signes (+,+) while True: (n1, d1) = (valeur_alea(-10, 10), valeur_alea(2, 10)) lepgcd = pgcd(n1, d1) if lepgcd != n1 and lepgcd != d1: break (n1, d1) = (n1 // lepgcd, d1 // lepgcd) while True: (n3, d3) = (valeur_alea(-10, 10), valeur_alea(2, 10)) lepgcd = pgcd(n3, d3) if lepgcd != n3 and lepgcd != d3: break (n3, d3) = (n3 // lepgcd, d3 // lepgcd) (n2, n4) = (valeur_alea(1, 10), valeur_alea(1, 10)) if randrange(2) == 0: s1 = '+' else: s1 = '-' if randrange(2) == 0: s2 = '+' else: s2 = '-' return ((n1, d1), (n2, 1), (n3, d3), (n4, 1), (s1, s2))
def valeurs_puissances(): # renvoie un tuple contenant les valeurs pour les deux exercices sur les puissances from math import floor, log10 (maxi, emax) = (10, 2) while True: (b1, b2) = (valeur_alea(2, maxi), valeur_alea(2, maxi)) (b1, b2) = (b1 / pgcd(b1, b2), b2 / pgcd(b1, b2)) if b1 != 1 and b2 != 1: break while True: (n1, n2) = ((b1 * valeur_alea(2, maxi)) * 10 ** randrange(-emax, emax), (b2 * valeur_alea(2, maxi)) * 10 ** randrange(-emax, emax)) n3 = ((b1 * b2) * choice((2, 4, 5, 8))) * 10 ** randrange(-emax, emax) if int(floor(log10(((n1 * n2) * 1.) / n3))) != 0 and n1 != 1 and \ n2 != 1 and n3 != 1: break (e1, e2, e3, e4) = (valeur_alea(-10, 10), valeur_alea(-10, 10), valeur_alea(2, 10), valeur_alea(2, 5)) a = verifie_type((n1, n2, n3, e1, e2, e3, e4)) while True: (b1, b2) = (valeur_alea(2, maxi), valeur_alea(2, maxi)) (b1, b2) = (b1 / pgcd(b1, b2), b2 / pgcd(b1, b2)) if b1 != 1 and b2 != 1: break (n1, n2) = ((b1 * valeur_alea(2, maxi)) * 10 ** randrange(-emax, emax + 1), (b2 * valeur_alea(2, maxi)) * 10 ** randrange(-emax, emax + 1)) n3 = ((b1 * b2) * choice((1, 2, 4, 5, 8))) * 10 ** randrange(-emax, emax + 1) (e1, e2, e3, e4) = (valeur_alea(-10, 10), valeur_alea(-10, 10), valeur_alea(-10, -2), valeur_alea(2, 5)) b = verifie_type((n1, n2, n3, e1, e2, e3, e4)) return (a, b)
def __init__(self): 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)] exercice = [list(pol)] val = [valeur_alea(-9, 9), valeur_alea(-9, 9)] val.append(Fraction(valeur_alea(-9, 9), val[0])) while val[2].d == 1: val = [valeur_alea(-9, 9), valeur_alea(-9, 9)] val.append(Fraction(valeur_alea(-9, 9), val[0])) sgn = -val[0] / abs(val[0]) pol = [[val[0], 2], [(-val[0] * (val[1] * val[2].d + val[2].n)) / val[2].d, 1], [(val[0] * val[1] * val[2].n) / val[2].d, 0]] shuffle(pol) exercice.append([pol, val[1], val[2]]) val = [sgn * valeur_alea(-9, 9), valeur_alea(-9, 9)] val.append(Fraction(valeur_alea(-9, 9), val[0]).simplifie()) while isinstance(val[2], int) or val[2].d == 1: val = [sgn * valeur_alea(-9, 9), valeur_alea(-9, 9)] val.append(Fraction(valeur_alea(-9, 9), val[0])) pol = [[val[0], 2], [(-val[0] * (val[1] * val[2].d + val[2].n)) / val[2].d, 1], [(val[0] * val[1] * val[2].n) / val[2].d, 0]] shuffle(pol) exercice.append([pol, val[1], val[2]]) self.exercice = exercice
def __init__(self): val = [valeur_alea(-9, 9), valeur_alea(-9, 9)] val.append(Fraction(valeur_alea(-9, 9), val[0])) while val[2].d == 1: val = [valeur_alea(-9, 9), valeur_alea(-9, 9)] val.append(Fraction(valeur_alea(-9, 9), val[0])) pol = [[val[0], 2], [(-val[0] * (val[1] * val[2].d + val[2].n)) / val[2].d, 1], [(val[0] * val[1] * val[2].n) / val[2].d, 0]] shuffle(pol) exercice = [[list(pol), val[1], val[2]]] pol = [creerPolydegre2(nb_racines=0).monomes] pol.append(creerPolydegre2(nb_racines=1).monomes) a, b = valeur_alea(-9, 9), valeur_alea(-9, 9) sgn = [1, -1][randrange(2)] pol.append([[sgn * a ** 2, 2], [-sgn * b ** 2, 0]]) a, b = valeur_alea(-9, 9), valeur_alea(-9, 9) pol.append([[a, 2], [b, 1]]) a, b = valeur_alea(-9, 9), valeur_alea(-9, 9) while abs(pgcd(a, b)) != 1: a, b = valeur_alea(-9, 9), valeur_alea(-9, 9) pol.append([[a, 2], [b, 0]]) pol.pop(randrange(1, len(pol))) pol.pop(randrange(1, len(pol))) pol.pop(randrange(1, len(pol))) shuffle(pol) exercice.append(pol) self.exercice = exercice