α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
⊢ (match Stream'.corec' (Corec.f f) (Sum.inr b) 0 with
    | none =>
      Sum.inr
        (tail
          { val := Stream'.corec' (Corec.f f) (Sum.inr b),
            property :=
              (_ :
                ∀ (n : ℕ) (a' : α),
                  Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                    Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') })
    | some a => Sum.inl a) =
    match f b with
    | Sum.inl a => Sum.inl a
    | Sum.inr b =>
      Sum.inr
        { val := Stream'.corec' (Corec.f f) (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
⊢ destruct (corec f b) = rmap (corec f) (f b)
dsimp [corec, destruct]
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
⊢ (match Sum.rec some (fun x => none) (f b) with
    | none =>
      Sum.inr
        (tail
          { val := Stream'.corec' (Corec.f f) (Sum.inr b),
            property :=
              (_ :
                ∀ (n : ℕ) (a' : α),
                  Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                    Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') })
    | some a => Sum.inl a) =
    match f b with
    | Sum.inl a => Sum.inl a
    | Sum.inr b =>
      Sum.inr
        { val := Stream'.corec' (Corec.f f) (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
⊢ (match Stream'.corec' (Corec.f f) (Sum.inr b) 0 with
    | none =>
      Sum.inr
        (tail
          { val := Stream'.corec' (Corec.f f) (Sum.inr b),
            property :=
              (_ :
                ∀ (n : ℕ) (a' : α),
                  Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                    Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') })
    | some a => Sum.inl a) =
    match f b with
    | Sum.inl a => Sum.inl a
    | Sum.inr b =>
      Sum.inr
        { val := Stream'.corec' (Corec.f f) (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }
rw [show Stream'.corec' (Corec.f f) (Sum.inr b) 0 =
  Sum.rec Option.some (λ _ => none) (f b) by
  dsimp [Corec.f, Stream'.corec', Stream'.corec, Stream'.map, Stream'.nth, Stream'.iterate]
  match (f b) with
  | Sum.inl x => rfl
  | Sum.inr x => rfl
  ]
case inl
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
a : α
h : f b = Sum.inl a
⊢ (match Sum.rec some (fun x => none) (Sum.inl a) with
    | none =>
      Sum.inr
        (tail
          { val := Stream'.corec' (Corec.f f) (Sum.inr b),
            property :=
              (_ :
                ∀ (n : ℕ) (a' : α),
                  Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                    Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') })
    | some a => Sum.inl a) =
    match Sum.inl a with
    | Sum.inl a => Sum.inl a
    | Sum.inr b =>
      Sum.inr
        { val := Stream'.corec' (Corec.f f) (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }

case inr
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ (match Sum.rec some (fun x => none) (Sum.inr b') with
    | none =>
      Sum.inr
        (tail
          { val := Stream'.corec' (Corec.f f) (Sum.inr b),
            property :=
              (_ :
                ∀ (n : ℕ) (a' : α),
                  Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                    Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') })
    | some a => Sum.inl a) =
    match Sum.inr b' with
    | Sum.inl a => Sum.inl a
    | Sum.inr b =>
      Sum.inr
        { val := Stream'.corec' (Corec.f f) (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
⊢ (match Sum.rec some (fun x => none) (f b) with
    | none =>
      Sum.inr
        (tail
          { val := Stream'.corec' (Corec.f f) (Sum.inr b),
            property :=
              (_ :
                ∀ (n : ℕ) (a' : α),
                  Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                    Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') })
    | some a => Sum.inl a) =
    match f b with
    | Sum.inl a => Sum.inl a
    | Sum.inr b =>
      Sum.inr
        { val := Stream'.corec' (Corec.f f) (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }
induction' h : f b with a b'
case inr
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ Sum.inr
      (tail
        {
          val :=
            Stream'.corec'
              (fun x =>
                match x with
                | Sum.inl a => (some a, Sum.inl a)
                | Sum.inr b =>
                  (match f b with
                    | Sum.inl a => some a
                    | Sum.inr val => none,
                    f b))
              (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }) =
    Sum.inr
      {
        val :=
          Stream'.corec'
            (fun x =>
              match x with
              | Sum.inl a => (some a, Sum.inl a)
              | Sum.inr b =>
                (match f b with
                  | Sum.inl a => some a
                  | Sum.inr val => none,
                  f b))
            (Sum.inr b'),
        property :=
          (_ :
            ∀ (n : ℕ) (a' : α),
              Stream'.corec' (Corec.f f) (Sum.inr b') n = some a' →
                Stream'.corec' (Corec.f f) (Sum.inr b') (n + 1) = some a') }
case inr
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ (match Sum.rec some (fun x => none) (Sum.inr b') with
    | none =>
      Sum.inr
        (tail
          { val := Stream'.corec' (Corec.f f) (Sum.inr b),
            property :=
              (_ :
                ∀ (n : ℕ) (a' : α),
                  Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                    Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') })
    | some a => Sum.inl a) =
    match Sum.inr b' with
    | Sum.inl a => Sum.inl a
    | Sum.inr b =>
      Sum.inr
        { val := Stream'.corec' (Corec.f f) (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }
dsimp [Corec.f, destruct]
case inr.h
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ tail
      {
        val :=
          Stream'.corec'
            (fun x =>
              match x with
              | Sum.inl a => (some a, Sum.inl a)
              | Sum.inr b =>
                (match f b with
                  | Sum.inl a => some a
                  | Sum.inr val => none,
                  f b))
            (Sum.inr b),
        property :=
          (_ :
            ∀ (n : ℕ) (a' : α),
              Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') } =
    {
      val :=
        Stream'.corec'
          (fun x =>
            match x with
            | Sum.inl a => (some a, Sum.inl a)
            | Sum.inr b =>
              (match f b with
                | Sum.inl a => some a
                | Sum.inr val => none,
                f b))
          (Sum.inr b'),
      property :=
        (_ :
          ∀ (n : ℕ) (a' : α),
            Stream'.corec' (Corec.f f) (Sum.inr b') n = some a' →
              Stream'.corec' (Corec.f f) (Sum.inr b') (n + 1) = some a') }
case inr
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ Sum.inr
      (tail
        {
          val :=
            Stream'.corec'
              (fun x =>
                match x with
                | Sum.inl a => (some a, Sum.inl a)
                | Sum.inr b =>
                  (match f b with
                    | Sum.inl a => some a
                    | Sum.inr val => none,
                    f b))
              (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }) =
    Sum.inr
      {
        val :=
          Stream'.corec'
            (fun x =>
              match x with
              | Sum.inl a => (some a, Sum.inl a)
              | Sum.inr b =>
                (match f b with
                  | Sum.inl a => some a
                  | Sum.inr val => none,
                  f b))
            (Sum.inr b'),
        property :=
          (_ :
            ∀ (n : ℕ) (a' : α),
              Stream'.corec' (Corec.f f) (Sum.inr b') n = some a' →
                Stream'.corec' (Corec.f f) (Sum.inr b') (n + 1) = some a') }
apply congr_arg
case inr.h.a
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ ↑(tail
        {
          val :=
            Stream'.corec'
              (fun x =>
                match x with
                | Sum.inl a => (some a, Sum.inl a)
                | Sum.inr b =>
                  (match f b with
                    | Sum.inl a => some a
                    | Sum.inr val => none,
                    f b))
              (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }) =
    ↑{
        val :=
          Stream'.corec'
            (fun x =>
              match x with
              | Sum.inl a => (some a, Sum.inl a)
              | Sum.inr b =>
                (match f b with
                  | Sum.inl a => some a
                  | Sum.inr val => none,
                  f b))
            (Sum.inr b'),
        property :=
          (_ :
            ∀ (n : ℕ) (a' : α),
              Stream'.corec' (Corec.f f) (Sum.inr b') n = some a' →
                Stream'.corec' (Corec.f f) (Sum.inr b') (n + 1) = some a') }
case inr.h
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ tail
      {
        val :=
          Stream'.corec'
            (fun x =>
              match x with
              | Sum.inl a => (some a, Sum.inl a)
              | Sum.inr b =>
                (match f b with
                  | Sum.inl a => some a
                  | Sum.inr val => none,
                  f b))
            (Sum.inr b),
        property :=
          (_ :
            ∀ (n : ℕ) (a' : α),
              Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') } =
    {
      val :=
        Stream'.corec'
          (fun x =>
            match x with
            | Sum.inl a => (some a, Sum.inl a)
            | Sum.inr b =>
              (match f b with
                | Sum.inl a => some a
                | Sum.inr val => none,
                f b))
          (Sum.inr b'),
      property :=
        (_ :
          ∀ (n : ℕ) (a' : α),
            Stream'.corec' (Corec.f f) (Sum.inr b') n = some a' →
              Stream'.corec' (Corec.f f) (Sum.inr b') (n + 1) = some a') }
apply Subtype.eq
case inr.h.a
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ Stream'.tail
      (Stream'.corec'
        (fun x =>
          match x with
          | Sum.inl a => (some a, Sum.inl a)
          | Sum.inr b =>
            (match f b with
              | Sum.inl a => some a
              | Sum.inr val => none,
              f b))
        (Sum.inr b)) =
    Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (Sum.inr b')
case inr.h.a
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ ↑(tail
        {
          val :=
            Stream'.corec'
              (fun x =>
                match x with
                | Sum.inl a => (some a, Sum.inl a)
                | Sum.inr b =>
                  (match f b with
                    | Sum.inl a => some a
                    | Sum.inr val => none,
                    f b))
              (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }) =
    ↑{
        val :=
          Stream'.corec'
            (fun x =>
              match x with
              | Sum.inl a => (some a, Sum.inl a)
              | Sum.inr b =>
                (match f b with
                  | Sum.inl a => some a
                  | Sum.inr val => none,
                  f b))
            (Sum.inr b'),
        property :=
          (_ :
            ∀ (n : ℕ) (a' : α),
              Stream'.corec' (Corec.f f) (Sum.inr b') n = some a' →
                Stream'.corec' (Corec.f f) (Sum.inr b') (n + 1) = some a') }
dsimp [corec, tail]
case inr.h.a
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (match Sum.inr b with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b)).snd =
    Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (Sum.inr b')
case inr.h.a
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ Stream'.tail
      (Stream'.corec'
        (fun x =>
          match x with
          | Sum.inl a => (some a, Sum.inl a)
          | Sum.inr b =>
            (match f b with
              | Sum.inl a => some a
              | Sum.inr val => none,
              f b))
        (Sum.inr b)) =
    Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (Sum.inr b')
rw [Stream'.corec'_eq, Stream'.tail_cons]
case inr.h.a
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (f b) =
    Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (Sum.inr b')
case inr.h.a
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (match Sum.inr b with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b)).snd =
    Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (Sum.inr b')
dsimp [Corec.f]
no goals
case inr.h.a
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
b' : β
h : f b = Sum.inr b'
⊢ Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (f b) =
    Stream'.corec'
      (fun x =>
        match x with
        | Sum.inl a => (some a, Sum.inl a)
        | Sum.inr b =>
          (match f b with
            | Sum.inl a => some a
            | Sum.inr val => none,
            f b))
      (Sum.inr b')
rw [h]
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
⊢ (match f b with
    | Sum.inl a => some a
    | Sum.inr val => none) =
    Sum.rec some (fun x => none) (f b)
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
⊢ Stream'.corec' (Corec.f f) (Sum.inr b) 0 = Sum.rec some (fun x => none) (f b)
dsimp [Corec.f, Stream'.corec', Stream'.corec, Stream'.map, Stream'.nth, Stream'.iterate]
no goals
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
⊢ (match f b with
    | Sum.inl a => some a
    | Sum.inr val => none) =
    Sum.rec some (fun x => none) (f b)
match (f b) with
| Sum.inl x => rfl
| Sum.inr x => rfl
no goals
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x : α
⊢ (match Sum.inl x with
    | Sum.inl a => some a
    | Sum.inr val => none) =
    Sum.rec some (fun x => none) (Sum.inl x)
rfl
no goals
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b x : β
⊢ (match Sum.inr x with
    | Sum.inl a => some a
    | Sum.inr val => none) =
    Sum.rec some (fun x => none) (Sum.inr x)
rfl
no goals
case inl
α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
x✝ : α ⊕ β
h✝ : f b = x✝
a : α
h : f b = Sum.inl a
⊢ (match Sum.rec some (fun x => none) (Sum.inl a) with
    | none =>
      Sum.inr
        (tail
          { val := Stream'.corec' (Corec.f f) (Sum.inr b),
            property :=
              (_ :
                ∀ (n : ℕ) (a' : α),
                  Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                    Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') })
    | some a => Sum.inl a) =
    match Sum.inl a with
    | Sum.inl a => Sum.inl a
    | Sum.inr b =>
      Sum.inr
        { val := Stream'.corec' (Corec.f f) (Sum.inr b),
          property :=
            (_ :
              ∀ (n : ℕ) (a' : α),
                Stream'.corec' (Corec.f f) (Sum.inr b) n = some a' →
                  Stream'.corec' (Corec.f f) (Sum.inr b) (n + 1) = some a') }
rfl