Commit 0a871a6b authored by Louis's avatar Louis
Browse files

Suppression de modules obsolètes (et non-utilisés)

parent 5c0d6c2b
......@@ -247,31 +247,6 @@ LaTeX
>>> str(Fraction('-5*2', '3*2', 'r'))
\dfrac{-5_{\times 2}}{3_{\times 2}}
.. _calculs_etapes_fractions:
Calculs avec étapes
"""""""""""""""""""
.. currentmodule:: pyromaths.outils.Fractions
.. warning::
Ces fonctions sont peut-être obsolètes. Voir `la discussion sur le forum <http://forum.pyromaths.org/viewtopic.php?f=19&t=399>`__.
Si ces fonctions sont supprimées, supprimer aussi la référence à cette partie plus haut dans la page.
* Somme et Différence (:func:`EffectueSommeFractions`). Pour choisir l'opération, utiliser comme argument ``s="+"`` ou ``s="-"``.
.. code-block:: python
>>> EffectueSommeFractions(Fraction(5, 6), Fraction(2, 3), "+", "AVANT", u"APRÈS")
???
.. TODO::
À supprimer, ou compléter avec :func:`EffectueProduitFractions` et :func:`EffectueQuotientFractions`.
Polynômes
---------
......@@ -741,7 +716,6 @@ LaTeX
- ``classes/Racine.py``
- ``classes/SquareRoot.py``
- ``classes/Terme.py``
- ``classes/Vecteurs.py``
- ``outils/Affichage.py``
- ``outils/Arithmetique.py``
......@@ -749,5 +723,4 @@ LaTeX
- ``outils/Geometrie.py``
- ``outils/Polynomes.py``
- ``outils/Priorites3.py``
- ``outils/TeXMiseEnForme.py``
- ``outils/decimaux.py``
# -*- coding: utf-8 -*-
class Terme:
def __init__(self, coeff, puiss=1, var='x'):
if (not (isinstance(puiss, int))) or (not (isinstance(var, str))):
print "Erreur de définition ! La puissance doit être un nombre relatif !"
self.puiss = puiss # Nombre entier
self.coeff = coeff # Coeff devant le terme
self.var = var # Lettre pour la var
def __add__(self, other):
if not (isinstance(other, Terme)):
return str(self) + " + " + str(other)
if (self.puiss == other.puiss) and (self.var == other.var):
return Terme(self.coeff + other.coeff, self.puiss, self.var)
else:
return str(self) + " + " + str(other)
def __radd__(self, other):
return self +other
def __sub__(self, other):
if not (isinstance(other, Terme)):
return str(self) + " + " + str(other)
if (self.puiss == other.puiss) and (self.var == other.var):
return Terme(self.coeff - other.coeff, self.puiss, self.var)
else:
return str(self) + " - " + str(other)
def __rsub__(self, other):
return -(self -other)
def __mul__(self, other):
if (isinstance(other, float)) or (isinstance(other, int)):
return Terme(self.coeff * other, self.puiss, self.var)
elif self.var == other.var:
return Terme(self.coeff * other.coeff, self.puiss + other.puiss, self.var)
else:
return Terme(self.coeff * other.coeff, self.puiss + other.puiss, self.var + other.var)
def __rmul__(self, other):
return self * other
def __div__(self, other):
if (isinstance(other, float)) or (isinstance(other, int)):
return Terme(self.coeff / other, self.puiss, self.var)
elif self.var == other.var:
return Terme(self.coeff / other.coeff, self.puiss - other.puiss, self.var)
else:
return str(self.coeff / other.coeff) + str(Terme(1, self.puiss, self.var)) + " / " + str(Terme(1, other.puiss, other.var))
def __rdiv__(self, other):
return self.inv() * other
def inv(self):
return Terme(1.0 / self.coeff, -self.puiss, self.var)
def __str__(self):
if self.coeff == 1:
coeff = ''
elif self.coeff == -1:
coeff = '-'
else:
coeff = str(self.coeff) + ' '
if self.puiss == 1:
terme = self.var
elif (self.puiss == 0) and ((self.coeff == 1) or (self.coeff == -1)):
terme = '1'
elif self.puiss == 0:
terme = ''
else:
terme = self.var + u'^' + str(self.puiss)
return coeff + terme
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Pyromaths
# Un programme en Python qui permet de créer des fiches d'exercices types de
# mathématiques niveau collège ainsi que leur corrigé en LaTeX.
# Copyright (C) 2006 -- Jérôme Ortais (jerome.ortais@pyromaths.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
from pyromaths.classes.Fractions import Fraction
from . import Arithmetique, Affichage
import random
import math
#===============================================================================
# Gère le calcul fractionnaire
#===============================================================================
def EffectueSommeFractions(fr1, fr2, s, pre, post):
if s == "+":
fr = fr1 + fr2
else:
fr = fr1 - fr2
cor = []
if fr1.n and fr2.n:
ppcm = Arithmetique.ppcm(fr2.d, fr1.d)
if abs(fr1.d) - abs(fr2.d):
cor.append("%s%s%s%s%s" % (pre, Fractions.TeX(fr1, True,
coef=ppcm // abs(fr1.d)), s, Fractions.TeX(fr2,
True, coef=ppcm // abs(fr2.d)), post))
if pre.rstrip().endswith('(') and post.lstrip().startswith(')'):
pre = pre.rstrip()[:len(pre.rstrip()) - 1]
post = post.lstrip()[1:]
cor.append("%s%s%s" % (pre, Fractions.TeX(fr, True), post))
if fr.n:
frs = Fractions.simplifie(fr)
if abs(frs.n) != abs(fr.n):
cor.append("%s%s%s" % (pre, Fractions.TeX(frs, True,
coef=fr.d // frs.d), post))
cor.append("%s%s%s" % (pre, Fractions.TeX(frs, True),
post))
else:
cor.append("%s%s%s" % (pre, Fractions.TeX(fr, True), post))
return cor
def EffectueProduitFractions(fr1, fr2, pre, post):
fr1s = Fractions.simplifie(fr1)
fr2s = Fractions.simplifie(fr2)
cor = []
if fr1.n and fr2.n:
if abs(fr1s.d) < abs(fr1.d) or abs(fr2s.d) < abs(fr2.d):
cor.append("%s%s \\times %s%s" % (pre, Fractions.TeXSimplifie(fr1),
Fractions.TeXSimplifie(fr2), post))
cor.append("%s%s \\times %s%s" % (pre, Fractions.TeX(fr1s,
True), Fractions.TeX(fr2s, True), post))
fr = fr1s * fr2s
frs = Fractions.simplifie(fr)
if abs(frs.d - fr.d):
cor.append("%s%s%s" % (pre, Fractions.TeXProduit(fr1s, fr2s),
post))
cor.append("%s%s%s" % (pre, Fractions.TeX(frs, True), post))
else:
cor.append("%s%s%s" % (pre, Fractions.TeX(Fractions(0), True),
post))
return cor
def EffectueQuotientFractions(fr1, fr2, pre, post):
fr2 = Fractions(1, 1) / fr2
cor = ["%s%s \\times %s%s" % (pre, Fractions.TeX(fr1, True),
Fractions.TeX(fr2, True), post)]
cor.extend(EffectueProduitFractions(fr1, fr2, pre, post))
return cor
# -*- coding: utf-8 -*-
#
# Pyromaths
# Un programme en Python qui permet de créer des fiches d'exercices types de
# mathématiques niveau collège ainsi que leur corrigé en LaTeX.
# Copyright (C) 2006 -- Jérôme Ortais (jerome.ortais@pyromaths.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
from . import Arithmetique
import string
import math
import os
from .Conversions import radians, degres
from pyromaths.classes.Fractions import Fraction
class TeXMiseEnForme:
def __init__(self, text):
self.text = text
def monome(self, coef, var, bplus=0, bpn=0, bpc=0):
# coef est le coefficient à écrire devant la variable var
# bplus est un booleen : s'il est vrai, il faut ecrire le signe +
# bpn est un booleen : s'il est vrai, il faut mettre des parentheses autour de l'ecriture si coef est negatif.
# bpc est un booleen : s'il est vrai, il faut mettre des parentheses autour de l'ecriture si coef =! 0 ou 1 et var est non vide
if coef != 0 and abs(coef) != 1:
if var == "":
if abs(coef) >= 1000:
a = _('\\nombre{%s}') % coef
else:
a = "%s" % coef
else:
if abs(coef) >= 1000:
a = _('\\nombre{%s}\\,%s') % (coef, var)
else:
a = '%s\\,%s' % (coef, var)
if bplus and coef > 0:
a = '+' + a
elif coef == 1:
if var == "":
a = '1'
else:
a = "%s" % var
if bplus:
a = '+' + a
elif coef == 0:
a = ""
elif coef == -1:
if var == "":
a = '-1'
else:
a = '-%s' % var
if bpn and coef < 0 or bpc and coef != 0 and coef != 1 and var != \
"":
a = '\\left( ' + a + '\\right)'
return a
def sepmilliers(self, nb, mathenvironment=0):
# Insère les espaces fines pour séparer les milliers et remplace le point
# décimal par une virgule
dec = [str(nb)[i] for i in range(len(str(nb)))]
if dec.count('e'): # nb ecrit en notation scientifique
exposant = int(("").join(dec[dec.index('e') + 1:]))
dec = dec[:dec.index('e')]
lg = len(dec)
if dec.count('.'):
virg = dec.index('.')
dec.remove('.')
else:
virg = len(dec)
if virg + exposant < 0: # L'ecriture decimale du nombre commence par 0,...
dec2 = ["0", '.']
for i in range(-virg - exposant):
dec2.append("0")
dec2.extend(dec)
dec = dec2
elif virg + exposant > lg:
# L'ecriture decimale du nombre finit par des 0
for i in range(-((lg - virg) - 1) + exposant):
dec.append("0")
dec2 = []
if dec.count('.'):
lavtvirg = dec.index('.')
laprvirg = (len(dec) - dec.index('.')) - 1
else:
lavtvirg = len(dec)
laprvirg = 0
nbsep = lavtvirg // 3 + 1
if lavtvirg > 3:
cpt = lavtvirg % 3
if cpt:
dec2 = dec[0:cpt]
dec2.append('\\,')
nbsep = nbsep - 1
for i in range(nbsep):
dec2.extend(dec[cpt:cpt + 3])
if nbsep - i > 1:
dec2.append('\\,')
cpt = cpt + 3
else:
if dec.count('.'):
dec2 = dec[0:dec.index('.')]
else:
dec2 = dec
if dec.count('.'):
cpt = dec.index('.')
else:
cpt = len(dec)
if laprvirg <= 3:
dec2.extend(dec[cpt:])
else:
nbsep = laprvirg // 3 - 1
dec2.extend(dec[cpt:cpt + 4])
dec2.append('\\,')
cpt = cpt + 4
for i in range(nbsep):
dec2.extend(dec[cpt:cpt + 3])
if cpt + 3 < len(dec):
dec2.append('\\,')
cpt = cpt + 3
dec2.extend(dec[cpt:])
nb = ("").join(dec2)
if nb.endswith('.0'):
nb = string.rsplit(nb, '.0')[0]
if mathenvironment:
return string.join(string.rsplit(nb, sep='.'), '{,}')
else:
return string.join(string.rsplit(nb, sep='.'), ',')
sepmilliers = TeXMiseEnForme("").sepmilliers
def Affichage(l):
"""\xc3\x89crit une expressions contenant des d\xc3\xa9cimaux et des fractions au format TeX
@param l: liste contenant l'expression [3, '+', 5, '*', 2]
"""
expr = "" # résultat
for i in range(len(l)): # on parcourt la liste
if ["+", "-", "*", "/", '(', ')'].count(l[i]): # Un opérateur
if l[i] == "*":
expr = expr + " \\times "
elif l[i] == "/":
expr = expr + " \\div "
elif l[i] == ")" and type(l[i - 1]) == type(Fractions(1, 1)):
expr = expr + " \\big) "
elif i < len(l) - 2 and l[i] == "(":
if type(l[i + 1]) == type(Fractions(1, 1)):
expr = expr + " \\big( "
else:
expr = expr + " " + l[i] + " "
elif type(l[i]) == type(Fractions(1, 1)):
# C'est une fraction
expr = expr + "%s" % Fractions.TeX(l[i], signe=0)
else:
# C'est un nombre
expr = expr + "%s" % Affichage.decimaux(l[i], 1)
return expr
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment