Voici le contenu du fichier
combinatorics.lua
dans lequel la fonction cnp
donne le coefficient binomial $C_n^p$ et la fonction anp
donne le nombre d'arrangements $A_n^p$.Code : Tout sélectionner
function cnp(n,p)
if (p == 0 or p == n) then
return 1
else
return n*cnp(n-1,p-1)/p
end
end
function anp(n,p)
if p == 0 then
return 1
else
return (n-p+1)*anp(n,p-1)
end
end
function fwrite(z)
tex.sprint(string.format("%.0f",z))
end
Code : Tout sélectionner
\documentclass{article}
\directlua{dofile('combinatorics.lua')}
\newcommand{\cnp}[2]{\directlua{fwrite(cnp(#1,#2))}}
\newcommand{\anp}[2]{\directlua{fwrite(anp(#1,#2))}}
\begin{document}
\begin{itemize}
\item $A_7^5 = \anp{7}{5}$
\item $C_7^5 = \cnp{7}{5}$
\end{itemize}
\end{document}