src/HOL/ex/ReflectionEx.thy
author wenzelm
Mon, 16 Mar 2009 18:24:30 +0100
changeset 30549 d2d7874648bd
parent 29668 33ba3faeaa0e
child 31021 53642251a04f
permissions -rw-r--r--
simplified method setup;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29650
cc3958d31b1d Reflection.thy now in HOL/Library
haftmann
parents: 28866
diff changeset
     1
(*  Title:      HOL/ex/ReflectionEx.thy
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
     2
    Author:     Amine Chaieb, TU Muenchen
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
     3
*)
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
     4
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
     5
header {* Examples for generic reflection and reification *}
29650
cc3958d31b1d Reflection.thy now in HOL/Library
haftmann
parents: 28866
diff changeset
     6
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
     7
theory ReflectionEx
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
     8
imports Reflection
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
     9
begin
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    10
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    11
text{* This theory presents two methods: reify and reflection *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    12
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    13
text{* 
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
    14
Consider an HOL type 'a, the structure of which is not recongnisable on the theory level. This is the case of bool, arithmetical terms such as int, real etc \dots
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    15
In order to implement a simplification on terms of type 'a we often need its structure.
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    16
Traditionnaly such simplifications are written in ML, proofs are synthesized.
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    17
An other strategy is to declare an HOL-datatype tau and an HOL function (the interpretation) that maps elements of tau to elements of 'a. The functionality of @{text reify} is to compute a term s::tau, which is the representant of t. For this it needs equations for the interpretation.
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    18
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    19
NB: All the interpretations supported by @{text reify} must have the type @{text "'b list \<Rightarrow> tau \<Rightarrow> 'a"}.
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    20
The method @{text reify} can also be told which subterm of the current subgoal should be reified. The general call for @{text reify} is: @{text "reify eqs (t)"}, where @{text eqs} are the defining equations of the interpretation and @{text "(t)"} is an optional parameter which specifies the subterm to which reification should be applied to. If @{text "(t)"} is abscent, @{text reify} tries to reify the whole subgoal.
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    21
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    22
The method reflection uses @{text reify} and has a very similar signature: @{text "reflection corr_thm eqs (t)"}. Here again @{text eqs} and @{text "(t)"} are as described above and @{text corr_thm} is a thorem proving @{term "I vs (f t) = I vs t"}. We assume that @{text I} is the interpretation and @{text f} is some useful and executable simplification of type @{text "tau \<Rightarrow> tau"}. The method @{text reflection} applies reification and hence the theorem @{term "t = I xs s"} and hence using @{text corr_thm} derives @{term "t = I xs (f s)"}. It then uses normalization by evaluation to prove @{term "f s = s'"} which almost finishes the proof of @{term "t = t'"} where @{term "I xs s' = t'"}.
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    23
*}
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    24
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    25
text{* Example 1 : Propositional formulae and NNF.*}
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    26
text{* The type @{text fm} represents simple propositional formulae: *}
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    27
23547
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    28
datatype form = TrueF | FalseF | Less nat nat |
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    29
                And form form | Or form form | Neg form | ExQ form
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    30
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    31
fun interp :: "form \<Rightarrow> ('a::ord) list \<Rightarrow> bool" where
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    32
"interp TrueF e = True" |
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    33
"interp FalseF e = False" |
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    34
"interp (Less i j) e = (e!i < e!j)" |
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    35
"interp (And f1 f2) e = (interp f1 e & interp f2 e)" |
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    36
"interp (Or f1 f2) e = (interp f1 e | interp f2 e)" |
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    37
"interp (Neg f) e = (~ interp f e)" |
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    38
"interp (ExQ f) e = (EX x. interp f (x#e))"
23547
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    39
23608
e65e36dbe0d2 Some examples for reifying type variables
chaieb
parents: 23547
diff changeset
    40
lemmas interp_reify_eqs = interp.simps
e65e36dbe0d2 Some examples for reifying type variables
chaieb
parents: 23547
diff changeset
    41
declare interp_reify_eqs[reify]
23547
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    42
23608
e65e36dbe0d2 Some examples for reifying type variables
chaieb
parents: 23547
diff changeset
    43
lemma "EX x. x < y & x < z"
e65e36dbe0d2 Some examples for reifying type variables
chaieb
parents: 23547
diff changeset
    44
  apply (reify )
e65e36dbe0d2 Some examples for reifying type variables
chaieb
parents: 23547
diff changeset
    45
  oops
23547
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    46
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    47
datatype fm = And fm fm | Or fm fm | Imp fm fm | Iff fm fm | NOT fm | At nat
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    48
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    49
consts Ifm :: "fm \<Rightarrow> bool list \<Rightarrow> bool"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    50
primrec
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    51
  "Ifm (At n) vs = vs!n"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    52
  "Ifm (And p q) vs = (Ifm p vs \<and> Ifm q vs)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    53
  "Ifm (Or p q) vs = (Ifm p vs \<or> Ifm q vs)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    54
  "Ifm (Imp p q) vs = (Ifm p vs \<longrightarrow> Ifm q vs)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    55
  "Ifm (Iff p q) vs = (Ifm p vs = Ifm q vs)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
    56
  "Ifm (NOT p) vs = (\<not> (Ifm p vs))"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    57
23547
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    58
lemma "Q \<longrightarrow> (D & F & ((~ D) & (~ F)))"
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    59
apply (reify Ifm.simps)
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    60
oops
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    61
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    62
  text{* Method @{text reify} maps a bool to an fm. For this it needs the 
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    63
  semantics of fm, i.e.\ the rewrite rules in @{text Ifm.simps}. *}
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    64
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    65
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    66
  (* You can also just pick up a subterm to reify \<dots> *)
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    67
lemma "Q \<longrightarrow> (D & F & ((~ D) & (~ F)))"
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    68
apply (reify Ifm.simps ("((~ D) & (~ F))"))
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    69
oops
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    70
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
    71
  text{* Let's perform NNF. This is a version that tends to generate disjunctions *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    72
consts fmsize :: "fm \<Rightarrow> nat"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    73
primrec
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    74
  "fmsize (At n) = 1"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    75
  "fmsize (NOT p) = 1 + fmsize p"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    76
  "fmsize (And p q) = 1 + fmsize p + fmsize q"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    77
  "fmsize (Or p q) = 1 + fmsize p + fmsize q"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    78
  "fmsize (Imp p q) = 2 + fmsize p + fmsize q"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    79
  "fmsize (Iff p q) = 2 + 2* fmsize p + 2* fmsize q"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    80
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    81
consts nnf :: "fm \<Rightarrow> fm"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    82
recdef nnf "measure fmsize"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    83
  "nnf (At n) = At n"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    84
  "nnf (And p q) = And (nnf p) (nnf q)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    85
  "nnf (Or p q) = Or (nnf p) (nnf q)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    86
  "nnf (Imp p q) = Or (nnf (NOT p)) (nnf q)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    87
  "nnf (Iff p q) = Or (And (nnf p) (nnf q)) (And (nnf (NOT p)) (nnf (NOT q)))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    88
  "nnf (NOT (And p q)) = Or (nnf (NOT p)) (nnf (NOT q))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    89
  "nnf (NOT (Or p q)) = And (nnf (NOT p)) (nnf (NOT q))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    90
  "nnf (NOT (Imp p q)) = And (nnf p) (nnf (NOT q))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    91
  "nnf (NOT (Iff p q)) = Or (And (nnf p) (nnf (NOT q))) (And (nnf (NOT p)) (nnf q))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    92
  "nnf (NOT (NOT p)) = nnf p"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    93
  "nnf (NOT p) = NOT p"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    94
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    95
  text{* The correctness theorem of nnf: it preserves the semantics of fm *}
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
    96
lemma nnf[reflection]: "Ifm (nnf p) vs = Ifm p vs"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    97
  by (induct p rule: nnf.induct) auto
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
    98
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
    99
  text{* Now let's perform NNF using our @{term nnf} function defined above. First to the whole subgoal. *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   100
lemma "(\<not> (A = B)) \<and> (B \<longrightarrow> (A \<noteq> (B | C \<and> (B \<longrightarrow> A | D)))) \<longrightarrow> A \<or> B \<and> D"
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   101
apply (reflection Ifm.simps)
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   102
oops
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   103
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   104
  text{* Now we specify on which subterm it should be applied*}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   105
lemma "(\<not> (A = B)) \<and> (B \<longrightarrow> (A \<noteq> (B | C \<and> (B \<longrightarrow> A | D)))) \<longrightarrow> A \<or> B \<and> D"
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   106
apply (reflection Ifm.simps only: "(B | C \<and> (B \<longrightarrow> A | D))")
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   107
oops
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   108
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   109
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   110
  (* Example 2 : Simple arithmetic formulae *)
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   111
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   112
  text{* The type @{text num} reflects linear expressions over natural number *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   113
datatype num = C nat | Add num num | Mul nat num | Var nat | CN nat nat num
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   114
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   115
text{* This is just technical to make recursive definitions easier. *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   116
consts num_size :: "num \<Rightarrow> nat" 
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   117
primrec 
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   118
  "num_size (C c) = 1"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   119
  "num_size (Var n) = 1"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   120
  "num_size (Add a b) = 1 + num_size a + num_size b"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   121
  "num_size (Mul c a) = 1 + num_size a"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   122
  "num_size (CN n c a) = 4 + num_size a "
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   123
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   124
  text{* The semantics of num *}
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   125
consts Inum:: "num \<Rightarrow> nat list \<Rightarrow> nat"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   126
primrec 
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   127
  Inum_C  : "Inum (C i) vs = i"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   128
  Inum_Var: "Inum (Var n) vs = vs!n"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   129
  Inum_Add: "Inum (Add s t) vs = Inum s vs + Inum t vs "
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   130
  Inum_Mul: "Inum (Mul c t) vs = c * Inum t vs "
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   131
  Inum_CN : "Inum (CN n c t) vs = c*(vs!n) + Inum t vs "
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   132
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   133
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   134
  text{* Let's reify some nat expressions \dots *}
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   135
lemma "4 * (2*x + (y::nat)) + f a \<noteq> 0"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   136
  apply (reify Inum.simps ("4 * (2*x + (y::nat)) + f a"))
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   137
oops
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   138
text{* We're in a bad situation!! x, y and f a have been recongnized as a constants, which is correct but does not correspond to our intuition of the constructor C. It should encapsulate constants, i.e. numbers, i.e. numerals.*}
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   139
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   140
  text{* So let's leave the @{text "Inum_C"} equation at the end and see what happens \dots*}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   141
lemma "4 * (2*x + (y::nat)) \<noteq> 0"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   142
  apply (reify Inum_Var Inum_Add Inum_Mul Inum_CN Inum_C ("4 * (2*x + (y::nat))"))
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   143
oops
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   144
text{* Hmmm let's specialize @{text Inum_C} with numerals.*}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   145
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   146
lemma Inum_number: "Inum (C (number_of t)) vs = number_of t" by simp
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   147
lemmas Inum_eqs = Inum_Var Inum_Add Inum_Mul Inum_CN Inum_number
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   148
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   149
  text{* Second attempt *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   150
lemma "1 * (2*x + (y::nat)) \<noteq> 0"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   151
  apply (reify Inum_eqs ("1 * (2*x + (y::nat))"))
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   152
oops
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   153
  text{* That was fine, so let's try another one \dots *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   154
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   155
lemma "1 * (2* x + (y::nat) + 0 + 1) \<noteq> 0"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   156
  apply (reify Inum_eqs ("1 * (2*x + (y::nat) + 0 + 1)"))
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   157
oops
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   158
  text{* Oh!! 0 is not a variable \dots\ Oh! 0 is not a @{text "number_of"} \dots\ thing. The same for 1. So let's add those equations too *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   159
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   160
lemma Inum_01: "Inum (C 0) vs = 0" "Inum (C 1) vs = 1" "Inum (C(Suc n)) vs = Suc n"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   161
  by simp+
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   162
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   163
lemmas Inum_eqs'= Inum_eqs Inum_01
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   164
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   165
text{* Third attempt: *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   166
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   167
lemma "1 * (2*x + (y::nat) + 0 + 1) \<noteq> 0"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   168
  apply (reify Inum_eqs' ("1 * (2*x + (y::nat) + 0 + 1)"))
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   169
oops
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   170
text{* Okay, let's try reflection. Some simplifications on num follow. You can skim until the main theorem @{text linum} *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   171
consts lin_add :: "num \<times> num \<Rightarrow> num"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   172
recdef lin_add "measure (\<lambda>(x,y). ((size x) + (size y)))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   173
  "lin_add (CN n1 c1 r1,CN n2 c2 r2) =
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   174
  (if n1=n2 then 
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   175
  (let c = c1 + c2
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   176
  in (if c=0 then lin_add(r1,r2) else CN n1 c (lin_add (r1,r2))))
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   177
  else if n1 \<le> n2 then (CN n1 c1 (lin_add (r1,CN n2 c2 r2))) 
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   178
  else (CN n2 c2 (lin_add (CN n1 c1 r1,r2))))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   179
  "lin_add (CN n1 c1 r1,t) = CN n1 c1 (lin_add (r1, t))"  
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   180
  "lin_add (t,CN n2 c2 r2) = CN n2 c2 (lin_add (t,r2))" 
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   181
  "lin_add (C b1, C b2) = C (b1+b2)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   182
  "lin_add (a,b) = Add a b"
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   183
lemma lin_add: "Inum (lin_add (t,s)) bs = Inum (Add t s) bs"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   184
apply (induct t s rule: lin_add.induct, simp_all add: Let_def)
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   185
apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all)
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 28866
diff changeset
   186
by (case_tac "n1 = n2", simp_all add: algebra_simps)
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   187
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   188
consts lin_mul :: "num \<Rightarrow> nat \<Rightarrow> num"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   189
recdef lin_mul "measure size "
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   190
  "lin_mul (C j) = (\<lambda> i. C (i*j))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   191
  "lin_mul (CN n c a) = (\<lambda> i. if i=0 then (C 0) else CN n (i*c) (lin_mul a i))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   192
  "lin_mul t = (\<lambda> i. Mul i t)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   193
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   194
lemma lin_mul: "Inum (lin_mul t i) bs = Inum (Mul i t) bs"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 28866
diff changeset
   195
by (induct t arbitrary: i rule: lin_mul.induct, auto simp add: algebra_simps)
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   196
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   197
consts linum:: "num \<Rightarrow> num"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   198
recdef linum "measure num_size"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   199
  "linum (C b) = C b"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   200
  "linum (Var n) = CN n 1 (C 0)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   201
  "linum (Add t s) = lin_add (linum t, linum s)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   202
  "linum (Mul c t) = lin_mul (linum t) c"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   203
  "linum (CN n c t) = lin_add (linum (Mul c (Var n)),linum t)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   204
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   205
lemma linum[reflection] : "Inum (linum t) bs = Inum t bs"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   206
by (induct t rule: linum.induct, simp_all add: lin_mul lin_add)
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   207
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   208
  text{* Now we can use linum to simplify nat terms using reflection *}
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   209
lemma "(Suc (Suc 1)) * (x + (Suc 1)*y) = 3*x + 6*y"
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   210
 apply (reflection Inum_eqs' only: "(Suc (Suc 1)) * (x + (Suc 1)*y)") 
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   211
oops
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   212
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   213
  text{* Let's lift this to formulae and see what happens *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   214
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   215
datatype aform = Lt num num  | Eq num num | Ge num num | NEq num num | 
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   216
  Conj aform aform | Disj aform aform | NEG aform | T | F
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   217
consts linaformsize:: "aform \<Rightarrow> nat"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   218
recdef linaformsize "measure size"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   219
  "linaformsize T = 1"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   220
  "linaformsize F = 1"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   221
  "linaformsize (Lt a b) = 1"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   222
  "linaformsize (Ge a b) = 1"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   223
  "linaformsize (Eq a b) = 1"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   224
  "linaformsize (NEq a b) = 1"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   225
  "linaformsize (NEG p) = 2 + linaformsize p"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   226
  "linaformsize (Conj p q) = 1 + linaformsize p + linaformsize q"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   227
  "linaformsize (Disj p q) = 1 + linaformsize p + linaformsize q"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   228
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   229
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   230
consts is_aform :: "aform => nat list => bool"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   231
primrec
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   232
  "is_aform T vs = True"
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   233
  "is_aform F vs = False"
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   234
  "is_aform (Lt a b) vs = (Inum a vs < Inum b vs)"
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   235
  "is_aform (Eq a b) vs = (Inum a vs = Inum b vs)"
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   236
  "is_aform (Ge a b) vs = (Inum a vs \<ge> Inum b vs)"
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   237
  "is_aform (NEq a b) vs = (Inum a vs \<noteq> Inum b vs)"
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   238
  "is_aform (NEG p) vs = (\<not> (is_aform p vs))"
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   239
  "is_aform (Conj p q) vs = (is_aform p vs \<and> is_aform q vs)"
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   240
  "is_aform (Disj p q) vs = (is_aform p vs \<or> is_aform q vs)"
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   241
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   242
  text{* Let's reify and do reflection *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   243
lemma "(3::nat)*x + t < 0 \<and> (2 * x + y \<noteq> 17)"
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   244
 apply (reify Inum_eqs' is_aform.simps) 
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   245
oops
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   246
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   247
text{* Note that reification handles several interpretations at the same time*}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   248
lemma "(3::nat)*x + t < 0 & x*x + t*x + 3 + 1 = z*t*4*z | x + x + 1 < 0"
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   249
 apply (reflection Inum_eqs' is_aform.simps only:"x + x + 1") 
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   250
oops
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   251
20337
36e2fae2c68a *** empty log message ***
chaieb
parents: 20319
diff changeset
   252
  text{* For reflection we now define a simple transformation on aform: NNF + linum on atoms *}
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   253
consts linaform:: "aform \<Rightarrow> aform"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   254
recdef linaform "measure linaformsize"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   255
  "linaform (Lt s t) = Lt (linum s) (linum t)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   256
  "linaform (Eq s t) = Eq (linum s) (linum t)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   257
  "linaform (Ge s t) = Ge (linum s) (linum t)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   258
  "linaform (NEq s t) = NEq (linum s) (linum t)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   259
  "linaform (Conj p q) = Conj (linaform p) (linaform q)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   260
  "linaform (Disj p q) = Disj (linaform p) (linaform q)"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   261
  "linaform (NEG T) = F"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   262
  "linaform (NEG F) = T"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   263
  "linaform (NEG (Lt a b)) = Ge a b"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   264
  "linaform (NEG (Ge a b)) = Lt a b"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   265
  "linaform (NEG (Eq a b)) = NEq a b"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   266
  "linaform (NEG (NEq a b)) = Eq a b"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   267
  "linaform (NEG (NEG p)) = linaform p"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   268
  "linaform (NEG (Conj p q)) = Disj (linaform (NEG p)) (linaform (NEG q))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   269
  "linaform (NEG (Disj p q)) = Conj (linaform (NEG p)) (linaform (NEG q))"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   270
  "linaform p = p"
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   271
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   272
lemma linaform: "is_aform (linaform p) vs = is_aform p vs"
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   273
  by (induct p rule: linaform.induct) (auto simp add: linum)
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   274
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   275
lemma "(((Suc(Suc (Suc 0)))*((x::nat) + (Suc (Suc 0)))) + (Suc (Suc (Suc 0))) * ((Suc(Suc (Suc 0)))*((x::nat) + (Suc (Suc 0))))< 0) \<and> (Suc 0  + Suc 0< 0)"
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   276
   apply (reflection Inum_eqs' is_aform.simps rules: linaform)  
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   277
oops
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   278
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   279
declare linaform[reflection]
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   280
lemma "(((Suc(Suc (Suc 0)))*((x::nat) + (Suc (Suc 0)))) + (Suc (Suc (Suc 0))) * ((Suc(Suc (Suc 0)))*((x::nat) + (Suc (Suc 0))))< 0) \<and> (Suc 0  + Suc 0< 0)"
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   281
   apply (reflection Inum_eqs' is_aform.simps)
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   282
oops
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   283
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   284
text{* We now give an example where Interpretaions have 0 or more than only one envornement of different types and show that automatic reification also deals with binding *}
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   285
datatype rb = BC bool| BAnd rb rb | BOr rb rb
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   286
consts Irb :: "rb \<Rightarrow> bool"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   287
primrec
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   288
  "Irb (BC p) = p"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   289
  "Irb (BAnd s t) = (Irb s \<and> Irb t)"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   290
  "Irb (BOr s t) = (Irb s \<or> Irb t)"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   291
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   292
lemma "A \<and> (B \<or> D \<and> B) \<and> A \<and> (B \<or> D \<and> B) \<or> A \<and> (B \<or> D \<and> B) \<or> A \<and> (B \<or> D \<and> B)"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   293
apply (reify Irb.simps)
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   294
oops
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   295
23650
0a6a719d24d5 Show the use of reflection attribute; fixed comments about the order of absorbing equations : f (C x) = x ; now automaically tried as last;
chaieb
parents: 23624
diff changeset
   296
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   297
datatype rint = IC int| IVar nat | IAdd rint rint | IMult rint rint | INeg rint | ISub rint rint
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   298
consts Irint :: "rint \<Rightarrow> int list \<Rightarrow> int"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   299
primrec
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   300
Irint_Var: "Irint (IVar n) vs = vs!n"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   301
Irint_Neg: "Irint (INeg t) vs = - Irint t vs"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   302
Irint_Add: "Irint (IAdd s t) vs = Irint s vs + Irint t vs"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   303
Irint_Sub: "Irint (ISub s t) vs = Irint s vs - Irint t vs"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   304
Irint_Mult: "Irint (IMult s t) vs = Irint s vs * Irint t vs"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   305
Irint_C: "Irint (IC i) vs = i"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   306
lemma Irint_C0: "Irint (IC 0) vs = 0"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   307
  by simp
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   308
lemma Irint_C1: "Irint (IC 1) vs = 1"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   309
  by simp
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   310
lemma Irint_Cnumberof: "Irint (IC (number_of x)) vs = number_of x"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   311
  by simp
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   312
lemmas Irint_simps = Irint_Var Irint_Neg Irint_Add Irint_Sub Irint_Mult Irint_C0 Irint_C1 Irint_Cnumberof 
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   313
lemma "(3::int) * x + y*y - 9 + (- z) = 0"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   314
  apply (reify Irint_simps ("(3::int) * x + y*y - 9 + (- z)"))
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   315
  oops
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   316
datatype rlist = LVar nat| LEmpty| LCons rint rlist | LAppend rlist rlist
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   317
consts Irlist :: "rlist \<Rightarrow> int list \<Rightarrow> (int list) list \<Rightarrow> (int list)"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   318
primrec
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   319
  "Irlist (LEmpty) is vs = []"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   320
  "Irlist (LVar n) is vs = vs!n"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   321
  "Irlist (LCons i t) is vs = ((Irint i is)#(Irlist t is vs))"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   322
  "Irlist (LAppend s t) is vs = (Irlist s is vs) @ (Irlist t is vs)"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   323
lemma "[(1::int)] = []"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   324
  apply (reify Irlist.simps Irint_simps ("[1]:: int list"))
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   325
  oops
20374
01b711328990 Reification now handels binders.
chaieb
parents: 20337
diff changeset
   326
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   327
lemma "([(3::int) * x + y*y - 9 + (- z)] @ []) @ xs = [y*y - z - 9 + (3::int) * x]"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   328
  apply (reify Irlist.simps Irint_simps ("([(3::int) * x + y*y - 9 + (- z)] @ []) @ xs"))
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   329
  oops
20374
01b711328990 Reification now handels binders.
chaieb
parents: 20337
diff changeset
   330
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   331
datatype rnat = NC nat| NVar nat| NSuc rnat | NAdd rnat rnat | NMult rnat rnat | NNeg rnat | NSub rnat rnat | Nlgth rlist
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   332
consts Irnat :: "rnat \<Rightarrow> int list \<Rightarrow> (int list) list \<Rightarrow> nat list \<Rightarrow> nat"
20374
01b711328990 Reification now handels binders.
chaieb
parents: 20337
diff changeset
   333
primrec
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   334
Irnat_Suc: "Irnat (NSuc t) is ls vs = Suc (Irnat t is ls vs)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   335
Irnat_Var: "Irnat (NVar n) is ls vs = vs!n"
28866
30cd9d89a0fb reactivated some dead theories (based on hints by Mark Hillebrand);
wenzelm
parents: 23650
diff changeset
   336
Irnat_Neg: "Irnat (NNeg t) is ls vs = 0"
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   337
Irnat_Add: "Irnat (NAdd s t) is ls vs = Irnat s is ls vs + Irnat t is ls vs"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   338
Irnat_Sub: "Irnat (NSub s t) is ls vs = Irnat s is ls vs - Irnat t is ls vs"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   339
Irnat_Mult: "Irnat (NMult s t) is ls vs = Irnat s is ls vs * Irnat t is ls vs"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   340
Irnat_lgth: "Irnat (Nlgth rxs) is ls vs = length (Irlist rxs is ls)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   341
Irnat_C: "Irnat (NC i) is ls vs = i"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   342
lemma Irnat_C0: "Irnat (NC 0) is ls vs = 0"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   343
by simp
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   344
lemma Irnat_C1: "Irnat (NC 1) is ls vs = 1"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   345
by simp
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   346
lemma Irnat_Cnumberof: "Irnat (NC (number_of x)) is ls vs = number_of x"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   347
by simp
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   348
lemmas Irnat_simps = Irnat_Suc Irnat_Var Irnat_Neg Irnat_Add Irnat_Sub Irnat_Mult Irnat_lgth
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   349
  Irnat_C0 Irnat_C1 Irnat_Cnumberof
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   350
lemma "(Suc n) * length (([(3::int) * x + y*y - 9 + (- z)] @ []) @ xs) = length xs"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   351
  apply (reify Irnat_simps Irlist.simps Irint_simps ("(Suc n) *length (([(3::int) * x + y*y - 9 + (- z)] @ []) @ xs)"))
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   352
  oops
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   353
datatype rifm = RT | RF | RVar nat
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   354
  | RNLT rnat rnat | RNILT rnat rint | RNEQ rnat rnat
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   355
  |RAnd rifm rifm | ROr rifm rifm | RImp rifm rifm| RIff rifm rifm
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   356
  | RNEX rifm | RIEX rifm| RLEX rifm | RNALL rifm | RIALL rifm| RLALL rifm
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   357
  | RBEX rifm | RBALL rifm
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   358
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   359
consts Irifm :: "rifm \<Rightarrow> bool list \<Rightarrow> int list \<Rightarrow> (int list) list \<Rightarrow> nat list \<Rightarrow> bool"
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   360
primrec
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   361
"Irifm RT ps is ls ns = True"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   362
"Irifm RF ps is ls ns = False"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   363
"Irifm (RVar n) ps is ls ns = ps!n"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   364
"Irifm (RNLT s t) ps is ls ns = (Irnat s is ls ns < Irnat t is ls ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   365
"Irifm (RNILT s t) ps is ls ns = (int (Irnat s is ls ns) < Irint t is)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   366
"Irifm (RNEQ s t) ps is ls ns = (Irnat s is ls ns = Irnat t is ls ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   367
"Irifm (RAnd p q) ps is ls ns = (Irifm p ps is ls ns \<and> Irifm q ps is ls ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   368
"Irifm (ROr p q) ps is ls ns = (Irifm p ps is ls ns \<or> Irifm q ps is ls ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   369
"Irifm (RImp p q) ps is ls ns = (Irifm p ps is ls ns \<longrightarrow> Irifm q ps is ls ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   370
"Irifm (RIff p q) ps is ls ns = (Irifm p ps is ls ns = Irifm q ps is ls ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   371
"Irifm (RNEX p) ps is ls ns =  (\<exists>x. Irifm p ps is ls (x#ns))"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   372
"Irifm (RIEX p) ps is ls ns =  (\<exists>x. Irifm p ps (x#is) ls ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   373
"Irifm (RLEX p) ps is ls ns =  (\<exists>x. Irifm p ps is (x#ls) ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   374
"Irifm (RBEX p) ps is ls ns =  (\<exists>x. Irifm p (x#ps) is ls ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   375
"Irifm (RNALL p) ps is ls ns = (\<forall>x. Irifm p ps is ls (x#ns))"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   376
"Irifm (RIALL p) ps is ls ns = (\<forall>x. Irifm p ps (x#is) ls ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   377
"Irifm (RLALL p) ps is ls ns = (\<forall>x. Irifm p ps is (x#ls) ns)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   378
"Irifm (RBALL p) ps is ls ns = (\<forall>x. Irifm p (x#ps) is ls ns)"
20374
01b711328990 Reification now handels binders.
chaieb
parents: 20337
diff changeset
   379
20564
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   380
lemma " \<forall>x. \<exists>n. ((Suc n) * length (([(3::int) * x + (f t)*y - 9 + (- z)] @ []) @ xs) = length xs) \<and> m < 5*n - length (xs @ [2,3,4,x*z + 8 - y]) \<longrightarrow> (\<exists>p. \<forall>q. p \<and> q \<longrightarrow> r)"
6857bd9f1a79 Reifiaction now deals with Interpretations with an arbtrary number of parameters. It deals with binding. The Atomic cases can be I ... = f (xs!n)
chaieb
parents: 20503
diff changeset
   381
  apply (reify Irifm.simps Irnat_simps Irlist.simps Irint_simps)
20374
01b711328990 Reification now handels binders.
chaieb
parents: 20337
diff changeset
   382
oops
01b711328990 Reification now handels binders.
chaieb
parents: 20337
diff changeset
   383
22199
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   384
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   385
  (* An example for equations containing type variables *)	
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   386
datatype prod = Zero | One | Var nat | Mul prod prod 
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   387
  | Pw prod nat | PNM nat nat prod
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   388
consts Iprod :: " prod \<Rightarrow> ('a::{ordered_idom,recpower}) list \<Rightarrow>'a" 
22199
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   389
primrec
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   390
  "Iprod Zero vs = 0"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   391
  "Iprod One vs = 1"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   392
  "Iprod (Var n) vs = vs!n"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   393
  "Iprod (Mul a b) vs = (Iprod a vs * Iprod b vs)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   394
  "Iprod (Pw a n) vs = ((Iprod a vs) ^ n)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   395
  "Iprod (PNM n k t) vs = (vs ! n)^k * Iprod t vs"
22199
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   396
consts prodmul:: "prod \<times> prod \<Rightarrow> prod"
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   397
datatype sgn = Pos prod | Neg prod | ZeroEq prod | NZeroEq prod | Tr | F 
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   398
  | Or sgn sgn | And sgn sgn
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   399
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   400
consts Isgn :: " sgn \<Rightarrow> ('a::{ordered_idom, recpower}) list \<Rightarrow>bool"
22199
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   401
primrec 
23624
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   402
  "Isgn Tr vs = True"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   403
  "Isgn F vs = False"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   404
  "Isgn (ZeroEq t) vs = (Iprod t vs = 0)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   405
  "Isgn (NZeroEq t) vs = (Iprod t vs \<noteq> 0)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   406
  "Isgn (Pos t) vs = (Iprod t vs > 0)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   407
  "Isgn (Neg t) vs = (Iprod t vs < 0)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   408
  "Isgn (And p q) vs = (Isgn p vs \<and> Isgn q vs)"
82091387f6d7 The order for parameter for interpretation is now inversted:
chaieb
parents: 23608
diff changeset
   409
  "Isgn (Or p q) vs = (Isgn p vs \<or> Isgn q vs)"
22199
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   410
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   411
lemmas eqs = Isgn.simps Iprod.simps
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   412
23547
cb1203d8897c More examples
chaieb
parents: 23477
diff changeset
   413
lemma "(x::'a::{ordered_idom, recpower})^4 * y * z * y^2 * z^23 > 0"
22199
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   414
  apply (reify eqs)
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   415
  oops
b617ddd200eb Now deals with simples cases where the input equations contain type variables
chaieb
parents: 20564
diff changeset
   416
20319
a8761e8568de Generic reflection and reification (by Amine Chaieb).
wenzelm
parents:
diff changeset
   417
end