diff options
author | Norbert Preining <norbert@preining.info> | 2022-11-06 03:01:22 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-11-06 03:01:22 +0000 |
commit | 0a7c9b85de9aeaffafa0cf8944fa81ffe9652d09 (patch) | |
tree | a8a932b3f786cf3601808c4e352b3b6b07731742 /macros/luatex/latex/luacas/tex/algebra/euclideandomain.lua | |
parent | 5a47812f51f3d10a580db0c74aa20d73f5ed2ae4 (diff) |
CTAN sync 202211060301
Diffstat (limited to 'macros/luatex/latex/luacas/tex/algebra/euclideandomain.lua')
-rw-r--r-- | macros/luatex/latex/luacas/tex/algebra/euclideandomain.lua | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/macros/luatex/latex/luacas/tex/algebra/euclideandomain.lua b/macros/luatex/latex/luacas/tex/algebra/euclideandomain.lua new file mode 100644 index 0000000000..fab2c5c7c2 --- /dev/null +++ b/macros/luatex/latex/luacas/tex/algebra/euclideandomain.lua @@ -0,0 +1,63 @@ +--- @class EuclideanDomain +--- Interface for an element of a euclidean domain. +EuclideanDomain = {} +__EuclideanDomain = {} + +---------------------- +-- Required methods -- +---------------------- + +--- @param b EuclideanDomain +--- @return EuclideanDomain, EuclideanDomain +function EuclideanDomain:divremainder(b) + error("Called unimplemented method : divremainder()") +end + +---------------------------- +-- Instance functionality -- +---------------------------- + +--- @return boolean +function EuclideanDomain:iscommutative() + return true +end + +-------------------------- +-- Instance metamethods -- +-------------------------- + +__EuclideanOperations = Copy(__RingOperations) + +-- Division with remainder +-- Unfortunately, this can only return 1 result, so it returns the quotient - for the remainder use a % b, or a:divremainder(b) +__EuclideanOperations.__idiv = function(a, b) + if(b == b:zero()) then + error("Cannot divide by zero.") + end + local aring, bring = a:getring(), b:getring() + local oring = Ring.resultantring(aring, bring) + if not oring then + error("Attempted to divide two elements of incompatable rings") + end + return a:inring(oring):divremainder(b:inring(oring)) +end + +__EuclideanOperations.__mod = function(a, b) + if(b == b:zero()) then + error("Cannot divide by zero.") + end + local aring, bring = a:getring(), b:getring() + local oring = Ring.resultantring(aring, bring) + if not oring then + error("Attempted to divide two elements of incompatable rings") + end + local _,q = a:inring(oring):divremainder(b:inring(oring)) + return q +end + +----------------- +-- Inheritance -- +----------------- + +__EuclideanDomain.__index = Ring +EuclideanDomain = setmetatable(EuclideanDomain, __EuclideanDomain)
\ No newline at end of file |