import Mathlib.Data.List.Basic import Mathlib.Data.Finset.Basic namespace Hieroglyphs /-- A deliberately bounded alphabet for the signs in the supplied stream. -/ inductive Glyph | eye -- ๐“‚€ | bread -- ๐“ | mouth -- ๐“‚‹ | flax -- ๐“Ž› | stroke -- ๐“ค | god -- ๐“Šน | ankh -- ๐“‹น | cobra -- ๐“†ฃ | sun -- ๐“‡ณ | unknownA -- ๐“‚ป | water -- ๐“ˆ– | stool -- ๐“Šช | owl -- ๐“…“ | basket -- ๐“Žผ deriving DecidableEq, Repr def transliterate : Glyph โ†’ String | .eye => "ir" | .bread => "t" | .mouth => "r" | .flax => "h" | .stroke => "ยท" | .god => "nแนฏr" | .ankh => "๊œฅnแธซ" | .cobra => "?" | .sun => "r๊œฅ" | .unknownA => "?" | .water => "n" | .stool => "p" | .owl => "m" | .basket => "g" /-- A decoding is only certified relative to an explicit grammar and lexicon. -/ structure DecodeSpec where lexical : List Glyph โ†’ Option String grammatical : List Glyph โ†’ Prop sound : โˆ€ xs meaning, lexical xs = some meaning โ†’ grammatical xs /-- Concrete recognition is distinct from semantic translation. -/ def Recognized (xs : List Glyph) : Prop := โˆ€ g, g โˆˆ xs โ†’ g = .eye โˆจ g = .bread โˆจ g = .mouth โˆจ g = .flax โˆจ g = .stroke โˆจ g = .god โˆจ g = .ankh โˆจ g = .cobra โˆจ g = .sun โˆจ g = .unknownA โˆจ g = .water โˆจ g = .stool โˆจ g = .owl โˆจ g = .basket /-- A formal definition of periodicity for a list. -/ def Periodic (period xs : List Glyph) : Prop := period โ‰  [] โˆง โˆƒ k, xs = List.join (List.replicate k period) /-- Example recurring motif โ€” not asserted to be Egyptian grammar. -/ def Motif : List Glyph := [.eye, .ankh, .god, .sun, .cobra, .unknownA, .water, .bread, .flax, .mouth, .stool, .owl] example : Periodic Motif (Motif ++ Motif) := by refine โŸจby decide, 2, ?_โŸฉ simp [Motif] /-- A truthful result type: never manufacture a semantic translation. -/ inductive DecodeResult | transliteration : List String โ†’ DecodeResult | grammatical : String โ†’ DecodeResult | insufficientEvidence : String โ†’ DecodeResult deriving Repr def decode (spec : DecodeSpec) (xs : List Glyph) : DecodeResult := match spec.lexical xs with | some meaning => if spec.grammatical xs then .grammatical meaning else .insufficientEvidence "Lexicon returned a reading rejected by grammar." | none => .insufficientEvidence "No certified lexical-and-grammatical interpretation for this glyph sequence." theorem no_semantic_claim_without_lexicon (spec : DecodeSpec) (xs : List Glyph) (h : spec.lexical xs = none) : decode spec xs = .insufficientEvidence "No certified lexical-and-grammatical interpretation for this glyph sequence." := by simp [decode, h] end Hieroglyphs