Skip to content

Commit

Permalink
Merge pull request #2 from dpvc/permutation-rtl
Browse files Browse the repository at this point in the history
Fix problem with RTL multiplication, and make it apply to numbers on the right
  • Loading branch information
paultpearson authored Jun 9, 2020
2 parents 6d44320 + 51cde24 commit a7ea081
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions macros/contextPermutation.pl
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,30 @@ sub make {
#
sub mult {
my ($self,$l,$r,$other) = Value::checkOpOrderWithPromote(@_);
if ($l->isReal) {
$l = $l->value;
Value->Error("Can't multiply %s by a non-integer value",$self->showType) unless $l == int($l);
Value->Error("Can't multiply %s by a negative value",$self->showType) if $l < 0;
my $n = $self->{P}{$l}; $n = $l unless defined $n;
return $self->Package("Real")->make($n);
if (!$self->getFlag('multiplyRightToLeft')) {
if ($l->isReal) {
$l = $l->value;
Value->Error("Can't multiply %s by a non-integer value",$self->showType) unless $l == int($l);
Value->Error("Can't multiply %s by a negative value",$self->showType) if $l < 0;
my $n = $self->{P}{$l}; $n = $l unless defined $n;
return $self->Package("Real")->make($n);
} else {
Value->Error("Can't multiply %s by %s",$l->showType,$r->showType)
unless $r->classMatch("Cycle","Permutation");
return $self->Package("Permutation")->new($l,$r);
}
} else {
Value->Error("Can't multiply %s by %s",$l->showType,$r->showType)
unless $r->classMatch("Cycle","Permutation");
return $self->getFlag("multiplyRightToLeft") ?
$self->Package("Permutation")->new($r,$l) : $self->Package("Permutation")->new($l,$r);
if ($r->isReal) {
$r = $r->value;
Value->Error("Can't multiply %s by a non-integer value",$self->showType) unless $r == int($r);
Value->Error("Can't multiply %s by a negative value",$self->showType) if $r < 0;
my $n = $self->{P}{$r}; $n = $r unless defined $n;
return $self->Package("Real")->make($n);
} else {
Value->Error("Can't multiply %s by %s",$l->showType,$r->showType)
unless $l->classMatch("Cycle","Permutation");
return $self->Package("Permutation")->new($l,$r);
}
}
}

Expand Down Expand Up @@ -387,7 +400,7 @@ sub new {
}

#
# Find the internal representation of the permutation
# Find the internal representation of the cycle
# (a hash representing where each element goes)
#
sub makeP {
Expand Down Expand Up @@ -443,6 +456,7 @@ sub new {
sub makeP {
my $self = shift; my $p = $self->{data};
my $P = {}; my %N;
$p = [reverse(@$p)] if $self->getFlag('multiplyRightToLeft');
foreach my $x (@$p) {map {$N{$_} = 1} (keys %{$x->{P}})} # get all elements used
foreach my $i (keys %N) {
my $j = $i;
Expand Down

0 comments on commit a7ea081

Please sign in to comment.