Download data/lean/OAI/Computability/WLIdentification/Model.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.57 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/WLIdentification/Model.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/WLIdentification/Model.lean
-
curl -L -o Model.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/WLIdentification/Model.lean
5.57 kB
| import Mathlib | |
| namespace OAI | |
| namespace WLIdentification | |
| structure Graph where | |
| order : β | |
| edge : Fin order β Fin order β Bool | |
| symmetric : β u v, edge u v = edge v u | |
| loopless : β u, edge u u = false | |
| def Isomorphic (G H : Graph) : Prop := | |
| β e : Fin G.order β Fin H.order, β u v, G.edge u v = H.edge (e u) (e v) | |
| /-- Colors retain their full history, and hence are shared between graphs. -/ | |
| def NeighborColor : β β Type | |
| | 0 => Unit | |
| | s + 1 => NeighborColor s Γ Multiset (NeighborColor s) | |
| def neighborColor (G : Graph) : (s : β) β Fin G.order β NeighborColor s | |
| | 0, _ => () | |
| | s + 1, v => (neighborColor G s v, | |
| (Finset.univ.filter (fun w => G.edge v w = true)).val.map (neighborColor G s)) | |
| def neighborHistogram (G : Graph) (s : β) : Multiset (NeighborColor s) := | |
| Finset.univ.val.map (neighborColor G s) | |
| def TupleColor (k : β) : β β Type | |
| | 0 => (Fin k β Fin k β Bool) Γ (Fin k β Fin k β Bool) | |
| | s + 1 => TupleColor k s Γ Multiset (Fin k β TupleColor k s) | |
| /-- Joint update: one multiset of whole replacement vectors, not independent marginals. -/ | |
| def tupleColor (G : Graph) (k : β) : (s : β) β (Fin k β Fin G.order) β TupleColor k s | |
| | 0, v => (fun i j => decide (v i = v j), fun i j => G.edge (v i) (v j)) | |
| | s + 1, v => (tupleColor G k s v, | |
| Finset.univ.val.map (fun z => fun i => tupleColor G k s (Function.update v i z))) | |
| def tupleHistogram (G : Graph) (k s : β) : Multiset (TupleColor k s) := | |
| Finset.univ.val.map (tupleColor G k s) | |
| def Equivalent (k : β) (G H : Graph) : Prop := | |
| if k = 1 then β s, neighborHistogram G s = neighborHistogram H s | |
| else β s, tupleHistogram G k s = tupleHistogram H k s | |
| /-- There is no restriction to mates from a graph construction or to a selected order. -/ | |
| def Identifies (k : β) (G : Graph) : Prop := | |
| β H : Graph, Equivalent k G H β Isomorphic G H | |
| /-- The infimum of the positive identifying dimensions; this set is nonempty for finite G. -/ | |
| noncomputable def WLdim (G : Graph) : β := | |
| sInf {k : β | 0 < k β§ Identifies k G} | |
| abbrev Word := List Bool | |
| abbrev BinaryLanguage := Set Word | |
| def binaryValue (bits : Word) : β := | |
| bits.foldl (fun z b => 2 * z + if b then 1 else 0) 0 | |
| def matrixWord (G : Graph) : Word := | |
| (List.ofFn (fun i : Fin G.order => List.ofFn (G.edge i))).flatten | |
| /-- Unary order header, row-major binary matrix, then most-significant-first binary k. -/ | |
| def inputWord (G : Graph) (bits : Word) : Word := | |
| List.replicate G.order true ++ [false] ++ matrixWord G ++ bits | |
| /-- A malformed word is rejected: membership requires a valid nonempty simple matrix and k>0. -/ | |
| def dimensionLanguage : BinaryLanguage := | |
| {w | β (G : Graph) (bits : Word), | |
| 0 < G.order β§ (β tail, bits = true :: tail) β§ 0 < binaryValue bits β§ | |
| w = inputWord G bits β§ WLdim G β€ binaryValue bits} | |
| /- The deterministic local machine model is explicit; no oracle or arbitrary | |
| state-transition on whole inputs is included. Both alphabets are fixed finite | |
| types for each machine. Extra symbols and states allow arbitrary finite tables. -/ | |
| inductive Move where | |
| | left | stay | right | |
| deriving DecidableEq | |
| def Move.displacement : Move β β€ | |
| | .left => -1 | |
| | .stay => 0 | |
| | .right => 1 | |
| structure Machine where | |
| extraSymbols : β | |
| extraStates : β | |
| transition : Fin (extraStates + 3) β Fin (extraSymbols + 3) β | |
| Fin (extraStates + 3) Γ Fin (extraSymbols + 3) Γ Move | |
| structure Configuration (M : Machine) where | |
| state : Fin (M.extraStates + 3) | |
| head : β€ | |
| tape : β€ β Fin (M.extraSymbols + 3) | |
| def inputSymbol (M : Machine) (b : Bool) : Fin (M.extraSymbols + 3) := | |
| if b then 2 else 1 | |
| def initial (M : Machine) (w : Word) : Configuration M where | |
| state := 0 | |
| head := 0 | |
| tape z := if 0 β€ z then (w[z.toNat]?).elim 0 (inputSymbol M) else 0 | |
| def Halted {M : Machine} (c : Configuration M) : Prop := | |
| c.state = 1 β¨ c.state = 2 | |
| /-- One read/write/head-movement transition. A halted configuration is frozen. -/ | |
| def step (M : Machine) (c : Configuration M) : Configuration M := | |
| if c.state = 1 β¨ c.state = 2 then c else | |
| let t := M.transition c.state (c.tape c.head) | |
| { state := t.1, head := c.head + t.2.2.displacement, | |
| tape := Function.update c.tape c.head t.2.1 } | |
| def run (M : Machine) (w : Word) (t : β) : Configuration M := | |
| (step M)^[t] (initial M w) | |
| /-- Output is the binary word beginning at origin and ending at its first blank. -/ | |
| def Output {M : Machine} (c : Configuration M) (w : Word) : Prop := | |
| (β i : Fin w.length, c.tape (i.val : β€) = inputSymbol M w[i]) β§ | |
| c.tape (w.length : β€) = 0 | |
| /-- Uniform genuine executions on every bit word, including malformed graph words. -/ | |
| def DecidesWithin (M : Machine) (L : BinaryLanguage) (bound : β β β) : Prop := | |
| β w, β t β€ bound w.length, Halted (run M w t) β§ ((run M w t).state = 1 β w β L) | |
| def InEXPTIME (L : BinaryLanguage) : Prop := | |
| β (M : Machine) (C d : β), | |
| DecidesWithin M L (fun n => 2 ^ (C * (n + 1) ^ d)) | |
| def ComputesWithin (M : Machine) (f : Word β Word) (bound : β β β) : Prop := | |
| β w, β t β€ bound w.length, (run M w t).state = 1 β§ Output (run M w t) (f w) | |
| def PolytimeManyOne (L S : BinaryLanguage) : Prop := | |
| β (f : Word β Word) (M : Machine) (C d : β), | |
| ComputesWithin M f (fun n => C * (n + 1) ^ d) β§ β w, w β L β f w β S | |
| def EXPTIMEComplete (S : BinaryLanguage) : Prop := | |
| InEXPTIME S β§ β L : BinaryLanguage, InEXPTIME L β PolytimeManyOne L S | |
| end WLIdentification | |
| end OAI | |