Documentation

CslibFrontier.Logics.Propositional.CNF.DenseRenaming

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:

The kernel does not evaluate the hash map; this renaming is for compiled code.

Main definitions #

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.

  • names : Array ℕ

    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.

Adding a variable keeps the numbers already given.

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.

  • toDense : ℕ → ℕ

    The number of each variable, 0 for a variable not in the formula.

  • fromDense : ℕ → ℕ

    The variable of each number: the i-th variable for i < 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 undoes the renaming on the variables of φ.

The renamed variables are below the number of distinct variables.