Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More arguments for newtypeTools.rich_new_type #1215

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/algebra/aat/aatmonoidScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ Proof
QED

val mrec as {absrep_id,...} =
newtypeTools.rich_new_type ("monoid", fullmonoids_exist)
newtypeTools.rich_new_type {tyname = "monoid",
exthm = fullmonoids_exist,
ABS = "monoid_ABS",
REP = "monoid_REP"};

Overload mkmonoid = “monoid_ABS”

Expand Down
11 changes: 5 additions & 6 deletions examples/bnf-datatypes/bnfAlgebraScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,13 @@ Type alg[local,pp] = “:α set # ((β,α)F -> α)”
val idx_tydef as
{absrep_id, newty, repabs_pseudo_id, termP, termP_exists,
termP_term_REP, ...} =
newtypeTools.rich_new_type(
"idx",
newtypeTools.rich_new_type{
tyname = "idx",
prove(“∃i : (α,β) alg. alg i”,
simp[EXISTS_PROD] >> qexists_tac ‘UNIV’ >>
simp[alg_def]));
Overload dIx = (#term_REP_t idx_tydef)
Overload mkIx = (#term_ABS_t idx_tydef)

simp[alg_def]),
ABS = "mkIx",
REP = "dIx"};

Definition bigprod_def:
bigprod : ((α,β)idx -> α, β) alg =
Expand Down
15 changes: 7 additions & 8 deletions examples/bnf-datatypes/concreteBNFScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,13 @@ Type alg[local,pp] = “:α set # ((β,α)F -> α)”
val idx_tydef as
{absrep_id, newty, repabs_pseudo_id, termP, termP_exists,
termP_term_REP, ...} =
newtypeTools.rich_new_type(
"idx",
prove(“∃i : (α,β) alg. alg i”,
simp[EXISTS_PROD] >> qexists_tac ‘UNIV’ >>
simp[alg_def]));
Overload dIx = (#term_REP_t idx_tydef)
Overload mkIx = (#term_ABS_t idx_tydef)

newtypeTools.rich_new_type{
tyname = "idx",
exthm = prove(“∃i : (α,β) alg. alg i”,
simp[EXISTS_PROD] >> qexists_tac ‘UNIV’ >>
simp[alg_def]),
ABS = "mkIx",
REP = "dIx"};

Definition bigprod_def:
bigprod : ((α,β)idx -> α, β) alg =
Expand Down
5 changes: 4 additions & 1 deletion examples/formal-languages/context-free/sexpcodeScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ QED

val {absrep_id, newty, repabs_pseudo_id, termP, termP_exists, termP_term_REP,
term_ABS_t, term_ABS_pseudo11, term_REP_t, term_REP_11} =
newtypeTools.rich_new_type("sexpcode", decencs_exist);
newtypeTools.rich_new_type{tyname = "sexpcode",
exthm = decencs_exist,
ABS = "sexpcode_ABS",
REP = "sexpcode_REP"};

Definition encode_def[nocompute]:
encode sc = SND (^term_REP_t sc)
Expand Down
68 changes: 48 additions & 20 deletions examples/generic_finite_graphs/genericGraphScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,47 @@ Definition edge_cst_def:
(dirp ⇒ ∀m n. CARD {(m,n,l) | l | (m,n,l) ∈ es} ≤ 1))
End

val SL_OK_tydefrec = newtypeTools.rich_new_type("SL_OK",
prove(“∃x:unit. (λx. T) x”, simp[]));
val noSL_tydefrec = newtypeTools.rich_new_type("noSL",
prove(“∃x:num. (λx. T) x”, simp[]));

val INF_OK_tydefrec = newtypeTools.rich_new_type("INF_OK",
prove(“∃x:num. (λx. T) x”, simp[]));
val finiteG_tydefrec = newtypeTools.rich_new_type("finiteG",
prove(“∃x:unit. (λx. T) x”, simp[]));

val undirectedG_tydefrec = newtypeTools.rich_new_type("undirectedG",
prove(“∃x:num. (λx. T) x”, simp[]));
val directedG_tydefrec = newtypeTools.rich_new_type("directedG",
prove(“∃x:unit. (λx. T) x”, simp[]));

val allEdgesOK_tydefrec = newtypeTools.rich_new_type("allEdgesOK",
prove(“∃x:num. (λx. T) x”, simp[]));
val SL_OK_tydefrec = newtypeTools.rich_new_type
{tyname = "SL_OK",
exthm = prove(“∃x:unit. (λx. T) x”, simp[]),
ABS = "SL_OK_ABS",
REP = "SL_OK_REP"};

val noSL_tydefrec = newtypeTools.rich_new_type
{tyname = "noSL",
exthm = prove(“∃x:num. (λx. T) x”, simp[]),
ABS = "noSL_ABS",
REP = "noSL_REP"};

val INF_OK_tydefrec = newtypeTools.rich_new_type
{tyname = "INF_OK",
exthm = prove(“∃x:num. (λx. T) x”, simp[]),
ABS = "INF_OK_ABS",
REP = "INF_OK_REP"};

val finiteG_tydefrec = newtypeTools.rich_new_type
{tyname = "finiteG",
exthm = prove(“∃x:unit. (λx. T) x”, simp[]),
ABS = "finiteG_ABS",
REP = "finiteG_REP"};

val undirectedG_tydefrec = newtypeTools.rich_new_type
{tyname = "undirectedG",
exthm = prove(“∃x:num. (λx. T) x”, simp[]),
ABS = "undirectedG_ABS",
REP = "undirectedG_REP"};

val directedG_tydefrec = newtypeTools.rich_new_type
{tyname = "directedG",
exthm = prove(“∃x:unit. (λx. T) x”, simp[]),
ABS = "directedG_ABS",
REP = "directedG_REP"};

val allEdgesOK_tydefrec = newtypeTools.rich_new_type
{tyname = "allEdgesOK",
exthm = prove(“∃x:num. (λx. T) x”, simp[]),
ABS = "allEdgesOK_ABS",
REP = "allEdgesOK_REP"};

Definition itself2set_def[simp]:
itself2set (:'a) = univ(:'a)
Expand Down Expand Up @@ -351,12 +375,15 @@ Proof
qexists ‘{}’ >> simp[]
QED

val tydefrec = newtypeTools.rich_new_type("graph", graphs_exist)
val tydefrec = newtypeTools.rich_new_type
{tyname = "graph",
exthm = graphs_exist,
ABS = "graph_ABS",
REP = "graph_REP"};

(* any undirected graph *)
Type udgraph[pp] = “:('a,undirectedG,'ec,'el,'nf,'nl,'sl)graph”


(* finite directed graph with labels on nodes and edges, possibility of
multiple, but finitely many edges, and with self-loops allowed *)
Type fdirgraph[pp] = “:('NodeEnum,
Expand Down Expand Up @@ -1886,4 +1913,5 @@ Proof
simp[DELETE_COMM, DIFF_COMM]
QED

val _ = export_theory();
val _ = export_theory();
val _ = html_theory "genericGraph";
4 changes: 3 additions & 1 deletion examples/lambda/basics/nomdatatype.sml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ fun new_type_step1 tyname n {vp, lp} = let
val {absrep_id, newty, repabs_pseudo_id, termP, termP_exists, termP_term_REP,
term_ABS_t, term_ABS_pseudo11,
term_REP_t, term_REP_11} =
newtypeTools.rich_new_type (tyname, term_exists)
newtypeTools.rich_new_type {tyname = tyname, exthm = term_exists,
ABS = tyname ^ "_ABS",
REP = tyname ^ "_REP"}
in
{term_ABS_pseudo11 = term_ABS_pseudo11, term_REP_11 = term_REP_11,
term_REP_t = term_REP_t, term_ABS_t = term_ABS_t, absrep_id = absrep_id,
Expand Down
20 changes: 19 additions & 1 deletion src/1/newtypeTools.sig
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
(*---------------------------------------------------------------------------*
* New routines supporting the definition of types *
* *
* USAGE: rich_new_type {tyname, exthm, ABS, REP} *
* *
* ARGUMENTS: tyname -- the name of the new type *
* *
* exthm --- the existence theorem of the new type (|- ?x. P x) *
* *
* ABS --- the name of the required abstraction function *
* *
* REP --- the name of the required representation function *
*---------------------------------------------------------------------------*)

signature newtypeTools =
sig

include Abbrev
val rich_new_type : string * thm ->
val rich_new_type : {tyname: string,
exthm: thm,
ABS: string,
REP: string}
->
{absrep_id: thm,
newty: hol_type,
repabs_pseudo_id: thm,
Expand Down
8 changes: 3 additions & 5 deletions src/1/newtypeTools.sml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ fun t1 /\ t2 = mk_conj(t1, t2)
fun t1 ==> t2 = mk_imp (t1,t2)
fun t1 == t2 = mk_eq(t1,t2)


fun rich_new_type (tyname, exthm) = let
fun rich_new_type {tyname, exthm, ABS, REP} = let
val bij_ax = new_type_definition(tyname, exthm)
val (termP, oldty) = let
val (bvar, exthm_body) = exthm |> concl |> dest_exists
Expand All @@ -23,8 +22,8 @@ fun rich_new_type (tyname, exthm) = let
val x = mk_var("x", oldty) and y = mk_var("y", oldty)
val newty = bij_ax |> concl |> dest_exists |> #1 |> type_of |> dom_rng |> #1
val term_ABSREP =
define_new_type_bijections { ABS = tyname ^ "_ABS", REP = tyname ^ "_REP",
name = tyname ^ "_ABSREP", tyax = bij_ax}
define_new_type_bijections { ABS = ABS, REP = REP,
name = tyname ^ "_ABSREP", tyax = bij_ax }
val absrep_id = term_ABSREP |> CONJUNCT1
val (term_ABS_t, term_REP_t) = let
val eqn1_lhs = absrep_id|> concl |> strip_forall |> #2 |> lhs
Expand Down Expand Up @@ -74,5 +73,4 @@ in
term_REP_t = term_REP_t, term_ABS_t = term_ABS_t}
end


end (* struct *)
9 changes: 6 additions & 3 deletions src/num/theories/cvScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ Inductive iscv:
[~pair:] (!c d. iscv c /\ iscv d ==> iscv (P0 c d))
End

val cv_tydefrec = newtypeTools.rich_new_type("cv",
prove(“?cv. iscv cv”,
Q.EXISTS_TAC ‘N0 0’ >> REWRITE_TAC[iscv_num]))
val cv_tydefrec = newtypeTools.rich_new_type
{tyname = "cv",
exthm = prove(“?cv. iscv cv”,
Q.EXISTS_TAC ‘N0 0’ >> REWRITE_TAC[iscv_num]),
ABS = "cv_ABS",
REP = "cv_REP"};

val Pair_def = new_definition("Pair_def",
“Pair c d = cv_ABS (P0 (cv_REP c) (cv_REP d))”);
Expand Down
2 changes: 1 addition & 1 deletion src/pred_set/src/more_theories/ordinalScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ val _ = save_thm ("ordlt_trichotomy", ordlt_trichotomy)
val _ = overload_on ("mkOrdinal", ``ordinal_ABS``)

val allOrds_def = Define`
allOrds = wellorder_ABS { (x,y) | (x = y) \/ ordlt x y }
allOrds = mkWO { (x,y) | (x = y) \/ ordlt x y }
`;
val EXISTS_PROD = pairTheory.EXISTS_PROD
val EXISTS_SUM = sumTheory.EXISTS_SUM
Expand Down
Loading