Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Las Vegas Algebraic Shifting #4381

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
corrected check algo
antonydellavecchia committed Dec 4, 2024
commit 8d6c7713ccfb7474c1a0c25db79eb38e8c8b4223
10 changes: 6 additions & 4 deletions experimental/AlgebraicShifting/src/PartialShift.jl
Original file line number Diff line number Diff line change
@@ -343,66 +343,68 @@
################################################################################
# Las Vegas Partial Shifting

function random_rothe_matrix(F::Field, p::PermGroupElem)
char = characteristic(F)
range = char == 0 ? 100 : char
n = degree(parent(p))
u = identity_matrix(F, n)
for (i, j) in inversions(p)
u[i, j] = F.(round.(Integer, range .* rand()) .- (range // 2))
end
return u * permutation_matrix(F, p)

Check warning on line 354 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L346-L354

Added lines #L346 - L354 were not covered by tests
end

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

Check warning on line 359 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L357-L359

Added lines #L357 - L359 were not covered by tests
end

random_shift(K::ComplexOrHypergraph, p::PermGroupElem) = random_shift(QQ, K, p)

Check warning on line 362 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L362

Added line #L362 was not covered by tests

# returns true if the target is the partial shift of src with respect to p
function check_shifted(F::Field, src::UniformHypergraph,

Check warning on line 365 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L365

Added line #L365 was not covered by tests
target::UniformHypergraph, p::PermGroupElem)
target_faces = faces(target)
target_faces = sort(faces(target))
max_face = length(target_faces) == 1 ? target_faces[1] : max(target_faces...)

Check warning on line 368 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L367-L368

Added lines #L367 - L368 were not covered by tests
num_rows = length(target_faces)
# currently number of faces of src and target are the same
# this may change in the future
num_rows = length(faces(src))
n = n_vertices(src)
k = face_size(src)
nCk = sort(subsets(n, k))
max_face_index = findfirst(x -> x == max_face, nCk)

Check warning on line 375 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L371-L375

Added lines #L371 - L375 were not covered by tests
# limits the columns by the max face of source
cols = nCk[1:max_face_index - 1]
r = rothe_matrix(F, p)

Check warning on line 378 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L377-L378

Added lines #L377 - L378 were not covered by tests

if max_face_index > num_rows
M = compound_matrix(r, src)[collect(1:num_rows), collect(1:length(cols))]
Oscar.ModStdQt.ref_ff_rc!(M)
nCk[independent_columns(M)] != target_faces && return false
nCk[independent_columns(M)] != target_faces[1:end - 1] && return false

Check warning on line 383 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L380-L383

Added lines #L380 - L383 were not covered by tests
end
return true

Check warning on line 385 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L385

Added line #L385 was not covered by tests
end

function check_shifted(F::Field, src::SimplicialComplex,

Check warning on line 388 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L388

Added line #L388 was not covered by tests
target::SimplicialComplex, 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_target = uniform_hypergraph(complex_faces(target, k - 1), n)
!check_shifted(F, uhg_src, uhg_target, p) && return false
k -= 1
end
return true

Check warning on line 399 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L390-L399

Added lines #L390 - L399 were not covered by tests
end

function exterior_shift_lv(F::Field, K::ComplexOrHypergraph, p::PermGroupElem)
sample_size = characteristic(F) == 0 ? 10 : 100
shift = partialsort!([random_shift(F, K, p) for _ in 1:sample_size], 1;

Check warning on line 404 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L402-L404

Added lines #L402 - L404 were not covered by tests
lt=isless_lex)
check_shifted(F, K, shift, p) && return shift
return exterior_shift_lv(F, K, p)
return nothing #exterior_shift_lv(F, K, p)

Check warning on line 407 in experimental/AlgebraicShifting/src/PartialShift.jl

Codecov / codecov/patch

experimental/AlgebraicShifting/src/PartialShift.jl#L406-L407

Added lines #L406 - L407 were not covered by tests
end

###############################################################################
2 changes: 2 additions & 0 deletions experimental/AlgebraicShifting/src/PartialShiftGraph.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: change Vector -> Set
const EdgeLabels = Dict{Tuple{Int, Int}, Vector{WeylGroupElem}}

function isless_lex(S1::Set{Set{Int}}, S2::Set{Set{Int}})
@@ -181,6 +182,7 @@ function partial_shift_graph(F::Field, complexes::Vector{T},
parallel::Bool = false,
show_progress::Bool = true,
task_size::Int=100) where T <: ComplexOrHypergraph
# see TODO above about changing EdgeLabels type
# Deal with trivial case
if length(complexes) == 1
@req is_shifted(complexes[1]) "The list of complexes should be closed under shifting by elements of W"