Skip to content

Enhance algebra functions#342

Closed
andrew-gardener wants to merge 3 commits into
openwebwork:developfrom
ubc:enhance-algebra-functions
Closed

Enhance algebra functions#342
andrew-gardener wants to merge 3 commits into
openwebwork:developfrom
ubc:enhance-algebra-functions

Conversation

@andrew-gardener
Copy link
Copy Markdown
Member

@andrew-gardener andrew-gardener commented Feb 2, 2018

Enhance context permutation

Add new permutation contextPermutationUBC.pl which differs from contextPermutation.pl by

  • perform permutation multiplication
  • allow displaying results in cycle, one line, or two line notation
  • parses both cycle and one notations (one line uses [] and is converted to cycles internally)
    Note: that these changes are in their own separate file as the changes may break existing usages of contextPermutation.pl

Add context Integer

  • Limits input to Integer values
  • Adds several integer functions for problem creation (phi, tau, lcm, gcd, isPrime, primeFactorization, randomPrime)

Add context Congruence

  • Adds a helper function for creating congruence solutions
  • reuses context Integer functions
  • Options to accept general solution only, all solutions only, or both

Example problems used for testing contexts to follow

An instructor requested some additional Webwork functionality. Hopefully this will be useful to others as well

Add new permutation `contextPermutationUBC.pl` which differs from `contextPermutation.pl` by
- perform permutation multiplication
- allow displaying results in cycle, one line, or two line notation
- parses both cycle and one notations (one line uses [] and is converted to cycles internally)
Note: that these changes are in their own seperate file as the changes may break existing usages of `contextPermutation.pl`
- Limits input to Integer values
- Adds several integer functions for problem creation (phi, tau, lcm, gcd, isPrime, primeFactorization, randomPrime)
- Adds a helper function for creating congruence solutions
- reuses context Integer functions
- Options to accept general solution only, all solutions only, or both
@andrew-gardener
Copy link
Copy Markdown
Member Author

permutation test problem

DOCUMENT();

loadMacros(
  "PGstandard.pl",
  "Parser.pl",
  "PGcourse.pl",
  "contextPermutationUBC.pl",
);

TEXT(&beginproblem);

# begin two line proccessing
Context(Permutation);
Context()->flags->set(displayTwoLineNotation => 1);
$twoLineSigma = Compute("(1 5 3 4)(2)(6)");
$twoLineTau = Compute("(1 2 3 4 5 6)");
$twoLineSigmaTeX = $twoLineSigma->TeX;
$twoLineTauTeX = $twoLineTau->TeX;

$twoLineAnswer1 = Compute("$twoLineSigma$twoLineTau");
$twoLineAnswer1TeX = $twoLineAnswer1->TeX;
$twoLineAnswer2 = Compute("$twoLineTau$twoLineSigma");
$twoLineAnswer2TeX = $twoLineAnswer2->TeX;
$twoLineAnswer3 = Compute("($twoLineSigma)^-1");
$twoLineAnswer3TeX = $twoLineAnswer3->TeX;
$twoLineAnswer4 = Compute("($twoLineTau)^-1");
$twoLineAnswer4TeX = $twoLineAnswer4->TeX;
$twoLineAnswer5 = Compute("$twoLineSigma$twoLineTau($twoLineSigma)^-1");
$twoLineAnswer5TeX = $twoLineAnswer5->TeX;

BEGIN_TEXT
$PAR

$BBOLD Two Line Notation $EBOLD
$BR
\(
  \sigma = $twoLineSigmaTeX, \tau = $twoLineTauTeX
\)
$PAR
\( \sigma\tau = \) \{ ans_rule(35) \}
$BR
\( answer1 = $twoLineAnswer1 \)
$BR
\( answer1 = $twoLineAnswer1TeX \)

$PAR
\( \tau\sigma = \) \{ ans_rule(35) \}
$BR
\( answer2 = $twoLineAnswer2 \)
$BR
\( answer2 = $twoLineAnswer2TeX \)

$PAR
\( \sigma^{-1} = \) \{ ans_rule(35) \}
$BR
\( answer3 = $twoLineAnswer3 \)
$BR
\( answer3 = $twoLineAnswer3TeX \)

$PAR
\( \tau^{-1} = \) \{ ans_rule(35) \}
$BR
\( answer4 = $twoLineAnswer4 \)
$BR
\( answer4 = $twoLineAnswer4TeX \)

$PAR
\( \sigma\tau\sigma^{-1} = \) \{ ans_rule(35) \}
$BR
\( answer5 = $twoLineAnswer5 \)
$BR
\( answer5 = $twoLineAnswer5TeX \)

END_TEXT
ANS($twoLineAnswer1->cmp);
ANS($twoLineAnswer2->cmp);
ANS($twoLineAnswer3->cmp);
ANS($twoLineAnswer4->cmp);
ANS($twoLineAnswer5->cmp);



# begin cycle proccessing
Context(Permutation);
Context()->flags->set(displayTwoLineNotation => 0);
$cycleSigma = Cycle(1,5,3,4);
$cycleTau = Cycle(1,2,3,4,5,6);
$cycleSigmaTeX = $cycleSigma->TeX;
$cycleTauTeX = $cycleTau->TeX;

$cycleAnswer1 = $cycleSigma * $cycleTau;
$cycleAnswer1TeX = $cycleAnswer1->TeX;
$cycleAnswer2 = $cycleTau * $cycleSigma;
$cycleAnswer2TeX = $cycleAnswer2->TeX;
$cycleAnswer3 = $cycleSigma ** -1;
$cycleAnswer3TeX = $cycleAnswer3->TeX;
$cycleAnswer4 = $cycleTau ** -1;
$cycleAnswer4TeX = $cycleAnswer4->TeX;
$cycleAnswer5 = $cycleSigma * $cycleTau * $cycleSigma ** -1;
$cycleAnswer5TeX = $cycleAnswer5->TeX;

BEGIN_TEXT
$PAR

$BBOLD Cycle Notation $EBOLD
$BR
\( \sigma = $cycleSigmaTeX, \tau = $cycleTauTeX  \)

$PAR
\( \sigma\tau = \) \{ ans_rule(35) \}
$BR
\( answer1 = $cycleAnswer1 \)
$BR
\( answer1 = $cycleAnswer1TeX \)

$PAR
\( \tau\sigma = \) \{ ans_rule(35) \}
$BR
\( answer2 = $cycleAnswer2 \)
$BR
\( answer2 = $cycleAnswer2TeX \)

$PAR
\( \sigma^{-1} = \) \{ ans_rule(35) \}
$BR
\( answer3 = $cycleAnswer3 \)
$BR
\( answer3 = $cycleAnswer3TeX \)

$PAR
\( \tau^{-1} = \) \{ ans_rule(35) \}
$BR
\( answer4 = $cycleAnswer4 \)
$BR
\( answer4 = $cycleAnswer4TeX \)

$PAR
\( \sigma\tau\sigma^{-1} = \) \{ ans_rule(35) \}
$BR
\( answer5 = $cycleAnswer5 \)
$BR
\( answer5 = $cycleAnswer5TeX \)

END_TEXT
ANS($cycleAnswer1->cmp);
ANS($cycleAnswer2->cmp);
ANS($cycleAnswer3->cmp);
ANS($cycleAnswer4->cmp);
ANS($cycleAnswer5->cmp);


# begin one line proccessing
Context(Permutation);
Context()->flags->set(displayOneLineNotation => 1);
$oneLineSigma = Compute("[5 2 4 1 3 6]");
$oneLineTau = Compute("[2 3 4 5 6 1]");
$oneLineSigmaTeX = $oneLineSigma->TeX;
$oneLineTauTeX = $oneLineTau->TeX;

$oneLineAnswer1 = Compute("$oneLineSigma$oneLineTau");
$oneLineAnswer1TeX = $oneLineAnswer1->TeX;
$oneLineAnswer2 = Compute("$oneLineTau$oneLineSigma");
$oneLineAnswer2TeX = $oneLineAnswer2->TeX;
$oneLineAnswer3 = Compute("($oneLineSigma)^-1");
$oneLineAnswer3TeX = $oneLineAnswer3->TeX;
$oneLineAnswer4 = Compute("($oneLineTau)^-1");
$oneLineAnswer4TeX = $oneLineAnswer4->TeX;
$oneLineAnswer5 = Compute("$oneLineSigma$oneLineTau($oneLineSigma)^-1");
$oneLineAnswer5TeX = $oneLineAnswer5->TeX;

$temp = Compute("[5 2 4 1 3 6]");
$tempTeX = $temp->TeX;

BEGIN_TEXT
$PAR

\( temp = $temp \)
$BR
\( temp = $tempTeX \)
$PAR
$PAR


$BBOLD One Line Notation $EBOLD
$BR
\(
  \sigma = $oneLineSigmaTeX, \tau = $oneLineTauTeX
\)
$PAR
\( \sigma\tau = \) \{ ans_rule(35) \}
$BR
\( answer1 = $oneLineAnswer1 \)
$BR
\( answer1 = $oneLineAnswer1TeX \)

$PAR
\( \tau\sigma = \) \{ ans_rule(35) \}
$BR
\( answer2 = $oneLineAnswer2 \)
$BR
\( answer2 = $oneLineAnswer2TeX \)

$PAR
\( \sigma^{-1} = \) \{ ans_rule(35) \}
$BR
\( answer3 = $oneLineAnswer3 \)
$BR
\( answer3 = $oneLineAnswer3TeX \)

$PAR
\( \tau^{-1} = \) \{ ans_rule(35) \}
$BR
\( answer4 = $oneLineAnswer4 \)
$BR
\( answer4 = $oneLineAnswer4TeX \)

$PAR
\( \sigma\tau\sigma^{-1} = \) \{ ans_rule(35) \}
$BR
\( answer5 = $oneLineAnswer5 \)
$BR
\( answer5 = $oneLineAnswer5TeX \)

END_TEXT
ANS($oneLineAnswer1->cmp);
ANS($oneLineAnswer2->cmp);
ANS($oneLineAnswer3->cmp);
ANS($oneLineAnswer4->cmp);
ANS($oneLineAnswer5->cmp);

ENDDOCUMENT();

@andrew-gardener
Copy link
Copy Markdown
Member Author

Integer test problem

DOCUMENT();

loadMacros(
  "PGstandard.pl",
  "Parser.pl",
  "PGcourse.pl",
  "parserMultiAnswer.pl",
  "contextInteger.pl",
);

TEXT(&beginproblem);

# (1) Prime Factorization
Context(Integer);
$randInt = random(10, 1001, 1);
@answer0 = primeFactorization($randInt);

BEGIN_TEXT
$PAR

$BBOLD (1) Prime Factorization $EBOLD

$PAR
Factor \( $randInt \) into primes: 
$BR
\( answer0 = \) @answer0
\{ ans_rule(35) \}
END_TEXT

ANS(List(@answer0)->cmp);


# GCD and Euclid's algorithm
Context(Integer);
$a1 = 5;
$b1 = 2;
$gcd1 = gcd($a1, $b1);

$answer1 = MultiAnswer($a1, $b1, $gcd1)->with(
  singleResult => 0,
  checker => sub {
    my ( $correct, $student, $self ) = @_;
    my ( $stuX, $stuY, $stuGcd ) = @{$student};
    my ( $a, $b, $gcd ) = @{$correct};
    my @results = (0,0,0);
    if ($a*$stuX + $b*$stuY == $gcd) {
      $results[0] = 1;
      $results[1] = 1;
    }
    if ($stuGcd == $gcd) {
      $results[2] = 1;
    }
    return @results;
  }
);

$a2 = 60;
$b2 = 36;
$gcd2 = gcd($a2, $b2);

$answer2 = MultiAnswer($a2, $b2, $gcd2)->with(
  singleResult => 0,
  checker => sub {
    my ( $correct, $student, $self ) = @_;
    my ( $stuX, $stuY, $stuGcd ) = @{$student};
    my ( $a, $b, $gcd ) = @{$correct};
    my @results = (0,0,0);
    if ($a*$stuX + $b*$stuY == $gcd) {
      $results[0] = 1;
      $results[1] = 1;
    }
    if ($stuGcd == $gcd) {
      $results[2] = 1;
    }
    return @results;
  }
);

BEGIN_TEXT
$PAR


$BBOLD (2) GCD and Euclids algorithm $EBOLD

$PAR
For each pair of integers a, b find gcd(a, b) and integers x, y such that ax + by = gcd(a, b)
$BR
(a) a = $a1, b = $b1: 
$BR
\( x = \) \{ ans_rule(10) \}, 
\( y = \) \{ ans_rule(10) \}, 
\( gcd(a, b) = \) \{ ans_rule(10) \}
$BR
\( gcd1 = $gcd1 \)

$BR
(b) a = $a2, b = $b2 : 
$BR
\( x = \) \{ ans_rule(10) \}, 
\( y = \) \{ ans_rule(10) \}, 
\( gcd(a, b) = \) \{ ans_rule(10) \}
$BR
\( gcd2 = $gcd2 \)

END_TEXT
ANS($answer1->cmp);
ANS($answer2->cmp);

# Least Common Multiple
Context(Integer);

$c1 = 36;
$d1 = 90;
$answer3 = lcm($c1, $d1);


BEGIN_TEXT
$PAR

$BBOLD (3) Least Common Multiple $EBOLD

$PAR
Find the least common multiple of $c1 and $d1
$BR
\( lcm($c1, $d1) = \) \{ ans_rule(10) \}
$BR
\( answer3 = $answer3 \)

END_TEXT
ANS(Compute($answer3)->cmp);



# phi and tau
Context(Integer);

$e1 = 365;
$answer4 = phi($e1);
$answer5 = tau($e1);

BEGIN_TEXT
$PAR

$BBOLD (4) \( \phi \) and \( \tau \) $EBOLD

$PAR
Find \( \phi($e1) \) and \( \tau($e1) \)
$BR
\( \phi($e1) = \) \{ ans_rule(10) \}
$BR
\( answer4 = $answer4 \)
$BR
\( \tau($e1) = \) \{ ans_rule(10) \}
$BR
\( answer5 = $answer5 \)

END_TEXT
ANS(Compute($answer4)->cmp);
ANS(Compute($answer5)->cmp);


ENDDOCUMENT();

@andrew-gardener
Copy link
Copy Markdown
Member Author

Congruence test problem

DOCUMENT();

loadMacros(
  "PGstandard.pl",
  "Parser.pl",
  "PGcourse.pl",
  "contextCongruence.pl",
);

TEXT(&beginproblem);

# Congruences General Solution
Context('Congruence-General-Solution');

$answer1 = Congruence(15, 10, 25);
$answer1_None = Congruence(15, 10, 24);

BEGIN_TEXT
$PAR

$BBOLD Congruences General Solution Only $EBOLD

$PAR
$BBOLD Solve congruences: $EBOLD find all solutions to \( 15x \equiv 10 (mod 25) \)
$BR
\( answer1 string = $answer1 \)
$BR
\{ ans_rule(30) \} enter 4+5k
$BR
\{ ans_rule(30) \} enter 4+25k,9+25k,14+25k,19+25k,24+25k
$BR
\{ ans_rule(30) \} enter None
END_TEXT

ANS($answer1->cmp);
ANS($answer1->cmp);
ANS($answer1->cmp);

BEGIN_TEXT
$PAR

$BBOLD Congruences General Solution Only (none) $EBOLD

$PAR
$BBOLD Solve congruences: $EBOLD find all solutions to \( 15x \equiv 10 (mod 24) \)
$BR
\( none string = $answer1_None \)
$BR
\{ ans_rule(30) \} enter 4+5k
$BR
\{ ans_rule(30) \} enter 4+25k,9+25k,14+25k,19+25k,24+25k
$BR
\{ ans_rule(30) \} enter None
END_TEXT

ANS($answer1_None->cmp);
ANS($answer1_None->cmp);
ANS($answer1_None->cmp);



# Congruences All Solutions
Context('Congruence-All-Solutions');

$answer2 = Congruence(15, 10, 25);
$answer2_None = Congruence(15, 10, 24);

BEGIN_TEXT
$PAR

$BBOLD Congruences All Solutions Only $EBOLD

$PAR
$BBOLD Solve congruences: $EBOLD find all solutions to \( 15x \equiv 10 (mod 25) \)
$BR
\( answer2 string = $answer2 \)
$BR
\{ ans_rule(30) \} enter 4+5k
$BR
\{ ans_rule(30) \} enter 4+25k,9+25k,14+25k,19+25k,24+25k
$BR
\{ ans_rule(30) \} enter None
END_TEXT

ANS($answer2->cmp);
ANS($answer2->cmp);
ANS($answer2->cmp);

BEGIN_TEXT
$PAR

$BBOLD Congruences All Solutions Only (none) $EBOLD

$PAR
$BBOLD Solve congruences: $EBOLD find all solutions to \( 15x \equiv 10 (mod 24) \)
$BR
\( none string = $answer2_None \)
$BR
\{ ans_rule(30) \} enter 4+5k
$BR
\{ ans_rule(30) \} enter 4+25k,9+25k,14+25k,19+25k,24+25k
$BR
\{ ans_rule(30) \} enter None
END_TEXT

ANS($answer2_None->cmp);
ANS($answer2_None->cmp);
ANS($answer2_None->cmp);


# Congruences Either Answer form
Context('Congruence');

$answer3 = Congruence(15, 10, 25);
$answer3_None = Congruence(15, 10, 24);

BEGIN_TEXT
$PAR

$BBOLD Congruences $EBOLD

$PAR
$BBOLD Solve congruences: $EBOLD find all solutions to \( 15x \equiv 10 (mod 25) \)
$BR
\( answer3 string = $answer3 \)
$BR
\{ ans_rule(30) \} enter 4+5k
$BR
\{ ans_rule(30) \} enter 4+25k,9+25k,14+25k,19+25k,24+25k
$BR
\{ ans_rule(30) \} enter None
END_TEXT

ANS($answer3->cmp);
ANS($answer3->cmp);
ANS($answer3->cmp);

BEGIN_TEXT
$PAR

$BBOLD Congruences (none) $EBOLD

$PAR
$BBOLD Solve congruences: $EBOLD find all solutions to \( 15x \equiv 10 (mod 24) \)
$BR
\( None string = $answer3_None \)
$BR
\{ ans_rule(30) \} enter 4+5k
$BR
\{ ans_rule(30) \} enter 4+25k,9+25k,14+25k,19+25k,24+25k
$BR
\{ ans_rule(30) \} enter None
END_TEXT

ANS($answer3_None->cmp);
ANS($answer3_None->cmp);
ANS($answer3_None->cmp);

ENDDOCUMENT();

@heiderich
Copy link
Copy Markdown
Member

I think (some of) the following subroutines could be of general interest, also when this specific context is not used. Would it make sense to have them in a separate macro file that could be loaded individually?

_divisor
_getPrimesInRange
primeFactorization
phi
tau
isPrime
randomPrime
gcd
egcd
mulularInverse
lcm

@andrew-gardener
Copy link
Copy Markdown
Member Author

@heiderich Sorry for taking a while to respond.

So you are basically asking for the functions to be moved to something like macros/integerFunctions.pl? That makes sense to me.

I'm still not 100% familiar with all the moving parts of webwork, but how would I expose these functions to problems across different contexts (I'm currently only really aware of exposing them though main::PG_restricted_eval which I believe is context aware)? Or would each context that loads the functions need to expose the functions with main::PG_restricted_eval? If the later then I think this could be done anyways by including the contextInteger.pl and then re-exposing the functions or inheriting from the context.

@heiderich
Copy link
Copy Markdown
Member

So you are basically asking for the functions to be moved to something like macros/integerFunctions.pl?

Yes, this was my idea. I am not sure what would be the proper way to expose these functions across different contexts. Maybe more experienced WeBWorK developers can help.

I am currently creating a new class of Math Objects for elements of finite cyclic rings, i.e. rings of the form Z/nZ. In the curse of this development it was helpful to actually have an own class for elements of the ring of integers and I started to create it. I think this could also be a good place for these functions.

I am not entirely sure about the concrete implementation yet, but it would be nice to be able to promote an integer either to a real number or to an element in a finite cyclic ring of given order.

Moreover it would be nice to be able to define Math Objects of a higher level (such as matrices) over any ring for which a Math Object class exists (besides R and C my idea is to first have classes for Z and Z/nZ, maybe also for Q). This would probably require bigger changes in pg. For instance I am not sure if there are currently Math Objects that can be promoted in different ways. For integers there would be several choices (the finite cyclic rings and Q). What do you think about this idea?

@Alex-Jordan
Copy link
Copy Markdown
Contributor

I think (some of) the following subroutines could be of general interest, also when this specific context is not used. Would it make sense to have them in a separate macro file that could be loaded individually?

gcd

gcd (and maybe lcm?) is already available all the time. It only returns the gcd of its first two arguments, so if you want a gcd of more numbers, you have to use gcd more than once.

@heiderich
Copy link
Copy Markdown
Member

gcd (and maybe lcm?) is already available all the time.

This is indeed the case. And it even works for Math Objects that are real or complex numbers... It even takes matrices (only abs, which is called in gcf then complains)...

It only returns the gcd of its first two arguments, so if you want a gcd of more numbers, you have to use gcd more than once

I did not ask for a function that calculates the gcd of more than two natural numbers., but for computations in finite cyclic rings one also wants the extended euclidean algorithm (egcd) that returns the coefficients in the Bézout identity.

Are there reasons against a Math Object class for integers?

@Alex-Jordan
Copy link
Copy Markdown
Contributor

| Are there reasons against a Math Object class for integers?

To the contrary, these are great additions. I'm thinking about some of the functions defined there, and what would be involved in just making them available all the time from any context. Or even when MathObjects is not even being used. They could be defined in PGbasicmacros.pl, but there may be better places.

I think these subroutines will need some testing and tweaking. For example, I think isPrime should first check that the argument is an integer. It uses the % operator in such a way that something like 5.5 would be considered prime, because 5.5 % 2 == 1. (The % operator ignores the decimal part, so 5.5 % 2 is equivalent to 5 % 2.)

@heiderich
Copy link
Copy Markdown
Member

heiderich commented Mar 12, 2018

To the contrary, these are great additions. I'm thinking about some of the functions defined there, and what would be involved in just making them available all the time from any context. Or even when MathObjects is not even being used. They could be defined in PGbasicmacros.pl, but there may be better places.

My point is that for many objects the output of gcd is currently not reasonable. As you mentioned, the same applies to isPrime. Therefore I think that they should check the type of the arguments. I guess if we would introduce a new Math Object class Integer and would require that the arguments of the existing gcd subroutine are objects of this class, this may break existing code in problems that do not use Math Objects (or we would have to convert "perl integers" into Math Object integers within the subroutine; however I do not oversee the effects this might have to existing problems). In the long term however I think that subroutines that check the type of the arguments would be desirable. So probably we would have to keep the existing gcd function in order not to break existing problems. However for new functions I would prefer them to check the type of the arguments and I believe that for several of the functions I mentioned above a class for integers would be suitable.

In the end many properties of numbers depend on the ring they belong to. The natural number 2 is not invertible in Z, but it is in Q. It would be very nice if WeBWorK could be aware of that and it could be controlled within the problem (and probably specified within the context) whether a number is promoted (for instance form Z to Q or to Z/nZ) or not.

@Alex-Jordan
Copy link
Copy Markdown
Contributor

Not that I would object to these going into pg/macros, but they could probably go into OPL/macros/UBC without needing to test anymore than Andrew has already tested. Is that a helpful observation?

@mgage mgage requested review from Alex-Jordan and dpvc May 16, 2018 15:22
@mgage
Copy link
Copy Markdown
Member

mgage commented May 16, 2018

I'm having trouble getting the test problems to run on ww 2.13. I get the message context
"Permutation" unknown. I get the same message when loading contextPermutation.pl instead of contextPermutationUBC.pl.

In both macro files I cannot find a "sub Init " subroutine as part of the context package -- this seems to be standard in other context macro packages. These two files
seem to use the "sub _contextPermutation_init" subroutine for a similar purpose, but perhaps it's not doing the job.

Has there been a change in the way that context packages are initialized?

@mgage
Copy link
Copy Markdown
Member

mgage commented Jan 5, 2019

I have tested these macro files using the test problems provided. The contextInteger.pl and contextCongruence.pl pass the tests. I still cannot get the contextPermutationUBC.pl to work with the problem provided. I get the message context "Permutation" unknown.

If the glitch with Permutation is fixed and there is some provisional consensus then I can pull these macro files.

If some one provides a plan to update, augment and refactor these files to provide more number theory capabilities we'll add that when it's ready.

Comment thread macros/contextInteger.pl
# Modular inverse
#
# x = mulinv(b) mod n, (x * b) % n == 1
sub mulularInverse {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be modularInverse instead of molularInverse?

Comment thread macros/contextInteger.pl
#
# Greatest Common Divisor
#
sub gcd {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a subroutine gcd in macros/PGauxiliaryFunctions.pl. Is there a need for both of them?

Comment thread macros/contextInteger.pl
}

package context::Integer::Function::Numeric;
our @ISA = qw(Parser::Function::numeric); # checks for 2 numeric inputs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subroutines here rather look like taking only 1 numeric input.

@heiderich
Copy link
Copy Markdown
Member

As I mentioned above, my main concern concerning the congruences context is the following: I think that a MathObject class for integers should be introduced and some of the functions I mentioned above should only take MathObjects of this class as input. I am worried that otherwise they may get used in situations they are not designed to be used in. What, for instance, is the output of gcd(a, b) when a and b are real numbers that are not integers?

I agree with @Alex-Jordan that OPL/macros/UBC might be a suitable alternative location for these functions.

BTW: I made some attempts to introduce new MathObject classes, including one for integers, in the following branch:

https://github.com/heiderich/pg/tree/CyclicRings_DRAFT

This is not yet ready for a pull request, but it might serve as an illustration of my idea.

@mgage mgage added this to the PG-2.16 milestone Sep 25, 2019
@dpvc dpvc added the MathObject issue Issue involving MathObects code label Jan 3, 2021
@Alex-Jordan
Copy link
Copy Markdown
Contributor

This PR is from about 3 years ago, and wants to add three context files. But they were already added in #394, about 2 years ago. The diff between what is here and what is already in develop is trivial on two of the three files (just changing the copyright symbol). The diff on contextPermutation.pl is significant. This thread suggests that something isn't right with the contextPermutation.pl that is here. I guess I would assume things are working with the version that is merged.

So I move to close this PR, unmerged. Is there any objection?

@drgrice1
Copy link
Copy Markdown
Member

I think that is correct.

@Alex-Jordan
Copy link
Copy Markdown
Contributor

Closing since it seems the three new files already made their way into develop at some point. One of them, presumably improved upon from this one here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MathObject issue Issue involving MathObects code needs a leader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants