This module contains the default implementation of the Formula
typeclass that is used in the
surface level LRAT checker.
The structure DefaultFormula n
takes in a parameter n
which is intended to be one greater than the total number of variables that
can appear in the formula (hence why the parameter n
is called numVarsSucc
below). The structure has 4 fields:
The
clauses
field maintains the total set of clauses that appear in the formula. Additionally, when a default formula is created by parsing a CNF file and modified by a series of LRAT additions and deletions, the following informal invariant is maintained:clauses[0]
is always set tonone
.- The m clauses in the original CNF file are stored in indices 1 through m of the
clauses
field (and they are stored in the order in which they appear in the CNF file). - Each subsequent LRAT addition is pushed to the very end of the
clauses
array, even if there are elements in the current array set to none. - When a clause index is deleted via
delete
, that index inclauses
is set tonone
The purpose of this invariant is to preserve a 1-to-1 correspondence between indices referenced by any external LRAT proof and the internal indices used within
clauses
The
rupUnits
field is empty except during the processing of RUP additions and RAT additions. During a RUP addition or a RAT addition, therupUnits
field is used to store negated units from the clause being evaluated for the addition. Regardless of whether the addition is successful, therupUnits
field is cleared prior to returning. The reason thatrupUnits
is included as part of the default formula structure (as opposed to simply being an Array that is passed through the helper functions relating to RUP and RAT additions) is to simplify the semantics of default formulas. SincerupUnits
is part of the default formula structure, it can be taken into account in thetoList
function that defines its satisfiability semantics, making it possible to "add" negated units to a default formula and have it affect its semantics in an easily reversible manner.The
ratUnits
field is empty except during the processing of RAT additions. This field serves an extremely similar role torupUnits
in that it is used to temporarily store negated units during unit propagation. The primary difference between therupUnits
field andratUnits
field is that therupUnits
field is only updated twice for each RUP or RAT addition (once to add negated units and then once again to remove said negated units), theratUnits
field is updated zero times for each RUP addition and updated m times for each RAT addition where m is the number of negative hints in said RAT addition (i.e. the number of clauses in the formula containing the RAT addition's negated pivot literal).The
assignments
field is maintained to quickly look up which values (if any) are entailed for a variable by the formula. At most points in time, (i.e. at all points in time except during a RUP or RAT addition), theassignments
field must satisfy theStrongAssignmentsInvariant
defined in Formula.Lemmas.lean. During RUP and RAT additions, theassignments
field must satisfy theAssignmentsInvariant
defined in Formula.Lemmas.lean. The reason that theassignments
field is contained as an explicit part of the default formula (as opposed to simply being an Array that is passed through the helper functions concerning unit propagation), is so that the (potentially large) Array does not need to repeatedly be allocated and deallocated. By having theassignments
Array be a field of the default formula, it is easier to ensure that the Array is used linearly.
- clauses : Array (Option (Std.Tactic.BVDecide.LRAT.Internal.DefaultClause numVarsSucc))
- rupUnits : Array (Std.Sat.Literal (Std.Tactic.BVDecide.LRAT.Internal.PosFin numVarsSucc))
- ratUnits : Array (Std.Sat.Literal (Std.Tactic.BVDecide.LRAT.Internal.PosFin numVarsSucc))
- assignments : Array Std.Tactic.BVDecide.LRAT.Internal.Assignment
Instances For
Equations
- One or more equations did not get rendered due to their size.
Note: This function is only for reasoning about semantics. Its efficiency doesn't actually matter
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Std.Tactic.BVDecide.LRAT.Internal.DefaultFormula.ofArray_fold_fn assignments none = assignments
Instances For
Note: This function assumes that the provided clauses
Array is indexed according to the clauses
field invariant described in the DefaultFormula doc comment.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- f.delete ids = Array.foldl (fun (f : Std.Tactic.BVDecide.LRAT.Internal.DefaultFormula n) (id : Nat) => f.deleteOne id) f ids
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns an updated formula f and a bool which indicates whether a contradiction was found in the process of updating f.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns an updated formula f and a bool which indicates whether a contradiction was found in the process of updating f.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Std.Tactic.BVDecide.LRAT.Internal.DefaultFormula.clearUnit x✝ (l, b) = x✝.modify l.val (Std.Tactic.BVDecide.LRAT.Internal.Assignment.removeAssignment b)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Reverts assignments to the array it was prior to adding derivedLits.
Equations
- Std.Tactic.BVDecide.LRAT.Internal.DefaultFormula.restoreAssignments assignments derivedLits = List.foldl Std.Tactic.BVDecide.LRAT.Internal.DefaultFormula.clearUnit assignments derivedLits
Instances For
The fold function used for performRupCheck.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Takes in a formula f and an array of rupHints and attempts to verify that f is unsatisfiable. It returns:
- f', which is the same as f but the assignments field has been updated to be consistent with anything learned over the course of the rupCheck
- derivedLits, which is the list of literals that were derived over the course of the rupCheck (these are needed to eventually reconstruct the original assignment)
- derivedEmpty, which indicates whether the empty clause or a contradiction was derived
- encounteredError, which is true if the rupCheck failed and false otherwise
Note: This function assumes that any rupUnits and ratUnits corresponding to this rup check have already been added to f.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Attempts to verify that c can be added to f via unit propagation. If it can, it returns
((f.insert c), true)
. If it can't, it returns false as the second part of the tuple
(and no guarantees are made about what formula is returned).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns an array of indices corresponding to clauses that contain the negation of l
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checks that for each clause c ∈ f
such that (Literal.negate pivot) ∈ c
, c
's index is in
ratHints.map (fun x => x.1)
. This function assumes that ratHints are ordered by the value of their
first argument, which is consistent with LRAT's specification
Equations
- One or more equations did not get rendered due to their size.
Instances For
Takes in a formula f
and a single ratHint
and attempts to verify that f
is inconsistent with the
negation of the ratHint
's clause. It returns:
f
which is the same as the originalf
(including the ratUnits and assignment fields)- Although the
ratUnits
andassignments
fields are updated during the procedure, they are restored prior to returning..
- Although the
success
, which indicates whether empty was successfully derived without any errors
Note: This function assumes that the ratUnits
corresponding to this rat check have NOT already
been added to f
. In terms of input expectations and output guarantees, this function is more
analogous to performRupAdd
than performRupCheck
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Attempts to verify that c
can be added to f
via unit propagation. If it can, it returns
((f.insert c), true)
. If it can't, it returns false as the second part of the tuple
(and no guarantees are made about what formula is returned).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.