src/HOL/ex/Conditional_Parametricity_Examples.thy
author traytel
Mon Dec 18 16:58:13 2017 +0100 (2017-12-18)
changeset 67224 341fbce5b26d
child 67399 eab6ce8368fa
permissions -rw-r--r--
a conditional paramitrecity prover
traytel@67224
     1
(*  Title:    HOL/ex/Conditional_Parametricity_Examples.thy
traytel@67224
     2
    Author:   Jan Gilcher, Andreas Lochbihler, Dmitriy Traytel, ETH Z├╝rich
traytel@67224
     3
traytel@67224
     4
Examples for the parametric_constant command
traytel@67224
     5
*)
traytel@67224
     6
traytel@67224
     7
theory Conditional_Parametricity_Examples
traytel@67224
     8
  imports "HOL-Library.Conditional_Parametricity"
traytel@67224
     9
begin
traytel@67224
    10
traytel@67224
    11
definition "bar x xs = rev (x # xs)"
traytel@67224
    12
parametric_constant bar_def
traytel@67224
    13
traytel@67224
    14
definition bar2 where "bar2 = bar"
traytel@67224
    15
parametric_constant bar2_def
traytel@67224
    16
traytel@67224
    17
parametric_constant bar_thm[transfer_rule]: bar_def
traytel@67224
    18
parametric_constant bar2_thm1: bar2_def
traytel@67224
    19
traytel@67224
    20
definition "t1 y x = zip x y"
traytel@67224
    21
parametric_constant t1_thm: t1_def
traytel@67224
    22
traytel@67224
    23
definition "t2 f x = f (rev x)"
traytel@67224
    24
parametric_constant t2_thm: t2_def
traytel@67224
    25
traytel@67224
    26
definition "t3 xs = rev (rev (xs :: 'b list))"
traytel@67224
    27
parametric_constant t3_thm: t3_def
traytel@67224
    28
traytel@67224
    29
definition "t4 f x = rev (f x (f x (rev x)))"
traytel@67224
    30
parametric_constant t4_thm: t4_def
traytel@67224
    31
traytel@67224
    32
definition "t5 x y = zip x (rev y)"
traytel@67224
    33
parametric_constant t5_thm: t5_def
traytel@67224
    34
traytel@67224
    35
(* Conditional Parametricity*)
traytel@67224
    36
traytel@67224
    37
definition "t6_1 x y = inf y x"
traytel@67224
    38
parametric_constant t6_1_thm: t6_1_def
traytel@67224
    39
traytel@67224
    40
definition "t6_2 x y = sup y x"
traytel@67224
    41
parametric_constant t6_2_thm: t6_2_def
traytel@67224
    42
traytel@67224
    43
definition "t6_3 x z y = sup (inf x y) z"
traytel@67224
    44
parametric_constant t6_3_thm: t6_3_def
traytel@67224
    45
traytel@67224
    46
definition "t6_4 x xs y = map (sup (inf y x)) xs"
traytel@67224
    47
parametric_constant t6_4_thm: t6_4_def
traytel@67224
    48
traytel@67224
    49
definition "t7 x y = (y = x)"
traytel@67224
    50
parametric_constant t7_thm: t7_def
traytel@67224
    51
traytel@67224
    52
definition "t8 x y = ((x=y) \<and> (y=x))"
traytel@67224
    53
parametric_constant t8_thm: t8_def
traytel@67224
    54
traytel@67224
    55
(* Definition via primrec*)
traytel@67224
    56
primrec delete where
traytel@67224
    57
  "delete _ [] = []"
traytel@67224
    58
| "delete x (y # ys) = (if x = y then ys else y # (delete x ys))"
traytel@67224
    59
parametric_constant delete_thm: delete_def
traytel@67224
    60
traytel@67224
    61
definition "foo f x y = (if f x = f y then x else sup y x)"
traytel@67224
    62
parametric_constant foo_parametricity: foo_def
traytel@67224
    63
traytel@67224
    64
end