@@ -8,7 +8,7 @@ public import Valaig.ForStd
88namespace Valaig.Aig
99
1010/--
11- The metadata of an input in the Aig
11+ The metadata of an input in the Aig.
1212-/
1313structure Input where
1414 var : Var
@@ -19,18 +19,6 @@ end Input
1919
2020/--
2121The metadata of a latch in the Aig.
22-
23- We require all latches to have a next state defined to make it easier to define their semantics,
24- even though sometimes this next state can't be known at latch construction time as they are cyclic.
25- To accomodate this, the next value should initially be set to a constant, before being subsequently
26- overwritten.
27-
28- We differ from Aiger 1.9 by requiring all latches to have a reset, meaning that all sources of
29- nondeterminism in the circuit are due to inputs so are easier to reason about.
30- Resets are stratified (acyclic), by requiring that the reset comes before the variable defined by
31- this latch. Note that this is not compatible with the binary aiger format, so for binary aiger we
32- need to reorder things to prevent this. We prefer this encoding as it is easier to reason about as
33- we have an explicit order on variables.
3422-/
3523structure Latch where
3624 var : Var
@@ -44,7 +32,6 @@ end Latch
4432abbrev Inputs := Array Input
4533abbrev Latches := Array Latch
4634
47- -- Switch to public by default
4835end Valaig.Aig
4936public section pub
5037namespace Valaig.Aig
@@ -77,7 +64,7 @@ end LatchIdx
7764
7865/--
7966An atom in the combinational aig is either an input or a latch, which is just
80- a reference back to the index in the inputs or latches arrays
67+ a reference back to the index in the inputs or latches arrays.
8168-/
8269inductive AtomIdx where
8370| input (idx : InputIdx)
@@ -90,7 +77,7 @@ end AtomIdx
9077
9178/--
9279An output of interest in the circuit - this is also used to represent other
93- nameable nodes in the Aiger format like bad and constraint nodes
80+ nameable nodes in the Aiger format like bad and constraint nodes.
9481-/
9582structure Output where
9683 lit : Lit
@@ -104,7 +91,8 @@ abbrev Outputs := Array Output
10491end Aig
10592
10693/--
107- A sequential Aig without any marked outputs. These should be stored separately
94+ A sequential And-Inverter Graph consisting of inputs, latches and And gates. Outputs should be
95+ stored separately as `Lit`s in the `Aig`.
10896-/
10997structure Aig where
11098 -- The underlying AIG
@@ -119,8 +107,8 @@ structure Aig where
119107namespace Aig
120108
121109/--
122- A representation of the node data stored for a particular variable in the Aig. For
123- inputs and latches this requires a further lookup with InputIdx.get or LatchIdx.get
110+ A representation of the node data stored for a particular variable in an ` Aig` . For inputs and
111+ latches this requires a further lookup with ` InputIdx.get` or ` LatchIdx.get`.
124112-/
125113inductive Node where
126114 | false
@@ -133,7 +121,7 @@ deriving instance Hashable, DecidableEq, Repr, Inhabited for Node
133121end Node
134122
135123/--
136- An Aig with just the constant node.
124+ An ` Aig` with just the constant node.
137125-/
138126def empty : Aig :=
139127 {
@@ -143,7 +131,7 @@ def empty : Aig :=
143131 }
144132
145133/--
146- The number of nodes currently allocated in the Aig
134+ The number of nodes currently allocated in aig.
147135-/
148136@ [local grind]
149137def size (aig : Aig) : Nat :=
@@ -229,7 +217,8 @@ def LatchIdx.setReset (idx : Aig.LatchIdx) (aig : Aig) (reset : Lit) (valid : id
229217 { aig with latches := aig.latches.modifyMem idx.idx (by simp_all) ({ ·.val with reset }) }
230218
231219/-
232- Generic index type that can be Var, InputIdx or LatchIdx used for proof reasoning.
220+ Generic index type that can be Var, InputIdx or LatchIdx used for proof reasoning, particularly
221+ when operations invalidate no indices.
233222-/
234223
235224inductive GenericIdx where
@@ -244,16 +233,14 @@ def GenericIdx.validIn (idx : GenericIdx) (aig : Aig) : Prop :=
244233 | latch idx => idx.validIn aig
245234
246235namespace GenericIdx
247-
248236variable {aig : Aig}
249- attribute [local simp] validIn
250237
251238/-
252239Lemmas to convert between specific and generic index forms.
253240-/
254- @ [simp, grind =, grind =_] theorem iff_node (var : Var) : (node var).validIn aig ↔ var.validIn aig := by simp
255- @ [simp, grind =, grind =_] theorem iff_input (idx : InputIdx) : (input idx).validIn aig ↔ idx.validIn aig := by simp
256- @ [simp, grind =, grind =_] theorem iff_latch (idx : LatchIdx) : (latch idx).validIn aig ↔ idx.validIn aig := by simp
241+ @ [simp, grind =, grind =_] theorem iff_node (var : Var) : (node var).validIn aig ↔ var.validIn aig := by rfl
242+ @ [simp, grind =, grind =_] theorem iff_input (idx : InputIdx) : (input idx).validIn aig ↔ idx.validIn aig := by rfl
243+ @ [simp, grind =, grind =_] theorem iff_latch (idx : LatchIdx) : (latch idx).validIn aig ↔ idx.validIn aig := by rfl
257244
258245end GenericIdx
259246
0 commit comments