Fixed local transitions for emitting a unit clause from marked bit tracks
DefinitionFixedWidthPhysicalClauseEmittercomplexity-theoryformal-verification
The local machine reads sender position bits, an item, and a clause counter from a bounded scratch tape. It emits each sign, identifier bit, and delimiter using a fixed finite set of control states.
Definition code
import Definitions.Def_PvsNP
set_option autoImplicit false
namespace PvsNP.FixedIdentifierSAT
def fixedBits (b j : ℕ) : Str := (List.range b).map j.testBit
/-- The sign, item bits, identifier-counter bits, high marker, and two
delimiter pairs are emitted verbatim. -/
def clauseWord (b position : ℕ) (item : Str) (j : ℕ) : Str :=
((position.testBit j :: (item ++ fixedBits b j ++ [true])).flatMap (fun bit => [false,bit])) ++
[true,false,true,true]
end PvsNP.FixedIdentifierSAT
namespace PvsNP.PhysicalClauseEmitter
structure Cell where
first : Bool
last : Bool
mark : Bool
item : Bool
counter : Bool
position : Bool
deriving Fintype
inductive Phase
| seekSign | signValue | returnItem | itemLead | itemValue
| returnCounter | counterLead | counterValue
| highValue | endLiteralLead | endLiteralTail | endClauseLead | endClauseTail | done
deriving DecidableEq
instance : Fintype Phase := ⟨
{.seekSign,.signValue,.returnItem,.itemLead,.itemValue,.returnCounter,.counterLead,.counterValue,
.highValue,.endLiteralLead,.endLiteralTail,.endClauseLead,.endClauseTail,.done},
by intro q; cases q <;> decide⟩
inductive Move
| stay | left | right
def headStep : Move → ℕ → ℕ
| .stay, h => h
| .left, h => h-1
| .right, h => h+1
/-- Finite local transition table for the read-only part of a clause
generator. The scratch tracks are fixed during this clause. -/
def command (c : Cell) : Phase → Phase × Move × Option Bool
| .seekSign => if c.mark then (.signValue,.stay,some false)
else if c.last then (.done,.stay,none) else (.seekSign,.right,none)
| .signValue => (.returnItem,.stay,some c.position)
| .returnItem => if c.first then (.itemLead,.stay,none) else (.returnItem,.left,none)
| .itemLead => if c.last then (.returnCounter,.stay,none) else (.itemValue,.stay,some false)
| .itemValue => if c.last then (.done,.stay,none) else (.itemLead,.right,some c.item)
| .returnCounter => if c.first then (.counterLead,.stay,none) else (.returnCounter,.left,none)
| .counterLead => if c.last then (.highValue,.stay,some false) else (.counterValue,.stay,some false)
| .counterValue => if c.last then (.done,.stay,none) else (.counterLead,.right,some c.counter)
| .highValue => (.endLiteralLead,.stay,some true)
| .endLiteralLead => (.endLiteralTail,.stay,some true)
| .endLiteralTail => (.endClauseLead,.stay,some false)
| .endClauseLead => (.endClauseTail,.stay,some true)
| .endClauseTail => (.done,.stay,some true)
| .done => (.done,.stay,none)
def tape (b i j : ℕ) (item : List Bool) (k : ℕ) : Cell :=
⟨decide (k=0),decide (k=b),decide (k=j),item[k]?.getD false,j.testBit k,i.testBit k⟩
def tick (tape : ℕ → Cell) (q : Phase) (h : ℕ) : Phase × ℕ × List Bool :=
let (next,move,emit) := command (tape h) q
(next,headStep move h,emit.toList)
def run (tape : ℕ → Cell) : ℕ → Phase → ℕ → Phase × ℕ × List Bool
| 0,q,h => (q,h,[])
| t+1,q,h =>
let (next,h',emit) := tick tape q h
let (q',p,more) := run tape t next h'
(q',p,emit++more)
def clauseCost (b j : ℕ) : ℕ := 2*j+5*b+11
end PvsNP.PhysicalClauseEmitter
Source
A streaming unit-CNF encoder for fixed-width element distinctness.