
#ifndef _WIN32
#include "../include/lminmaxgd.h"
#else
#include "..\include\lminmaxgd.h"
#endif

/**************************************************************************************/
/* this example present the main function of the library
   and the different manner to declare monomial polynom serie and matrix */
/**************************************************************************************/
using namespace std;

#include "..\src\gd.cpp"
#include "..\src\poly.cpp"
#include "..\src\serie.cpp"
#include "..\src\smatrix.cpp"
#include "..\src\tools.cpp"
int main(void)
{
try{
 smatrix a(7,7), as(7,7), b(7,1), c(1,7), asb(7,1), h(1,1), cas(1,7);
smatrix aF(7,7);
int i,j;
  a(1,0) = gd(0,2);
  a(0,1) = gd(3,1);
  a(2,1) = gd(0,2);
  a(4,1) = gd(0,1);
  //a(3,2) = gd(1,3);
  a(3,2) = gd(0,3);
  //a(2,3) = gd(1,1);
  a(2,3) = gd(2,1);
  a(5,4) = gd(0,1);
  //a(4,5) = gd(2,1);
  a(4,5) = gd(2,3);
  a(6,5) = gd(0,1);
  a(6,3) = gd(0,1);

  aF(1,0) = gd(0,infinity);
  aF(0,1) = gd(3,infinity);
  aF(2,1) = gd(0,infinity);
  aF(4,1) = gd(0,infinity);
  //aF(3,2) = gd(1,infinity);
  aF(3,2) = gd(0,infinity);
  //aF(2,3) = gd(1,infinity);
  aF(2,3) = gd(2,infinity);
  aF(5,4) = gd(0,infinity);
  aF(4,5) = gd(2,infinity);
  aF(6,5) = gd(0,infinity);
  aF(6,3) = gd(0,infinity);


  b(0,0) = e;
  c(0,6) = e;


  as = star(a);
  asb = otimes(as,b);
  h = otimes(c,asb);
  cas = otimes(c,as);

smatrix test(7,1), aopt1(7,7);
  aopt1 = lfrac(cas,cas);

cout<<"H"<<h<<endl;;
cout<<"A"<<a<<endl;
cout<<"Aopt"<<aopt1;

// embrion de projecteur
aopt1=inf(aopt1,aF);
gd m;

for(i=0;i<aopt1.getrow();i++)
{for(j=0;j<aopt1.getcol();j++)

    {
        if (aopt1(i,j).getp().getpol(0)==epsilon)
        {//cout<<"!!! aopt("<<i<<","<<j<<")="<<aopt1(i,j).getq().getpol(0)<<endl;
            m=aopt1(i,j).getq().getpol(0);
            aopt1(i,j)=m;
           // cout<<"!!! aopt("<<i<<","<<j<<")="<<aopt1(i,j)<<endl;
        }
        else
        {
            m=aopt1(i,j).getp().getpol(0);
            aopt1(i,j)=m;

        }
    }
    }

cout<<"Aopt"<<aopt1;
for(i=0;i<aopt1.getrow();i++)
{for(j=0;j<aopt1.getcol();j++)

    {
        if (!(aopt1(i,j)==a(i,j)))
        {
            cout<<"aopt("<<i<<","<<j<<")="<<aopt1(i,j)<<endl;
        }

    }
    }
}







  catch(mem_limite l)
 {
	 cout<<"Exception : too many coefficent in polynom "<<l.memoire<<endl;
	 return(1);
 }

 catch(taille_incorrecte obj)
 { // 0 : r non causal
   // 1 : tentative d'accès à un element d'une matrice avec un indice incorrect
   // 2 : matrice de taille incompatible pour oplus, inf, otimes, rfrac, lfrac
   // 3 : etoile de matrice carré uniquement
	 cout<<"Exception  "<<obj.erreur<<endl;
	 return(1);
 }
}
