Math-Groups
view release on metacpan or search on metacpan
lib/Math/Groups.pm view on Meta::CPAN
}
}
identity($g); # Check that the group has an identity
for my $a(keys %$ð²) # Find the identity and confirm that there is only one
{confess "No inverse for: $a" unless defined inverse($g, $a); # Helpfully indicate element with no inverse
}
orders($g); # Order if each element
1 # It is a group
}
sub Group(&@) # Create a group
{my $sub = shift; # Operator, elements
my $g = bless {&Elements=>{}, &Inverses=>{}, &Orders=>{}}; # Empty group
for my $a(@_) # Create multiplication table
{for my $b(@_)
{$g->{&Elements}{$a}{$b} = &$sub($a, $b);
}
}
check($g); # Check we have a group
$g # Return results
}
lib/Math/Groups.pm view on Meta::CPAN
sub isoMorphic($$@) # Isomorphic
{my $g = shift; # First group
my $ð´ = shift; # Second group
ref($ð´) eq __PACKAGE__ or confess "Second parameter must be a group too!"; # Check it is a group isomorphism
my %m = @_; # Mapping between groups
my %ðº = reverse %m; # Mapping between groups
keys(%m) == keys(%ðº) or confess "Please supply a bijective mapping!"; # Check that the mapping is bijective
$g->homoMorphic($ð´, %m) && $ð´->homoMorphic($g, %ðº) # Bijective homomorphism is an isomorphism
}
sub isoMorphisms(&$$) # Find all the isomorphisms between two groups
{my ($sub, $g, $ð´) = @_; # Sub to call to process found isomorphisms, first group, second group
ref($ð´) eq __PACKAGE__ or confess "Second parameter must be a group too!"; # Check it is a group
order($g) == order($ð´) or confess "Groups have different orders!"; # Check groups have same order
my $i = e($g); # Identity of first group
my $ð¶ = e($ð´); # Identity of second group
my $e = [grep {$_ ne $i} sort keys %{ð²($g)}]; # Elements of first group in fixed order without identity
my $ð² = [grep {$_ ne $ð¶} sort keys %{ð²($ð´)}]; # Elements of second group in fixed order without identity
permute # Permute the elements to obtain all possible mappings
{my %m = map {$$e[$_]=>$$ð²[$_[$_]]} 0..$#_; # Mapping to test
&$sub(%m) if isoMorphic($g, $ð´, %m); # Process mapping if isomorphic
} 0..$#$e; # Elements to permute
}
sub autoMorphic($@) # Automorphic
{my $g = shift; # Group
$g->isoMorphic($g, @_) # Check
}
sub autoMorphisms(&$) # Find all the automorphisms of a group
{my ($sub, $g) = @_; # Sub to call to process found automorphisms, group
&isoMorphisms($sub,$g,$g)
}
# Export details
require 5;
require Exporter;
use vars qw(@ISA @EXPORT $VERSION);
( run in 0.391 second using v1.01-cache-2.11-cpan-49f99fa48dc )