
#ifndef _WIN32
#include "../include/lminmaxgd.h"
#else
#include "..\include\lminmaxgd.h"
using namespace std;
#endif

#include <time.h>
#include <stdio.h>
// XavierTestCACABABStar.cpp :
// you must link with a library which contains all source files given in folder src
// gd.cpp poly.cpp serie.cpp smatrix.cpp tools.cpp interf.cpp
// or add these files in your project
// or alternatively you can include the folowing files
//
#include "..\src\gd.cpp"
#include "..\src\poly.cpp"
#include "..\src\serie.cpp"
#include "..\src\smatrix.cpp"
#include "..\src\tools.cpp"




#define n 8
#define nI 4
#define nO 4

int main()

{
	try
	{
//**********************************************************************/
// this example check if
// CA\CAB/AB is a star
// After work with Xavier April 2012
//**********************************************************************/



	smatrix A(n,n);// matrix of series declaration
	smatrix B(n,n);
	smatrix C(n,n);
	smatrix Asn,An1;
	smatrix CAsn,AsBn;
	smatrix Hn;
	gd m; // monomial declaration
	gd r;
    int k,i,j,val,flag,boucle; //
srand((int)(time(NULL)));
serie s;
serie sigma;
serie pr;
sigma.init(epsilon,m.init(0,2),r.init(3,3));
s.init(epsilon,m.init(0,1),r.init(2,5));
pr=frac(s,sigma);
cout<<"pr"<<pr<<endl;
pr=otimes(sigma,pr);
cout<<"sigma*pr"<<pr<<endl;
for (k=0;k<5;k++) // nombre de boucles
{


 val=6;

 for (i=0;i<n;i++)
 {
	 for (j=0;j<n;j++)    {
								int d=rand()%val; // dans [0,val-1]

							A(i,j).init(epsilon,m.init(rand()%val,d),e);
							if (rand()%5==0) // 0 ou 1

                            C(i,j).init(epsilon,e,e); // e

							if (rand()%5==0) // 0 ou 1
                            B(i,j).init(epsilon,e,e);

			 				}
 }
			 				An1=star(A);

			 				flag=0;
			 				boucle=0;
 do{
    Asn=An1;
    CAsn=otimes(C,Asn);
    AsBn=otimes(Asn,B);
    Hn=otimes(C,AsBn);
 //std::cout<<"Hn  "<<Hn;
    An1=lfrac(Hn,CAsn);
    An1=rfrac(An1,AsBn);
    if (An1==otimes(An1,An1))
    { cout<<" a star matrix boucle ="<<boucle<<endl;
      flag=1;


    }
 boucle++;
 }while(flag!=1&& boucle <4);






	}
	return 0;
	}
catch(mem_limite l)
 {
 std::cout<<"Exception : too many coefficent in polynom "<<l.memoire<< std::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
 std::cout<<"Exception  "<<obj.erreur<< std::endl;
	 return(1);
 }

}
