4AG. Groups - JulTob/Mathematics GitHub Wiki

Groups

A group $G$ denoted by { $𝔾,✳$ } is a set under some operation $(✳)$ if it satisfais the $CAIN$ properties

  • C - Closure a✳b ∈𝔾
  • A - Associative a✳b✳c = (a✳b)✳c = a✳(b✳c)
  • I - Identity a✳i = a : i∈𝔾
  • N - iNverse a✳ä = i : ä∈𝔾

$(✳)$ is a binary operation $a,b ∈𝔾$: $✳(a,b)⟶c$

-- Generic Group Definition --
generic
   type Element is private;
   with function "*" (A, B : Element) return Element;  -- Group operation. Closure: n1 * n2 = n3
   with function Identity return Element;                  -- Identity element. n * I = n
   with function Inverse(A : Element) return Element;      -- Inverse of an element. n * N = 0
   procedure Generic_Group_Test;
-- Generic Group Implementation
procedure Generic_Group_Test is
   -- Test for Associativity: (A * B) * C = A * (B * C)
   function Is_Associative return Boolean is
      E1, E2, E3 : Element; -- Example elements
      begin
         return (E1 * E2) * E3) = (E1 * (E2 * E3));
         end Is_Associative;

   -- Test for Identity: A * I = A and I * A = A
   function Has_Identity return Boolean is
      E : Element := Identity;
      begin
         return (E * Identity) = E) and (Identity * E) = E);
         end Has_Identity;

   -- Test for Inverse: A * A⁻¹ = I
   function Has_Inverse return Boolean is
      E : Element;
      begin
         return E * Inverse(E)) = Identity;
         end Has_Inverse;

   begin
     Ada.Text_IO.Put_Line("Testing Group Properties...");
     Ada.Text_IO.Put_Line("Associativity: " & Boolean'Image(Is_Associative));
     Ada.Text_IO.Put_Line("Identity: " & Boolean'Image(Has_Identity));
     Ada.Text_IO.Put_Line("Inverse: " & Boolean'Image(Has_Inverse));
     end Generic_Group_Test;

Here’s how we can define a specific group (e.g., with colors) in another file and bind it to the generic group test.

-- Color Group Definition
package Color_Group is
   type Color is new Integer range 0 .. 359; 
        -- Hue values at the range [0° , 360°).


   -- Define the group operation.
   function Mix(A, B : Color) return Color;

   -- Define the identity element.
   function Neutral return Color;

   -- Define the inverse function.
   function Inverse(A : Color) return Color;
end Color_Group;

package body Color_Group is
   function Mix(A, B : Color) return Color is
   begin
      return (A + B) mod 360;
      end Mix;

   function Neutral return Color is
   begin
      return 0; -- Identity element.
   end Neutral;

   function Inverse(A : Color) return Color is
   begin
      return (360 - A) mod 360; 
      end Inverse;
end Color_Group;
-- Instantiating the Generic Group
with Color_Group;
with Generic_Group_Test;

procedure Test_Color_Group is
   -- Instantiate the generic group test with Color_Group.
   procedure Test is new Generic_Group_Test(
      Element   => Color_Group.Color,
      "*" => Color_Group.Mix,
      Identity  => Color_Group.Neutral,
      Inverse   => Color_Group.Inverse
      );
   begin
      Test; -- Run the group tests for the Color group.
      end Test_Color_Group;

Abelian Groups

A group is abelian if $a⋅b = b⋅a$

Cyclic Groups