How to use the pyromaths.outils.Priorites3 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 / classes / Polynome.py View on Github external
'''renvoie la Fraction ou l'int P(x)'''
        if x == float("inf") or x == float("-inf"):
            if self.degre_max == 0:
                return self[0]
            elif self.deg % 2 == 0:
                return self[self.deg] * float("inf")
            else:
                return self[self.deg] * x
        elif isinstance(x, str):
            return self.TeX(var=x)
        else:
            result = 0
            for i in self.dictio.iterkeys():
                result = result + self[i] * x ** i
            if isinstance(result, str):
                result = eval(Priorites3.priorites(result)[-1][0])
            if isinstance(result, (int, float)):
                return result
            elif isinstance(result, Fraction):
                result = result.simplifie()
                if isinstance(result, int):
                    return result
                if result.d == 1:
                    return result.n
                else:
                    return result
            elif result.denominateur == 1:
                return result.numerateur
            else:
                return result
github Pyromaths / pyromaths / src / pyromaths / ex / lycee / equations.py View on Github external
y = [y[1], y[1], y[1], y[0], y[0], y[0]]
            self.points = list([(l1[i], y[i]) for i in range(6)])
            p = Lagrange(self.points)
            self.polynome = eval(Priorites3.priorites(p)[-1][0])
            End = True
            for val in range(13):
                #===============================================================
                # try:
                #     ordonnee = eval(self.polynome(val - 6))
                # except:
                #     print repr(self.polynome), val - 6
                # if isinstance(ordonnee, str):
                #     ordonnee = eval(Priorites3.priorites(ordonnee)[-1][0])
                #===============================================================
                try:
                    ordonnee = eval(Priorites3.priorites(self.polynome(val - 6))[-1][0])
                except IndexError:
                    ordonnee = eval(self.polynome(val - 6))
                if ordonnee > 5 or ordonnee < -5:
                    End = False
                    break
github Pyromaths / pyromaths / src / pyromaths / ex / troisiemes / developpements.py View on Github external
lpoly = [id_rem1(l[0], l[1]), id_rem2(l[2], l[3]), id_rem3(l[4], l[5]), id_rem4(l[6], l[7])]
    shuffle(lpoly)
    lid = [id_rem1, id_rem2, id_rem3, id_rem4]
    lpoly2 = [lid.pop(randrange(4))(Fraction(l[8], l[9]), Fraction(l[10], l[11]))]
    lpoly2.append('-' + lid.pop(randrange(3))(l[12], l[13]))
    shuffle(lpoly2)
    lpoly.extend(lpoly2)
    expr = [Priorites3.texify([Priorites3.splitting(lpoly[i])]) for i in range(6)]
    exo = ["\\exercice", u"Développer chacune des expressions littérales suivantes :"]
    exo.append("\\begin{multicols}{2}")
    exo.append('\\\\\n'.join(['$%s=%s$' % (chr(i + 65), expr[i][0]) for i in range(6)]))
    exo.append("\\end{multicols}")
    cor = ["\\exercice*", u"Développer chacune des expressions littérales suivantes :"]
    cor.append("\\begin{multicols}{2}")
    for i in range(6):
        dev = Priorites3.texify(Priorites3.priorites(lpoly[i]))
        dev.insert(0, expr[i][0])
        cor.append('\\\\\n'.join(['$%s=%s$' % (chr(i + 65), dev[j]) for j in range(len(dev) - 1)]))
        cor.append('\\\\')
        cor.append('\\fbox{$%s=%s$}\\\\\n' % (chr(i + 65), dev[-1]))
    cor.append("\\end{multicols}")

    return exo, cor
github Pyromaths / pyromaths / src / pyromaths / ex / troisiemes / affine.py View on Github external
dfrac{4}{3}\\,x-2$.', 'On sait que $f(0)=-2$ et $f(-3)=\\dfrac{4}{3}\\times \\le
            ft( -3\\right) -2=\\dfrac{4\\times \\cancel{3}\\times -1}{\\cancel{3}\\times 1}-
            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
github Pyromaths / pyromaths / src / pyromaths / classes / SquareRoot.py View on Github external
def print_coef(coef):
            """Gère le format du coef
            """
            if isinstance(coef, (float, int)):
                if coef > 0: return "+" + decimaux(coef)
                else: return decimaux(coef)
            if isinstance(coef, classes.Fractions.Fraction):
                if isinstance(coef.n, int) and isinstance(coef.d, int) and coef.n < 0 and coef.d > 0:
                    return "-" + str(Fraction(-coef.n, coef.d, coef.code))
                return "+" + str(coef)
            if isinstance(coef, str):
                texte = "(" + "".join(Priorites3.texify([Priorites3.splitting(coef)])) + ")"
                if texte[0] != "-": return "+" + texte
                else: return texte
        s = ""
github Pyromaths / pyromaths / src / pyromaths / ex / troisiemes / factorisations.py View on Github external
exo = ["\\exercice", u"Factoriser chacune des expressions littérales suivantes :"]
    exo.append("\\begin{multicols}{2}")
    cor = ["\\exercice*", u"Factoriser chacune des expressions littérales suivantes :"]
    cor.append("\\begin{multicols}{2}")
    for i in range(len(lexo)):
        p = [lexo[i]]
        while True:
            fact = factoriser(p[-1])
            if fact:
                p.append(fact)
            else: break
        p = Priorites3.texify([Priorites3.splitting(p[j]) for j in range(len(p))])
        cor.append('\\\\\n'.join(['$%s=%s$' % (chr(i + 65), p[j]) for j in range(len(p) - 1)]))
        cor.append('\\\\')
        cor.append('\\fbox{$%s=%s$}\\\\\n' % (chr(i + 65), p[-1]))
    exo.append('\\\\\n'.join(['$%s=%s$' % (chr(i + 65), Priorites3.texify([Priorites3.splitting(lexo[i])])[0]) for i in range(len(lexo))]))
    exo.append("\\end{multicols}")
    cor.append("\\end{multicols}")
    return exo, cor
github Pyromaths / pyromaths / src / pyromaths / ex / troisiemes / developpements.py View on Github external
Dans un premier temps, on n'utilise que des nombres entiers, puis des fractions, puis l'opposé 
    d'une expression littérale.
    """

    l = [randrange(1, 11) for dummy in range(14)]
    while pgcd(l[8], l[9]) != 1 or pgcd(l[10], l[11]) != 1 or (l[9] == 1 and l[11] == 1):
        # On crée deux rationnels irréductibles non tous deux entiers.
        l = [randrange(1, 11) for dummy in range(14)]
    lpoly = [id_rem1(l[0], l[1]), id_rem2(l[2], l[3]), id_rem3(l[4], l[5]), id_rem4(l[6], l[7])]
    shuffle(lpoly)
    lid = [id_rem1, id_rem2, id_rem3, id_rem4]
    lpoly2 = [lid.pop(randrange(4))(Fraction(l[8], l[9]), Fraction(l[10], l[11]))]
    lpoly2.append('-' + lid.pop(randrange(3))(l[12], l[13]))
    shuffle(lpoly2)
    lpoly.extend(lpoly2)
    expr = [Priorites3.texify([Priorites3.splitting(lpoly[i])]) for i in range(6)]
    exo = ["\\exercice", u"Développer chacune des expressions littérales suivantes :"]
    exo.append("\\begin{multicols}{2}")
    exo.append('\\\\\n'.join(['$%s=%s$' % (chr(i + 65), expr[i][0]) for i in range(6)]))
    exo.append("\\end{multicols}")
    cor = ["\\exercice*", u"Développer chacune des expressions littérales suivantes :"]
    cor.append("\\begin{multicols}{2}")
    for i in range(6):
        dev = Priorites3.texify(Priorites3.priorites(lpoly[i]))
        dev.insert(0, expr[i][0])
        cor.append('\\\\\n'.join(['$%s=%s$' % (chr(i + 65), dev[j]) for j in range(len(dev) - 1)]))
        cor.append('\\\\')
        cor.append('\\fbox{$%s=%s$}\\\\\n' % (chr(i + 65), dev[-1]))
    cor.append("\\end{multicols}")

    return exo, cor
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)):
            calcul = list(pre)
            calcul.extend(fc)
            if unreste[0][0] != '-':
                calcul.append('+')
            else:
                calcul.append('-')
                unreste[0] = unreste[0][1:]
            calcul.extend(unreste)
github Pyromaths / pyromaths / src / pyromaths / ex / lycee / SecondDegre.py View on Github external
sol = [[str(m[1][0]), '**', '2', '-', '4', '*', str(m[0][0]), '*', str(m[2][0])]]
                    sol.extend(Priorites3.priorites('%s**2-4*%s*%s' % (m[1][0], m[0][0], m[2][0])))
                else:
                    sol = [['(', str(m[1][0]), ')', '**', '2', '-', '4', '*', str(m[0][0]), '*', str(m[2][0])]]
                    sol.extend(Priorites3.priorites('(%s)**2-4*%s*%s' % (m[1][0], m[0][0], m[2][0])))
                solTeX = Priorites3.texify(sol)
                for s in solTeX:
                    question[i].append(u'\\Delta &= %s\\\\' % s)
                question[i].append(r'\end{aligned}$}')
                question[i].append(r'&')
                question[i].append(r'{$\! \begin{aligned}')
                delta = sol[-1][0]
                print(sol)
                sol = [['Fraction(SquareRoot([[%s, None], [-1, %s]]),\'2*%s\')' % (-m[1][0], delta, m[0][0])]]
                sol.extend(Priorites3.priorites(sol[0][0]))
                sol = Priorites3.texify(sol)
                for s in sol:
                    question[i].append(u'x_1 &= %s\\\\' % s)
                racines = [sol[-1]]
                question[i].append(r'\end{aligned}$}')
                question[i].append(r'&')
                question[i].append(r'{$\! \begin{aligned}')
                sol = [['Fraction(SquareRoot([[%s, None], [1, %s]]),\'2*%s\')' % (-m[1][0], delta, m[0][0])]]
                sol.extend(Priorites3.priorites(sol[0][0]))
                sol = Priorites3.texify(sol)
                for s in sol:
                    question[i].append(u'x_2 &= %s\\\\' % s)
                racines.append(sol[-1])
                question[i].append(r'\end{aligned}$}')
                question[i].append(r'\end{tabularx}\par')
                question[i].append(_(u'\\underline{Les racines de $%s$ sont }\\fbox{$%s$}') % (noms[i].rstrip(r' &= '), _('$}\\underline{ et }\\fbox{$').join(racines)))
                if i == 1: question.append(question[1])