Renaming the variables of a formula to 0, …, k - 1, with a hash map #
A formula over ℕ may use arbitrary variable names, such as 0 and 10⁹. A solver that keeps
arrays indexed by variable would then allocate by the largest name.
Cslib.Logic.PL.CNF.denseRenaming numbers the k distinct variables of φ as 0, …, k - 1, in
order of first occurrence (the numbering of Cslib.Logic.PL.CNF.denseRelabel), in one pass over
the occurrences with a hash map. It returns the renaming toDense and a map fromDense back:
fromDenseundoestoDenseon the variables ofφ(Cslib.Logic.PL.CNF.DenseRenaming.fromDense_toDense), so renamingφalongtoDenseand then alongfromDensegivesφback (Cslib.Logic.PL.CNF.DenseRenaming.relabel_relabel);fromDenseis injective (Cslib.Logic.PL.CNF.DenseRenaming.fromDense_injective), so it carries certificates for the renamed formula back toφ;- the renamed variables are below
k(Cslib.Logic.PL.CNF.DenseRenaming.toDense_lt).
The kernel does not evaluate the hash map; this renaming is for compiled code.
Main definitions #
Cslib.Logic.PL.CNF.denseRenaming: the renaming of a formula, with the map back.
The state of the renaming pass: the number given to each variable seen so far, and the variables in the order of their numbers.
The number of each variable seen so far.
The variables seen so far, in the order of their numbers.
Give v the next number, unless it already has one.
The numbers and the names are inverse to each other.
A numbered variable is the name at its number.
Every name has its own number.
Adding a list of variables keeps the invariant and numbers every variable of the list.
The renaming of the variables of a formula to 0, …, k - 1, with the map back.
The number of each variable,
0for a variable not in the formula.The variable of each number: the
i-th variable fori < k, and above every variable otherwise, so that the map is injective.- size : ℕ
The number of distinct variables.
The numbering of the variables of φ, in order of first occurrence.
The renaming of the variables of φ to 0, …, k - 1.
The map back is injective.
Renaming along toDense and back gives φ.