\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{pro-glineor}[09/07/2008 version 1.01 ]


% This work may be distributed and/or mofified under the conditions
% or the LaTeX Project Public Licence, either v1.3 or (at your option)
% any later version. The latest version is in
%   http://www.latex-project.org/lppl/
% This work consists of the files pro-glineor.sty.



\RequirePackage{professor}
\RequirePackage{pstricks}


\DeclareOption{xcas}{\setboolean{xcas}{true}}


 \ProcessOptions\relax




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% proglin
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



\begin{VerbatimOut}{proglin.cxx}
proglin(L,S,X,XS):={
n:=nops(L)-1;
D:=NULL;DX:=NULL;
P:=NULL;PX:=NULL;
F:=[];
Le:=NULL;
Intx:=NULL;
Inty:=NULL;
W:=[0,0,0,0];

for(k:=0;k<=n;k++){L[k]:=solve(L[k],y)[0]; if((size(solve(L[k],x))!=0) and (solve(L[k],x)!=[x])){Intx:=Intx,solve(L[k],x)[0]};
                   F:=append(F,unapply(L[k],x));Inty:=Inty,F[k](0)}



W[0]:=-0.1*maxnorm([Intx]); W[1]:=1.2*(max(maxnorm(X),maxnorm([Intx])));
W[2]:=-0.1*maxnorm([Inty]); W[3]:=1.2*maxnorm([Inty]);



if(nops(X)>0){
nx:=nops(X)-1;
for(k:=0;k<=nx;k++){
 Le:=Le,legende(X[k]+i*(k+1)*W[3]/(k+5),"D"+(n+1+k));
 DX:=DX,droite(x=X[k]);
 PX:=PX,if(XS[k]==p){display(polygone(1.2*W[0]+i*6*W[2],1.2*W[0]+1.2*W[3]*i,X[k]+1.2*W[3]*i,X[k]+i*6*W[2]),(k+6+nx)+rempli);}
              else{display(polygone(1.2*W[1]+i*6*W[2],1.2*W[1]+1.2*W[3]*i,X[k]+1.2*W[3]*i,X[k]+i*6*W[2]),(k+6+nx)+rempli);}
  }
}

 for(k:=0;k<=n;k++){
 Le:=Le,legende(((5-k)*W[0]+(k+2)*W[1])/(7)+i*F[k](((5-k)*W[0]+(k+2)*W[1])/(7)),"D"+k);
 D:=D,droite(y=L[k]);
 P:=P,if(S[k]==m){display(polygone(1.2*W[0]+i*F[k](1.2*W[0]),1.2*W[0]+1.2*W[3]*i,1.2*W[1]+1.2*W[3]*i,1.2*W[1]+i*F[k](1.2*W[1])),(k+2)+rempli);}
               else{display(polygone(1.2*W[0]+i*F[k](1.2*W[0]),1.2*W[0]+6*W[2]*i,1.2*W[1]+6*W[2]*i,1.2*W[1]+i*F[k](1.2*W[1])),(k+2)+rempli);}
  }
xyztrange(W[0],W[1],W[2],W[3],-10,10,-1,6,W[0],W[1],W[2],W[3],1);
//Be:=unapply(B,x,y):;
//Bmax:=Be(maxnorm([Intx]),maxnorm([Inty]));
D:=D,DX;
P,PX,DX,D,Le;//display(droite(B=R),line_width_4) 
 
}:;
\end{VerbatimOut}

                   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{VerbatimOut}{proglin.giac}
maple_mode(0);
read("proglin.cxx");
Sortie:=fopen("XCASproglin.tex");
fprint(Sortie,Unquoted,latex(read("proglin.user")));
fclose(Sortie);
\end{VerbatimOut}


%% initialise le compteur
\newcounter{Cptproglin}
\newcommand{\plin}{\theCptproglin}
%% \plin change a chaque figure

                   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newenvironment{proglin}
{\VerbatimEnvironment\begin{VerbatimOut}{proglin.user}}
{\end{VerbatimOut}

\immediate\write18{\rem XCASproglin.tex}
\executGiacmp{proglin.giac}
\immediate\write18{\rem \nomtravail.proglin\plin.tex}
\immediate\write18{\cat XCASproglin.tex >> \nomtravail.proglin\plin.tex}

\ifpdf
\immediate\write18{latex -interaction=nonstopmode \nomtravail.proglin\plin.tex}
\immediate\write18{dvips -o \nomtravail.proglin\plin.ps \nomtravail.proglin\plin.dvi}
\immediate\write18{ps2pdf \nomtravail.proglin\plin.ps \nomtravail.proglin\plin.pdf}
\fi

           \begin{center}
             \ifpdf
             \includegraphics{\nomtravail.proglin\plin.pdf}
             \else
             \input{\nomtravail.proglin\plin}
              \fi
           \end{center}
\stepcounter{Cptproglin}
}







%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% proglinb
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\begin{VerbatimOut}{proglinb.cxx}
proglinb(L,S,X,XS,B,a,b):={
n:=nops(L)-1;
D:=NULL;DX:=NULL;
P:=NULL;PX:=NULL;
F:=[];
Le:=NULL;
Intx:=NULL;
Inty:=NULL;
W:=[0,0,0,0];

for(k:=0;k<=n;k++){L[k]:=solve(L[k],y)[0]; if((size(solve(L[k],x))!=0) and (solve(L[k],x)!=[x])){Intx:=Intx,solve(L[k],x)[0]};
                   F:=append(F,unapply(L[k],x));Inty:=Inty,F[k](0)}



W[0]:=-0.1*maxnorm([Intx]); W[1]:=1.2*(max(maxnorm(X),maxnorm([Intx])));
W[2]:=-0.1*maxnorm([Inty]); W[3]:=1.2*maxnorm([Inty]);



if(nops(X)>0){
nx:=nops(X)-1;
for(k:=0;k<=nx;k++){
 Le:=Le,legende(X[k]+i*(k+1)*W[3]/(k+5),"D"+(n+1+k));
 DX:=DX,droite(x=X[k]);
 PX:=PX,if(XS[k]==p){display(polygone(1.2*W[0]+i*6*W[2],1.2*W[0]+1.2*W[3]*i,X[k]+1.2*W[3]*i,X[k]+i*6*W[2]),(k+6+nx)+rempli);}
              else{display(polygone(1.2*W[1]+i*6*W[2],1.2*W[1]+1.2*W[3]*i,X[k]+1.2*W[3]*i,X[k]+i*6*W[2]),(k+6+nx)+rempli);}
  }
}

 for(k:=0;k<=n;k++){
 Le:=Le,legende(((5-k)*W[0]+(k+2)*W[1])/(7)+i*F[k](((5-k)*W[0]+(k+2)*W[1])/(7)),"D"+k);
 D:=D,droite(y=L[k]);
 P:=P,if(S[k]==m){display(polygone(1.2*W[0]+i*F[k](1.2*W[0]),1.2*W[0]+1.2*W[3]*i,1.2*W[1]+1.2*W[3]*i,1.2*W[1]+i*F[k](1.2*W[1])),(k+2)+rempli);}
               else{display(polygone(1.2*W[0]+i*F[k](1.2*W[0]),1.2*W[0]+6*W[2]*i,1.2*W[1]+6*W[2]*i,1.2*W[1]+i*F[k](1.2*W[1])),(k+2)+rempli);}
  }
xyztrange(W[0],W[1],W[2],W[3],-10,10,-1,6,W[0],W[1],W[2],W[3],1);
Be:=unapply(B,x,y):;
//Bmax:=Be(maxnorm([Intx]),maxnorm([Inty]));
D:=D,DX;
J:=inter_unique(D[a],D[b]);
Bmax:=Be(abscisse(J),ordonnee(J));
//title="Le point extreme a pour coordonnees ("+abscisse(J)+","+ordonnee(J)+")";
P,PX,DX,D,Le,display(droite(B=Bmax),line_width_4),display(open_polygon(point(0,ordonnee(J)),J,point(abscisse(J),0)),line_width_3+dot_line),legende(abscisse(J),exact(abscisse(J)),quadrant4),legende(i*ordonnee(J),exact(ordonnee(J)),quadrant2); 
 
}:;
\end{VerbatimOut}

                   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{VerbatimOut}{proglinb.giac}
maple_mode(0);
read("proglinb.cxx");
Sortie:=fopen("XCASproglinb.tex");
fprint(Sortie,Unquoted,latex(read("proglinb.user")));
fclose(Sortie);
\end{VerbatimOut}


%% initialise le compteur
\newcounter{Cptproglinb}
\newcommand{\plinb}{\theCptproglinb}
%% \plinb change a chaque figure

                   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\newenvironment{proglinb}
{\VerbatimEnvironment\begin{VerbatimOut}{proglinb.user}}
{\end{VerbatimOut}

\immediate\write18{\rem XCASproglinb.tex}
\executGiacmp{proglinb.giac}
\immediate\write18{\rem \nomtravail.proglinb\plinb.tex}
\immediate\write18{\cat XCASproglinb.tex >> \nomtravail.proglinb\plinb.tex}


\ifpdf
\immediate\write18{latex -interaction=nonstopmode \nomtravail.proglinb\plinb.tex}
\immediate\write18{dvips -o \nomtravail.proglinb\plinb.ps \nomtravail.proglinb\plinb.dvi}
\immediate\write18{ps2pdf \nomtravail.proglinb\plinb.ps \nomtravail.proglinb\plinb.pdf}
\fi
           \begin{center}
             \ifpdf
             \includegraphics{\nomtravail.proglinb\plinb.pdf}
             \else
             \input{\nomtravail.proglinb\plinb}
              \fi
           \end{center}
\stepcounter{Cptproglinb}
}

