Skip to content

Commit

Permalink
some cleanup, still need docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antonydellavecchia committed Dec 4, 2024
1 parent b990e1a commit fa57b77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 42 deletions.
1 change: 0 additions & 1 deletion experimental/AlgebraicShifting/src/AlgebraicShifting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export contracted_partial_shift_graph
export exterior_shift
export face_size
export generic_unipotent_matrix
export partial_ext_shift_lv
export partial_shift_graph
export partial_shift_graph_vertices
export rothe_matrix
Expand Down
66 changes: 25 additions & 41 deletions experimental/AlgebraicShifting/src/PartialShift.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,59 +316,46 @@ julia> L = exterior_shift(GF(2), K, w)
Abstract simplicial complex of dimension 2 on 6 vertices
```
"""
function exterior_shift(F::Field, K::ComplexOrHypergraph, p::PermGroupElem)
function exterior_shift(F::Field, K::ComplexOrHypergraph,
p::PermGroupElem; las_vegas::Bool=false)
n = n_vertices(K)
@req n == degree(parent(p)) "number of vertices - 1 should equal the rank of the root system"
return exterior_shift(K, rothe_matrix(F, p))
las_vegas && return exterior_shift_lv(F, K, p)
return exterior_shift(K, rothe_matrix(F, p);)
end

function exterior_shift(F::Field, K::ComplexOrHypergraph, w::WeylGroupElem)
function exterior_shift(F::Field, K::ComplexOrHypergraph, w::WeylGroupElem; kw...)
n = n_vertices(K)
phi = isomorphism(PermGroup, parent(w))
return exterior_shift(F, K, phi(w))
return exterior_shift(F, K, phi(w); kw)
end

function exterior_shift(F::Field, K::ComplexOrHypergraph)
function exterior_shift(F::Field, K::ComplexOrHypergraph; kw...)
n = n_vertices(K)
W = weyl_group(:A, n - 1)
return exterior_shift(F, K, longest_element(W))
end

exterior_shift(K::ComplexOrHypergraph) = exterior_shift(QQ, K)
exterior_shift(K::ComplexOrHypergraph; kw...) = exterior_shift(QQ, K; kw)

################################################################################
# Las Vegas Partial Shifting

# returns a random invertible matrices of the given sample size
function random_invertible_matrices(n::Int; range::Int = 100, sample_size::Int=100, F::Field=QQ)
n_samples = 0
samples = Set{MatElem}()
n_non_inv = 0
while (n_samples < sample_size)
a = matrix(F, round.(Integer, range .* rand(n,n)) .- range // 2)
if iszero(det(a))
n_non_inv += 1
continue
end
push!(samples, a)
n_samples = length(samples)
end
# @info "probability of non invertible matrix" n_non_inv / (n_non_inv + sample_size)
return collect(samples)
end

function random_unipotent_matrix(F::Field, n::Int)
function random_rothe_matrix(F::Field, p::PermGroupElem)
char = characteristic(F)
range = char == 0 ? 100 : char
upper_triangular_matrix(
reduce(vcat, [
[F(1); F.(round.(Integer, range .* rand(i)) .- (range // 2))] for i in reverse(0:n-1)
]))
u = identity_matrix(F, n)
n = degree(parent(p))
for (i, j) in inversions(p)
u[i, j] = F.(round.(Integer, range .* rand(i)) .- (range // 2))
end

return u * permutation_matrix(F, p)
end

function random_shift(F::Field, K::ComplexOrHypergraph, p::PermGroupElem;)
n = n_vertices(K)
exterior_shift(K, random_unipotent_matrix(F, n) * permutation_matrix(F, p))
exterior_shift(K, random_rothe_matrix(F, p))
end

random_shift(K::ComplexOrHypergraph, p::PermGroupElem) = random_shift(QQ, K, p)
Expand All @@ -377,7 +364,7 @@ random_shift(K::ComplexOrHypergraph, p::PermGroupElem) = random_shift(QQ, K, p)
function check_shifted(F::Field,
src::UniformHypergraph,
dst::UniformHypergraph,
w::WeylGroupElem,)
p::PermGroupElem)
dst_faces = faces(dst)
if length(dst_faces) == 1
max_face = dst_faces[1]
Expand All @@ -390,7 +377,7 @@ function check_shifted(F::Field,
nCk = sort(subsets(n, k))
max_face_index = findfirst(x -> x == max_face, nCk)
cols = nCk[1:max_face_index - 1]
r = rothe_matrix(F, w)
r = rothe_matrix(F, p)

if max_face_index > num_rows
M = compound_matrix(r, src)[collect(1:num_rows), collect(1:length(cols))]
Expand All @@ -403,29 +390,26 @@ end
function check_shifted(F::Field,
src::SimplicialComplex,
dst::SimplicialComplex,
w::WeylGroupElem)
p::PermGroupElem)
n = n_vertices(src)
f_vec = f_vector(src)
k = length(f_vec)

while k > 1
uhg_src = uniform_hypergraph(complex_faces(src, k - 1), n)
uhg_dst = uniform_hypergraph(complex_faces(dst, k - 1), n)
!check_shifted(F, uhg_src, uhg_dst, w) && return false
!check_shifted(F, uhg_src, uhg_dst, p) && return false
k -= 1
end
return true
end

function partial_ext_shift_lv(F::Field, K::ComplexOrHypergraph, w::WeylGroupElem)
function exterior_shift_lv(F::Field, K::ComplexOrHypergraph, p::PermGroupElem)
sample_size = characteristic(F) == 0 ? 10 : 100
W = parent(w)
phi = isomorphism(PermGroup, W)

shift = partialsort!([random_shift(F, K, phi(w)) for _ in 1:sample_size], 1;
shift = partialsort!([random_shift(F, K, p) for _ in 1:sample_size], 1;
lt=isless_lex)
check_shifted(F, K, shift, w) && return shift
return nothing # partial_ext_shift_lv(F, w, K)
check_shifted(F, K, shift, p) && return shift
return nothing
end

###############################################################################
Expand Down

0 comments on commit fa57b77

Please sign in to comment.