summary |
shortlog |
changelog |
graph |
tags |
branches |
files |
changeset |
file |
revisions |
annotate |
diff |
raw

src/HOL/TLA/Intensional.thy

author | haftmann |

Fri Jun 11 17:14:02 2010 +0200 (2010-06-11) | |

changeset 37407 | 61dd8c145da7 |

parent 35354 | 2e8dc3c64430 |

child 38549 | d0385f2764d8 |

permissions | -rw-r--r-- |

declare lex_prod_def [code del]

1 (* Title: HOL/TLA/Intensional.thy

2 Author: Stephan Merz

3 Copyright: 1998 University of Munich

4 *)

6 header {* A framework for "intensional" (possible-world based) logics

7 on top of HOL, with lifting of constants and functions *}

9 theory Intensional

10 imports Main

11 begin

13 classes world

14 classrel world < type

16 (** abstract syntax **)

18 types

19 ('w,'a) expr = "'w => 'a" (* intention: 'w::world, 'a::type *)

20 'w form = "('w, bool) expr"

22 consts

23 Valid :: "('w::world) form => bool"

24 const :: "'a => ('w::world, 'a) expr"

25 lift :: "['a => 'b, ('w::world, 'a) expr] => ('w,'b) expr"

26 lift2 :: "['a => 'b => 'c, ('w::world,'a) expr, ('w,'b) expr] => ('w,'c) expr"

27 lift3 :: "['a => 'b => 'c => 'd, ('w::world,'a) expr, ('w,'b) expr, ('w,'c) expr] => ('w,'d) expr"

29 (* "Rigid" quantification (logic level) *)

30 RAll :: "('a => ('w::world) form) => 'w form" (binder "Rall " 10)

31 REx :: "('a => ('w::world) form) => 'w form" (binder "Rex " 10)

32 REx1 :: "('a => ('w::world) form) => 'w form" (binder "Rex! " 10)

34 (** concrete syntax **)

36 nonterminals

37 lift

38 liftargs

40 syntax

41 "" :: "id => lift" ("_")

42 "" :: "longid => lift" ("_")

43 "" :: "var => lift" ("_")

44 "_applC" :: "[lift, cargs] => lift" ("(1_/ _)" [1000, 1000] 999)

45 "" :: "lift => lift" ("'(_')")

46 "_lambda" :: "[idts, 'a] => lift" ("(3%_./ _)" [0, 3] 3)

47 "_constrain" :: "[lift, type] => lift" ("(_::_)" [4, 0] 3)

48 "" :: "lift => liftargs" ("_")

49 "_liftargs" :: "[lift, liftargs] => liftargs" ("_,/ _")

50 "_Valid" :: "lift => bool" ("(|- _)" 5)

51 "_holdsAt" :: "['a, lift] => bool" ("(_ |= _)" [100,10] 10)

53 (* Syntax for lifted expressions outside the scope of |- or |= *)

54 "_LIFT" :: "lift => 'a" ("LIFT _")

56 (* generic syntax for lifted constants and functions *)

57 "_const" :: "'a => lift" ("(#_)" [1000] 999)

58 "_lift" :: "['a, lift] => lift" ("(_<_>)" [1000] 999)

59 "_lift2" :: "['a, lift, lift] => lift" ("(_<_,/ _>)" [1000] 999)

60 "_lift3" :: "['a, lift, lift, lift] => lift" ("(_<_,/ _,/ _>)" [1000] 999)

62 (* concrete syntax for common infix functions: reuse same symbol *)

63 "_liftEqu" :: "[lift, lift] => lift" ("(_ =/ _)" [50,51] 50)

64 "_liftNeq" :: "[lift, lift] => lift" ("(_ ~=/ _)" [50,51] 50)

65 "_liftNot" :: "lift => lift" ("(~ _)" [40] 40)

66 "_liftAnd" :: "[lift, lift] => lift" ("(_ &/ _)" [36,35] 35)

67 "_liftOr" :: "[lift, lift] => lift" ("(_ |/ _)" [31,30] 30)

68 "_liftImp" :: "[lift, lift] => lift" ("(_ -->/ _)" [26,25] 25)

69 "_liftIf" :: "[lift, lift, lift] => lift" ("(if (_)/ then (_)/ else (_))" 10)

70 "_liftPlus" :: "[lift, lift] => lift" ("(_ +/ _)" [66,65] 65)

71 "_liftMinus" :: "[lift, lift] => lift" ("(_ -/ _)" [66,65] 65)

72 "_liftTimes" :: "[lift, lift] => lift" ("(_ */ _)" [71,70] 70)

73 "_liftDiv" :: "[lift, lift] => lift" ("(_ div _)" [71,70] 70)

74 "_liftMod" :: "[lift, lift] => lift" ("(_ mod _)" [71,70] 70)

75 "_liftLess" :: "[lift, lift] => lift" ("(_/ < _)" [50, 51] 50)

76 "_liftLeq" :: "[lift, lift] => lift" ("(_/ <= _)" [50, 51] 50)

77 "_liftMem" :: "[lift, lift] => lift" ("(_/ : _)" [50, 51] 50)

78 "_liftNotMem" :: "[lift, lift] => lift" ("(_/ ~: _)" [50, 51] 50)

79 "_liftFinset" :: "liftargs => lift" ("{(_)}")

80 (** TODO: syntax for lifted collection / comprehension **)

81 "_liftPair" :: "[lift,liftargs] => lift" ("(1'(_,/ _'))")

82 (* infix syntax for list operations *)

83 "_liftCons" :: "[lift, lift] => lift" ("(_ #/ _)" [65,66] 65)

84 "_liftApp" :: "[lift, lift] => lift" ("(_ @/ _)" [65,66] 65)

85 "_liftList" :: "liftargs => lift" ("[(_)]")

87 (* Rigid quantification (syntax level) *)

88 "_ARAll" :: "[idts, lift] => lift" ("(3! _./ _)" [0, 10] 10)

89 "_AREx" :: "[idts, lift] => lift" ("(3? _./ _)" [0, 10] 10)

90 "_AREx1" :: "[idts, lift] => lift" ("(3?! _./ _)" [0, 10] 10)

91 "_RAll" :: "[idts, lift] => lift" ("(3ALL _./ _)" [0, 10] 10)

92 "_REx" :: "[idts, lift] => lift" ("(3EX _./ _)" [0, 10] 10)

93 "_REx1" :: "[idts, lift] => lift" ("(3EX! _./ _)" [0, 10] 10)

95 translations

96 "_const" == "CONST const"

97 "_lift" == "CONST lift"

98 "_lift2" == "CONST lift2"

99 "_lift3" == "CONST lift3"

100 "_Valid" == "CONST Valid"

101 "_RAll x A" == "Rall x. A"

102 "_REx x A" == "Rex x. A"

103 "_REx1 x A" == "Rex! x. A"

104 "_ARAll" => "_RAll"

105 "_AREx" => "_REx"

106 "_AREx1" => "_REx1"

108 "w |= A" => "A w"

109 "LIFT A" => "A::_=>_"

111 "_liftEqu" == "_lift2 (op =)"

112 "_liftNeq u v" == "_liftNot (_liftEqu u v)"

113 "_liftNot" == "_lift (CONST Not)"

114 "_liftAnd" == "_lift2 (op &)"

115 "_liftOr" == "_lift2 (op | )"

116 "_liftImp" == "_lift2 (op -->)"

117 "_liftIf" == "_lift3 (CONST If)"

118 "_liftPlus" == "_lift2 (op +)"

119 "_liftMinus" == "_lift2 (op -)"

120 "_liftTimes" == "_lift2 (op *)"

121 "_liftDiv" == "_lift2 (op div)"

122 "_liftMod" == "_lift2 (op mod)"

123 "_liftLess" == "_lift2 (op <)"

124 "_liftLeq" == "_lift2 (op <=)"

125 "_liftMem" == "_lift2 (op :)"

126 "_liftNotMem x xs" == "_liftNot (_liftMem x xs)"

127 "_liftFinset (_liftargs x xs)" == "_lift2 (CONST insert) x (_liftFinset xs)"

128 "_liftFinset x" == "_lift2 (CONST insert) x (_const {})"

129 "_liftPair x (_liftargs y z)" == "_liftPair x (_liftPair y z)"

130 "_liftPair" == "_lift2 (CONST Pair)"

131 "_liftCons" == "CONST lift2 (CONST Cons)"

132 "_liftApp" == "CONST lift2 (op @)"

133 "_liftList (_liftargs x xs)" == "_liftCons x (_liftList xs)"

134 "_liftList x" == "_liftCons x (_const [])"

138 "w |= ~A" <= "_liftNot A w"

139 "w |= A & B" <= "_liftAnd A B w"

140 "w |= A | B" <= "_liftOr A B w"

141 "w |= A --> B" <= "_liftImp A B w"

142 "w |= u = v" <= "_liftEqu u v w"

143 "w |= ALL x. A" <= "_RAll x A w"

144 "w |= EX x. A" <= "_REx x A w"

145 "w |= EX! x. A" <= "_REx1 x A w"

147 syntax (xsymbols)

148 "_Valid" :: "lift => bool" ("(\<turnstile> _)" 5)

149 "_holdsAt" :: "['a, lift] => bool" ("(_ \<Turnstile> _)" [100,10] 10)

150 "_liftNeq" :: "[lift, lift] => lift" (infixl "\<noteq>" 50)

151 "_liftNot" :: "lift => lift" ("\<not> _" [40] 40)

152 "_liftAnd" :: "[lift, lift] => lift" (infixr "\<and>" 35)

153 "_liftOr" :: "[lift, lift] => lift" (infixr "\<or>" 30)

154 "_liftImp" :: "[lift, lift] => lift" (infixr "\<longrightarrow>" 25)

155 "_RAll" :: "[idts, lift] => lift" ("(3\<forall>_./ _)" [0, 10] 10)

156 "_REx" :: "[idts, lift] => lift" ("(3\<exists>_./ _)" [0, 10] 10)

157 "_REx1" :: "[idts, lift] => lift" ("(3\<exists>!_./ _)" [0, 10] 10)

158 "_liftLeq" :: "[lift, lift] => lift" ("(_/ \<le> _)" [50, 51] 50)

159 "_liftMem" :: "[lift, lift] => lift" ("(_/ \<in> _)" [50, 51] 50)

160 "_liftNotMem" :: "[lift, lift] => lift" ("(_/ \<notin> _)" [50, 51] 50)

162 syntax (HTML output)

163 "_liftNeq" :: "[lift, lift] => lift" (infixl "\<noteq>" 50)

164 "_liftNot" :: "lift => lift" ("\<not> _" [40] 40)

165 "_liftAnd" :: "[lift, lift] => lift" (infixr "\<and>" 35)

166 "_liftOr" :: "[lift, lift] => lift" (infixr "\<or>" 30)

167 "_RAll" :: "[idts, lift] => lift" ("(3\<forall>_./ _)" [0, 10] 10)

168 "_REx" :: "[idts, lift] => lift" ("(3\<exists>_./ _)" [0, 10] 10)

169 "_REx1" :: "[idts, lift] => lift" ("(3\<exists>!_./ _)" [0, 10] 10)

170 "_liftLeq" :: "[lift, lift] => lift" ("(_/ \<le> _)" [50, 51] 50)

171 "_liftMem" :: "[lift, lift] => lift" ("(_/ \<in> _)" [50, 51] 50)

172 "_liftNotMem" :: "[lift, lift] => lift" ("(_/ \<notin> _)" [50, 51] 50)

174 defs

175 Valid_def: "|- A == ALL w. w |= A"

177 unl_con: "LIFT #c w == c"

178 unl_lift: "lift f x w == f (x w)"

179 unl_lift2: "LIFT f<x, y> w == f (x w) (y w)"

180 unl_lift3: "LIFT f<x, y, z> w == f (x w) (y w) (z w)"

182 unl_Rall: "w |= ALL x. A x == ALL x. (w |= A x)"

183 unl_Rex: "w |= EX x. A x == EX x. (w |= A x)"

184 unl_Rex1: "w |= EX! x. A x == EX! x. (w |= A x)"

187 subsection {* Lemmas and tactics for "intensional" logics. *}

189 lemmas intensional_rews [simp] =

190 unl_con unl_lift unl_lift2 unl_lift3 unl_Rall unl_Rex unl_Rex1

192 lemma inteq_reflection: "|- x=y ==> (x==y)"

193 apply (unfold Valid_def unl_lift2)

194 apply (rule eq_reflection)

195 apply (rule ext)

196 apply (erule spec)

197 done

199 lemma intI [intro!]: "(!!w. w |= A) ==> |- A"

200 apply (unfold Valid_def)

201 apply (rule allI)

202 apply (erule meta_spec)

203 done

205 lemma intD [dest]: "|- A ==> w |= A"

206 apply (unfold Valid_def)

207 apply (erule spec)

208 done

210 (** Lift usual HOL simplifications to "intensional" level. **)

212 lemma int_simps:

213 "|- (x=x) = #True"

214 "|- (~#True) = #False" "|- (~#False) = #True" "|- (~~ P) = P"

215 "|- ((~P) = P) = #False" "|- (P = (~P)) = #False"

216 "|- (P ~= Q) = (P = (~Q))"

217 "|- (#True=P) = P" "|- (P=#True) = P"

218 "|- (#True --> P) = P" "|- (#False --> P) = #True"

219 "|- (P --> #True) = #True" "|- (P --> P) = #True"

220 "|- (P --> #False) = (~P)" "|- (P --> ~P) = (~P)"

221 "|- (P & #True) = P" "|- (#True & P) = P"

222 "|- (P & #False) = #False" "|- (#False & P) = #False"

223 "|- (P & P) = P" "|- (P & ~P) = #False" "|- (~P & P) = #False"

224 "|- (P | #True) = #True" "|- (#True | P) = #True"

225 "|- (P | #False) = P" "|- (#False | P) = P"

226 "|- (P | P) = P" "|- (P | ~P) = #True" "|- (~P | P) = #True"

227 "|- (! x. P) = P" "|- (? x. P) = P"

228 "|- (~Q --> ~P) = (P --> Q)"

229 "|- (P|Q --> R) = ((P-->R)&(Q-->R))"

230 apply (unfold Valid_def intensional_rews)

231 apply blast+

232 done

234 declare int_simps [THEN inteq_reflection, simp]

236 lemma TrueW [simp]: "|- #True"

237 by (simp add: Valid_def unl_con)

241 (* ======== Functions to "unlift" intensional implications into HOL rules ====== *)

243 ML {*

244 (* Basic unlifting introduces a parameter "w" and applies basic rewrites, e.g.

245 |- F = G becomes F w = G w

246 |- F --> G becomes F w --> G w

247 *)

249 fun int_unlift th =

250 rewrite_rule @{thms intensional_rews} (th RS @{thm intD} handle THM _ => th);

252 (* Turn |- F = G into meta-level rewrite rule F == G *)

253 fun int_rewrite th =

254 zero_var_indexes (rewrite_rule @{thms intensional_rews} (th RS @{thm inteq_reflection}))

256 (* flattening turns "-->" into "==>" and eliminates conjunctions in the

257 antecedent. For example,

259 P & Q --> (R | S --> T) becomes [| P; Q; R | S |] ==> T

261 Flattening can be useful with "intensional" lemmas (after unlifting).

262 Naive resolution with mp and conjI may run away because of higher-order

263 unification, therefore the code is a little awkward.

264 *)

265 fun flatten t =

266 let

267 (* analogous to RS, but using matching instead of resolution *)

268 fun matchres tha i thb =

269 case Seq.chop 2 (Thm.biresolution true [(false,tha)] i thb) of

270 ([th],_) => th

271 | ([],_) => raise THM("matchres: no match", i, [tha,thb])

272 | _ => raise THM("matchres: multiple unifiers", i, [tha,thb])

274 (* match tha with some premise of thb *)

275 fun matchsome tha thb =

276 let fun hmatch 0 = raise THM("matchsome: no match", 0, [tha,thb])

277 | hmatch n = matchres tha n thb handle THM _ => hmatch (n-1)

278 in hmatch (nprems_of thb) end

280 fun hflatten t =

281 case (concl_of t) of

282 Const _ $ (Const ("op -->", _) $ _ $ _) => hflatten (t RS mp)

283 | _ => (hflatten (matchsome conjI t)) handle THM _ => zero_var_indexes t

284 in

285 hflatten t

286 end

288 fun int_use th =

289 case (concl_of th) of

290 Const _ $ (Const ("Intensional.Valid", _) $ _) =>

291 (flatten (int_unlift th) handle THM _ => th)

292 | _ => th

293 *}

295 attribute_setup int_unlift = {* Scan.succeed (Thm.rule_attribute (K int_unlift)) *} ""

296 attribute_setup int_rewrite = {* Scan.succeed (Thm.rule_attribute (K int_rewrite)) *} ""

297 attribute_setup flatten = {* Scan.succeed (Thm.rule_attribute (K flatten)) *} ""

298 attribute_setup int_use = {* Scan.succeed (Thm.rule_attribute (K int_use)) *} ""

300 lemma Not_Rall: "|- (~(! x. F x)) = (? x. ~F x)"

301 by (simp add: Valid_def)

303 lemma Not_Rex: "|- (~ (? x. F x)) = (! x. ~ F x)"

304 by (simp add: Valid_def)

306 end