Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem with RTL multiplication, and make it apply to numbers on the right #2

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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