Enhance algebra functions#342
Conversation
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
|
permutation test problem |
|
Integer test problem |
|
Congruence test problem |
|
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 |
|
@heiderich Sorry for taking a while to respond. So you are basically asking for the functions to be moved to something like 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 |
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? |
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. |
This is indeed the case. And it even works for Math Objects that are real or complex numbers... It even takes matrices (only
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? |
|
| 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 |
My point is that for many objects the output of 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. |
|
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? |
|
I'm having trouble getting the test problems to run on ww 2.13. I get the message context 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 Has there been a change in the way that context packages are initialized? |
|
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. |
| # Modular inverse | ||
| # | ||
| # x = mulinv(b) mod n, (x * b) % n == 1 | ||
| sub mulularInverse { |
There was a problem hiding this comment.
Should this be modularInverse instead of molularInverse?
| # | ||
| # Greatest Common Divisor | ||
| # | ||
| sub gcd { |
There was a problem hiding this comment.
There is already a subroutine gcd in macros/PGauxiliaryFunctions.pl. Is there a need for both of them?
| } | ||
|
|
||
| package context::Integer::Function::Numeric; | ||
| our @ISA = qw(Parser::Function::numeric); # checks for 2 numeric inputs |
There was a problem hiding this comment.
The subroutines here rather look like taking only 1 numeric input.
|
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 I agree with @Alex-Jordan that 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. |
|
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 So I move to close this PR, unmerged. Is there any objection? |
|
I think that is correct. |
|
Closing since it seems the three new files already made their way into |
Enhance context permutation
Add new permutation
contextPermutationUBC.plwhich differs fromcontextPermutation.plbyNote: that these changes are in their own separate file as the changes may break existing usages of
contextPermutation.plAdd context Integer
Add context Congruence
Example problems used for testing contexts to follow
An instructor requested some additional Webwork functionality. Hopefully this will be useful to others as well