From 93126378733005343eea12ae419ac53459cce575 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Mon, 17 Jan 2022 21:50:33 +0100 Subject: [PATCH] add TriangleGrp for parsing purposes --- data/parse_presentations.jl | 46 +++++++++++++++++++++++++++++ data/smallhyperbolicgrp.jl | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 data/smallhyperbolicgrp.jl diff --git a/data/parse_presentations.jl b/data/parse_presentations.jl index 9892ae2..e61b279 100644 --- a/data/parse_presentations.jl +++ b/data/parse_presentations.jl @@ -26,3 +26,49 @@ function parse_grouppresentations_abstract(filename::AbstractString) end return groups end + +# parse_grouppresentations_abstract("./data/presentations_2_4_4.txt") + +function _tf_missing(x::Any) + s = strip(x) + mis = !isnothing(match(r"(\?)*", x)) + no = !isnothing(match(r"no"i, x)) + yes = !isnothing(match(r"yes"i, x)) + mis && return missing + yes && !no && return true + !yes && no && return false + throw(ArgumentError("Unrecognized option: $x")) +end + +function parse_vec(s::AbstractString) + m = match(r"^\s*\[(.*)\]\s*$", s) + isnothing(m) && throw("String does not seem to represent a vector: $s") + content = m[1] + return strip.(split(content, ',')) +end + +parse_vec(T::Type{<:AbstractString}, s::AbstractString) = T.(parse_vec(s)) +function parse_vec(::Type{T}, s::AbstractString) where {T<:Number} + v = parse_vec(String, s) + isempty(v) && return T[] + length(v) == 1 && isempty(first(v)) && return T[] + return parse.(T, parse_vec(String, s)) +end + +function parse_vec( + ::Type{T}, + s::AbstractString, +) where {A<:AbstractString,B<:Number,T<:Tuple{A,B}} + v = parse_vec(s) + if length(v) == 1 + @assert isempty(first(v)) + return Tuple{A,B}[] + end + @assert iseven(length(v)) + return map(1:2:length(v)) do i + @assert first(v[i]) == '(' && last(v[i+1]) == ')' + key = v[i][begin+1:end] + val = v[i+1][begin:end-1] + (A(key), parse(B, val)) + end +end diff --git a/data/smallhyperbolicgrp.jl b/data/smallhyperbolicgrp.jl new file mode 100644 index 0000000..e47f9dc --- /dev/null +++ b/data/smallhyperbolicgrp.jl @@ -0,0 +1,59 @@ +struct TriangleGrp + generators::Vector{String} + relations::Vector{String} + order1::Int + order2::Int + order3::Int + index::Int + presentation_length::Int + hyperbolic::Union{Missing,Bool} + witnesses_non_hyperbolictity::Union{Missing,Vector{String}} + virtually_torsion_free::Union{Missing,Bool} + Kazdhdan_property_T::Union{Missing,Bool} + abelianization_dimension::Int + L2_quotients::Vector{String} + quotients::Vector{Pair{String,Int}} + alternating_quotients::Vector{Int} + maximal_order_alt_quo::Int +end + +_name(G) = "G_$(G.order1)_$(G.order2)_$(G.order3)_$(G.index)" +name(G::TriangleGrp) = _name(G) +grp_name(nt::NamedTuple) = _name(nt) + +latex_name(G::TriangleGrp) ="\$G^{$(G.order1),$(G.order2),$(G.order3)}_$(G.index)" + +function TriangleGrp(generators, relations, nt::NamedTuple) + # @assert fieldnames(SmallHyperbolicGrp) == propertynames(nt) + hyperbolic, witness = if hasproperty(nt, :hyperbolic) + h = _tf_missing(nt.hyperbolic) + nh_w = nt.witnesses_for_non_hyperbolicity + w = isempty(strip(nh_w)) ? missing : parse_vec(String, '[' * nh_w * ']') + h, w + elseif 1 // nt.order1 + 1 // nt.order2 + 1 // nt.order3 < 1 + true, missing + else + missing, missing + end + + TriangleGrp( + convert(Vector{String}, generators), + convert(Vector{String}, relations), + convert(Int, nt.order1), + convert(Int, nt.order2), + convert(Int, nt.order3), + convert(Int, nt.index), + convert(Int, nt.presentation_length), + hyperbolic, + witness, + _tf_missing(nt.virtually_torsion_free), + _tf_missing(nt.Kazhdan), + convert(Int, nt.abelianization_dimension), + parse_vec(String, nt.L2_quotients), + [Pair(p...) for p in parse_vec(Tuple{String,Int}, nt.quotients)], + parse_vec(Int, nt.alternating_quotients), + convert(Int, nt.maximal_order_for_alternating_quotients), + ) +end + +