% environnement "ifactors" : decomposition en produit de facteurs premiers

\begin{VerbatimOut}{decomp.cxx}
maple_mode(0);
n:=read("n.val");
F:=ifactors(n);
l:=size(F);
T:="";
c:=0;
for (k:=0;k<l;k:=k+2) { if c!=0 then T:=T+"\\times"; end_if T:=T+F[k]+"^{"+F[k+1]+"}"; c++; };
Sortie:=fopen("decomp.tex");
fprint(Sortie,Unquoted,T);
fclose(Sortie);
\end{VerbatimOut}
  
\newenvironment*{ifactors}
{\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
{\end{VerbatimOut}
\immediate\write18{giac <decomp.cxx}
\ensuremath{\input{decomp.tex}}
}

% environnement "ifactors_table"

\begin{VerbatimOut}{decomp_table.cxx}
maple_mode(0);
n:=read("n.val");
F:=ifactors(n);
l:=size(F);
for (k:=0;k<l;k:=k+2){ L[k/2]:=F[k]; }; 
T:="\\begin{tabular}{r|l}";
k:=0;
while (n!=1) { T:=T+n+"&"; if (irem(n,L[k])==0) { T:=T+L[k]+"\\\\"; n:=n/L[k]; } else { k:=k+1; T:=T+L[k]+"\\\\"; n:=n/L[k]; };  };
T:=T+"1 & \\\\\\end{tabular}";
Sortie:=fopen("decomp_table.tex");
fprint(Sortie,Unquoted,T);
fclose(Sortie);
\end{VerbatimOut}
  
\newenvironment*{ifactorstable}
{\VerbatimEnvironment\begin{VerbatimOut}{n.val}}
{\end{VerbatimOut}
\immediate\write18{giac <decomp_table.cxx}
\input{decomp_table.tex}
}