From 9bb2aba6f6e0f86b261140e1a3ab5f172b1b1908 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 25 Mar 2020 03:38:33 +0100 Subject: [PATCH] add issubword, issubsymbol --- src/Groups.jl | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Groups.jl b/src/Groups.jl index 7ac68ab..c153849 100644 --- a/src/Groups.jl +++ b/src/Groups.jl @@ -348,11 +348,32 @@ end # # Replacement of symbols / sub-words # -############################################################################### issubsymbol(s::GSymbol, t::GSymbol) = s.id == t.id && (0 ≤ s.pow ≤ t.pow || 0 ≥ s.pow ≥ t.pow) +function issubsymbol(s::FreeSymbol, w::GWord, sindex::Integer) + @boundscheck 1 ≤ sindex ≤ syllablelength(w) || throw(BoundsError(w, sindex)) + return issubsymbol(s, syllables(w)[sindex]) +end + +function issubword(z::GWord, w::GWord, sindex::Integer) + isempty(z) && return true + @boundscheck 1 ≤ sindex ≤ syllablelength(w) || throw(BoundsError(w, sindex)) + n = syllablelength(z) + n == 1 && return issubsymbol(first(syllables(z)), syllables(w)[sindex]) + + lastindex = sindex + n - 1 + lastindex > syllablelength(w) && return false + + issubsymbol(first(z), syllables(w)[sindex]) || return false + issubsymbol(syllables(z)[end], syllables(w)[lastindex]) || return false + for (zidx, widx) in zip(2:n-1, sindex+1:lastindex-1) + syllables(z)[zidx] == syllables(w)[widx] || return false + end + return true +end + """doc Find the first linear index k>=i such that Z < W.symbols[k:k+length(Z)-1] """