From 670de54bd219fffcb54ee2a2e2d7edff44c956ff Mon Sep 17 00:00:00 2001 From: Sasha Demin Date: Tue, 3 Oct 2023 01:49:29 +0200 Subject: [PATCH] take variable names seriously --- src/parametrizations.jl | 10 ++++----- src/util.jl | 36 +++++++++++++++++++++++++++++++++ test/constructive_membership.jl | 11 ++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/parametrizations.jl b/src/parametrizations.jl index 39ab8705f..0023f8f0d 100644 --- a/src/parametrizations.jl +++ b/src/parametrizations.jl @@ -165,9 +165,9 @@ function check_constructive_field_membership( @assert length(fracs_gen) == length(tag_names) tag_names else - map(i -> "T$i", 1:length(fracs_gen)) + gen_tag_names(length(fracs_gen), "Tag") end - sat_string = "_t" + sat_string = gen_tag_name("Sat") @info """ Tags: $(join(map(x -> string(x[1]) * " -> " * string(x[2]), zip(fracs_gen, tag_strings)), "\t\n")) @@ -318,9 +318,9 @@ function reparametrize_with_respect_to(ode, new_states, new_params) n_active_generators = (length(generating_funcs) - length(ode.u_vars) - length(ode.y_vars)) tag_names = vcat( - ["_T$i" for i in 1:n_active_generators], - map(v -> "_$(uppercase(string(v)))", ode.u_vars), - map(v -> "_$(uppercase(string(v)))", ode.y_vars), + gen_tag_names(n_active_generators, "Internal"), + gen_tag_names(length(ode.u_vars), "Input"), + gen_tag_names(length(ode.y_vars), "Output"), ) @info """ Tag names: diff --git a/src/util.jl b/src/util.jl index 068780c54..474c73d32 100644 --- a/src/util.jl +++ b/src/util.jl @@ -408,6 +408,42 @@ end # ------------------------------------------------------------------------------ +""" + gen_tag_name(base; stop_words) + gen_tag_names(n, base; stop_words) + +Generates a string which will not collide with the words in `stop_words`. + +## Arguments + +- `n`: Generates a sequence of unique strings of length `n` +- `base`: A string or a vector of strings, the base for the generated sequence +- `stop_words`: A vector of strings, stop words +""" +function gen_tag_name(base = "T"; stop_words = Vector{String}()) + return first(gen_tag_names(1, base, stop_words = stop_words)) +end + +function gen_tag_names(n::Integer, base = "T"; stop_words = Vector{String}()) + sequence = if base isa Vector{String} + @assert n == length(base) + base + else + repeat([base], n) + end + while true + rand_token = Int(rand(UInt8)) + sequence = map(c -> "$(rand_token)__$c", sequence) + sequence = map(ic -> "$(ic[2])_$(ic[1])", enumerate(sequence)) + if all(elem -> !(elem in stop_words), sequence) + break + end + end + return sequence +end + +# ------------------------------------------------------------------------------ + """ switch_ring(v, ring) diff --git a/test/constructive_membership.jl b/test/constructive_membership.jl index 927579d09..d80aca25f 100644 --- a/test/constructive_membership.jl +++ b/test/constructive_membership.jl @@ -8,6 +8,7 @@ StructuralIdentifiability.check_constructive_field_membership( StructuralIdentifiability.RationalFunctionField(generators), map(f -> f // one(f), to_be_reduced), + tag_names = ["T1", "T2"], ) tags = gens(base_ring(parent(first(remainders)))) @@ -26,6 +27,16 @@ [(generators = [T1^2], to_be_reduced = [T1, T1^2], memberships = Bool[0, 1])], ) + R, (T1, t, _t) = PolynomialRing(Nemo.QQ, ["T1", "t", "_t"]) + append!( + cases, + [( + generators = [T1, t, _t], + to_be_reduced = [_t, t, T1 * t * _t], + memberships = Bool[1, 1, 1], + )], + ) + R, (x,) = PolynomialRing(Nemo.QQ, ["x"]) append!( cases,