Download data/lean/OAI/Computability/PerfectCompleteness/Machines/BinaryRenameWords.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.22 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Machines/BinaryRenameWords.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/PerfectCompleteness/Machines/BinaryRenameWords.lean
-
curl -L -o BinaryRenameWords.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Machines/BinaryRenameWords.lean
6.22 kB
Lean 4 · 22
declarations statementsfull
def clauseLiterals (c : Clause) : List Literal := [(c)[0], (c)[1], (c)[2]] def literals (clauses : List Clause) : List Literal := clauses.flatMap clauseLiterals def token (literal : Literal) : BinaryNameSearch.Token := body · 1 line
(literal.positive, literal.name.bits)
def tokens (clauses : List Clause) : List BinaryNameSearch.Token := body · 1 line
(literals clauses).map token
@[simp] theorem literals_nil : literals [] = [] := rfl @[simp] theorem literals_cons (c : Clause) (cs : List Clause) :
literals (c :: cs) = (c)[0] :: (c)[1] :: (c)[2] :: literals cs := rfl @[simp] theorem literals_length (cs : List Clause) :
(literals cs).length = 3 * cs.length := by proof · 3 lines
induction cs with
| nil => rfl
| cons c cs ih => simp only [literals_cons, List.length_cons, ih]; omega@[simp] theorem tokens_length (cs : List Clause) :
(tokens cs).length = 3 * cs.length := by simp [tokens] theorem literals_names (F : Formula) :
(literals F.clauses).map Literal.name = sourceNames F := by proof · 2 lines
simp only [literals, sourceNames, List.map_flatMap]
rfltheorem tokens_payloads (F : Formula) :
BinaryNameSearch.payloads (tokens F.clauses) = (sourceNames F).map Nat.bits := by proof · 2 lines
rw [← literals_names]
simp only [BinaryNameSearch.payloads, tokens, List.map_map, token, Function.comp_def]theorem token_bits (literal : Literal) :
BinaryNameSearch.tokenBits (token literal) = BinaryEncoding.literalBits literal := by proof · 2 lines
simp only [BinaryNameSearch.tokenBits, token, BinaryEncoding.literalBits,
BinaryEncoding.nameBits, BinaryParsing.frame_eq]theorem tokens_stream (cs : List Clause) :
BinaryNameSearch.stream (tokens cs) = BinaryTokenMachine.tokens cs := by proof · 8 lines
induction cs with
| nil => rfl
| cons c cs ih =>
simp only [tokens, literals_cons, List.map_cons, BinaryNameSearch.stream_cons,
token_bits, BinaryTokenMachine.tokens_cons, BinaryEncoding.clauseBits]
simpa only [tokens, List.append_assoc] using
congrArg (fun tail => BinaryEncoding.literalBits (c)[0] ++
BinaryEncoding.literalBits (c)[1] ++ BinaryEncoding.literalBits (c)[2] ++ tail) ihtheorem tokens_canonical (cs : List Clause) :
∀ t ∈ tokens cs, BinaryNameMachine.canonical t.2 = true := by proof · 3 lines
intro t mem
obtain ⟨literal, _, rfl⟩ := List.mem_map.mp mem
exact BinaryParsing.canonical_nat_bits literal.nametheorem payload_index (F : Formula) (name : Nat) :
(BinaryNameSearch.payloads (tokens F.clauses)).idxOf name.bits =
(sourceNames F).idxOf name := by proof · 1 line
rw [tokens_payloads, BinaryOccurrenceRename.idxOf_binary_payloads]theorem token_payload_mem (cs : List Clause) (literal : Literal)
(mem : literal ∈ literals cs) :
literal.name.bits ∈ BinaryNameSearch.payloads (tokens cs) := by proof · 3 lines
apply List.mem_map.mpr
refine ⟨token literal, ?_, rfl⟩
exact List.mem_map.mpr ⟨literal, mem, rfl⟩theorem payloadSize_tokens (cs : List Clause) :
BinaryNameSearch.payloadSize (tokens cs) = BinaryEncoding.namesBitSize cs := by proof · 10 lines
induction cs with
| nil => rfl
| cons c cs ih =>
simp only [tokens, literals_cons, List.map_cons,
BinaryNameSearch.payloadSize_cons, token, Nat.size_eq_bits_len,
BinaryEncoding.namesBitSize_cons] at *
simpa only [BinaryEncoding.clauseNameSize, BinaryFormula.clauseNames,
List.map_cons, List.map_nil, List.sum_cons, List.sum_nil,
Nat.add_zero, Nat.add_assoc] using congrArg
(fun tail => (c)[0].name.size + ((c)[1].name.size + ((c)[2].name.size + tail))) ihdef outputLiteral (names : List Nat) (literal : Literal) : List Bool := body · 2 lines
Complexity.encodeWord (names.idxOf literal.name) ++
Complexity.encodeWord (if literal.positive then 1 else 0)def body (F : Formula) : List Bool := body · 1 line
(literals F.clauses).flatMap (outputLiteral (sourceNames F))theorem encoded_clause (F : Formula) (c : Clause) (mem : c ∈ F.clauses) :
Complexity.encodeWords (Complexity.clauseWords (BinaryOccurrenceRename.clause F c mem)) =
(clauseLiterals c).flatMap (outputLiteral (sourceNames F)) := by proof · 4 lines
simp [Complexity.clauseWords, Complexity.literalWords, Complexity.encodeWords,
BinaryOccurrenceRename.clause, BinaryOccurrenceRename.literal,
BinaryOccurrenceRename.nameIndex, clauseLiterals, outputLiteral, List.append_assoc]
rflprivate theorem encodeWords_flatMap {α : Type} (xs : List α) (f : α → List Nat) :
Complexity.encodeWords (xs.flatMap f) =
xs.flatMap (fun x => Complexity.encodeWords (f x)) := by proof · 3 lines
induction xs with
| nil => rfl
| cons x xs ih => simp only [List.flatMap_cons, Complexity.encodeWords_append, ih]theorem encoded_body (F : Formula) :
Complexity.encodeWords ((BinaryOccurrenceRename.renamed F).clauses.flatMap
Complexity.clauseWords) = body F := by proof · 9 lines
rw [encodeWords_flatMap]
change (F.clauses.attach.map (fun c => BinaryOccurrenceRename.clause F c.val c.property)).flatMap
(fun c => Complexity.encodeWords (Complexity.clauseWords c)) = body F
rw [List.flatMap_map]
simp only [encoded_clause]
have h := congrArg (fun cs : List Clause =>
cs.flatMap (fun c => (clauseLiterals c).flatMap (outputLiteral (sourceNames F))))
(List.attach_map_subtype_val F.clauses)
simpa only [List.flatMap_map, body, literals, List.flatMap_assoc] using htheorem encoded_renamed (F : Formula) :
Complexity.formulaBits (BinaryOccurrenceRename.renamed F) =
Complexity.encodeWord (3 * F.clauses.length) ++
Complexity.encodeWord F.clauses.length ++ body F := by proof · 4 lines
simp only [Complexity.formulaBits, Complexity.formulaWords, Complexity.encodeWords_append,
Complexity.encodeWords, List.append_nil,
BinaryOccurrenceRename.renamed_variable_count,
BinaryOccurrenceRename.renamed_clause_count, encoded_body, List.append_assoc]Outline
- def
clauseLiterals14 - def
literals16 - def
token18 - def
tokens21 - theorem
literals_nil24 - theorem
literals_cons26 - theorem
literals_length29 - theorem
tokens_length35 - theorem
literals_names38 - theorem
tokens_payloads43 - theorem
token_bits48 - theorem
tokens_stream53 - theorem
tokens_canonical64 - theorem
payload_index70 - theorem
token_payload_mem75 - theorem
payloadSize_tokens82 - def
outputLiteral95 - def
body99 - theorem
encoded_clause102 - theorem
encodeWords_flatMap110 - theorem
encoded_body117 - theorem
encoded_renamed130