import Mathlib.MeasureTheory.Order.Lattice import Mathlib.Probability.Kernel.Composition.Prod import Mathlib.Probability.Kernel.Composition.CompProd import Mathlib.MeasureTheory.MeasurableSpace.Embedding import Lean.Elab.Tactic.Location import Lean.Meta.DecLevel import Lean.Meta.Transform import Lean.Util.Recognizers import Lean.Meta.Tactic.Replace import Lean.Meta.Tactic.Rewrite import Mathlib.Probability.Kernel.Deterministic import Mathlib.Combinatorics.Quiver.ReflQuiver import Mathlib.Probability.Kernel.Category.SFinKer import Mathlib.MeasureTheory.Integral.Lebesgue.Countable /-! # Standalone extraction for `checkRightUnitor` Definitions are copied verbatim; theorem proofs are replaced by `sorry`. Auto-generated by Referee. -/ set_option quotPrecheck false -- Namespace stubs (so later `open`s resolve). namespace Finset end Finset namespace Lean end Lean namespace Lean.Meta end Lean.Meta namespace ProbabilityTheory end ProbabilityTheory namespace ProbabilityTheory.Kernel end ProbabilityTheory.Kernel -- ═══ ForMathlib.MeasureTheory.Order.Lattice ═══ section open Finset variable {α δ : Type*} [MeasurableSpace δ] [SemilatticeInf α] {m : MeasurableSpace α} [MeasurableInf₂ α] attribute [to_dual existing] MeasurableInf₂ end -- ═══ Tactic.EqLift.Tactic.Kernel.Utils ═══ section public meta section open Lean Meta ProbabilityTheory Elab Term /-- Extract `(X, Y, u, v)` from an expression of type `Kernel X Y`. -/ def getTypesFromKernel (κ : Expr) : MetaM (Expr × Expr × Level × Level) := do let κType ← inferType κ match κType.getAppFn with | Expr.const ``Kernel univs => let args := κType.getAppArgs if args.size < 2 then throwError "Kernel type with insufficient arguments: {κType}." let X := args[0]! let Y := args[1]! let xLevel := univs[0]! let yLevel := univs[1]! return (X, Y, xLevel, yLevel) | _ => throwError "Expected a kernel type, got: {κType}." end end -- ═══ Tactic.KernelHom.Tactic.KernelHom ═══ section public meta section open Lean Elab Tactic Meta CategoryTheory Parser.Tactic ProbabilityTheory MonoidalCategory open ProbabilityTheory.Kernel /-- Check if a kernel expression corresponds to a left or right unitor. -/ def checkUnitors (κ : Expr) (offset : Nat) (prod : Name) : MetaM Bool := do let κ := κ.consumeMData if !κ.isAppOf ``Kernel.map then return false let args := κ.getAppArgs let fn := args[args.size - 1]! let idKernel := args[args.size - 2]! if !fn.isAppOf prod then return false if !idKernel.isAppOf ``Kernel.id then return false let (src, _, _) ← getTypesFromKernel κ match src.getAppFn with | Expr.const ``Prod _ => let args := src.getAppArgs if args.size < 2 then return false let punit? := args[offset]! match punit?.getAppFn with | Expr.const ``PUnit _ | Expr.const ``Unit _ => return true | _ => return false | _ => return false /-- Check if a kernel expression corresponds to a right unitor. -/ def checkRightUnitor (κ : Expr) : MetaM Bool := checkUnitors κ 1 ``Prod.fst end