Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
lafrite 2015-05-14 11:02:48 +02:00
commit a418b64977
5 changed files with 345 additions and 93 deletions

View File

@ -8,14 +8,23 @@ import csv
from path import path
from texenv import texenv
import math as m
import random as rd
from pymath.expression import Expression
from pymath.polynom import Polynom
from pymath.polynomDeg2 import Polynom_deg2
from pymath.fraction import Fraction
pymath_tools = {"Expression":Expression,\
export_dict = {}
export_dict.update(m.__dict__)
export_dict.update(rd.__dict__)
export_dict.update(__builtins__.__dict__)
export_dict.update({"Expression":Expression,\
"Polynom":Polynom,\
"Polynom_deg2":Polynom_deg2,\
"Fraction":Fraction,\
}
})
def main(options):
#template = report_renderer.get_template(options.template)
@ -52,7 +61,7 @@ def main(options):
dest = path(str(infos['num']) + output)
tmp_pdf.append(dest.namebase + ".pdf")
with open( dest, 'w') as f:
f.write(template.render( infos = infos, **pymath_tools ))
f.write(template.render( infos = infos, **export_dict ))
if not options.no_compil:
os.system("pdflatex " + dest)

View File

@ -1,106 +1,107 @@
\documentclass[a4paper,10pt]{/media/documents/Cours/Prof/Enseignements/Archive/2013-2014/tools/style/classDS}
\usepackage{/media/documents/Cours/Prof/Enseignements/Archive/2013-2014/2013_2014}
\documentclass[a4paper,10pt]{article}
\RequirePackage[utf8x]{inputenc}
\RequirePackage[francais]{babel}
\RequirePackage{amssymb}
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{subfig}
\RequirePackage{graphicx}
\RequirePackage{color}
% Title Page
\titre{Calcul littéral et statistiques}
% \quatreC \quatreD \troisB \troisPro
\classe{\troisB}
\date{26 septemble 2013}
% DS DSCorr DM DMCorr Corr
\typedoc{DS}
\duree{1 heure}
\sujet{}
\title{Calcul littéral et statistiques}
\date{\today}
\begin{document}
\maketitle
\Calc
Le barème est donné à titre indicatif, il pourra être modifié.
\begin{Exo}[4.5]
Développer et réduire les expressions suivantes:
\begin{eqnarray*}
A &=& \frac{ 1 }{ 2 } + 2 \\
P(x) &=& 6 x - 2 \\
Q(x) &=& 4 x + 11\\
R(x) &=& ( 6 x - 2 ) \times ( 4 x + 11 )
\end{eqnarray*}
Solutions:
\begin{eqnarray*}
A & = & \frac{ 1 }{ 2 } + 2 \\
A & = & \frac{ 1 \times 1 }{ 2 \times 1 } + \frac{ 2 \times 2 }{ 1 \times 2 } \\
A & = & \frac{ 1 + 4 }{ 2 } \\
A & = & \frac{ 5 }{ 2 }
\end{eqnarray*}
\begin{eqnarray*}
P(2) & = & 6 \times 2 - 2 \\
P(2) & = & 12 - 2 \\
P(2) & = & 10
\end{eqnarray*}
\begin{eqnarray*}
Q(2) & = & 4 \times 2 + 11 \\
Q(2) & = & 8 + 11 \\
Q(2) & = & 19
\end{eqnarray*}
\begin{eqnarray*}
P(x) + Q(X) & = & 6 x + 4 x - 2 + 11 \\
P(x) + Q(X) & = & ( 6 + 4 ) x + ( -2 ) + 11 \\
P(x) + Q(X) & = & 10 x + 9
\end{eqnarray*}
\begin{eqnarray*}
P(x) + Q(X) & = & 6 x - 2 + 4 x + 11 \\
P(x) + Q(X) & = & 4 x + 6 x + 11 - 2 \\
P(x) + Q(X) & = & ( 4 + 6 ) x + 11 + ( -2 ) \\
P(x) + Q(X) & = & 10 x + 9
\end{eqnarray*}
\begin{eqnarray*}
R(x) & = & ( 6 x - 2 ) \times ( 4 x + 11 ) \\
R(x) & = & 6 \times 4 x^{ 2 } + ( -2 ) \times 4 x + 6 \times 11 x + ( -2 ) \times 11 \\
R(x) & = & 6 \times 4 x^{ 2 } + ( ( -2 ) \times 4 + 6 \times 11 ) x + ( -2 ) \times 11 \\
R(x) & = & 24 x^{ 2 } + ( ( -8 ) + 66 ) x - 22 \\
R(x) & = & 24 x^{ 2 } + 58 x - 22
\end{eqnarray*}
\section{Polynômes}
\end{Exo}
\begin{Exo}
Résoudre l'équation suivante
\begin{eqnarray*}
3 x^{ 2 } + x + 10 & = & 0
- 3 x^{ 2 } + 6 x - 3 & = & 0
\end{eqnarray*}
Solution:
On commence par calculer le discriminant
\begin{eqnarray*}
\Delta & = & b^2-4ac
\Delta & = & b^2-4ac \\
\Delta & = & 6^{ 2 } - 4 \times ( -3 ) \times ( -3 ) \\
\Delta & = & 36 - ( -12 ) \times ( -3 ) \\
\Delta & = & 36 - 36 \\
\Delta & = & 0
\end{eqnarray*}
\begin{eqnarray*}
\Delta & = & 1^{ 2 } - 4 \times 3 \times 10 \\
\Delta & = & 1 - 12 \times 10 \\
\Delta & = & 1 - 120 \\
\Delta & = & -119
\end{eqnarray*}
Alors $\Delta = -119$
Alors $\Delta = 0 = 0$ donc il y a une solution
\begin{eqnarray*}
x_1 = \frac{-b}{2a} = \frac{ -6 }{ 2 \times ( -3 ) } = \frac{ -6 }{ -6 } = \frac{ 6 }{ 6 } = 1 = \frac{ -6 }{ -6 }
\end{eqnarray*}
Les solutions sont donc $\mathcal{S} = \left\{ \frac{ -6 }{ -6 }\right\}$
\bigskip
~\dotfill
\bigskip
\end{Exo}
Résoudre l'équation suivante
\begin{eqnarray*}
- 7 x^{ 2 } - 7 x + 9 & = & - 2 x^{ 2 } + x - 9
\end{eqnarray*}
Solution:
On commence par se ramener à une équation de la forme $ax^2+bx+c = 0$.
\begin{eqnarray*}
- 7 x^{ 2 } - 7 x + 9 = - 2 x^{ 2 } + x - 9 & \Leftrightarrow & - 7 x^{ 2 } - 7 x + 9 - (- 2 x^{ 2 } + x - 9) = 0 \\
& \Leftrightarrow & - 7 x^{ 2 } + 2 x^{ 2 } - 7 x - x + 9 + 9= 0 \\
& \Leftrightarrow & ( ( -7 ) + 2 ) x^{ 2 } + ( ( -7 ) + ( -1 ) ) x + 9 + 9= 0 \\
& \Leftrightarrow & - 5 x^{ 2 } - 8 x + 18= 0
\end{eqnarray*}
On cherche maintenant à résoudre l'équation $- 5 x^{ 2 } - 8 x + 18 = 0$.
On commence par calculer le discriminant
\begin{eqnarray*}
\Delta & = & b^2-4ac \\
\Delta & = & ( -8 )^{ 2 } - 4 \times ( -5 ) \times 18 \\
\Delta & = & 64 - ( -20 ) \times 18 \\
\Delta & = & 64 - ( -360 ) \\
\Delta & = & 424
\end{eqnarray*}
Alors $\Delta = 424 > 0$ donc il y a deux solutions
\begin{eqnarray*}
x_1 & = & \frac{-b - \sqrt{\Delta}}{2a} = \frac{-8 - \sqrt{424}}{2 \times -5} = 1.26 \\
x_2 & = & \frac{-b + \sqrt{\Delta}}{2a} = \frac{-8 + \sqrt{424}}{2 \times -5} = -2.86
\end{eqnarray*}
Les solutions sont donc $\mathcal{S} = \left\{ 1.26; -2.86 \right\}$
\end{document}

124
example/tpl_2ndDeg.tex Normal file
View File

@ -0,0 +1,124 @@
\documentclass[a4paper,10pt]{article}
\RequirePackage[utf8x]{inputenc}
\RequirePackage[francais]{babel}
\RequirePackage{amssymb}
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{subfig}
\RequirePackage{graphicx}
\RequirePackage{color}
% Title Page
\title{Calcul littéral et statistiques}
\date{\today}
\begin{document}
\maketitle
\section{Polynômes}
\Block{set P = Polynom_deg2.random(["{a}", "{b}", "{c}"], ["{b}**2 - 4*{a}*{c} == 0"])}
Résoudre l'équation suivante
\begin{eqnarray*}
\Var{P} & = & 0
\end{eqnarray*}
Solution:
On commence par calculer le discriminant de $P(x) = \Var{P}$.
\begin{eqnarray*}
\Delta & = & b^2-4ac \\
\Var{P.delta.explain()|calculus(name="\\Delta")}
\end{eqnarray*}
\Block{if P.delta > 0}
comme $\Delta = \Var{P.delta} > 0$ donc $P$ a deux racines
\begin{eqnarray*}
x_1 & = & \frac{-b - \sqrt{\Delta}}{2a} = \frac{\Var{-P.b} - \sqrt{\Var{P.delta}}}{2 \times \Var{P.a}} = \Var{P.roots()[0] } \\
x_2 & = & \frac{-b + \sqrt{\Delta}}{2a} = \frac{\Var{-P.b} + \sqrt{\Var{P.delta}}}{2 \times \Var{P.a}} = \Var{P.roots()[1] }
\end{eqnarray*}
Les solutions de l'équation $\Var{P} = 0$ sont donc $\mathcal{S} = \left\{ \Var{min(P.roots())}; \Var{max(P.roots())} \right\}$
\Block{elif P.delta == 0}
Comme $\Delta = 0$ donc $P$ a deux racines
\begin{eqnarray*}
x_1 = \frac{-b}{2a} = \Var{P.roots()[0]} \\
\end{eqnarray*}
La solution de $\Var{P} = 0$ est donc $\mathcal{S} = \left\{ \Var{P.roots()[0]}\right\}$
\Block{else}
Alors $\Delta = \Var{P.delta} < 0$ donc $P$ n'a pas de racine donc l'équation $\var{P} = 0$ n'a pas de solution.
\Block{endif}
\bigskip
~\dotfill
\bigskip
\Block{set P = Polynom_deg2.random(["{a}", "{b}", "{c}"])}
\Block{set Q = Polynom_deg2.random(["{a}", "{b}", "{c}"])}
Résoudre l'équation suivante
\begin{eqnarray*}
\Var{P} & = & \Var{Q}
\end{eqnarray*}
Solution:
On commence par se ramener à une équation de la forme $ax^2+bx+c = 0$.
\Block{set R = Polynom_deg2((P-Q)._coef)}
\begin{eqnarray*}
\Var{P} = \Var{Q} & \Leftrightarrow & \Var{P} - (\Var{Q}) = 0 \\
\Var{R.explain() | calculus(name = "", sep = "\\Leftrightarrow", end = "= 0")}
\end{eqnarray*}
On cherche maintenant à résoudre l'équation $\Var{R} = 0$.
On commence par calculer le discriminant de $R(x) = \Var{R}$.
\begin{eqnarray*}
\Delta & = & b^2-4ac \\
\Var{R.delta.explain()|calculus(name="\\Delta")}
\end{eqnarray*}
\Block{set Delta = R.delta}
\Block{if R.delta > 0}
comme $\Delta = \Var{R.delta} > 0$ donc $R$ a deux racines
\begin{eqnarray*}
x_1 & = & \frac{-b - \sqrt{\Delta}}{2a} = \frac{\Var{-R.b} - \sqrt{\Var{Delta}}}{2 \times \Var{R.a}} = \Var{R.roots()[0] } \\
x_2 & = & \frac{-b + \sqrt{\Delta}}{2a} = \frac{\Var{-R.b} + \sqrt{\Var{Delta}}}{2 \times \Var{R.a}} = \Var{R.roots()[1] }
\end{eqnarray*}
Les solutions de l'équation $\Var{R} = 0$ sont donc $\mathcal{S} = \left\{ \Var{min(R.roots())}; \Var{max(R.roots())} \right\}$
\Block{elif R.delta == 0}
Comme $\Delta = 0$ donc $R$ a deux racines
\begin{eqnarray*}
x_1 = \frac{-b}{2a} = \Var{R.roots()[0]} \\
\end{eqnarray*}
La solution de $\Var{R} = 0$ est donc $\mathcal{S} = \left\{ \Var{R.roots()[0]}\right\}$
\Block{else}
Alors $\Delta = \Var{R.delta} < 0$ donc $R$ n'a pas de racine donc l'équation $\Var{R} = 0$ n'a pas de solution.
\Block{endif}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master"
%%% End:

View File

@ -1,4 +1,5 @@
\documentclass[a4paper,10pt]{article}
<<<<<<< HEAD
\usepackage[utf8x]{inputenc}
\usepackage[francais]{babel}
\usepackage{amssymb}
@ -10,10 +11,25 @@
% \quatreC \quatreD \troisB \troisPro
\date{}
=======
\RequirePackage[utf8x]{inputenc}
\RequirePackage[francais]{babel}
\RequirePackage{amssymb}
\RequirePackage{amsmath}
\RequirePackage{amsfonts}
\RequirePackage{subfig}
\RequirePackage{graphicx}
\RequirePackage{color}
% Title Page
\title{Calcul littéral et statistiques}
\date{\today}
>>>>>>> origin/dev
\begin{document}
\maketitle
<<<<<<< HEAD
<<<<<<< HEAD
\section{Exercice de simplification de fraction}
\Block{do RdExpression.set_form("exp")}
@ -77,6 +93,13 @@ Le barème est donné à titre indicatif, il pourra être modifié.
\begin{Exo}
\Block{set P = Polynom.random(["{a}", "{b}", "{c}"])}
=======
\section{Polynômes}
\Block{set P = Polynom.random(["{a}", "{b}", "{c}"], ["{b}**2 - 4*{a}*{c} == 0"])}
>>>>>>> origin/dev
Résoudre l'équation suivante
\begin{eqnarray*}
\Var{P} & = & 0
@ -85,17 +108,107 @@ Le barème est donné à titre indicatif, il pourra être modifié.
Solution:
On commence par calculer le discriminant
\begin{eqnarray*}
\Delta & = & b^2-4ac
\end{eqnarray*}
\Block{set Delta = Expression("{b}^2 - 4*{a}*{c}".format(a = P._coef[2], b = P._coef[1], c = P._coef[0]))}
\Var{Delta.simplify()|calculus(name="\\Delta")}
\begin{eqnarray*}
\Delta & = & b^2-4ac \\
\Var{Delta.simplify()|calculus(name="\\Delta")}
\end{eqnarray*}
\Block{set Delta = Delta.simplified()}
Alors $\Delta = \Var{Delta}$
\Block{if Delta > 0}
Alors $\Delta = \Var{Delta} > 0$ donc il y a deux solutions
\Block{set x1 = (-P._coef[1] - sqrt(Delta))/(2*P._coef[2])}
\Block{set x2 = (-P._coef[1] + sqrt(Delta))/(2*P._coef[2])}
\begin{eqnarray*}
x_1 & = & \frac{-b - \sqrt{\Delta}}{2a} = \frac{\Var{-P._coef[1]} - \sqrt{\Var{Delta}}}{2 \times \Var{P._coef[2]}} = \Var{x1 | round(2)} \\
x_2 & = & \frac{-b + \sqrt{\Delta}}{2a} = \frac{\Var{-P._coef[1]} + \sqrt{\Var{Delta}}}{2 \times \Var{P._coef[2]}} = \Var{x2 | round(2)}
\end{eqnarray*}
Les solutions sont donc $\mathcal{S} = \left\{ \Var{x1|round(2)}; \Var{x2|round(2)} \right\}$
\Block{elif Delta == 0}
Alors $\Delta = \Var{Delta} = 0$ donc il y a une solution
\Block{set x1 = Expression("-{b}/(2*{a})".format(b = P._coef[1], a = P._coef[2]))}
\begin{eqnarray*}
x_1 = \frac{-b}{2a} = \Var{" = ".join(x1.simplify())}
\end{eqnarray*}
Les solutions sont donc $\mathcal{S} = \left\{ \Var{x1.simplified()}\right\}$
\Block{else}
Alors $\Delta = \Var{Delta} < 0$ donc il n'y a pas de solution.
\Block{endif}
\bigskip
~\dotfill
\bigskip
\Block{set P = Polynom.random(["{a}", "{b}", "{c}"])}
\Block{set Q = Polynom.random(["{a}", "{b}", "{c}"])}
Résoudre l'équation suivante
\begin{eqnarray*}
\Var{P} & = & \Var{Q}
\end{eqnarray*}
Solution:
On commence par se ramener à une équation de la forme $ax^2+bx+c = 0$.
\begin{eqnarray*}
\Var{P} = \Var{Q} & \Leftrightarrow & \Var{P} - (\Var{Q}) = 0 \\
\Var{(P - Q)|calculus(name = "", sep = "\\Leftrightarrow", end = "= 0")}
\end{eqnarray*}
\Block{set R = (P-Q)[-1]}
On cherche maintenant à résoudre l'équation $\Var{R} = 0$.
<<<<<<< HEAD
\end{Exo}
>>>>>>> origin/dev
=======
On commence par calculer le discriminant
\Block{set Delta = Expression("{b}^2 - 4*{a}*{c}".format(a = R._coef[2], b = R._coef[1], c = R._coef[0]))}
\begin{eqnarray*}
\Delta & = & b^2-4ac \\
\Var{Delta.simplify()|calculus(name="\\Delta")}
\end{eqnarray*}
\Block{set Delta = Delta.simplified()}
\Block{if Delta > 0}
Alors $\Delta = \Var{Delta} > 0$ donc il y a deux solutions
\Block{set x1 = (-R._coef[1] - sqrt(Delta))/(2*R._coef[2])}
\Block{set x2 = (-R._coef[1] + sqrt(Delta))/(2*R._coef[2])}
\begin{eqnarray*}
x_1 & = & \frac{-b - \sqrt{\Delta}}{2a} = \frac{\Var{-R._coef[1]} - \sqrt{\Var{Delta}}}{2 \times \Var{R._coef[2]}} = \Var{x1 | round(2)} \\
x_2 & = & \frac{-b + \sqrt{\Delta}}{2a} = \frac{\Var{-R._coef[1]} + \sqrt{\Var{Delta}}}{2 \times \Var{R._coef[2]}} = \Var{x2 | round(2)}
\end{eqnarray*}
Les solutions sont donc $\mathcal{S} = \left\{ \Var{x1|round(2)}; \Var{x2|round(2)} \right\}$
\Block{elif Delta == 0}
Alors $\Delta = \Var{Delta} = 0$ donc il y a une solution
\Block{set x1 = Expression("-{b}/(2*{a})".format(b = R._coef[1], a = R._coef[2]))}
\begin{eqnarray*}
x_1 = \frac{-b}{2a} = \Var{" = ".join(x1.simplify())}
\end{eqnarray*}
Les solutions sont donc $\mathcal{S} = \left\{ \Var{x1.simplified()}\right\}$
\Block{else}
Alors $\Delta = \Var{Delta} < 0$ donc il n'y a pas de solution.
\Block{endif}
>>>>>>> origin/dev
\end{document}

View File

@ -16,23 +16,28 @@ texenv = jinja2.Environment(
# Filters
def do_calculus(steps, name = "A"):
def do_calculus(steps, name = "A", sep = "=", end = "", joining = " \\\\ \n"):
"""Display properly the calculus
Generate this form string:
"name & sep & a_step end joining"
:param steps: list of steps
:returns: latex string ready to be endbeded
"""
ans = "\\begin{eqnarray*}\n"
#ans = "\\begin{eqnarray*}\n"
ans += " \\\\ \n".join([name + " & = & " + str(s) for s in steps])
ans += "\n\\end{eqnarray*}\n"
ans = joining.join([name + " & " + sep + " & " + str(s) + end for s in steps])
#ans += "\n\\end{eqnarray*}\n"
return ans
texenv.filters['calculus'] = do_calculus
from random import shuffle
texenv.filters['shuffle'] = shuffle
if __name__ == '__main__':
from pymath.expression import Expression