File size: 1,568 Bytes
ea76aac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Mathlib

namespace OAI

/-! Infinite stacks, finite prefixes and tails. -/

noncomputable section
open scoped ContDiff
namespace PrefixFlows
namespace Interspersed
abbrev Stack (A : Type*) := ℕ → A

def push {A : Type*} (a : A) (L : Stack A) : Stack A
  | 0 => a
  | n + 1 => L n

@[simp] theorem push_zero {A : Type*} (a : A) (L : Stack A) : push a L 0 = a := rfl

@[simp] theorem push_succ {A : Type*} (a : A) (L : Stack A) (n : ℕ) :
    push a L (n + 1) = L n := rfl

@[simp] theorem push_inj {A : Type*} {a b : A} {L R : Stack A} :
    push a L = push b R ↔ a = b ∧ L = R := by
  constructor
  · intro h
    exact ⟨congrFun h 0, funext (fun n => congrFun h (n + 1))⟩
  · rintro ⟨rfl, rfl⟩
    rfl

def prepend {B : Type*} : List B → Stack B → Stack B
  | [], L => L
  | a :: w, L => push a (prepend w L)

@[simp] theorem prepend_nil {B : Type*} (L : Stack B) : prepend [] L = L := rfl

@[simp] theorem prepend_cons {B : Type*} (a : B) (w : List B) (L : Stack B) :
    prepend (a :: w) L = push a (prepend w L) := rfl

theorem prepend_append {B : Type*} (v w : List B) (L : Stack B) :
    prepend (v ++ w) L = prepend v (prepend w L) := by
  induction v with
  | nil => rfl
  | cons a v ih => simp [ih]

def tail {B : Type*} (L : Stack B) : Stack B := fun n => L (n + 1)

@[simp] theorem tail_push {B : Type*} (a : B) (L : Stack B) : tail (push a L) = L := rfl

@[simp] theorem push_constant {B : Type*} (b : B) :
    push b (fun _ => b) = (fun _ => b) := by
  funext n
  cases n <;> rfl
end Interspersed
end PrefixFlows
end

end OAI