We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d808a59 commit 82092f3Copy full SHA for 82092f3
src/arithmetic.jl
@@ -20,10 +20,23 @@ function is_invertible(a::Mod{N})::Bool where {N}
20
end
21
is_invertible(a::GaussMod)::Bool = is_invertible(real(a * a'))
22
23
-inv(a::Mod{N}) where {N} = Mod{N}(invmod(value(a), N))
+function _invmod(x::S, m::T) where {S<:Integer,T<:Integer}
24
+ (g, v, _) = gcdx(x, m)
25
+ if g != 1
26
+ error("Mod{$m}($x) is not invertible")
27
+ end
28
+ return v
29
+end
30
+
31
+inv(a::Mod{N}) where {N} = Mod{N}(_invmod(value(a), N))
32
function inv(a::GaussMod{N}) where {N}
33
d = real(a * a')
- return inv(d) * a'
34
+ try
35
+ result = inv(d) * a'
36
+ return result
37
+ catch
38
+ error("$a is not invertible")
39
40
41
42
(/)(a::AbstractMod, b::AbstractMod) = a * inv(b)
0 commit comments