src/HOL/Quotient_Examples/Lifting_Code_Dt_Test.thy
author haftmann
Sun, 06 May 2018 18:20:25 +0000
changeset 68099 305f9f3edf05
parent 61169 4de9ff3ea29a
permissions -rw-r--r--
typo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
60237
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
     1
(*  Title:      HOL/Quotient_Examples/Lifting_Code_Dt_Test.thy
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
     2
    Author:     Ondrej Kuncar, TU Muenchen
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
     3
    Copyright   2015
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
     4
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
     5
Miscellaneous lift_definition(code_dt) definitions (for testing purposes).
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
     6
*)
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
     7
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
     8
theory Lifting_Code_Dt_Test
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
     9
imports Main
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    10
begin
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    11
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    12
(* basic examples *)
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    13
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    14
typedef bool2 = "{x. x}" by auto
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    15
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    16
setup_lifting type_definition_bool2
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    17
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    18
lift_definition(code_dt) f1 :: "bool2 option" is "Some True" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    19
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    20
lift_definition(code_dt) f2 :: "bool2 list" is "[True]" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    21
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    22
lift_definition(code_dt) f3 :: "bool2 \<times> int" is "(True, 42)" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    23
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    24
lift_definition(code_dt) f4 :: "int + bool2" is "Inr True" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    25
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    26
lift_definition(code_dt) f5 :: "'a \<Rightarrow> (bool2 \<times> 'a) option" is "\<lambda>x. Some (True, x)" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    27
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    28
(* ugly (i.e., sensitive to rewriting done in my tactics) definition of T *)
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    29
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    30
typedef 'a T = "{ x::'a. \<forall>(y::'a) z::'a. \<exists>(w::'a). (z = z) \<and> eq_onp top y y 
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    31
  \<or> rel_prod (eq_onp top) (eq_onp top) (x, y) (x, y) \<longrightarrow> pred_prod top top (w, w) }"
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    32
  by auto
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    33
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    34
setup_lifting type_definition_T
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    35
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    36
lift_definition(code_dt) f6 :: "bool T option" is "Some True" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    37
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    38
lift_definition(code_dt) f7 :: "(bool T \<times> int) option" is "Some (True, 42)" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    39
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    40
lift_definition(code_dt) f8 :: "bool T \<Rightarrow> int \<Rightarrow> (bool T \<times> int) option" 
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    41
  is "\<lambda>x y. if x then Some (x, y) else None" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    42
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    43
lift_definition(code_dt) f9 :: "nat \<Rightarrow> ((bool T \<times> int) option) list \<times> nat" 
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    44
  is "\<lambda>x. ([Some (True, 42)], x)" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    45
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    46
(* complicated nested datatypes *)
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    47
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    48
(* stolen from Datatype_Examples *)
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    49
datatype 'a tree = Empty | Node 'a "'a tree list"
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    50
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    51
datatype 'a ttree = TEmpty | TNode 'a "'a ttree list tree"
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    52
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    53
datatype 'a tttree = TEmpty | TNode 'a "'a tttree list ttree list tree"
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    54
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    55
lift_definition(code_dt) f10 :: "int \<Rightarrow> int T tree" is "\<lambda>i. Node i [Node i Nil, Empty]" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    56
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    57
lift_definition(code_dt) f11 :: "int \<Rightarrow> int T ttree" 
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    58
  is "\<lambda>i. ttree.TNode i (Node [ttree.TNode i Empty] [])" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    59
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    60
lift_definition(code_dt) f12 :: "int \<Rightarrow> int T tttree" is "\<lambda>i. tttree.TNode i Empty" by simp
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    61
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    62
(* Phantom type variables *)
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    63
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    64
datatype 'a phantom = PH1 | PH2 
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    65
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    66
datatype ('a, 'b) phantom2 = PH21 'a | PH22 "'a option"
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    67
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    68
lift_definition(code_dt) f13 :: "int \<Rightarrow> int T phantom" is "\<lambda>i. PH1" by auto
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    69
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    70
lift_definition(code_dt) f14 :: "int \<Rightarrow> (int T, nat T) phantom2" is "\<lambda>i. PH22 (Some i)" by auto
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    71
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    72
(* Mutual datatypes *)
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    73
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    74
datatype 'a M1 = Empty 'a | CM "'a M2"
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    75
and 'a M2 = CM2 "'a M1"
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    76
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    77
lift_definition(code_dt) f15 :: "int \<Rightarrow> int T M1" is "\<lambda>i. Empty i" by auto
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    78
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    79
(* Codatatypes *)
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    80
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    81
codatatype 'a stream = S 'a "'a stream"
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    82
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    83
primcorec 
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    84
  sconst :: "'a \<Rightarrow> 'a stream" where
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    85
  "sconst a = S a (sconst a)"
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    86
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    87
lift_definition(code_dt) f16 :: "int \<Rightarrow> int T stream" is "\<lambda>i. sconst i"  unfolding pred_stream_def
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    88
by auto
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    89
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    90
(* Sort constraints *)
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    91
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    92
datatype ('a::finite, 'b::finite) F = F 'a | F2 'b
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    93
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 60237
diff changeset
    94
instance T :: (finite) finite by standard (transfer, auto)
60237
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    95
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    96
lift_definition(code_dt) f17 :: "bool \<Rightarrow> (bool T, 'b::finite) F" is "\<lambda>b. F b" by auto
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    97
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    98
export_code f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
    99
  checking SML OCaml? Haskell? Scala? 
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
   100
d47387d4a3c6 add testing file for code_dt extension of lifting
kuncar
parents:
diff changeset
   101
end