Formalism/HermitianCurvature/HermitianCurvatureProofs/CutCptCopy.lean
51if us.any (fun c => terminal c || tainted.contains c) then (seen, tainted.insert n, order.push n)52else (seen, tainted, order)5354def toCopy (env : Environment) : NameSet × Array Name :=55let (_, tainted, order) := roots.foldl (fun s r => go env r s) ({}, {}, #[])56(tainted, order)5758def mapName (tainted : NameSet) (n : Name) : Name :=59match special.lookup n with60| some m => m61| none => if manual.contains n || tainted.contains n then suffixed n else n6263def subst (tainted : NameSet) (e : Expr) : Expr :=64e.replace fun65| .const n ls => some (.const (mapName tainted n) ls)66| _ => none6768def copyAll (defsOnly : Bool) : CoreM Nat := do69let (tainted, order) := toCopy (← getEnv)70let mut k := 071for n in order do72let env ← getEnv73let n' := mapName tainted n74if env.contains n' then continue75let some ci := env.find? n | throwError "missing {n}"76match ci with77| .defnInfo d =>78addDecl (.defnDecl { d with name := n', type := subst tainted d.type, value := subst tainted d.value })79k := k + 180| .thmInfo t =>81if defsOnly then continue82addDecl (.thmDecl { t with name := n', type := subst tainted t.type, value := subst tainted t.value })83k := k + 184| _ => throwError "cannot copy {n}"85return k8687elab "cpt_copy_thms" : command => do88let k ← liftCoreM (copyAll false)89logInfo m!"copied {k} declarations"9091end Formalism.FourierDecayAlt.P.CptCopy