How to use the pyromaths.outils.Priorites3.priorites function in pyromaths

To help you get started, we’ve selected a few pyromaths examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Pyromaths / pyromaths / src / pyromaths / ex / lycee / ExoPolynome.py View on Github external
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
github Pyromaths / pyromaths / src / pyromaths / ex / quatriemes / litteral.py View on Github external
def double_distributivite():
    """Crée un exercice permettant de s'entrainer sur la double distributivité
    """
    lcalc, expr = [], []
    for i in range(2):
        tmp = ['Polynome([[%s, 1]], details=3)' % ([1, randrange(2, 10)][i]), 'Polynome([[%s, 1]], details=3)' % randrange(2, 10)]
        shuffle(tmp)
        lcalc.append(["*".join(tmp)])
        lcalc[i].extend(priorites(lcalc[i][0]))
        lcalc[i][0] = splitting(lcalc[i][0])
        expr.append(texify(lcalc[i]))
    tmp = [0, 1, 2]
    for i in range(2, 5):
        a = valeurs_reduire_somme(2)
        b = valeurs_reduire_somme(2)
        exp = tmp.pop(randrange(len(tmp)))
        if exp != 1:
            c = 'Polynome([[%s, %s]], details=3)' % (randrange(1, 11) * (-1) ** randrange(3), exp)
        else:
            c = valeurs_reduire_somme(2)
        lpoly = [a, b]
        if randrange(2): lpoly.insert(0, c)
        else: lpoly.append(c)
        if c == lpoly[0]:
            lcalc.append(['%s+%s*%s' % (lpoly[0], lpoly[1], lpoly[2])])
github Pyromaths / pyromaths / src / pyromaths / ex / quatriemes / litteral.py View on Github external
def exo_comptable():
    """Exercice tiré de l'excellent ouvrage Des maths ensemble et pour chacun quatrième
    """
    exo = ["\\exercice", u"Le principe est le suivant : l'extrémité de chaque flèche indique la somme de la ligne ou de la colonne correspondante. Compléter, sachant que $x$ représente un nombre quelconque et que le contenu des deux cases grises doit être le même.\\par"]
    cor = ["\\exercice*", u"Le principe est le suivant : l'extrémité de chaque flèche indique la somme de la ligne ou de la colonne correspondante. Compléter, sachant que $x$ représente un nombre quelconque et que le contenu des deux cases grises doit être le même.\\par"]
    lexo = [valeurs_reduire_somme(2) for dummy in range(8)]
    lcalc = [["%s+%s" % (lexo[4], lexo[0])], ["%s+%s" % (lexo[5], lexo[1])], ["%s+%s" % (lexo[6], lexo[2])], ["%s+%s" % (lexo[7], lexo[3])], \
             ["%s+%s+%s+%s" % tuple(lexo[0:4])], [ "%s+%s+%s+%s" % tuple(lexo[4:])]]
    for i in range(6):
        sol = priorites(lcalc[i][0])
        lcalc[i].extend(["".join(sol[j]) for j in range(len(sol))])
    lcalc.append(["%s+%s+%s+%s" % (lcalc[0][-1], lcalc[1][-1], lcalc[2][-1], lcalc[3][-1])])
    lcalc.append(["%s+%s" % (lcalc[4][-1], lcalc[5][-1])])
    for i in range(6, 8):
        sol = priorites(lcalc[i][0])
        lcalc[i].extend(["".join(sol[j]) for j in range(len(sol))])
    for i in range(8):
        for j in range(len(lcalc[i])):
            lcalc[i][j] = splitting(lcalc[i][j])
    expr = [texify(lcalc[i]) for i in range(8)]
    # expr = [texify([splitting(lexo[i])]) for i in range(8)]
    txt = []
    # txt.append(r"\psset{xunit=1.1cm,yunit=1.5cm}")
    txt.append(r"\begin{center}")
    txt.append(r"\begin{pspicture}(16,6)")
    txt.append(r"\psframe[fillstyle=solid,fillcolor=Gray](0,0)(2,1)")
    txt.append(r"\psframe[fillstyle=solid,fillcolor=Gray](14,5)(16,6)")
    txt.append(r"\psframe(14,2)(16,3)")
    txt.append(r"\psframe(14,3)(16,4)")
    txt.append(r"\multido{\i=4+2}{4}{")
    txt.append(r"\rput(\i,0){\psframe(0,0)(2,1)\psline[linewidth=2pt]{<-}(1,1.2)(1,1.8)}")
github Pyromaths / pyromaths / src / pyromaths / ex / lycee / SecondDegre.py View on Github external
def resolution(self, m, pre=[], post=[]):
        sgn = '+-'[m[1][0] < 0]
        if isinstance(m[1][0], Fraction):
            b = Priorites3.priorites(abs(m[1][0]) / 2)[-1][0]
        elif m[1][0] % 2:
            b = 'Fraction(%s, 2)' % abs(m[1][0])
        else:
            b = abs(m[1][0]) / 2
        fc = ['Polynome("%sx%s%s")' % (m[0][0], sgn, b), '**', '2']
        reste = ['-']
        if m[2][0] > 0 or isinstance(m[2][0], Fraction):
            reste.extend(Priorites3.splitting('%s**2+%r' % (b, m[2][0])))
        else:
            reste.extend(Priorites3.splitting('%s**2%r' % (b, m[2][0])))
        etapes = list(pre)
        etapes.extend(fc)
        etapes.extend(reste)
        etapes.extend(post)
        etapes = [etapes]
        for unreste in Priorites3.priorites(''.join(reste)):
github Pyromaths / pyromaths / src / pyromaths / ex / lycee / ExoPolynome.py View on Github external
def factorisation_degre2(P, factorisation=True):
    # x1=x2=0
    from pyromaths.classes.Fractions import Fraction

    var = P.var
    X = Polynome({1:1}, var)
    delta = int(eval(priorites('%r**2-4*%r*%r' % (P[1], P[2], P[0]))[-1][0]))
    if delta < 0:
        factorisation = []
        str_racines = []
        racines = []
        simplrac = [False]
    elif delta == 0:
        x0 = eval(priorites('Fraction(-1, 2)*%r/%r' % (P[1], P[2]))[-1][0])
        simplrac = [False]
        if isinstance(x0, (Fraction, RacineDegre2)):
            racines = [x0.simplifie()]
        else:
            racines = [x0]
        str_racines = ["\\dfrac{-%s}{2\\times %s}" % (pTeX(P[1]), pTeX(P[2]))]


        P0 = "%s-%s" % (var, pTeX(racines[0]))