This commit is contained in:
Lafrite 2015-01-06 09:22:52 +01:00
parent 8c4312aafe
commit a261a44334
5 changed files with 159 additions and 11 deletions

View File

@ -8,7 +8,14 @@ import csv
from path import path
from texenv import texenv
from pymath.random_expression import RdExpression
from pymath.expression import Expression
from pymath.polynom import Polynom
from pymath.fraction import Fraction
pymath_tools = {"Expression":Expression,\
"Polynom":Polynom,\
"Fraction":Fraction,\
}
def main(options):
#template = report_renderer.get_template(options.template)
@ -45,7 +52,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( RdExpression = RdExpression , infos = infos))
f.write(template.render( infos = infos, **pymath_tools ))
if not options.no_compil:
os.system("pdflatex " + dest)

113
example/1_example.tex Normal file
View File

@ -0,0 +1,113 @@
\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}
% 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{}
\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*}
\end{Exo}
\begin{Exo}
Résoudre l'équation suivante
\begin{eqnarray*}
3 x^{ 2 } + x + 10 & = & 0
\end{eqnarray*}
Solution:
On commence par calculer le discriminant
\begin{eqnarray*}
\Delta & = & b^2-4ac
\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$
\end{Exo}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master"
%%% End:

BIN
example/all_example.pdf Normal file

Binary file not shown.

View File

@ -19,18 +19,46 @@
Le barème est donné à titre indicatif, il pourra être modifié.
\begin{Exo}[4.5]
\Block{do RdExpression.set_form("exp")}
\Block{set A = RdExpression("{a} / 2 + 2")()}
\Block{set B = RdExpression("{a} / 2 + 4")()}
\Block{set A = Expression.random("{a} / 2 + 2")}
\Block{set P = Polynom.random(["{b}","{a}"])}
\Block{set Q = Polynom.random(["{b+2}","{a}"])}
\Block{set R = P('x')*Q('x') }
Développer et réduire les expressions suivantes:
\begin{equation*}
A = \Var{ A } \\
B = \Var{ B }
\end{equation*}
\begin{eqnarray*}
A &=& \Var{ A } \\
P(x) &=& \Var{ P } \\
Q(x) &=& \Var{ Q }\\
R(x) &=& \Var{R}
\end{eqnarray*}
Solutions:
\Var{A.simplify() | calculus}
\Var{B.simplify() | calculus(name = "B")}
\Var{P(2).simplify() | calculus(name = "P(2)")}
\Var{Q(2).simplify() | calculus(name = "Q(2)")}
\Var{(P+Q) | calculus(name = "P(x) + Q(X)")}
\Var{(P('x')+Q('x')).simplify() | calculus(name = "P(x) + Q(X)")}
\Var{R.simplify() | calculus(name = "R(x)")}
\end{Exo}
\begin{Exo}
\Block{set P = Polynom.random(["{a}", "{b}", "{c}"])}
Résoudre l'équation suivante
\begin{eqnarray*}
\Var{P} & = & 0
\end{eqnarray*}
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")}
\Block{set Delta = Delta.simplified()}
Alors $\Delta = \Var{Delta}$
\end{Exo}

View File

@ -25,7 +25,7 @@ def do_calculus(steps, name = "A"):
"""
ans = "\\begin{eqnarray*}\n"
ans += " \\\\ \n".join([name + " & = & " + s for s in steps])
ans += " \\\\ \n".join([name + " & = & " + str(s) for s in steps])
ans += "\n\\end{eqnarray*}\n"
return ans