#ifndef PERMUTATIONFUNC_H
#define PERMUTATIONFUNC_H

#include <typedefs.h>

/*!
\brief Store a list of permutation functions and
       calculate the binary operator * on these states.

General support for permutations so looking
 at the classes interface does not help much.

This class was written was to calculate
 the states given the operators as permutations.

\par Example
\verbatim
  cout << "Test if flipping a triange and rotating it form a group." << endl;

  uint fop[] = 
  {
    0,1,2,
    1,2,0,
    2,0,1,
    0,2,1,
    2,1,0,
    1,0,2
  };
  permutationfunc pf(fop,6,3);

  cout << "Generate the binary table" << endl;

  uint mat[6*6];
  bool result;
  pf.writeBinaryOperator(result,mat);
  if (result==false)
  {
    cout << "Failed to form a binary operator." << endl;
    return;
  }

  binopproperties gt(mat,6);
  cout << "isGroup()=" << gt.isGroup() << endl;
\endverbatim
*/
class permutationfunc
{
public:

  /** Initialize the class with the matrix of functions, 
      the number of functions and the permutations dimension. */
  permutationfunc
  (
    uintc * fop_,
    uintc N_,
    uintc dim_
  ) : fop(fop_), N(N_), dim(dim_) {}

  /** A pointer to the matrix of size N by dim. */
  uintc * fop;
  /** The number of functions. */
  uintc N;
  /** The dimension of the permutation. */
  uintc dim;

  /** Return the function. ie the i'th row. */
  uintc * fi(uintc i) const
    { return fop + dim*i; }

  /** Apply binary functions i(k(0,1,..,dim-1) and store in x. */
  void ik(uint * x, uintc i, uintc k) const;
  /** Apply binary functions i(k(0,1,..,dim-1) and return the 
     result as a state. */
  uintc ik(bool & found, uintc i, uintc k) const;
  /** Given a permutation find the index if it exists. */
  uintc inverse(bool & found, uintc * x) const;

  /** Write the operator to matrix mat which is assumed to be
      N by N in length. */
  void writeBinaryOperator(bool & result, uint * mat) const;
};


#endif



