update SL.jl

This commit is contained in:
kalmarek 2017-09-10 15:40:52 +02:00
parent a28df98741
commit 8a022c03e0

112
SL.jl
View File

@ -5,41 +5,57 @@ import SCS.SCSSolver
using PropertyT using PropertyT
function E(i::Int, j::Int, M::Nemo.MatSpace) ###############################################################################
#
# Generating set
#
###############################################################################
function E(i::Int, j::Int, M::MatSpace, val=one(M.base_ring))
@assert i≠j @assert i≠j
m = one(M) m = one(M)
m[i,j] = m[1,1] m[i,j] = val
return m return m
end end
function SL_generatingset(n::Int)
indexing = [(i,j) for i in 1:n for j in 1:n if i≠j]
G = Nemo.MatrixSpace(Nemo.ZZ, n,n)
S = [E(i,j,G) for (i,j) in indexing];
S = vcat(S, [transpose(x) for x in S]);
return unique(S)
end
function SLsize(n,p) function SLsize(n,p)
result = 1 result = BigInt(1)
for k in 0:n-1 for k in 0:n-1
result *= p^n - p^k result *= p^n - p^k
end end
return div(result, p-1) return div(result, p-1)
end end
function SL_generatingset(n::Int, p::Int) function SL_generatingset(n::Int, X::Bool=false)
p == 0 && return SL_generatingset(n) indexing = [(i,j) for i in 1:n for j in 1:n if i≠j]
(p > 1 && n > 0) || throw(ArgumentError("Both n and p should be positive integers!")) G = MatrixSpace(ZZ, n, n)
println("Size(SL($n,$p)) = $(SLsize(n,p))") if X
F = Nemo.ResidueRing(Nemo.ZZ, p) S = [E(i,j,G,v) for (i,j) in indexing for v in [1, 100]]
G = Nemo.MatrixSpace(F, n,n) else
S = [E(i,j,G,v) for (i,j) in indexing for v in [1]]
end
S = vcat(S, [inv(x) for x in S])
return G, unique(S)
end
function SL_generatingset(n::Int, p::Int, X::Bool=false)
p == 0 && return SL_generatingset(n, X)
(p > 1 && n > 1) || throw("Both n and p should be positive integers!")
info("Size(SL($n,$p)) = $(SLsize(n,p))")
F = ResidueRing(ZZ, p)
G = MatrixSpace(F, n, n)
indexing = [(i,j) for i in 1:n for j in 1:n if i≠j] indexing = [(i,j) for i in 1:n for j in 1:n if i≠j]
S = [E(i, j, G) for (i,j) in indexing] S = [E(i, j, G) for (i,j) in indexing]
S = vcat(S, [transpose(x) for x in S]) S = vcat(S, [inv(x) for x in S])
return unique(S) return G, unique(S)
end end
###############################################################################
#
# Parsing command line
#
###############################################################################
function cpuinfo_physicalcores() function cpuinfo_physicalcores()
maxcore = -1 maxcore = -1
for line in eachline("/proc/cpuinfo") for line in eachline("/proc/cpuinfo")
@ -52,40 +68,40 @@ function cpuinfo_physicalcores()
end end
function parse_commandline() function parse_commandline()
s = ArgParseSettings() settings = ArgParseSettings()
@add_arg_table s begin @add_arg_table settings begin
"--tol" "--tol"
help = "set numerical tolerance for the SDP solver (default: 1e-5)" help = "set numerical tolerance for the SDP solver"
arg_type = Float64 arg_type = Float64
default = 1e-5 default = 1e-6
"--iterations" "--iterations"
help = "set maximal number of iterations for the SDP solver (default: 20000)" help = "set maximal number of iterations for the SDP solver (default: 20000)"
arg_type = Int arg_type = Int
default = 20000 default = 50000
"--upper-bound" "--upper-bound"
help = "Set an upper bound for the spectral gap (default: Inf)" help = "Set an upper bound for the spectral gap"
arg_type = Float64 arg_type = Float64
default = Inf default = Inf
"--cpus" "--cpus"
help = "Set number of cpus used by solver (default: auto)" help = "Set number of cpus used by solver"
arg_type = Int arg_type = Int
required = false required = false
"-N" "-N"
help = "Consider matrices of size N (default: N=3)" help = "Consider elementary matrices EL(N)"
arg_type = Int arg_type = Int
default = 3 default = 2
"-p" "-p"
help = "Matrices over filed of p-elements (default: p=0 => over ZZ)" help = "Matrices over field of p-elements (p=0 => over ZZ)"
arg_type = Int arg_type = Int
default = 0 default = 0
"--radius" "--radius"
help = "Find the decomposition over B_r(e,S)" help = "Radius of ball B_r(e,S) to find solution over"
arg_type = Int arg_type = Int
default = 2 default = 2
end end
return parse_args(s) return parse_args(settings)
end end
function main() function main()
@ -95,40 +111,40 @@ function main()
if parsed_args["cpus"] > cpuinfo_physicalcores() if parsed_args["cpus"] > cpuinfo_physicalcores()
warn("Number of specified cores exceeds the physical core cound. Performance will suffer.") warn("Number of specified cores exceeds the physical core cound. Performance will suffer.")
end end
Blas.set_num_threads(parsed_args["cpus"]) BLAS.set_num_threads(parsed_args["cpus"])
end end
tol = parsed_args["tol"]
iterations = parsed_args["iterations"]
solver = SCSSolver(eps=tol, max_iters=iterations, linearsolver=SCS.Direct)
N = parsed_args["N"] N = parsed_args["N"]
upper_bound = parsed_args["upper-bound"]
p = parsed_args["p"] p = parsed_args["p"]
if p == 0 if p == 0
name = "SL$(N)Z" dirname = "SL$(N)Z"
else else
name = "SL$(N)_$p" dirname = "SL$(N)_$p"
end end
radius = parsed_args["radius"]   radius = parsed_args["radius"]
tol = parsed_args["tol"]
iterations = parsed_args["iterations"]
upper_bound = parsed_args["upper-bound"]
name = "$(name)_$(upper_bound)_r=$radius" dirname = "$(dirname)_$(upper_bound)_r=$radius"
logger = PropertyT.setup_logging(name) logger = PropertyT.setup_logging(dirname)
info(logger, "Group: $name") info(logger, "Group: $dirname")
info(logger, "Iterations: $iterations") info(logger, "Iterations: $iterations")
info(logger, "Precision: $tol") info(logger, "Precision: $tol")
info(logger, "Upper bound: $upper_bound") info(logger, "Upper bound: $upper_bound")
S = SL_generatingset(N, p) G, S = SL_generatingset(N, p)
S = unique([S; [inv(s) for s in S]]) info(logger, G)
Id = one(parent(S[1])) info(logger, "Symmetric generating set of size $(length(S))")
Id = one(G)
@time PropertyT.check_property_T(name, S, Id, solver, upper_bound, tol, radius) solver = SCSSolver(eps=tol, max_iters=iterations, linearsolver=SCS.Direct)
@time PropertyT.check_property_T(dirname, S, Id, solver, upper_bound, tol, radius)
return 0 return 0
end end