(* Title: HoTT/HoTT_Methods.thy Author: Josh Chen Date: Jun 2018 Method setup for the HoTT library. Relies heavily on Eisbach. *) theory HoTT_Methods imports "HOL-Eisbach.Eisbach" "HOL-Eisbach.Eisbach_Tools" HoTT_Base Prod begin section \Method setup\ text "Prove type judgments \A : U\ and inhabitation judgments \a : A\ using rules declared [intro] and [elim], as well as additional provided lemmas. Can also perform typechecking, and search for elements of a type." method simple uses lems = (assumption | standard | rule lems)+ text "Find a proof of any valid typing judgment derivable from a given wellformed judgment." \ \\wellform\ is declared in HoTT_Base.thy\ method wellformed uses jdgmt declares wellform = match wellform in rl: "PROP ?P" \ \( catch \rule rl[OF jdgmt]\ \fail\ | catch \wellformed jdgmt: rl[OF jdgmt]\ \fail\ )\ text "Combine \simple\ and \wellformed\ to search for derivations. \wellformed\ uses the facts passed as \lems\ to derive any required typing judgments. Definitions passed as \unfolds\ are unfolded throughout. Roughly speaking \derive\ is more powerful than \simple\, but may fail to find a proof where \simple\ does if it reduces too eagerly." method derive uses lems unfolds = ( unfold unfolds | simple lems: lems | match lems in lem: "?X : ?Y" \ \wellformed jdgmt: lem\ )+ text "Simplify a function application." method simplify for expr::Term uses lems = match (expr) in "(\<^bold>\x:?A. ?b x)`?a" \ \ print_term "Single application", rule Prod_comp, derive lems: lems \ \ "(F`a)`b" for F a b \ \ print_term "Repeated application", simplify "F`a" \ text "Verify a function application simplification." method verify_simp uses lems = ( print_term "Attempting simplification", ( rule comp | derive lems: lems | simp add: lems )+ | print_fact lems, match conclusion in "F`a`b \ x" for F a b x \ \ print_term "Chained application", print_term F, print_term a, print_term b, print_term x, match (F) in "\<^bold>\x:A. f x" for A f \ \ print_term "Matched abstraction", print_fact Prod_comp[where ?A = A and ?b = f and ?a = a] \ \ "?x" \ \ print_term "Constant application", print_fact comp \ \ ) end