simp [double_transpose, toy_semantics_region, toy_semantics_op]
t1 : RankedTensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32
⊢ run_toy (toy_semantics_region double_transpose)
      (SSAEnv.One
        [(SSAVal.SSAVal "t1",
            { fst := builtin.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32, snd := t1 })]) =
    Fitree.ret
      ((),
        SSAEnv.One
          [(SSAVal.SSAVal "t1",
              { fst := builtin.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32, snd := t1 }),
            (SSAVal.SSAVal "t2",
              { fst := builtin.tensor [Dimension.Known 4, Dimension.Known 2] MLIRType.i32, snd := transpose t1 }),
            (SSAVal.SSAVal "t3",
              { fst := builtin.tensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32, snd := t1 })])
t1 : RankedTensor [Dimension.Known 2, Dimension.Known 4] MLIRType.i32
⊢ Fitree.interp ToyOp.handle
      (interpSSA'
        (interpUB'!
          (Fitree.bind
            (match
              Op.mk "toy.transpose"
                [(SSAVal.SSAVal "t2",
                    MLIRType.extended
                      (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2] (MLIRType.int Signedness.Signless 32)))]
                [(SSAVal.SSAVal "t1",
                    MLIRType.extended
                      (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4] (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 "t2",
                                MLIRType.extended
                                  (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                    (MLIRType.int Signedness.Signless 32)))]
                            [(SSAVal.SSAVal "t1",
                                MLIRType.extended
                                  (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                    (MLIRType.int Signedness.Signless 32)))]
                            [] (AttrDict.mk [])) ++
                      toString "")
                | some t_lit =>
                  Fitree.bind (Fitree.trigger (ToyOp.Constant D₁ τ₁ t_lit)) fun t =>
                    SSAEnv.set? (MLIRType.extended (builtin.σ.tensor D₁ τ₁)) (some res) t
              | x =>
                raiseUB
                  (toString "" ++
                      toString
                        (Op.mk "toy.transpose"
                          [(SSAVal.SSAVal "t2",
                              MLIRType.extended
                                (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                  (MLIRType.int Signedness.Signless 32)))]
                          [(SSAVal.SSAVal "t1",
                              MLIRType.extended
                                (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                  (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.bind
                  (Fitree.trigger
                    (SSAEnvE.Get (MLIRType.extended (builtin.σ.tensor [Dimension.Known n, Dimension.Known m] τ))
                      t_name))
                  fun t =>
                  Fitree.bind (Fitree.trigger (ToyOp.Transpose τ n m t)) fun t' =>
                    SSAEnv.set? (MLIRType.extended (builtin.σ.tensor [Dimension.Known m, Dimension.Known n] τ))
                      (some res) t'
              | x =>
                raiseUB
                  (toString "" ++
                      toString
                        (Op.mk "toy.transpose"
                          [(SSAVal.SSAVal "t2",
                              MLIRType.extended
                                (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                  (MLIRType.int Signedness.Signless 32)))]
                          [(SSAVal.SSAVal "t1",
                              MLIRType.extended
                                (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                  (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.bind (Fitree.trigger (SSAEnvE.Get (MLIRType.extended (builtin.σ.tensor D τ₁)) t_name)) fun t =>
                  Fitree.bind
                    (Fitree.trigger
                      (ToyOp.Reshape τ₁ D D' (_ : DimList.known D = true) (_ : DimList.known D' = true)
                        (_ : DimList.prod D' = DimList.prod D) t))
                    fun t' =>
                    SSAEnv.set? (MLIRType.extended (builtin.σ.tensor D' τ₂)) (some res)
                      (cast (_ : RankedTensor D' τ₁ = RankedTensor D' τ₂) t')
              else
                raiseUB
                  (toString "" ++
                      toString
                        (Op.mk "toy.transpose"
                          [(SSAVal.SSAVal "t2",
                              MLIRType.extended
                                (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                  (MLIRType.int Signedness.Signless 32)))]
                          [(SSAVal.SSAVal "t1",
                              MLIRType.extended
                                (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                  (MLIRType.int Signedness.Signless 32)))]
                          [] (AttrDict.mk [])) ++
                    toString "")
            | x =>
              raiseUB
                (toString "" ++
                    toString
                      (Op.mk "toy.transpose"
                        [(SSAVal.SSAVal "t2",
                            MLIRType.extended
                              (builtin.σ.tensor [Dimension.Known 4, Dimension.Known 2]
                                (MLIRType.int Signedness.Signless 32)))]
                        [(SSAVal.SSAVal "t1",
                            MLIRType.extended
                              (builtin.σ.tensor [Dimension.Known 2, Dimension.Known 4]
                                (MLIRType.int Signedness.Signless 32)))]
                        [] (AttrDict.mk [])) ++
                  toString ""))
            fun x =>
            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.bind (Fitree.trigger (ToyOp.Constant D₁ τ₁ t_lit)) fun t =>
                    SSAEnv.set? (MLIRType.extended (builtin.σ.tensor D₁ τ₁)) (some res) t
              | 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.bind
                  (Fitree.trigger
                    (SSAEnvE.Get (MLIRType.extended (builtin.σ.tensor [Dimension.Known n, Dimension.Known m] τ))
                      t_name))
                  fun t =>
                  Fitree.bind (Fitree.trigger (ToyOp.Transpose τ n m t)) fun t' =>
                    SSAEnv.set? (MLIRType.extended (builtin.σ.tensor [Dimension.Known m, Dimension.Known n] τ))
                      (some res) t'
              | 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.bind (Fitree.trigger (SSAEnvE.Get (MLIRType.extended (builtin.σ.tensor D τ₁)) t_name)) fun t =>
                  Fitree.bind
                    (Fitree.trigger
                      (ToyOp.Reshape τ₁ D D' (_ : DimList.known D = true) (_ : DimList.known D' = true)
                        (_ : DimList.prod D' = DimList.prod D) t))
                    fun t' =>
                    SSAEnv.set? (MLIRType.extended (builtin.σ.tensor D' τ₂)) (some res)
                      (cast (_ : RankedTensor D' τ₁ = RankedTensor D' τ₂) t')
              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 })])