@@ -72,7 +72,7 @@ function find_perfect_aliases!(
7272 state:: TearingState , eqs_to_rm:: Vector{Int} , vars_to_rm:: Vector{Int}
7373 )
7474 (; sys, fullvars, structure) = state
75- (; graph, solvable_graph, var_to_diff) = structure
75+ (; graph, solvable_graph, var_to_diff, state_priorities ) = structure
7676
7777 @assert solvable_graph === nothing
7878 diff_to_var = invview (var_to_diff)
@@ -122,7 +122,7 @@ function find_perfect_aliases!(
122122
123123 group_target = Dict {Int, Int} ()
124124 for (root, group_vars) in alias_sets
125- group_target[root] = pick_alias_target (state . sys, fullvars, group_vars, state . structure . state_priorities)
125+ group_target[root] = pick_alias_target (fullvars, group_vars, state_priorities, irreducibles )
126126 end
127127
128128 # Queue an alias equation for removal only if both endpoints collapse onto the
@@ -132,8 +132,8 @@ function find_perfect_aliases!(
132132 # rewrites the kept equation into `I ~ T` form automatically.
133133 for (ieq, v1, v2) in candidate_eqs
134134 target = group_target[DataStructures. find_root! (alias_groups, v1)]
135- c1 = contains_possibly_indexed_element (irreducibles, fullvars[v1]) ? v1 : target
136- c2 = contains_possibly_indexed_element (irreducibles, fullvars[v2]) ? v2 : target
135+ c1 = contains_possibly_indexed_element (irreducibles, fullvars[v1]) || state_priorities[v1] > 0 ? v1 : target
136+ c2 = contains_possibly_indexed_element (irreducibles, fullvars[v2]) || state_priorities[v2] > 0 ? v2 : target
137137 c1 == c2 && push! (eqs_to_rm, ieq)
138138 end
139139
@@ -144,10 +144,11 @@ function find_perfect_aliases!(
144144 v == target && continue
145145 # Irreducibles other than the target stay as unknowns; only non-irreducibles
146146 # are eliminated in favor of the target.
147- if contains_possibly_indexed_element (irreducibles, fullvars[v])
147+ if contains_possibly_indexed_element (irreducibles, fullvars[v]) || state_priorities[v] > 0
148148 state. always_present[v] = true
149149 continue
150150 end
151+
151152 push! (vars_to_rm, v)
152153 subs[fullvars[v]] = fullvars[target]
153154 push! (state. additional_observed, fullvars[v] ~ fullvars[target])
0 commit comments