Theorem: double_transpose_correct
Proof state before:
t1 : RankedTensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32
⊢ Fitree.interp ToyOp.handle
      (interpSSA'
        (Fitree.bind
          (Fitree.trigger
            (Sum.inl
              (SSAEnvE.Get
                (MLIRType.extended
                  (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] (MLIRType.int Signedness.Signless 32)))
                (SSAVal.SSAVal "t1"))))
          fun x =>
          Fitree.bind (Fitree.trigger (Sum.inr (ToyOp.Transpose (MLIRType.int Signedness.Signless 32) 2 4 x))) fun x =>
            Fitree.bind
              (Fitree.trigger
                (Sum.inl
                  (SSAEnvE.Set
                    (MLIRType.extended
                      (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2] (MLIRType.int Signedness.Signless 32)))
                    (SSAVal.SSAVal "t2") x)))
              fun x =>
              Fitree.interp (Fitree.case UBE.handle! fun T => Fitree.trigger)
                (match
                  Op.mk "toy.transpose"
                    [(SSAVal.SSAVal "t3",
                        MLIRType.extended
                          (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                            (MLIRType.int Signedness.Signless 32)))]
                    [(SSAVal.SSAVal "t2",
                        MLIRType.extended
                          (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                            (MLIRType.int Signedness.Signless 32)))]
                    [] (AttrDict.mk []) with
                | Op.mk "toy.constant" [(res, MLIRType.extended (Sum.inl (Sum.inl (D₁, τ₁))))] [] [] attrs =>
                  match AttrDict.find attrs "value" with
                  | some (AttrValue.extended { elem := elem, τ_sig := Sum.inl (Sum.inl (D₂, τ₂)) }) =>
                    match TensorLiteral.ofTensorElem elem D₁ τ₁ with
                    | none =>
                      raiseUB
                        (toString "" ++
                            toString
                              (Op.mk "toy.transpose"
                                [(SSAVal.SSAVal "t3",
                                    MLIRType.extended
                                      (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                        (MLIRType.int Signedness.Signless 32)))]
                                [(SSAVal.SSAVal "t2",
                                    MLIRType.extended
                                      (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                        (MLIRType.int Signedness.Signless 32)))]
                                [] (AttrDict.mk [])) ++
                          toString "")
                    | some t_lit =>
                      Fitree.Vis (Sum.inr (Sum.inr (ToyOp.Constant D₁ τ₁ t_lit))) fun r =>
                        Fitree.Vis (Sum.inr (Sum.inl (SSAEnvE.Set (MLIRType.extended (builtin.σ.tensor D₁ τ₁)) res r)))
                          Fitree.Ret
                  | x =>
                    raiseUB
                      (toString "" ++
                          toString
                            (Op.mk "toy.transpose"
                              [(SSAVal.SSAVal "t3",
                                  MLIRType.extended
                                    (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                      (MLIRType.int Signedness.Signless 32)))]
                              [(SSAVal.SSAVal "t2",
                                  MLIRType.extended
                                    (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                      (MLIRType.int Signedness.Signless 32)))]
                              [] (AttrDict.mk [])) ++
                        toString "")
                | Op.mk "toy.transpose" [(res, τ₂)] [(t_name, MLIRType.extended (Sum.inl (Sum.inl (D, τ))))] [] attrs =>
                  match D with
                  | [Dimension.Known n, Dimension.Known m] =>
                    Fitree.Vis
                      (Sum.inr
                        (Sum.inl
                          (SSAEnvE.Get (MLIRType.extended (builtin.σ.tensor [Dimension.Known n, Dimension.Known m] τ))
                            t_name)))
                      fun r =>
                      Fitree.Vis (Sum.inr (Sum.inr (ToyOp.Transpose τ n m r))) fun r =>
                        Fitree.Vis
                          (Sum.inr
                            (Sum.inl
                              (SSAEnvE.Set
                                (MLIRType.extended (builtin.σ.tensor [Dimension.Known m, Dimension.Known n] τ)) res r)))
                          Fitree.Ret
                  | x =>
                    raiseUB
                      (toString "" ++
                          toString
                            (Op.mk "toy.transpose"
                              [(SSAVal.SSAVal "t3",
                                  MLIRType.extended
                                    (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                      (MLIRType.int Signedness.Signless 32)))]
                              [(SSAVal.SSAVal "t2",
                                  MLIRType.extended
                                    (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                      (MLIRType.int Signedness.Signless 32)))]
                              [] (AttrDict.mk [])) ++
                        toString "")
                |
                Op.mk "toy.reshape" [(res, MLIRType.extended (Sum.inl (Sum.inl (D', τ₂))))]
                    [(t_name, MLIRType.extended (Sum.inl (Sum.inl (D, τ₁))))] [] attrs =>
                  if h :
                      τ₁ = τ₂ ∧ DimList.known D = true ∧ DimList.known D' = true ∧ DimList.prod D' = DimList.prod D then
                    Fitree.Vis (Sum.inr (Sum.inl (SSAEnvE.Get (MLIRType.extended (builtin.σ.tensor D τ₁)) t_name)))
                      fun r =>
                      Fitree.Vis
                        (Sum.inr
                          (Sum.inr
                            (ToyOp.Reshape τ₁ D D' (_ : DimList.known D = true) (_ : DimList.known D' = true)
                              (_ : DimList.prod D' = DimList.prod D) r)))
                        fun r =>
                        Fitree.Vis
                          (Sum.inr
                            (Sum.inl
                              (SSAEnvE.Set (MLIRType.extended (builtin.σ.tensor D' τ₂)) res
                                (cast (_ : RankedTensor D' τ₁ = RankedTensor D' τ₂) r))))
                          Fitree.Ret
                  else
                    raiseUB
                      (toString "" ++
                          toString
                            (Op.mk "toy.transpose"
                              [(SSAVal.SSAVal "t3",
                                  MLIRType.extended
                                    (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                      (MLIRType.int Signedness.Signless 32)))]
                              [(SSAVal.SSAVal "t2",
                                  MLIRType.extended
                                    (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                      (MLIRType.int Signedness.Signless 32)))]
                              [] (AttrDict.mk [])) ++
                        toString "")
                | x =>
                  raiseUB
                    (toString "" ++
                        toString
                          (Op.mk "toy.transpose"
                            [(SSAVal.SSAVal "t3",
                                MLIRType.extended
                                  (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                    (MLIRType.int Signedness.Signless 32)))]
                            [(SSAVal.SSAVal "t2",
                                MLIRType.extended
                                  (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                    (MLIRType.int Signedness.Signless 32)))]
                            [] (AttrDict.mk [])) ++
                      toString "")))
        (SSAEnv.One
          [(SSAVal.SSAVal "t1",
              { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32),
                snd := t1 })])) =
    Fitree.Ret
      ((),
        SSAEnv.One
          [(SSAVal.SSAVal "t1",
              { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32),
                snd := t1 }),
            (SSAVal.SSAVal "t2",
              { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2] MLIRType.i32),
                snd := transpose t1 }),
            (SSAVal.SSAVal "t3",
              { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32),
                snd := t1 })])
Tactic:
simp_itree
Proof state after:
t1 : RankedTensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32
⊢ Fitree.interp ToyOp.handle
      (Fitree.bind
        (match
          SSAEnv.get (SSAVal.SSAVal "t1")
            (MLIRType.extended
              (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] (MLIRType.int Signedness.Signless 32)))
            (SSAEnv.One
              [(SSAVal.SSAVal "t1",
                  { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32),
                    snd := t1 })]) with
        | some v =>
          Fitree.Ret
            (v,
              SSAEnv.One
                [(SSAVal.SSAVal "t1",
                    { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32),
                      snd := t1 })])
        | none =>
          Fitree.Ret
            (default,
              SSAEnv.One
                [(SSAVal.SSAVal "t1",
                    { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32),
                      snd := t1 })]))
        fun x =>
        Fitree.Vis (ToyOp.Transpose (MLIRType.int Signedness.Signless 32) 2 4 x.fst) fun x_1 =>
          Fitree.bind
            (match
              SSAEnv.get (SSAVal.SSAVal "t2")
                (MLIRType.extended
                  (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2] (MLIRType.int Signedness.Signless 32)))
                (SSAEnv.set (SSAVal.SSAVal "t2")
                  (MLIRType.extended
                    (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2] (MLIRType.int Signedness.Signless 32)))
                  x_1 x.snd) with
            | some v =>
              Fitree.Ret
                (v,
                  SSAEnv.set (SSAVal.SSAVal "t2")
                    (MLIRType.extended
                      (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2] (MLIRType.int Signedness.Signless 32)))
                    x_1 x.snd)
            | none =>
              Fitree.Ret
                (default,
                  SSAEnv.set (SSAVal.SSAVal "t2")
                    (MLIRType.extended
                      (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2] (MLIRType.int Signedness.Signless 32)))
                    x_1 x.snd))
            fun x =>
            Fitree.Vis (ToyOp.Transpose (MLIRType.int Signedness.Signless 32) 4 2 x.fst) fun x_2 =>
              interpSSA' (Fitree.Ret ())
                (SSAEnv.set (SSAVal.SSAVal "t3")
                  (MLIRType.extended
                    (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] (MLIRType.int Signedness.Signless 32)))
                  x_2 x.snd)) =
    Fitree.Ret
      ((),
        SSAEnv.One
          [(SSAVal.SSAVal "t1",
              { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32),
                snd := t1 }),
            (SSAVal.SSAVal "t2",
              { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2] MLIRType.i32),
                snd := transpose t1 }),
            (SSAVal.SSAVal "t3",
              { fst := MLIRType.extended (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32),
                snd := t1 })])