Skip to content

Commit

Permalink
Add linear independence check function
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Feb 23, 2024
1 parent 3d396ed commit 0d49beb
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/DeformationBases/ArcDiagDeformBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ struct ArcDiagDeformBasis{C <: RingElem} <: DeformBasis{C}
iter = Iterators.flatten(iters)
if !no_normalize
iter = unique(Iterators.filter(b -> !iszero(b), iter))
collected = Vector{eltype(iter)}(collect(iter))
if !isempty(collected)
_, rels = is_linearly_independent_with_relations(coefficient_ring(sp), reverse(collected))
inds = [1 + ncols(rels) - (findfirst(!iszero, vec(rels[i, :]))::Int) for i in nrows(rels):-1:1]
deleteat!(collected, inds)
end
iter = collected
len = length(iter)
end
return new{C}(len, iter, extra_data, normalize)
Expand Down
7 changes: 7 additions & 0 deletions src/DeformationBases/PseudographDeformBasis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ struct PseudographDeformBasis{C <: RingElem} <: DeformBasis{C}
iter = Iterators.flatten(iters)
if !no_normalize
iter = unique(Iterators.filter(b -> !iszero(b), iter))
collected = Vector{eltype(iter)}(collect(iter))
if !isempty(collected)
_, rels = is_linearly_independent_with_relations(coefficient_ring(sp), reverse(collected))
inds = [1 + ncols(rels) - (findfirst(!iszero, vec(rels[i, :]))::Int) for i in nrows(rels):-1:1]
deleteat!(collected, inds)
end
iter = collected
len = length(iter)
end
return new{C}(len, iter, extra_data, normalize)
Expand Down
71 changes: 71 additions & 0 deletions src/LinearIndependence.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
function is_linearly_independent(F::Field, V::Vector{T}) where {T}
return is_linearly_independent_with_relations(F, V)[1]
end

function is_linearly_independent(V::Vector{T}) where {T}
return is_linearly_independent_with_relations(V)[1]
end

function is_linearly_independent_with_relations(F::Field, V::Vector{<:FieldElem})
n, M = kernel(matrix(F, length(V), 1, V); side=:left)
return n == 0, M
end

function is_linearly_independent_with_relations(F::Field, V::Vector{<:PolyRingElem})
n = length(V)
if n == 0
return false, zero_matrix(F, 0, 0)
end
rels = identity_matrix(F, n)
maxdeg = maximum(degree, V)
for i in 1:maxdeg
rels = basis_intersection(rels, is_linearly_independent_with_relations(F, [coeff(v, i) for v in V])[2])
iszero(rels) && return true, rels
end
return false, rels
end

function is_linearly_independent_with_relations(F::Field, V::Vector{<:MatElem})
n = length(V)
if n == 0
return false, zero_matrix(F, 0, 0)
end
@req all(size(v) == size(V[1]) for v in V) "Size mismatch"
rels = identity_matrix(F, n)
for i in eachindex(V[1])
rels = basis_intersection(rels, is_linearly_independent_with_relations(F, [v[i] for v in V])[2])
iszero(rels) && return true, rels
end
return false, rels
end

function is_linearly_independent_with_relations(F::Field, V::Vector{<:FreeAssAlgElem})
coeff_maps = [Dict{Vector{Int}, elem_type(F)}(zip(exponent_words(v), coefficients(v))) for v in V]
words = reduce(union, keys.(coeff_maps))
n = length(V)
rels = identity_matrix(F, n)
for word in words
rels = basis_intersection(
rels,
is_linearly_independent_with_relations(F, [get(coeff_map, word, zero(F)) for coeff_map in coeff_maps])[2],
)
iszero(rels) && return true, rels
end
return false, rels
end

function basis_intersection(V::MatElem{T}, W::MatElem{T}) where {T <: FieldElem}
# using Zassenhaus
@req base_ring(V) == base_ring(W) "Incompatible base rings"
@req ncols(V) == ncols(W) "Size mismatch"
if nrows(V) == 0 || nrows(W) == 0
return zero(V, 0, ncols(V))
end
if V == W
return V
end
block_mat = vcat(hcat(V, V), hcat(W, zero(W)))
s = rref!(block_mat)
r = rank(block_mat[:, 1:ncols(V)])
return block_mat[r+1:s, ncols(V)+1:end]
end
3 changes: 3 additions & 0 deletions src/PBWDeformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export general_linear_lie_algebra
export inneighbor
export inneighbors
export is_crossing_free
export is_linearly_independent
export is_linearly_independent_with_relations
export is_pbwdeformation
export isomorphic_module_with_simple_structure
export lookup_data
Expand Down Expand Up @@ -117,6 +119,7 @@ end

include("OscarPatches.jl")

include("LinearIndependence.jl")
include("ModuleSimpleStructure.jl")

include("DeformationBases/DeformBasis.jl")
Expand Down

0 comments on commit 0d49beb

Please sign in to comment.