proj home

Files   Classes   Functions   Hierarchy  

binopproperties Class Reference

Investigate the binary operators mathematical properties. More...

#include <binopproperties.h>

Collaboration diagram for binopproperties:

List of all members.

Public Member Functions

 binopproperties (uintc *mat_, uintc N_)
 mat_ is a pointer to a N_ by N_ matrix representing the binary operator.
uintc inverseright (bool &found, uintc i, uintc e) const
 i*k == e then determine k.
uintc inverseleft (bool &found, uintc k, uintc e) const
 i*k == e then determine i.
uintc identityfind (bool &found) const
 Find the identity element.
uintc matik (uintc i, uintc k) const
 Access the binary operator i*k.
boolc isClosed () const
 Is the operator closed : each element 0 <= i*j < N .
boolc isCommutative () const
 Is a*b == b*a?
boolc isAssociative () const
 Is a*(b*c) == (a*b)*c?
boolc isGroup () const
 Operator * is closed, associative, has identity and inverse on each element?
boolc isGroupAbelian () const
 A group plus a*b==b*a.

Public Attributes

uintcmat
 Matrix of binary operator N by N.
uintc N
 N operators.


Detailed Description

Investigate the binary operators mathematical properties.

For example is the binary operator a group?

The binary matrix is passed in as a square N by N matrix. The matrix is made up of zero and positive integers. Let * be the binary operator.

Example
  cout << "Test if rotating a triange and flipping it form a group." << endl;
  uint mat[] = 
  {
    0,1,2,3,4,5,
    1,2,0,5,3,4,
    2,0,1,4,5,3,
    3,4,5,0,1,2,
    4,5,3,2,0,1,
    5,3,4,1,2,0
  };

  binopproperties gt(mat,6);
  cout << "isGroup()=" << gt.isGroup() << endl;

Definition at line 36 of file binopproperties.h.


Constructor & Destructor Documentation

binopproperties::binopproperties ( uintc mat_,
uintc  N_ 
) [inline]

mat_ is a pointer to a N_ by N_ matrix representing the binary operator.

Definition at line 42 of file binopproperties.h.

00043     : mat(mat_), N(N_) {}


Member Function Documentation

uintc binopproperties::identityfind ( bool found  )  const

Find the identity element.

Definition at line 5 of file binopproperties.cpp.

References matik(), and N.

Referenced by isGroup(), binoppropertiestest::test04(), and binoppropertiestest::test05().

00006 {
00007   uint k;
00008   for (uint i=0; i<N; ++i)
00009   {
00010     found=true;
00011     for (k=0; k<N; ++k)
00012     {
00013       if ((matik(i,k)==k) && (matik(k,i)==k))
00014         continue;
00015 
00016       found=false;
00017       k=N;
00018     }
00019 
00020     if (found)
00021       return i;
00022   }
00023 
00024   return 0;
00025 }

uintc binopproperties::inverseleft ( bool found,
uintc  k,
uintc  e 
) const

i*k == e then determine i.

Definition at line 148 of file binopproperties.cpp.

Referenced by isGroup().

00153 {
00154   found=true;
00155   for (uint w=0; w<N; ++w)
00156   {
00157     if (matik(w,k)==e)
00158       return w;
00159   }
00160 
00161   found=false;
00162   return 0;
00163 }

uintc binopproperties::inverseright ( bool found,
uintc  i,
uintc  e 
) const

i*k == e then determine k.

Definition at line 130 of file binopproperties.cpp.

Referenced by isGroup().

00135 {
00136   found=true;
00137   for (uint w=0; w<N; ++w)
00138   {
00139     if (matik(i,w)==e)
00140       return w;
00141   }
00142 
00143   found=false;
00144   return 0;
00145 }

boolc binopproperties::isAssociative (  )  const

Is a*(b*c) == (a*b)*c?

Definition at line 98 of file binopproperties.cpp.

References matik(), and N.

Referenced by isGroup(), binoppropertiestest::test04(), and binoppropertiestest::test05().

00099 {
00100   uint i;
00101   uint k;
00102   uint w;
00103 
00104   uint a1;
00105   uint a2;
00106   for ( i=0; i<N; ++i)
00107   {
00108     for (k=0; k<N; ++k)
00109     {
00110       for (w=0; w<N; ++w)
00111       {
00112         a2 = matik(k,w);
00113         a2 = matik(i,a2);
00114 
00115         a1 = matik(i,k);
00116         a1 = matik(a1,w);
00117 
00118         if (a2!=a1)
00119           return false;
00120       }
00121     }
00122   }
00123 
00124   return true;
00125 }

bool const binopproperties::isClosed (  )  const

Is the operator closed : each element 0 <= i*j < N .

Definition at line 27 of file binopproperties.cpp.

References matik(), and N.

Referenced by isGroup(), binoppropertiestest::test04(), and binoppropertiestest::test05().

00028 {
00029   uint x;
00030   for (uint i=0; i<N; ++i)
00031   {
00032     for (uint k=0; k<N; ++k)
00033     {
00034       x = matik(i,k);
00035       if (x>=N)
00036         return false;
00037     }
00038   }
00039 
00040   return true;
00041 }

boolc binopproperties::isCommutative (  )  const

Is a*b == b*a?

Definition at line 43 of file binopproperties.cpp.

References matik(), and N.

Referenced by isGroupAbelian(), binoppropertiestest::test04(), and binoppropertiestest::test05().

00044 {
00045   for (uint i=0; i<N; ++i)
00046   {
00047     for (uint k=0; k<N/2; ++k)
00048     {      
00049       if (matik(i,k)!=matik(k,i))
00050         return false;
00051     }
00052   }
00053 
00054   return true;
00055 }

boolc binopproperties::isGroup (  )  const

Operator * is closed, associative, has identity and inverse on each element?

Definition at line 57 of file binopproperties.cpp.

References identityfind(), inverseleft(), inverseright(), isAssociative(), isClosed(), and N.

Referenced by isGroupAbelian(), binoppropertiestest::test04(), and binoppropertiestest::test05().

00058 {
00059   if (isClosed()==false)
00060     return false;
00061 
00062   if (isAssociative()==false)
00063     return false;
00064 
00065   bool found;
00066   uint id = identityfind(found);
00067   if (found==false)
00068     return false;
00069 
00070   for (uint i=0; i<N; ++i)
00071   {
00072     inverseright(found,i,id);
00073     if (found==false)
00074       return false;
00075   }
00076 
00077   for (uint i=0; i<N; ++i)
00078   {
00079     inverseleft(found,i,id);
00080     if (found==false)
00081       return false;
00082   }
00083 
00084   return true;
00085 }

boolc binopproperties::isGroupAbelian (  )  const

A group plus a*b==b*a.

Definition at line 87 of file binopproperties.cpp.

References isCommutative(), and isGroup().

00088 {
00089   if (isGroup()==false)
00090     return false;
00091 
00092   if (isCommutative()==false)
00093     return false;
00094 
00095   return true;
00096 }

uintc binopproperties::matik ( uintc  i,
uintc  k 
) const [inline]

Access the binary operator i*k.

Definition at line 59 of file binopproperties.h.

References mat, and N.

Referenced by identityfind(), isAssociative(), isClosed(), and isCommutative().

00060     { assert(i<N); assert(k<N); return mat[i*N+k]; }


Member Data Documentation

Matrix of binary operator N by N.

Definition at line 46 of file binopproperties.h.

Referenced by matik().

N operators.

Definition at line 48 of file binopproperties.h.

Referenced by identityfind(), isAssociative(), isClosed(), isCommutative(), isGroup(), and matik().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:49:50 2011 for Chelton Evans Source by  doxygen 1.5.8