1261
853abc14c5c6
added IsaMakefile...but so far included only a test for the parser
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1
theory Parser
1494
923413256cbb
Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 2
imports "Nominal2_Atoms" "Nominal2_Eqvt" "Nominal2_Supp" "Perm" "Fv" "Rsp" "Lift"
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 3
begin
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 4
1194
+ − 5
section{* Interface for nominal_datatype *}
+ − 6
+ − 7
text {*
+ − 8
+ − 9
Nominal-Datatype-part:
+ − 10
+ − 11
1266
+ − 12
1nd Arg: (string list * binding * mixfix * (binding * typ list * mixfix) list) list
1194
+ − 13
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ − 14
type(s) to be defined constructors list
+ − 15
(ty args, name, syn) (name, typs, syn)
+ − 16
+ − 17
Binder-Function-part:
+ − 18
1266
+ − 19
2rd Arg: (binding * typ option * mixfix) list
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 20
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1194
+ − 21
binding function(s)
+ − 22
to be defined
+ − 23
(name, type, syn)
+ − 24
1266
+ − 25
3th Arg: term list
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 26
^^^^^^^^^
1194
+ − 27
the equations of the binding functions
+ − 28
(Trueprop equations)
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 29
*}
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 30
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 31
ML {*
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 32
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 33
*}
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 34
1194
+ − 35
text {*****************************************************}
+ − 36
ML {*
+ − 37
(* nominal datatype parser *)
+ − 38
local
+ − 39
structure P = OuterParse
1266
+ − 40
+ − 41
fun tuple ((x, y, z), u) = (x, y, z, u)
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 42
fun tswap (((x, y), z), u) = (x, y, u, z)
1194
+ − 43
in
+ − 44
+ − 45
val _ = OuterKeyword.keyword "bind"
+ − 46
val anno_typ = Scan.option (P.name --| P.$$$ "::") -- P.typ
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 47
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 48
(* binding specification *)
1266
+ − 49
(* maybe use and_list *)
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 50
val bind_parser =
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 51
P.enum "," ((P.$$$ "bind" |-- P.term) -- (P.$$$ "in" |-- P.name) >> swap)
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 52
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 53
val constr_parser =
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 54
P.binding -- Scan.repeat anno_typ
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 55
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 56
(* datatype parser *)
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 57
val dt_parser =
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 58
(P.type_args -- P.binding -- P.opt_mixfix >> P.triple1) --
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 59
(P.$$$ "=" |-- P.enum1 "|" (constr_parser -- bind_parser -- P.opt_mixfix >> tswap)) >> tuple
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 60
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 61
(* function equation parser *)
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 62
val fun_parser =
1194
+ − 63
Scan.optional (P.$$$ "binder" |-- P.fixes -- SpecParse.where_alt_specs) ([],[])
+ − 64
+ − 65
(* main parser *)
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 66
val main_parser =
1266
+ − 67
(P.and_list1 dt_parser) -- fun_parser >> P.triple2
1194
+ − 68
+ − 69
end
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 70
*}
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 71
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 72
(* adds "_raw" to the end of constants and types *)
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 73
ML {*
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 74
fun add_raw s = s ^ "_raw"
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 75
fun add_raws ss = map add_raw ss
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 76
fun raw_bind bn = Binding.suffix_name "_raw" bn
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 77
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 78
fun replace_str ss s =
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 79
case (AList.lookup (op=) ss s) of
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 80
SOME s' => s'
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 81
| NONE => s
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 82
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 83
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts)
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 84
| replace_typ ty_ss T = T
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 85
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 86
fun raw_dts ty_ss dts =
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 87
let
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 88
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 89
fun raw_dts_aux1 (bind, tys, mx) =
1289
+ − 90
(raw_bind bind, map (replace_typ ty_ss) tys, mx)
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 91
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 92
fun raw_dts_aux2 (ty_args, bind, mx, constrs) =
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 93
(ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs)
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 94
in
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 95
map raw_dts_aux2 dts
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 96
end
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 97
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 98
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T)
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 99
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T)
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 100
| replace_aterm trm_ss trm = trm
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 101
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 102
fun replace_term trm_ss ty_ss trm =
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 103
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss)
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 104
*}
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 105
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 106
ML {*
1289
+ − 107
fun get_cnstrs dts =
1290
+ − 108
map (fn (_, _, _, constrs) => constrs) dts
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 109
1289
+ − 110
fun get_typed_cnstrs dts =
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 111
flat (map (fn (_, bn, _, constrs) =>
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 112
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts)
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 113
1289
+ − 114
fun get_cnstr_strs dts =
1290
+ − 115
map (fn (bn, _, _) => Binding.name_of bn) (flat (get_cnstrs dts))
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 116
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 117
fun get_bn_fun_strs bn_funs =
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 118
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 119
*}
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 120
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 121
ML {*
1289
+ − 122
fun rawify_dts dt_names dts dts_env =
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 123
let
1289
+ − 124
val raw_dts = raw_dts dts_env dts
1287
+ − 125
val raw_dt_names = add_raws dt_names
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 126
in
1287
+ − 127
(raw_dt_names, raw_dts)
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 128
end
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 129
*}
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 130
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 131
ML {*
1289
+ − 132
fun rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs =
+ − 133
let
+ − 134
val bn_funs' = map (fn (bn, ty, mx) =>
+ − 135
(raw_bind bn, replace_typ dts_env ty, mx)) bn_funs
+ − 136
+ − 137
val bn_eqs' = map (fn (attr, trm) =>
+ − 138
(attr, replace_term (cnstrs_env @ bn_fun_env) dts_env trm)) bn_eqs
+ − 139
in
+ − 140
(bn_funs', bn_eqs')
+ − 141
end
+ − 142
*}
+ − 143
+ − 144
ML {*
1293
+ − 145
fun rawify_binds dts_env cnstrs_env bn_fun_env binds =
+ − 146
map (map (map (map (fn (opt_trm, i, j) =>
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 147
(Option.map (apfst (replace_term (cnstrs_env @ bn_fun_env) dts_env)) opt_trm, i, j))))) binds
1293
+ − 148
*}
+ − 149
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 150
ML {*
1392
+ − 151
fun find [] _ = error ("cannot find element")
+ − 152
| find ((x, z)::xs) y = if (Long_Name.base_name x) = y then z else find xs y
+ − 153
*}
+ − 154
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 155
ML {* @{term "{x, y}"} *}
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 156
ML range_type
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 157
ML {*
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 158
fun strip_union t =
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 159
case t of
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 160
Const (@{const_name sup}, _) $ l $ r => strip_union l @ strip_union r
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 161
| (h as (Const (@{const_name insert}, T))) $ x $ y =>
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 162
(h $ x $ Const (@{const_name bot}, range_type (range_type T))) :: strip_union y
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 163
| Const (@{const_name bot}, _) => []
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 164
| _ => [t]
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 165
*}
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 166
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 167
ML {*
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 168
fun bn_or_atom t =
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 169
case t of
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 170
Const (@{const_name insert}, _) $ (Const (@{const_name atom}, _) $ Bound i) $
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 171
Const (@{const_name bot}, _) => (i, NONE)
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 172
| f $ Bound i => (i, SOME f)
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 173
| _ => error "Unsupported binding function"
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 174
*}
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 175
1392
+ − 176
ML {*
1403
4a10338c2535
almost done with showing the equivalence between old and new alpha-equivalence (one subgoal remaining)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 177
fun prep_bn dt_names dts eqs =
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 178
let
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 179
fun aux eq =
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 180
let
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 181
val (lhs, rhs) = eq
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 182
|> strip_qnt_body "all"
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 183
|> HOLogic.dest_Trueprop
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 184
|> HOLogic.dest_eq
1392
+ − 185
val (bn_fun, [cnstr]) = strip_comb lhs
+ − 186
val (_, ty) = dest_Free bn_fun
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 187
val (ty_name, _) = dest_Type (domain_type ty)
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 188
val dt_index = find_index (fn x => x = ty_name) dt_names
1392
+ − 189
val (cnstr_head, cnstr_args) = strip_comb cnstr
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 190
val rhs_elements = map bn_or_atom (strip_union rhs)
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 191
val included = map (apfst (fn i => length (cnstr_args) - i - 1)) rhs_elements
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 192
in
1392
+ − 193
(dt_index, (bn_fun, (cnstr_head, included)))
+ − 194
end
+ − 195
fun order dts i ts =
+ − 196
let
+ − 197
val dt = nth dts i
+ − 198
val cts = map (fn (x, _, _) => Binding.name_of x) ((fn (_, _, _, x) => x) dt)
+ − 199
val ts' = map (fn (x, y) => (fst (dest_Const x), y)) ts
+ − 200
in
+ − 201
map (find ts') cts
+ − 202
end
+ − 203
+ − 204
val unordered = AList.group (op=) (map aux eqs)
+ − 205
val unordered' = map (fn (x, y) => (x, AList.group (op=) y)) unordered
+ − 206
val ordered = map (fn (x, y) => (x, map (fn (v, z) => (v, order dts x z)) y)) unordered'
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 207
in
1392
+ − 208
ordered
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 209
end
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 210
*}
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 211
1293
+ − 212
ML {*
1289
+ − 213
fun add_primrec_wrapper funs eqs lthy =
+ − 214
if null funs then (([], []), lthy)
+ − 215
else
+ − 216
let
+ − 217
val eqs' = map (fn (_, eq) => (Attrib.empty_binding, eq)) eqs
+ − 218
val funs' = map (fn (bn, ty, mx) => (bn, SOME ty, mx)) funs
+ − 219
in
+ − 220
Primrec.add_primrec funs' eqs' lthy
+ − 221
end
+ − 222
*}
+ − 223
1293
+ − 224
ML {*
+ − 225
fun add_datatype_wrapper dt_names dts =
+ − 226
let
+ − 227
val conf = Datatype.default_config
+ − 228
in
+ − 229
Local_Theory.theory_result (Datatype.add_datatype conf dt_names dts)
+ − 230
end
+ − 231
*}
1289
+ − 232
+ − 233
ML {*
1293
+ − 234
fun raw_nominal_decls dts bn_funs bn_eqs binds lthy =
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 235
let
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 236
val thy = ProofContext.theory_of lthy
1289
+ − 237
val thy_name = Context.theory_name thy
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 238
1289
+ − 239
val dt_names = map (fn (_, s, _, _) => Binding.name_of s) dts
+ − 240
val dt_full_names = map (Long_Name.qualify thy_name) dt_names
+ − 241
val dt_full_names' = add_raws dt_full_names
+ − 242
val dts_env = dt_full_names ~~ dt_full_names'
+ − 243
+ − 244
val cnstrs = get_cnstr_strs dts
+ − 245
val cnstrs_ty = get_typed_cnstrs dts
+ − 246
val cnstrs_full_names = map (Long_Name.qualify thy_name) cnstrs
+ − 247
val cnstrs_full_names' = map (fn (x, y) => Long_Name.qualify thy_name
+ − 248
(Long_Name.qualify (add_raw x) (add_raw y))) cnstrs_ty
+ − 249
val cnstrs_env = cnstrs_full_names ~~ cnstrs_full_names'
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 250
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 251
val bn_fun_strs = get_bn_fun_strs bn_funs
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 252
val bn_fun_strs' = add_raws bn_fun_strs
1266
+ − 253
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
1293
+ − 254
val bn_fun_full_env = map (pairself (Long_Name.qualify thy_name))
+ − 255
(bn_fun_strs ~~ bn_fun_strs')
+ − 256
1289
+ − 257
val (raw_dt_names, raw_dts) = rawify_dts dt_names dts dts_env
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 258
1289
+ − 259
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs
1293
+ − 260
+ − 261
val raw_binds = rawify_binds dts_env cnstrs_env bn_fun_full_env binds
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 262
1403
4a10338c2535
almost done with showing the equivalence between old and new alpha-equivalence (one subgoal remaining)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 263
val raw_bns = prep_bn dt_full_names' raw_dts (map snd raw_bn_eqs)
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 264
1480
21cbb5b0e321
cheat_alpha_eqvt no longer needed. Cleaned the tracing messages.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 265
(*val _ = tracing (cat_lines (map PolyML.makestring raw_bns))*)
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 266
in
1289
+ − 267
lthy
1293
+ − 268
|> add_datatype_wrapper raw_dt_names raw_dts
1289
+ − 269
||>> add_primrec_wrapper raw_bn_funs raw_bn_eqs
1293
+ − 270
||>> pair raw_binds
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 271
||>> pair raw_bns
1293
+ − 272
end
+ − 273
*}
+ − 274
1341
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 275
lemma equivp_hack: "equivp x"
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 276
sorry
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 277
ML {*
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 278
fun equivp_hack ctxt rel =
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 279
let
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 280
val thy = ProofContext.theory_of ctxt
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 281
val ty = domain_type (fastype_of rel)
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 282
val cty = ctyp_of thy ty
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 283
val ct = cterm_of thy rel
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 284
in
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 285
Drule.instantiate' [SOME cty] [SOME ct] @{thm equivp_hack}
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 286
end
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 287
*}
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 288
1595
+ − 289
ML {* val cheat_equivp = Unsynchronized.ref false *}
1623
+ − 290
ML {* val cheat_bn_eqvt = Unsynchronized.ref false *}
1547
57f7af5d7564
Use fs typeclass in showing finite support + some cheat cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 291
ML {* val cheat_fv_eqvt = Unsynchronized.ref false *}
57f7af5d7564
Use fs typeclass in showing finite support + some cheat cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 292
ML {* val cheat_alpha_eqvt = Unsynchronized.ref false *}
1623
+ − 293
ML {* val cheat_bn_rsp = Unsynchronized.ref false *}
+ − 294
ML {* val cheat_fv_rsp = Unsynchronized.ref false *}
+ − 295
ML {* val cheat_const_rsp = Unsynchronized.ref false *}
1576
+ − 296
ML {* val cheat_alpha_bn_rsp = Unsynchronized.ref false *}
1341
c25f797c7e6e
Added lifting of pseudo-injectivity, commented out the code again and enabled the weird examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 297
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 298
ML {* fun map_option _ NONE = NONE
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 299
| map_option f (SOME x) = SOME (f x) *}
1428
+ − 300
1346
+ − 301
ML {*
1293
+ − 302
fun nominal_datatype2 dts bn_funs bn_eqs binds lthy =
+ − 303
let
1480
21cbb5b0e321
cheat_alpha_eqvt no longer needed. Cleaned the tracing messages.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 304
val _ = tracing "Raw declarations";
1340
+ − 305
val thy = ProofContext.theory_of lthy
+ − 306
val thy_name = Context.theory_name thy
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 307
val ((((raw_dt_names, (raw_bn_funs_loc, raw_bn_eqs_loc)), raw_binds), raw_bns), lthy2) =
1293
+ − 308
raw_nominal_decls dts bn_funs bn_eqs binds lthy
1396
+ − 309
val morphism_2_1 = ProofContext.export_morphism lthy2 lthy
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 310
fun export_fun f (t, l) = (f t, map (map (apsnd (map_option f))) l);
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 311
val raw_bns_exp = map (apsnd (map (export_fun (Morphism.term morphism_2_1)))) raw_bns;
1396
+ − 312
val bn_funs_decls = flat (map (fn (ith, l) => map (fn (bn, data) => (bn, ith, data)) l) raw_bns_exp);
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 313
val raw_bn_funs = map (Morphism.term morphism_2_1) raw_bn_funs_loc
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 314
val raw_bn_eqs = ProofContext.export lthy2 lthy raw_bn_eqs_loc
1497
+ − 315
1295
0ecc775e5fce
Link calls to Raw permutations, FV definition and alpha_definition into the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 316
val dtinfo = Datatype.the_info (ProofContext.theory_of lthy2) (hd raw_dt_names);
1309
+ − 317
val descr = #descr dtinfo;
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 318
val sorts = #sorts dtinfo;
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 319
val all_typs = map (fn i => typ_of_dtyp descr sorts (DtRec i)) (map fst descr)
1309
+ − 320
val all_full_tnames = map (fn (_, (n, _, _)) => n) descr;
+ − 321
val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy2)) all_full_tnames;
1342
+ − 322
val rel_dtinfos = List.take (dtinfos, (length dts));
1309
+ − 323
val inject = flat (map #inject dtinfos);
1428
+ − 324
val distincts = flat (map #distinct dtinfos);
1342
+ − 325
val rel_distinct = map #distinct rel_dtinfos;
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 326
val induct = #induct dtinfo;
1309
+ − 327
val inducts = #inducts dtinfo;
1576
+ − 328
val exhausts = map #exhaust dtinfos;
1480
21cbb5b0e321
cheat_alpha_eqvt no longer needed. Cleaned the tracing messages.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 329
val _ = tracing "Defining permutations, fv and alpha";
1295
0ecc775e5fce
Link calls to Raw permutations, FV definition and alpha_definition into the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 330
val ((raw_perm_def, raw_perm_simps, perms), lthy3) =
0ecc775e5fce
Link calls to Raw permutations, FV definition and alpha_definition into the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 331
Local_Theory.theory_result (define_raw_perms dtinfo (length dts)) lthy2;
0ecc775e5fce
Link calls to Raw permutations, FV definition and alpha_definition into the parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 332
val raw_binds_flat = map (map flat) raw_binds;
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 333
val ((((fv_ts, ordered_fv_ts), fv_def), ((alpha_ts, alpha_intros), (alpha_cases, alpha_induct))), lthy4) =
1497
+ − 334
define_fv_alpha_export dtinfo raw_binds_flat bn_funs_decls lthy3;
1448
+ − 335
val (fv_ts_nobn, fv_ts_bn) = chop (length perms) fv_ts;
1416
+ − 336
val (alpha_ts_nobn, alpha_ts_bn) = chop (length perms) alpha_ts
1576
+ − 337
val alpha_inducts = Project_Rule.projects lthy4 (1 upto (length dts)) alpha_induct;
1309
+ − 338
val dts_names = map (fn (i, (s, _, _)) => (s, i)) (#descr dtinfo);
+ − 339
val bn_tys = map (domain_type o fastype_of) raw_bn_funs;
+ − 340
val bn_nos = map (dtyp_no_of_typ dts_names) bn_tys;
1497
+ − 341
val bns = raw_bn_funs ~~ bn_nos;
1576
+ − 342
val rel_dists = flat (map (distinct_rel lthy4 alpha_cases)
+ − 343
(rel_distinct ~~ alpha_ts_nobn));
+ − 344
val rel_dists_bn = flat (map (distinct_rel lthy4 alpha_cases)
+ − 345
((map (fn i => nth rel_distinct i) bn_nos) ~~ alpha_ts_bn))
1496
fd483d8f486b
Prove pseudo-inject (eq-iff) on the exported level and rename appropriately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 346
val alpha_eq_iff = build_alpha_inj alpha_intros (inject @ distincts) alpha_cases lthy4
1480
21cbb5b0e321
cheat_alpha_eqvt no longer needed. Cleaned the tracing messages.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 347
val _ = tracing "Proving equivariance";
1623
+ − 348
fun build_bv_eqvt simps inducts (t, n) ctxt =
+ − 349
build_eqvts Binding.empty [t]
+ − 350
(if !cheat_bn_eqvt then (fn _ => fn _ => Skip_Proof.cheat_tac thy)
+ − 351
else build_eqvts_tac (nth inducts n) simps ctxt
+ − 352
) ctxt
1409
+ − 353
val (bv_eqvts, lthy5) = fold_map (build_bv_eqvt (raw_bn_eqs @ raw_perm_def) inducts) bns lthy4;
1411
+ − 354
val fv_eqvt_tac =
+ − 355
if !cheat_fv_eqvt then (fn _ => fn _ => Skip_Proof.cheat_tac thy)
1495
+ − 356
else build_eqvts_tac induct ((flat (map snd bv_eqvts)) @ fv_def @ raw_perm_def) lthy5
+ − 357
val (fv_eqvts, lthy6) = build_eqvts Binding.empty fv_ts_nobn fv_eqvt_tac lthy5;
+ − 358
val (fv_bn_eqvts, lthy6a) =
+ − 359
if fv_ts_bn = [] then ([], lthy6) else
+ − 360
fold_map (build_bv_eqvt ((flat (map snd bv_eqvts)) @ fv_def @ raw_perm_def) inducts)
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 361
(fv_ts_bn ~~ bn_nos) lthy6;
1495
+ − 362
val raw_fv_bv_eqvt = flat (map snd bv_eqvts) @ (snd fv_eqvts) @ flat (map snd fv_bn_eqvts)
1454
7c8cd6eae8e2
FV_bn generated for recursive functions as well, and used in main fv for bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 363
fun alpha_eqvt_tac' _ =
7c8cd6eae8e2
FV_bn generated for recursive functions as well, and used in main fv for bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 364
if !cheat_alpha_eqvt then Skip_Proof.cheat_tac thy
1496
fd483d8f486b
Prove pseudo-inject (eq-iff) on the exported level and rename appropriately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 365
else alpha_eqvt_tac alpha_induct (raw_perm_def @ alpha_eq_iff @ raw_fv_bv_eqvt) lthy6a 1
1495
+ − 366
val alpha_eqvt = build_alpha_eqvts alpha_ts alpha_eqvt_tac' lthy6a;
1480
21cbb5b0e321
cheat_alpha_eqvt no longer needed. Cleaned the tracing messages.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 367
val _ = tracing "Proving equivalence";
1573
+ − 368
val (rfv_ts_nobn, rfv_ts_bn) = chop (length perms) ordered_fv_ts;
+ − 369
val fv_alpha_all = combine_fv_alpha_bns (rfv_ts_nobn, rfv_ts_bn) (alpha_ts_nobn, alpha_ts_bn) bn_nos;
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 370
val reflps = build_alpha_refl fv_alpha_all alpha_ts induct alpha_eq_iff lthy6a;
1494
923413256cbb
Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 371
val alpha_equivp =
1495
+ − 372
if !cheat_equivp then map (equivp_hack lthy6a) alpha_ts_nobn
1559
+ − 373
else build_equivps alpha_ts reflps alpha_induct
1496
fd483d8f486b
Prove pseudo-inject (eq-iff) on the exported level and rename appropriately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 374
inject alpha_eq_iff distincts alpha_cases alpha_eqvt lthy6a;
1412
+ − 375
val qty_binds = map (fn (_, b, _, _) => b) dts;
+ − 376
val qty_names = map Name.of_binding qty_binds;
+ − 377
val qty_full_names = map (Long_Name.qualify thy_name) qty_names
1316
0577afdb1732
Porting from Lift to Parser; until defining the Quotient type.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 378
val lthy7 = define_quotient_type
1414
+ − 379
(map (fn ((b, t), alpha) => (([], b, NoSyn), (t, alpha))) ((qty_binds ~~ all_typs) ~~ alpha_ts_nobn))
1495
+ − 380
(ALLGOALS (resolve_tac alpha_equivp)) lthy6a;
1340
+ − 381
val const_names = map Name.of_binding (flat (map (fn (_, _, _, t) => map (fn (b, _, _) => b) t) dts));
+ − 382
val raw_consts =
+ − 383
flat (map (fn (i, (_, _, l)) =>
+ − 384
map (fn (cname, dts) =>
+ − 385
Const (cname, map (typ_of_dtyp descr sorts) dts --->
+ − 386
typ_of_dtyp descr sorts (DtRec i))) l) descr);
1494
923413256cbb
Clean 'Lift', start working only on exported things in Parser.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 387
val (consts, const_defs, lthy8) = quotient_lift_consts_export (const_names ~~ raw_consts) lthy7;
1428
+ − 388
(* Could be done nicer *)
+ − 389
val q_tys = distinct (op =) (map (snd o strip_type o fastype_of) consts);
1480
21cbb5b0e321
cheat_alpha_eqvt no longer needed. Cleaned the tracing messages.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 390
val _ = tracing "Proving respects";
1340
+ − 391
val (bns_rsp_pre, lthy9) = fold_map (
1623
+ − 392
fn (bn_t, i) => prove_const_rsp Binding.empty [bn_t] (fn _ =>
+ − 393
if !cheat_bn_rsp then (Skip_Proof.cheat_tac thy) else
+ − 394
fvbv_rsp_tac (nth alpha_inducts i) raw_bn_eqs lthy8 1)) bns lthy8;
1340
+ − 395
val bns_rsp = flat (map snd bns_rsp_pre);
1416
+ − 396
fun fv_rsp_tac _ = if !cheat_fv_rsp then Skip_Proof.cheat_tac thy
1573
+ − 397
else fvbv_rsp_tac alpha_induct fv_def lthy8 1;
+ − 398
val fv_rsps = prove_fv_rsp fv_alpha_all alpha_ts fv_rsp_tac lthy9;
+ − 399
val (fv_rsp_pre, lthy10) = fold_map
+ − 400
(fn fv => fn ctxt => prove_const_rsp Binding.empty [fv]
+ − 401
(fn _ => asm_simp_tac (HOL_ss addsimps fv_rsps) 1) ctxt) fv_ts lthy9;
+ − 402
val fv_rsp = flat (map snd fv_rsp_pre);
1416
+ − 403
val (perms_rsp, lthy11) = prove_const_rsp Binding.empty perms
+ − 404
(fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10;
1623
+ − 405
fun const_rsp_tac _ =
+ − 406
if !cheat_const_rsp then Skip_Proof.cheat_tac thy
+ − 407
else let val alpha_alphabn = build_alpha_alphabn fv_alpha_all alpha_inducts alpha_eq_iff lthy11
+ − 408
in constr_rsp_tac alpha_eq_iff (fv_rsp @ bns_rsp @ reflps @ alpha_alphabn) 1 end
1561
+ − 409
val (const_rsps, lthy11a) = fold_map (fn cnst => prove_const_rsp Binding.empty [cnst]
+ − 410
const_rsp_tac) raw_consts lthy11
+ − 411
val (alpha_bn_rsps, lthy12) = fold_map (fn cnst => prove_const_rsp Binding.empty [cnst]
1623
+ − 412
(fn _ =>
+ − 413
if !cheat_alpha_bn_rsp then Skip_Proof.cheat_tac thy
+ − 414
else
+ − 415
let val alpha_bn_rsp_pre = flat (map (prove_alpha_bn_rsp alpha_ts_nobn alpha_inducts exhausts
+ − 416
(alpha_eq_iff @ rel_dists @ rel_dists_bn) (alpha_equivp) lthy11a) (alpha_ts_bn ~~ bn_nos)) in
+ − 417
asm_simp_tac (HOL_ss addsimps alpha_bn_rsp_pre) 1 end)) alpha_ts_bn lthy11a
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 418
val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) ordered_fv_ts
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 419
val (qfv_ts, qfv_defs, lthy12a) = quotient_lift_consts_export (qfv_names ~~ ordered_fv_ts) lthy12;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 420
val (qfv_ts_nobn, qfv_ts_bn) = chop (length perms) qfv_ts;
1340
+ − 421
val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs
+ − 422
val (qbn_defs, lthy12b) = fold_map Quotient_Def.quotient_lift_const (qbn_names ~~ raw_bn_funs) lthy12a;
1417
+ − 423
val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_ts_bn
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 424
val (qalpha_ts_bn, qbn_defs, lthy12c) = quotient_lift_consts_export (qalpha_bn_names ~~ alpha_ts_bn) lthy12b;
1480
21cbb5b0e321
cheat_alpha_eqvt no longer needed. Cleaned the tracing messages.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 425
val _ = tracing "Lifting permutations";
1417
+ − 426
val thy = Local_Theory.exit_global lthy12c;
1340
+ − 427
val perm_names = map (fn x => "permute_" ^ x) qty_names
+ − 428
val thy' = define_lifted_perms qty_full_names (perm_names ~~ perms) raw_perm_simps thy;
+ − 429
val lthy13 = Theory_Target.init NONE thy';
+ − 430
val q_name = space_implode "_" qty_names;
1515
+ − 431
fun suffix_bind s = Binding.qualify true q_name (Binding.name s);
1480
21cbb5b0e321
cheat_alpha_eqvt no longer needed. Cleaned the tracing messages.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 432
val _ = tracing "Lifting induction";
1511
+ − 433
val constr_names = map (Long_Name.base_name o fst o dest_Const) consts;
+ − 434
val q_induct = Rule_Cases.name constr_names (lift_thm lthy13 induct);
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 435
fun note_suffix s th ctxt =
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 436
snd (Local_Theory.note ((suffix_bind s, []), th) ctxt);
1510
+ − 437
fun note_simp_suffix s th ctxt =
1515
+ − 438
snd (Local_Theory.note ((suffix_bind s, [Attrib.internal (K Simplifier.simp_add)]), th) ctxt);
+ − 439
val (_, lthy14) = Local_Theory.note ((suffix_bind "induct",
1512
+ − 440
[Attrib.internal (K (Rule_Cases.case_names constr_names))]), [Rule_Cases.name constr_names q_induct]) lthy13;
1447
378b8c791de8
derive "inducts" from "induct" instead of lifting again is much faster.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 441
val q_inducts = Project_Rule.projects lthy13 (1 upto (length alpha_inducts)) q_induct
1515
+ − 442
val (_, lthy14a) = Local_Theory.note ((suffix_bind "inducts", []), q_inducts) lthy14;
1511
+ − 443
val q_perm = map (lift_thm lthy14) raw_perm_def;
1510
+ − 444
val lthy15 = note_simp_suffix "perm" q_perm lthy14a;
1422
+ − 445
val q_fv = map (lift_thm lthy15) fv_def;
1510
+ − 446
val lthy16 = note_simp_suffix "fv" q_fv lthy15;
1422
+ − 447
val q_bn = map (lift_thm lthy16) raw_bn_eqs;
1510
+ − 448
val lthy17 = note_simp_suffix "bn" q_bn lthy16;
1496
fd483d8f486b
Prove pseudo-inject (eq-iff) on the exported level and rename appropriately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 449
val _ = tracing "Lifting eq-iff";
fd483d8f486b
Prove pseudo-inject (eq-iff) on the exported level and rename appropriately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 450
val eq_iff_unfolded1 = map (Local_Defs.unfold lthy17 @{thms alpha_gen2}) alpha_eq_iff
fd483d8f486b
Prove pseudo-inject (eq-iff) on the exported level and rename appropriately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 451
val eq_iff_unfolded2 = map (Local_Defs.unfold lthy17 @{thms alpha_gen}) eq_iff_unfolded1
fd483d8f486b
Prove pseudo-inject (eq-iff) on the exported level and rename appropriately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 452
val q_eq_iff_pre1 = map (lift_thm lthy17) eq_iff_unfolded2;
fd483d8f486b
Prove pseudo-inject (eq-iff) on the exported level and rename appropriately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 453
val q_eq_iff_pre2 = map (Local_Defs.fold lthy17 @{thms alpha_gen2}) q_eq_iff_pre1
fd483d8f486b
Prove pseudo-inject (eq-iff) on the exported level and rename appropriately.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 454
val q_eq_iff = map (Local_Defs.fold lthy17 @{thms alpha_gen}) q_eq_iff_pre2
1515
+ − 455
val (_, lthy18) = Local_Theory.note ((suffix_bind "eq_iff", []), q_eq_iff) lthy17;
1422
+ − 456
val q_dis = map (lift_thm lthy18) rel_dists;
1510
+ − 457
val lthy19 = note_simp_suffix "distinct" q_dis lthy18;
1422
+ − 458
val q_eqvt = map (lift_thm lthy19) raw_fv_bv_eqvt;
1346
+ − 459
val (_, lthy20) = Local_Theory.note ((Binding.empty,
+ − 460
[Attrib.internal (fn _ => Nominal_ThmDecls.eqvt_add)]), q_eqvt) lthy19;
1480
21cbb5b0e321
cheat_alpha_eqvt no longer needed. Cleaned the tracing messages.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 461
val _ = tracing "Finite Support";
1547
57f7af5d7564
Use fs typeclass in showing finite support + some cheat cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 462
val supports = map (prove_supports lthy20 q_perm) consts;
57f7af5d7564
Use fs typeclass in showing finite support + some cheat cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 463
val fin_supp = HOLogic.conj_elims (prove_fs lthy20 q_induct supports q_tys);
1428
+ − 464
val thy3 = Local_Theory.exit_global lthy20;
+ − 465
val lthy21 = Theory_Target.instantiation (qty_full_names, [], @{sort fs}) thy3;
+ − 466
fun tac _ = Class.intro_classes_tac [] THEN (ALLGOALS (resolve_tac fin_supp))
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 467
val lthy22 = Class.prove_instantiation_instance tac lthy21
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 468
val fv_alpha_all = combine_fv_alpha_bns (qfv_ts_nobn, qfv_ts_bn) (alpha_ts_nobn, qalpha_ts_bn) bn_nos;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 469
val (names, supp_eq_t) = supp_eq fv_alpha_all;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 470
val q_supp = HOLogic.conj_elims (Goal.prove lthy22 names [] supp_eq_t (fn _ => supp_eq_tac q_induct q_fv q_perm q_eq_iff lthy22 1)) handle _ => [];
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 471
val lthy23 = note_suffix "supp" q_supp lthy22;
1293
+ − 472
in
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 473
((raw_dt_names, raw_bn_funs, raw_bn_eqs, raw_binds), lthy23)
1346
+ − 474
end
978
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 475
*}
1340
+ − 476
1422
+ − 477
1284
+ − 478
ML {*
+ − 479
(* parsing the datatypes and declaring *)
+ − 480
(* constructors in the local theory *)
+ − 481
fun prepare_dts dt_strs lthy =
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 482
let
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 483
val thy = ProofContext.theory_of lthy
1284
+ − 484
+ − 485
fun mk_type full_tname tvrs =
+ − 486
Type (full_tname, map (fn a => TVar ((a, 0), [])) tvrs)
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 487
1284
+ − 488
fun prep_cnstr lthy full_tname tvs (cname, anno_tys, mx, _) =
+ − 489
let
+ − 490
val tys = map (Syntax.read_typ lthy o snd) anno_tys
+ − 491
val ty = mk_type full_tname tvs
+ − 492
in
+ − 493
((cname, tys ---> ty, mx), (cname, tys, mx))
+ − 494
end
+ − 495
+ − 496
fun prep_dt lthy (tvs, tname, mx, cnstrs) =
+ − 497
let
+ − 498
val full_tname = Sign.full_name thy tname
+ − 499
val (cnstrs', cnstrs'') =
+ − 500
split_list (map (prep_cnstr lthy full_tname tvs) cnstrs)
+ − 501
in
+ − 502
(cnstrs', (tvs, tname, mx, cnstrs''))
+ − 503
end
1266
+ − 504
1284
+ − 505
val (cnstrs, dts) =
+ − 506
split_list (map (prep_dt lthy) dt_strs)
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 507
in
1284
+ − 508
lthy
+ − 509
|> Local_Theory.theory (Sign.add_consts_i (flat cnstrs))
+ − 510
|> pair dts
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 511
end
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 512
*}
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 513
1284
+ − 514
ML {*
1285
+ − 515
(* parsing the binding function specification and *)
+ − 516
(* declaring the functions in the local theory *)
1284
+ − 517
fun prepare_bn_funs bn_fun_strs bn_eq_strs lthy =
+ − 518
let
+ − 519
val ((bn_funs, bn_eqs), _) =
+ − 520
Specification.read_spec bn_fun_strs bn_eq_strs lthy
+ − 521
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 522
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx)
1284
+ − 523
val bn_funs' = map prep_bn_fun bn_funs
+ − 524
in
+ − 525
lthy
+ − 526
|> Local_Theory.theory (Sign.add_consts_i bn_funs')
+ − 527
|> pair (bn_funs', bn_eqs)
+ − 528
end
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 529
*}
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 530
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 531
ML {*
1290
+ − 532
fun find_all eq xs (k',i) =
+ − 533
maps (fn (k, (v1, v2)) => if eq (k, k') then [(v1, v2, i)] else []) xs
1285
+ − 534
*}
1284
+ − 535
1285
+ − 536
ML {*
1290
+ − 537
(* associates every SOME with the index in the list; drops NONEs *)
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 538
fun mk_env xs =
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 539
let
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 540
fun mapp (_: int) [] = []
1285
+ − 541
| mapp i (a :: xs) =
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 542
case a of
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 543
NONE => mapp (i + 1) xs
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 544
| SOME x => (x, i) :: mapp (i + 1) xs
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 545
in mapp 0 xs end
1285
+ − 546
*}
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 547
1285
+ − 548
ML {*
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 549
fun env_lookup xs x =
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 550
case AList.lookup (op =) xs x of
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 551
SOME x => x
1287
+ − 552
| NONE => error ("cannot find " ^ x ^ " in the binding specification.");
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 553
*}
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 554
978
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 555
ML {*
1484
+ − 556
val recursive = Unsynchronized.ref false
1436
+ − 557
*}
+ − 558
+ − 559
ML {*
1284
+ − 560
fun prepare_binds dt_strs lthy =
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 561
let
1287
+ − 562
fun extract_annos_binds dt_strs =
1290
+ − 563
map (map (fn (_, antys, _, bns) => (map fst antys, bns))) dt_strs
1285
+ − 564
+ − 565
fun prep_bn env bn_str =
+ − 566
case (Syntax.read_term lthy bn_str) of
1290
+ − 567
Free (x, _) => (NONE, env_lookup env x)
1436
+ − 568
| Const (a, T) $ Free (x, _) => (SOME (Const (a, T), !recursive), env_lookup env x)
1285
+ − 569
| _ => error (bn_str ^ " not allowed as binding specification.");
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 570
1290
+ − 571
fun prep_typ env (i, opt_name) =
1285
+ − 572
case opt_name of
+ − 573
NONE => []
1290
+ − 574
| SOME x => find_all (op=) env (x,i);
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 575
1287
+ − 576
(* annos - list of annotation for each type (either NONE or SOME fo a type *)
+ − 577
+ − 578
fun prep_binds (annos, bind_strs) =
1284
+ − 579
let
1290
+ − 580
val env = mk_env annos (* for every label the index *)
1284
+ − 581
val binds = map (fn (x, y) => (x, prep_bn env y)) bind_strs
+ − 582
in
1290
+ − 583
map_index (prep_typ binds) annos
1284
+ − 584
end
1287
+ − 585
969
cc5d18c78446
Parsing of the input as terms and types, and passing them as such to the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 586
in
1290
+ − 587
map (map prep_binds) (extract_annos_binds (get_cnstrs dt_strs))
969
cc5d18c78446
Parsing of the input as terms and types, and passing them as such to the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 588
end
966
+ − 589
*}
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 590
1284
+ − 591
ML {*
+ − 592
fun nominal_datatype2_cmd (dt_strs, bn_fun_strs, bn_eq_strs) lthy =
+ − 593
let
+ − 594
fun prep_typ (tvs, tname, mx, _) = (tname, length tvs, mx)
+ − 595
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 596
val lthy0 =
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 597
Local_Theory.theory (Sign.add_types (map prep_typ dt_strs)) lthy
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 598
val (dts, lthy1) =
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 599
prepare_dts dt_strs lthy0
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 600
val ((bn_funs, bn_eqs), lthy2) =
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 601
prepare_bn_funs bn_fun_strs bn_eq_strs lthy1
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 602
val binds = prepare_binds dt_strs lthy2
1284
+ − 603
in
1380
dab8d99b37c1
added bn-information, but it is not yet ordered according to the dts
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 604
nominal_datatype2 dts bn_funs bn_eqs binds lthy |> snd
1284
+ − 605
end
+ − 606
*}
+ − 607
+ − 608
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 609
(* Command Keyword *)
1283
6a133abb7633
generated the "binding list" from the input; at the moment it is only printed out as tracing; does not yet include the "bind itself binders"
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 610
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 611
ML {*
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 612
let
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 613
val kind = OuterKeyword.thy_decl
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 614
in
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 615
OuterSyntax.local_theory "nominal_datatype" "test" kind
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 616
(main_parser >> nominal_datatype2_cmd)
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 617
end
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 618
*}
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 619
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
+ − 620
961
+ − 621
end
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 622
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 623
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 624