Skip to content

Commit

Permalink
take variable names seriously
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasha Demin committed Oct 2, 2023
1 parent 52f4d62 commit 670de54
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/parametrizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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:
Expand Down
36 changes: 36 additions & 0 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/constructive_membership.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

Expand All @@ -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,
Expand Down

0 comments on commit 670de54

Please sign in to comment.