Theorem: Computation.corec_eq
File: Mathlib/Data/Seq/Computation.lean

tactic: dsimp [corec, destruct]
state_before: α : Type u
β : Type v
γ : Type w
f : β → α ⊕ β
b : β
⊢ destruct (corec f b) = rmap (corec f) (f b)

tactic: 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
  ]
state_before: α : 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') }

tactic: induction' h : f b with a b'
state_before: α : 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') }

tactic: dsimp [Corec.f, destruct]
state_before: 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') }

tactic: apply congr_arg
state_before: 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') }

tactic: apply Subtype.eq
state_before: 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') }

tactic: dsimp [corec, tail]
state_before: 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') }

tactic: rw [Stream'.corec'_eq, Stream'.tail_cons]
state_before: 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')

tactic: dsimp [Corec.f]
state_before: 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')

tactic: rw [h]
state_before: 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')

tactic: dsimp [Corec.f, Stream'.corec', Stream'.corec, Stream'.map, Stream'.nth, Stream'.iterate]
state_before: α : 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)

tactic: match (f b) with
| Sum.inl x => rfl
| Sum.inr x => rfl
state_before: α : 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)

tactic: rfl
state_before: α : 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)

tactic: rfl
state_before: α : 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)

tactic: rfl
state_before: 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') }