-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScenes.thy
More file actions
674 lines (507 loc) · 34.5 KB
/
Scenes.thy
File metadata and controls
674 lines (507 loc) · 34.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
section \<open> Scenes \<close>
theory Scenes
imports Lens_Symmetric
begin
text \<open> Like lenses, scenes characterise a region of a source type. However, unlike lenses, scenes
do not explicitly assign a view type to this region, and consequently they have just one type
parameter. This means they can be more flexibly composed, and in particular it is possible to
show they form nice algebraic structures in Isabelle/HOL. They are mainly of use in characterising
sets of variables, where, of course, we do not care about the types of those variables and
therefore representing them as lenses is inconvenient. \<close>
subsection \<open> Overriding Functions \<close>
text \<open> Overriding functions provide an abstract way of replacing a region of an existing source
with the corresponding region of another source. \<close>
locale overrider =
fixes F :: "'s \<Rightarrow> 's \<Rightarrow> 's" (infixl "\<triangleright>" 65)
assumes
ovr_overshadow_left: "x \<triangleright> y \<triangleright> z = x \<triangleright> z" and
ovr_overshadow_right: "x \<triangleright> (y \<triangleright> z) = x \<triangleright> z"
begin
lemma ovr_assoc: "x \<triangleright> (y \<triangleright> z) = x \<triangleright> y \<triangleright> z"
by (simp add: ovr_overshadow_left ovr_overshadow_right)
end
locale idem_overrider = overrider +
assumes ovr_idem: "x \<triangleright> x = x"
declare overrider.ovr_overshadow_left [simp]
declare overrider.ovr_overshadow_right [simp]
declare idem_overrider.ovr_idem [simp]
subsection \<open> Scene Type \<close>
typedef 's scene = "{F :: 's \<Rightarrow> 's \<Rightarrow> 's. overrider F}"
by (rule_tac x="\<lambda> x y. x" in exI, simp, unfold_locales, simp_all)
setup_lifting type_definition_scene
lift_definition idem_scene :: "'s scene \<Rightarrow> bool" is idem_overrider .
lift_definition region :: "'s scene \<Rightarrow> 's rel"
is "\<lambda> F. {(s\<^sub>1, s\<^sub>2). (\<forall> s. F s s\<^sub>1 = F s s\<^sub>2)}" .
lift_definition coregion :: "'s scene \<Rightarrow> 's rel"
is "\<lambda> F. {(s\<^sub>1, s\<^sub>2). (\<forall> s. F s\<^sub>1 s = F s\<^sub>2 s)}" .
lemma equiv_region: "equiv UNIV (region X)"
apply (transfer)
apply (rule equivI)
apply (rule refl_onI)
apply (auto)
apply (rule symI)
apply (auto)
apply (rule transI)
apply (auto)
done
lemma equiv_coregion: "equiv UNIV (coregion X)"
apply (transfer)
apply (rule equivI)
apply (rule refl_onI)
apply (auto)
apply (rule symI)
apply (auto)
apply (rule transI)
apply (auto)
done
lemma region_coregion_Id:
"idem_scene X \<Longrightarrow> region X \<inter> coregion X = Id"
by (transfer, auto, metis idem_overrider.ovr_idem)
lemma state_eq_iff: "idem_scene S \<Longrightarrow> x = y \<longleftrightarrow> (x, y) \<in> region S \<and> (x, y) \<in> coregion S"
by (metis IntE IntI pair_in_Id_conv region_coregion_Id)
lift_definition scene_override :: "'a \<Rightarrow> 'a \<Rightarrow> ('a scene) \<Rightarrow> 'a" ("_ \<oplus>\<^sub>S _ on _" [95,0,96] 95)
is "\<lambda> s\<^sub>1 s\<^sub>2 F. F s\<^sub>1 s\<^sub>2" .
abbreviation (input) scene_copy :: "'a scene \<Rightarrow> 'a \<Rightarrow> ('a \<Rightarrow> 'a)" ("cp\<^bsub>_\<^esub>") where
"cp\<^bsub>A\<^esub> s \<equiv> (\<lambda> s'. s' \<oplus>\<^sub>S s on A)"
lemma scene_override_idem [simp]: "idem_scene X \<Longrightarrow> s \<oplus>\<^sub>S s on X = s"
by (transfer, simp)
lemma scene_override_overshadow_left [simp]:
"S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on X \<oplus>\<^sub>S S\<^sub>3 on X = S\<^sub>1 \<oplus>\<^sub>S S\<^sub>3 on X"
by (transfer, simp)
lemma scene_override_overshadow_right [simp]:
"S\<^sub>1 \<oplus>\<^sub>S (S\<^sub>2 \<oplus>\<^sub>S S\<^sub>3 on X) on X = S\<^sub>1 \<oplus>\<^sub>S S\<^sub>3 on X"
by (transfer, simp)
definition scene_equiv :: "'a \<Rightarrow> 'a \<Rightarrow> ('a scene) \<Rightarrow> bool" ("_ \<approx>\<^sub>S _ on _" [65,0,66] 65) where
[lens_defs]: "S\<^sub>1 \<approx>\<^sub>S S\<^sub>2 on X = (S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on X = S\<^sub>1)"
lemma scene_equiv_region: "idem_scene X \<Longrightarrow> region X = {(S\<^sub>1, S\<^sub>2). S\<^sub>1 \<approx>\<^sub>S S\<^sub>2 on X}"
by (simp add: lens_defs, transfer, auto)
(metis idem_overrider.ovr_idem, metis overrider.ovr_overshadow_right)
lift_definition scene_indep :: "'a scene \<Rightarrow> 'a scene \<Rightarrow> bool" (infix "\<bowtie>\<^sub>S" 50)
is "\<lambda> F G. (\<forall> s\<^sub>1 s\<^sub>2 s\<^sub>3. G (F s\<^sub>1 s\<^sub>2) s\<^sub>3 = F (G s\<^sub>1 s\<^sub>3) s\<^sub>2)" .
lemma scene_indep_override:
"X \<bowtie>\<^sub>S Y = (\<forall> s\<^sub>1 s\<^sub>2 s\<^sub>3. s\<^sub>1 \<oplus>\<^sub>S s\<^sub>2 on X \<oplus>\<^sub>S s\<^sub>3 on Y = s\<^sub>1 \<oplus>\<^sub>S s\<^sub>3 on Y \<oplus>\<^sub>S s\<^sub>2 on X)"
by (transfer, auto)
lemma scene_indep_copy:
"X \<bowtie>\<^sub>S Y = (\<forall> s\<^sub>1 s\<^sub>2. cp\<^bsub>X\<^esub> s\<^sub>1 \<circ> cp\<^bsub>Y\<^esub> s\<^sub>2 = cp\<^bsub>Y\<^esub> s\<^sub>2 \<circ> cp\<^bsub>X\<^esub> s\<^sub>1)"
by (auto simp add: scene_indep_override comp_def fun_eq_iff)
lemma scene_indep_sym:
"X \<bowtie>\<^sub>S Y \<Longrightarrow> Y \<bowtie>\<^sub>S X"
by (transfer, auto)
text \<open> Compatibility is a weaker notion than independence; the scenes can overlap but they must
agree when they do. \<close>
lift_definition scene_compat :: "'a scene \<Rightarrow> 'a scene \<Rightarrow> bool" (infix "##\<^sub>S" 50)
is "\<lambda> F G. (\<forall> s\<^sub>1 s\<^sub>2. G (F s\<^sub>1 s\<^sub>2) s\<^sub>2 = F (G s\<^sub>1 s\<^sub>2) s\<^sub>2)" .
lemma scene_compat_copy:
"X ##\<^sub>S Y = (\<forall> s. cp\<^bsub>X\<^esub> s \<circ> cp\<^bsub>Y\<^esub> s = cp\<^bsub>Y\<^esub> s \<circ> cp\<^bsub>X\<^esub> s)"
by (transfer, auto simp add: fun_eq_iff)
lemma scene_indep_compat [simp]: "X \<bowtie>\<^sub>S Y \<Longrightarrow> X ##\<^sub>S Y"
by (transfer, auto)
lemma scene_compat_refl: "X ##\<^sub>S X"
by (transfer, simp)
lemma scene_compat_sym: "X ##\<^sub>S Y \<Longrightarrow> Y ##\<^sub>S X"
by (transfer, simp)
lemma scene_override_commute_indep:
assumes "X \<bowtie>\<^sub>S Y"
shows "S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on X \<oplus>\<^sub>S S\<^sub>3 on Y = S\<^sub>1 \<oplus>\<^sub>S S\<^sub>3 on Y \<oplus>\<^sub>S S\<^sub>2 on X"
using assms
by (transfer, auto)
instantiation scene :: (type) "{bot, top, uminus, sup, inf}"
begin
lift_definition bot_scene :: "'a scene" is "\<lambda> x y. x" by (unfold_locales, simp_all)
lift_definition top_scene :: "'a scene" is "\<lambda> x y. y" by (unfold_locales, simp_all)
lift_definition uminus_scene :: "'a scene \<Rightarrow> 'a scene" is "\<lambda> F x y. F y x"
by (unfold_locales, simp_all)
text \<open> Scene union requires that the two scenes are at least compatible. If they are not, the
result is the bottom scene. \<close>
lift_definition sup_scene :: "'a scene \<Rightarrow> 'a scene \<Rightarrow> 'a scene"
is "\<lambda> F G. if (\<forall> s\<^sub>1 s\<^sub>2. G (F s\<^sub>1 s\<^sub>2) s\<^sub>2 = F (G s\<^sub>1 s\<^sub>2) s\<^sub>2) then (\<lambda> s\<^sub>1 s\<^sub>2. G (F s\<^sub>1 s\<^sub>2) s\<^sub>2) else (\<lambda> s\<^sub>1 s\<^sub>2. s\<^sub>1)"
by (unfold_locales, auto, metis overrider.ovr_overshadow_right)
definition inf_scene :: "'a scene \<Rightarrow> 'a scene \<Rightarrow> 'a scene" where
[lens_defs]: "inf_scene X Y = - (sup (- X) (- Y))"
instance ..
end
abbreviation union_scene :: "'s scene \<Rightarrow> 's scene \<Rightarrow> 's scene" (infixl "\<squnion>\<^sub>S" 65)
where "union_scene \<equiv> sup"
abbreviation inter_scene :: "'s scene \<Rightarrow> 's scene \<Rightarrow> 's scene" (infixl "\<sqinter>\<^sub>S" 70)
where "inter_scene \<equiv> inf"
abbreviation top_scene :: "'s scene" ("\<top>\<^sub>S")
where "top_scene \<equiv> top"
abbreviation bot_scene :: "'s scene" ("\<bottom>\<^sub>S")
where "bot_scene \<equiv> bot"
instantiation scene :: (type) "minus"
begin
definition minus_scene :: "'a scene \<Rightarrow> 'a scene \<Rightarrow> 'a scene" where
"minus_scene A B = A \<sqinter>\<^sub>S (- B)"
instance ..
end
lemma bot_idem_scene [simp]: "idem_scene \<bottom>\<^sub>S"
by (transfer, unfold_locales, simp_all)
lemma top_idem_scene [simp]: "idem_scene \<top>\<^sub>S"
by (transfer, unfold_locales, simp_all)
lemma uminus_top_scene [simp]: "- \<top>\<^sub>S = \<bottom>\<^sub>S"
by (transfer, simp)
lemma uminus_bot_scene [simp]: "- \<bottom>\<^sub>S = \<top>\<^sub>S"
by (transfer, simp)
lemma uminus_scene_twice: "- (- (X :: 's scene)) = X"
by (transfer, simp)
lemma inj_uminus_scene: "inj (uminus :: 'a scene \<Rightarrow> 'a scene)"
by (metis injI uminus_scene_twice)
lemma scene_override_id [simp]: "S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on \<top>\<^sub>S = S\<^sub>2"
by (transfer, simp)
lemma scene_override_unit [simp]: "S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on \<bottom>\<^sub>S = S\<^sub>1"
by (transfer, simp)
lemma scene_override_commute: "S\<^sub>2 \<oplus>\<^sub>S S\<^sub>1 on (- X) = S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on X"
by (transfer, simp)
lemma scene_union_incompat: "\<not> X ##\<^sub>S Y \<Longrightarrow> X \<squnion>\<^sub>S Y = \<bottom>\<^sub>S"
by (transfer, auto)
lemma scene_override_union: "X ##\<^sub>S Y \<Longrightarrow> S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on (X \<squnion>\<^sub>S Y) = (S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on X) \<oplus>\<^sub>S S\<^sub>2 on Y"
by (transfer, auto)
lemma scene_override_inter: "-X ##\<^sub>S -Y \<Longrightarrow> S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on (X \<sqinter>\<^sub>S Y) = S\<^sub>1 \<oplus>\<^sub>S S\<^sub>1 \<oplus>\<^sub>S S\<^sub>2 on X on Y"
by (simp add: inf_scene_def scene_override_commute scene_override_union)
lemma scene_equiv_bot [simp]: "a \<approx>\<^sub>S b on \<bottom>\<^sub>S"
by (simp add: scene_equiv_def)
lemma scene_equiv_refl [simp]: "idem_scene a \<Longrightarrow> s \<approx>\<^sub>S s on a"
by (simp add: scene_equiv_def)
lemma scene_equiv_sym: "idem_scene a \<Longrightarrow> s\<^sub>1 \<approx>\<^sub>S s\<^sub>2 on a \<Longrightarrow> s\<^sub>2 \<approx>\<^sub>S s\<^sub>1 on a"
by (metis scene_equiv_def scene_override_idem scene_override_overshadow_right)
lemma scene_union_unit [simp]: "X \<squnion>\<^sub>S \<bottom>\<^sub>S = X" "\<bottom>\<^sub>S \<squnion>\<^sub>S X = X"
by (transfer, simp)+
lemma scene_indep_bot [simp]: "X \<bowtie>\<^sub>S \<bottom>\<^sub>S"
by (transfer, simp)
text \<open> A unitary scene admits only one element, and therefore top and bottom are the same. \<close>
lemma unit_scene_top_eq_bot: "(\<bottom>\<^sub>S :: unit scene) = \<top>\<^sub>S"
by (transfer, simp)
lemma idem_scene_union [simp]: "\<lbrakk> idem_scene A; idem_scene B \<rbrakk> \<Longrightarrow> idem_scene (A \<squnion>\<^sub>S B)"
apply (transfer, auto)
apply (unfold_locales, auto)
apply (metis overrider.ovr_overshadow_left)
apply (metis overrider.ovr_overshadow_right)
done
lemma scene_union_annhil: "idem_scene X \<Longrightarrow> X \<squnion>\<^sub>S \<top>\<^sub>S = \<top>\<^sub>S"
by (transfer, simp)
lemma scene_union_pres_compat: "\<lbrakk> A ##\<^sub>S B; A ##\<^sub>S C \<rbrakk> \<Longrightarrow> A ##\<^sub>S (B \<squnion>\<^sub>S C)"
by (transfer, auto)
lemma scene_indep_pres_compat: "\<lbrakk> A \<bowtie>\<^sub>S B; A \<bowtie>\<^sub>S C \<rbrakk> \<Longrightarrow> A \<bowtie>\<^sub>S (B \<squnion>\<^sub>S C)"
by (transfer, auto)
lemma scene_indep_self_compl: "A \<bowtie>\<^sub>S -A"
by (transfer, simp)
lemma scene_compat_self_compl: "A ##\<^sub>S -A"
by (transfer, simp)
lemma scene_compat_bot [simp]: "a ##\<^sub>S \<bottom>\<^sub>S" "\<bottom>\<^sub>S ##\<^sub>S a"
by (transfer, simp)+
lemma scene_compat_top [simp]:
"idem_scene a \<Longrightarrow> a ##\<^sub>S \<top>\<^sub>S"
"idem_scene a \<Longrightarrow> \<top>\<^sub>S ##\<^sub>S a"
by (transfer, simp)+
lemma scene_union_assoc:
assumes "X ##\<^sub>S Y" "X ##\<^sub>S Z" "Y ##\<^sub>S Z"
shows "X \<squnion>\<^sub>S (Y \<squnion>\<^sub>S Z) = (X \<squnion>\<^sub>S Y) \<squnion>\<^sub>S Z"
using assms by (transfer, auto)
lemma scene_inter_indep:
assumes "idem_scene X" "idem_scene Y" "X \<bowtie>\<^sub>S Y"
shows "X \<sqinter>\<^sub>S Y = \<bottom>\<^sub>S"
using assms
unfolding lens_defs
apply (transfer, auto)
apply (metis (no_types, opaque_lifting) idem_overrider.ovr_idem overrider.ovr_assoc overrider.ovr_overshadow_right)
apply (metis (no_types, opaque_lifting) idem_overrider.ovr_idem overrider.ovr_overshadow_right)
done
lemma scene_union_indep_uniq:
assumes "idem_scene X" "idem_scene Y" "idem_scene Z" "X \<bowtie>\<^sub>S Z" "Y \<bowtie>\<^sub>S Z" "X \<squnion>\<^sub>S Z = Y \<squnion>\<^sub>S Z"
shows "X = Y"
using assms apply (transfer, simp)
by (metis (no_types, opaque_lifting) ext idem_overrider.ovr_idem overrider_def)
lemma scene_union_idem: "X \<squnion>\<^sub>S X = X"
by (transfer, simp)
lemma scene_union_compl: "idem_scene X \<Longrightarrow> X \<squnion>\<^sub>S - X = \<top>\<^sub>S"
by (transfer, auto)
lemma scene_inter_idem: "X \<sqinter>\<^sub>S X = X"
by (simp add: inf_scene_def, transfer, auto)
lemma scene_union_commute: "X \<squnion>\<^sub>S Y = Y \<squnion>\<^sub>S X"
by (transfer, auto)
lemma scene_inter_compl: "idem_scene X \<Longrightarrow> X \<sqinter>\<^sub>S - X = \<bottom>\<^sub>S"
by (simp add: inf_scene_def, transfer, auto)
lemma scene_demorgan1: "-(X \<squnion>\<^sub>S Y) = -X \<sqinter>\<^sub>S -Y"
by (simp add: inf_scene_def, transfer, auto)
lemma scene_demorgan2: "-(X \<sqinter>\<^sub>S Y) = -X \<squnion>\<^sub>S -Y"
by (simp add: inf_scene_def, transfer, auto)
lemma scene_inter_commute: "X \<sqinter>\<^sub>S Y = Y \<sqinter>\<^sub>S X"
by (simp add: inf_scene_def scene_union_commute)
lemma scene_union_inter_distrib:
"\<lbrakk> idem_scene x; x \<bowtie>\<^sub>S y; x \<bowtie>\<^sub>S z; y ##\<^sub>S z \<rbrakk> \<Longrightarrow> x \<squnion>\<^sub>S y \<sqinter>\<^sub>S z = (x \<squnion>\<^sub>S y) \<sqinter>\<^sub>S (x \<squnion>\<^sub>S z)"
apply (simp add: inf_scene_def, transfer)
apply (auto simp add: fun_eq_iff)
apply (unfold overrider_def idem_overrider_def idem_overrider_axioms_def)
apply metis+
done
lemma idem_scene_uminus [simp]: "idem_scene X \<Longrightarrow> idem_scene (- X)"
by (simp add: uminus_scene_def idem_scene_def Abs_scene_inverse idem_overrider_axioms_def idem_overrider_def overrider.intro)
lemma scene_minus_cancel: "\<lbrakk> a \<bowtie>\<^sub>S b; idem_scene a; idem_scene b \<rbrakk> \<Longrightarrow> a \<squnion>\<^sub>S (b \<sqinter>\<^sub>S - a) = a \<squnion>\<^sub>S b"
apply (simp add: lens_defs, transfer, auto simp add: fun_eq_iff)
apply (metis (mono_tags, lifting) overrider.ovr_overshadow_left)
apply (metis (no_types, opaque_lifting) idem_overrider.ovr_idem overrider.ovr_overshadow_right)
done
instantiation scene :: (type) ord
begin
text \<open> $X$ is a subscene of $Y$ provided that overriding with first $Y$ and then $X$ can
be rewritten using the complement of $X$. \<close>
definition less_eq_scene :: "'a scene \<Rightarrow> 'a scene \<Rightarrow> bool" where
[lens_defs]: "less_eq_scene X Y = (\<forall> s\<^sub>1 s\<^sub>2 s\<^sub>3. s\<^sub>1 \<oplus>\<^sub>S s\<^sub>2 on Y \<oplus>\<^sub>S s\<^sub>3 on X = s\<^sub>1 \<oplus>\<^sub>S (s\<^sub>2 \<oplus>\<^sub>S s\<^sub>3 on X) on Y)"
definition less_scene :: "'a scene \<Rightarrow> 'a scene \<Rightarrow> bool" where
[lens_defs]: "less_scene x y = (x \<le> y \<and> \<not> y \<le> x)"
instance ..
end
abbreviation subscene :: "'a scene \<Rightarrow> 'a scene \<Rightarrow> bool" (infix "\<subseteq>\<^sub>S" 55)
where "subscene X Y \<equiv> X \<le> Y"
lemma subscene_refl: "X \<subseteq>\<^sub>S X"
by (simp add: less_eq_scene_def)
lemma subscene_trans: "\<lbrakk> idem_scene Y; X \<subseteq>\<^sub>S Y; Y \<subseteq>\<^sub>S Z \<rbrakk> \<Longrightarrow> X \<subseteq>\<^sub>S Z"
by (simp add: less_eq_scene_def, transfer, auto, metis (no_types, opaque_lifting) idem_overrider.ovr_idem)
lemma subscene_antisym: "\<lbrakk> idem_scene Y; X \<subseteq>\<^sub>S Y; Y \<subseteq>\<^sub>S X \<rbrakk> \<Longrightarrow> X = Y"
apply (simp add: less_eq_scene_def, transfer, auto)
apply (rule ext)
apply (rule ext)
apply (metis (full_types) idem_overrider.ovr_idem overrider.ovr_overshadow_left)
done
lemma subscene_copy_def:
assumes "idem_scene X" "idem_scene Y"
shows "X \<subseteq>\<^sub>S Y = (\<forall> s\<^sub>1 s\<^sub>2. cp\<^bsub>X\<^esub> s\<^sub>1 \<circ> cp\<^bsub>Y\<^esub> s\<^sub>2 = cp\<^bsub>Y\<^esub> (cp\<^bsub>X\<^esub> s\<^sub>1 s\<^sub>2))"
using assms
by (simp add: less_eq_scene_def fun_eq_iff, transfer, auto)
lemma subscene_eliminate:
"\<lbrakk> idem_scene Y; X \<le> Y \<rbrakk> \<Longrightarrow> s\<^sub>1 \<oplus>\<^sub>S s\<^sub>2 on X \<oplus>\<^sub>S s\<^sub>3 on Y = s\<^sub>1 \<oplus>\<^sub>S s\<^sub>3 on Y"
by (metis less_eq_scene_def scene_override_overshadow_left scene_override_idem)
lemma scene_bot_least: "\<bottom>\<^sub>S \<le> X"
unfolding less_eq_scene_def by (transfer, auto)
lemma scene_top_greatest: "X \<le> \<top>\<^sub>S"
unfolding less_eq_scene_def by (transfer, auto)
lemma scene_union_ub: "\<lbrakk> idem_scene Y; X \<bowtie>\<^sub>S Y \<rbrakk> \<Longrightarrow> X \<le> (X \<squnion>\<^sub>S Y)"
by (simp add: less_eq_scene_def, transfer, auto)
(metis (no_types, opaque_lifting) idem_overrider.ovr_idem overrider.ovr_overshadow_right)
lemma scene_union_lb: "\<lbrakk> a ##\<^sub>S b; a \<le> c; b \<le> c \<rbrakk> \<Longrightarrow> a \<squnion>\<^sub>S b \<le> c"
by (simp add: less_eq_scene_def scene_override_union)
lemma scene_union_mono: "\<lbrakk> a \<subseteq>\<^sub>S c; b \<subseteq>\<^sub>S c; a ##\<^sub>S b; idem_scene a; idem_scene b \<rbrakk> \<Longrightarrow> a \<squnion>\<^sub>S b \<subseteq>\<^sub>S c"
by (simp add: less_eq_scene_def, transfer, auto)
lemma scene_le_then_compat: "\<lbrakk> idem_scene X; idem_scene Y; X \<le> Y \<rbrakk> \<Longrightarrow> X ##\<^sub>S Y"
unfolding less_eq_scene_def
by (transfer, auto, metis (no_types, lifting) idem_overrider.ovr_idem overrider_def)
lemma indep_then_compl_in: "A \<bowtie>\<^sub>S B \<Longrightarrow> A \<le> -B"
unfolding less_eq_scene_def by (transfer, simp)
lemma scene_override_overshadow_indep:
assumes "idem_scene b" "a \<bowtie>\<^sub>S b"
shows "s\<^sub>3 \<oplus>\<^sub>S (s\<^sub>1 \<oplus>\<^sub>S s\<^sub>2 on a) on b = s\<^sub>3 \<oplus>\<^sub>S s\<^sub>1 on b"
by (metis assms(1,2) idem_scene_uminus indep_then_compl_in scene_override_commute subscene_eliminate)
lemma scene_le_iff_indep_inv:
"A \<bowtie>\<^sub>S - B \<longleftrightarrow> A \<le> B"
by (auto simp add: less_eq_scene_def scene_indep_override scene_override_commute)
lift_definition scene_comp :: "'a scene \<Rightarrow> ('a \<Longrightarrow> 'b) \<Rightarrow> 'b scene" (infixl ";\<^sub>S" 80)
is "\<lambda> S X a b. if (vwb_lens X) then put\<^bsub>X\<^esub> a (S (get\<^bsub>X\<^esub> a) (get\<^bsub>X\<^esub> b)) else a"
by (unfold_locales, auto)
lemma scene_comp_idem [simp]: "idem_scene S \<Longrightarrow> idem_scene (S ;\<^sub>S X)"
by (transfer, unfold_locales, simp_all)
lemma scene_comp_lens_indep [simp]: "X \<bowtie> Y \<Longrightarrow> (A ;\<^sub>S X) \<bowtie>\<^sub>S (A ;\<^sub>S Y)"
by (transfer, auto simp add: lens_indep.lens_put_comm lens_indep.lens_put_irr2)
lemma scene_comp_indep [simp]: "A \<bowtie>\<^sub>S B \<Longrightarrow> (A ;\<^sub>S X) \<bowtie>\<^sub>S (B ;\<^sub>S X)"
by (transfer, auto)
lemma scene_comp_bot [simp]: "\<bottom>\<^sub>S ;\<^sub>S x = \<bottom>\<^sub>S"
by (transfer, auto)
lemma scene_comp_id_lens [simp]: "A ;\<^sub>S 1\<^sub>L = A"
by (transfer, auto, simp add: id_lens_def)
lemma scene_union_comp_distl: "a ##\<^sub>S b \<Longrightarrow> (a \<squnion>\<^sub>S b) ;\<^sub>S x = (a ;\<^sub>S x) \<squnion>\<^sub>S (b ;\<^sub>S x)"
by (transfer, auto simp add: fun_eq_iff)
lemma scene_comp_assoc: "\<lbrakk> vwb_lens X; vwb_lens Y \<rbrakk> \<Longrightarrow> A ;\<^sub>S X ;\<^sub>S Y = A ;\<^sub>S (X ;\<^sub>L Y)"
by (transfer, auto simp add: lens_comp_def fun_eq_iff)
(metis comp_vwb_lens lens_comp_def)
lemma scene_comp_quot_eq [simp]:
assumes "vwb_lens y" "vwb_lens z" "y \<subseteq>\<^sub>L z"
shows "x ;\<^sub>S (y /\<^sub>L z) ;\<^sub>S z = x ;\<^sub>S y"
by (simp add: assms(1,2,3) lens_quotient_comp lens_quotient_vwb scene_comp_assoc)
lift_definition scene_quotient :: "'b scene \<Rightarrow> ('a \<Longrightarrow> 'b) \<Rightarrow> 'a scene" (infixl "'/\<^sub>S" 80)
is "\<lambda> S X a b. if (vwb_lens X \<and> (\<forall>s\<^sub>1 s\<^sub>2 s\<^sub>3. S (s\<^sub>1 \<triangleleft>\<^bsub>X\<^esub> s\<^sub>2) s\<^sub>3 = s\<^sub>1 \<triangleleft>\<^bsub>X\<^esub> S s\<^sub>2 s\<^sub>3)) then get\<^bsub>X\<^esub> (S (create\<^bsub>X\<^esub> a) (create\<^bsub>X\<^esub> b)) else a"
by (unfold_locales, auto simp add: lens_create_def lens_override_def)
(metis (no_types, lifting) overrider.ovr_overshadow_right)
lemma scene_quotient_idem: "idem_scene S \<Longrightarrow> idem_scene (S /\<^sub>S X)"
by (transfer, unfold_locales, auto simp add: lens_create_def lens_override_def)
(metis (no_types, lifting) overrider.ovr_overshadow_right)
lemma scene_quotient_indep: "A \<bowtie>\<^sub>S B \<Longrightarrow> (A /\<^sub>S X) \<bowtie>\<^sub>S (B /\<^sub>S X)"
by (transfer, auto simp add: lens_create_def lens_override_def)
lemma scene_bot_quotient [simp]: "\<bottom>\<^sub>S /\<^sub>S X = \<bottom>\<^sub>S"
by (transfer, auto)
lemma scene_comp_quotient: "vwb_lens X \<Longrightarrow> (A ;\<^sub>S X) /\<^sub>S X = A"
by (transfer, auto simp add: fun_eq_iff lens_override_def)
lemma scene_quot_id_lens [simp]: "(A /\<^sub>S 1\<^sub>L) = A"
by (transfer, simp, simp add: lens_defs)
subsection \<open> Linking Scenes and Lenses \<close>
text \<open> The following function extracts a scene from a very well behaved lens \<close>
lift_definition lens_scene :: "('v \<Longrightarrow> 's) \<Rightarrow> 's scene" ("\<lbrakk>_\<rbrakk>\<^sub>\<sim>") is
"\<lambda> X s\<^sub>1 s\<^sub>2. if (mwb_lens X) then s\<^sub>1 \<oplus>\<^sub>L s\<^sub>2 on X else s\<^sub>1"
by (unfold_locales, auto simp add: lens_override_def)
lemma vwb_impl_idem_scene [simp]:
"vwb_lens X \<Longrightarrow> idem_scene \<lbrakk>X\<rbrakk>\<^sub>\<sim>"
by (transfer, unfold_locales, auto simp add: lens_override_overshadow_left lens_override_overshadow_right)
lemma idem_scene_impl_vwb:
"\<lbrakk> mwb_lens X; idem_scene \<lbrakk>X\<rbrakk>\<^sub>\<sim> \<rbrakk> \<Longrightarrow> vwb_lens X"
apply (cases "mwb_lens X")
apply (transfer, unfold idem_overrider_def overrider_def, auto)
apply (simp add: idem_overrider_axioms_def override_idem_implies_vwb)
done
lemma lens_compat_scene: "\<lbrakk> mwb_lens X; mwb_lens Y \<rbrakk> \<Longrightarrow> X ##\<^sub>L Y \<longleftrightarrow> \<lbrakk>X\<rbrakk>\<^sub>\<sim> ##\<^sub>S \<lbrakk>Y\<rbrakk>\<^sub>\<sim>"
by (auto simp add: lens_scene.rep_eq scene_compat.rep_eq lens_defs)
text \<open> Next we show some important congruence properties \<close>
lemma zero_lens_scene: "\<lbrakk>0\<^sub>L\<rbrakk>\<^sub>\<sim> = \<bottom>\<^sub>S"
by (transfer, simp)
lemma one_lens_scene: "\<lbrakk>1\<^sub>L\<rbrakk>\<^sub>\<sim> = \<top>\<^sub>S"
by (transfer, simp)
lemma scene_comp_top_scene [simp]: "vwb_lens x \<Longrightarrow> \<top>\<^sub>S ;\<^sub>S x = \<lbrakk>x\<rbrakk>\<^sub>\<sim>"
by (transfer, simp add: fun_eq_iff lens_override_def)
lemma scene_comp_lens_scene_indep [simp]: "x \<bowtie> y \<Longrightarrow> \<lbrakk>x\<rbrakk>\<^sub>\<sim> \<bowtie>\<^sub>S a ;\<^sub>S y"
by (transfer, simp add: lens_indep.lens_put_comm lens_indep.lens_put_irr2 lens_override_def)
lemma lens_scene_override:
"mwb_lens X \<Longrightarrow> s\<^sub>1 \<oplus>\<^sub>S s\<^sub>2 on \<lbrakk>X\<rbrakk>\<^sub>\<sim> = s\<^sub>1 \<oplus>\<^sub>L s\<^sub>2 on X"
by (transfer, simp)
lemma lens_indep_scene:
assumes "vwb_lens X" "vwb_lens Y"
shows "(X \<bowtie> Y) \<longleftrightarrow> \<lbrakk>X\<rbrakk>\<^sub>\<sim> \<bowtie>\<^sub>S \<lbrakk>Y\<rbrakk>\<^sub>\<sim>"
using assms
by (auto, (simp add: scene_indep_override, transfer, simp add: lens_indep_override_def)+)
lemma lens_indep_impl_scene_indep [simp]:
"(X \<bowtie> Y) \<Longrightarrow> \<lbrakk>X\<rbrakk>\<^sub>\<sim> \<bowtie>\<^sub>S \<lbrakk>Y\<rbrakk>\<^sub>\<sim>"
by (transfer, auto simp add: lens_indep_comm lens_override_def)
lemma get_scene_override_indep:
assumes "vwb_lens x" "\<lbrakk>x\<rbrakk>\<^sub>\<sim> \<bowtie>\<^sub>S a"
shows "get\<^bsub>x\<^esub> (s \<oplus>\<^sub>S s' on a) = get\<^bsub>x\<^esub> s"
by (metis assms(1,2) lens_override_def lens_scene_override mwb_lens_def scene_indep_sym scene_override_overshadow_indep vwb_impl_idem_scene vwb_lens_mwb
weak_lens.view_determination)
lemma put_scene_override_indep:
"\<lbrakk> vwb_lens x; \<lbrakk>x\<rbrakk>\<^sub>\<sim> \<bowtie>\<^sub>S a \<rbrakk> \<Longrightarrow> put\<^bsub>x\<^esub> s v \<oplus>\<^sub>S s' on a = put\<^bsub>x\<^esub> (s \<oplus>\<^sub>S s' on a) v"
by (transfer, auto)
(metis lens_override_def mwb_lens_weak vwb_lens_mwb weak_lens.put_get)
lemma get_scene_override_le: "\<lbrakk> vwb_lens x; \<lbrakk>x\<rbrakk>\<^sub>\<sim> \<le> a \<rbrakk> \<Longrightarrow> get\<^bsub>x\<^esub> (s \<oplus>\<^sub>S s' on a) = get\<^bsub>x\<^esub> s'"
by (metis get_scene_override_indep scene_le_iff_indep_inv scene_override_commute)
lemma put_scene_override_le: "\<lbrakk> vwb_lens x; idem_scene a; \<lbrakk>x\<rbrakk>\<^sub>\<sim> \<le> a \<rbrakk> \<Longrightarrow> put\<^bsub>x\<^esub> s v \<oplus>\<^sub>S s' on a = s \<oplus>\<^sub>S s' on a"
by (metis lens_override_idem lens_override_put_right_in lens_scene_override sublens_refl subscene_eliminate vwb_lens_mwb)
lemma put_scene_override_le_distrib:
"\<lbrakk> vwb_lens x; idem_scene A; \<lbrakk>x\<rbrakk>\<^sub>\<sim> \<le> A \<rbrakk> \<Longrightarrow> put\<^bsub>x\<^esub> (s\<^sub>1 \<oplus>\<^sub>S s\<^sub>2 on A) v = (put\<^bsub>x\<^esub> s\<^sub>1 v) \<oplus>\<^sub>S (put\<^bsub>x\<^esub> s\<^sub>2 v) on A"
by (metis put_scene_override_indep put_scene_override_le scene_le_iff_indep_inv scene_override_commute)
lemma lens_plus_scene:
"\<lbrakk> vwb_lens X; vwb_lens Y; X \<bowtie> Y \<rbrakk> \<Longrightarrow> \<lbrakk>X +\<^sub>L Y\<rbrakk>\<^sub>\<sim> = \<lbrakk>X\<rbrakk>\<^sub>\<sim> \<squnion>\<^sub>S \<lbrakk>Y\<rbrakk>\<^sub>\<sim>"
by (transfer, auto simp add: lens_override_plus lens_indep_override_def lens_indep_overrideI)
lemma subscene_implies_sublens': "\<lbrakk> vwb_lens X; vwb_lens Y \<rbrakk> \<Longrightarrow> \<lbrakk>X\<rbrakk>\<^sub>\<sim> \<le> \<lbrakk>Y\<rbrakk>\<^sub>\<sim> \<longleftrightarrow> X \<subseteq>\<^sub>L' Y"
by (simp add: lens_defs, transfer, simp add: lens_override_def)
lemma sublens'_implies_subscene: "\<lbrakk> vwb_lens X; vwb_lens Y; X \<subseteq>\<^sub>L' Y \<rbrakk> \<Longrightarrow> \<lbrakk>X\<rbrakk>\<^sub>\<sim> \<le> \<lbrakk>Y\<rbrakk>\<^sub>\<sim>"
by (simp add: lens_defs, auto simp add: lens_override_def lens_scene_override)
lemma sublens_iff_subscene:
assumes "vwb_lens X" "vwb_lens Y"
shows "X \<subseteq>\<^sub>L Y \<longleftrightarrow> \<lbrakk>X\<rbrakk>\<^sub>\<sim> \<le> \<lbrakk>Y\<rbrakk>\<^sub>\<sim>"
by (simp add: assms sublens_iff_sublens' subscene_implies_sublens')
lemma lens_scene_indep_compl [simp]:
assumes "vwb_lens x" "vwb_lens y"
shows "\<lbrakk>x\<rbrakk>\<^sub>\<sim> \<bowtie>\<^sub>S - \<lbrakk>y\<rbrakk>\<^sub>\<sim> \<longleftrightarrow> x \<subseteq>\<^sub>L y"
by (simp add: assms scene_le_iff_indep_inv sublens_iff_subscene)
lemma lens_scene_comp: "\<lbrakk> vwb_lens X; vwb_lens Y \<rbrakk> \<Longrightarrow> \<lbrakk>X ;\<^sub>L Y\<rbrakk>\<^sub>\<sim> = \<lbrakk>X\<rbrakk>\<^sub>\<sim> ;\<^sub>S Y"
by (transfer, simp add: fun_eq_iff comp_vwb_lens)
(simp add: lens_comp_def lens_override_def)
lemma scene_comp_pres_indep: "\<lbrakk> idem_scene a; idem_scene b; a \<bowtie>\<^sub>S \<lbrakk>x\<rbrakk>\<^sub>\<sim> \<rbrakk> \<Longrightarrow> a \<bowtie>\<^sub>S b ;\<^sub>S x"
by (transfer, auto)
(metis (no_types, opaque_lifting) lens_override_def lens_override_idem vwb_lens_def wb_lens_weak weak_lens.put_get)
lemma scene_comp_le: "A ;\<^sub>S X \<le> \<lbrakk>X\<rbrakk>\<^sub>\<sim>"
unfolding less_eq_scene_def by (transfer, auto simp add: fun_eq_iff lens_override_def)
lemma scene_quotient_comp: "\<lbrakk> vwb_lens X; idem_scene A; A \<le> \<lbrakk>X\<rbrakk>\<^sub>\<sim> \<rbrakk> \<Longrightarrow> (A /\<^sub>S X) ;\<^sub>S X = A"
unfolding less_eq_scene_def
proof (transfer, simp add: fun_eq_iff, safe)
fix X :: "'a \<Longrightarrow> 'b" and A :: "'b \<Rightarrow> 'b \<Rightarrow> 'b" and x :: 'b and y :: 'b
assume a1: "vwb_lens X"
assume a2: "overrider A"
assume a3: "idem_overrider A"
assume a4: "\<forall>s\<^sub>1 s\<^sub>2 s\<^sub>3. A (s\<^sub>1 \<triangleleft>\<^bsub>X\<^esub> s\<^sub>2) s\<^sub>3 = s\<^sub>1 \<triangleleft>\<^bsub>X\<^esub> A s\<^sub>2 s\<^sub>3"
have "\<And>b. A b b = b"
using a3 by simp
then have "A x (put\<^bsub>X\<^esub> src\<^bsub>X\<^esub> (get\<^bsub>X\<^esub> y)) = A x y"
by (metis a2 a4 lens_override_def overrider.ovr_overshadow_right)
then show "put\<^bsub>X\<^esub> x (get\<^bsub>X\<^esub> (A (create\<^bsub>X\<^esub> (get\<^bsub>X\<^esub> x)) (create\<^bsub>X\<^esub> (get\<^bsub>X\<^esub> y)))) = A x y"
using a4 a1 by (metis lens_create_def lens_override_def vwb_lens_def wb_lens.get_put wb_lens_weak weak_lens.put_get)
qed
lemma lens_scene_quotient: "\<lbrakk> vwb_lens Y; X \<subseteq>\<^sub>L Y \<rbrakk> \<Longrightarrow> \<lbrakk>X /\<^sub>L Y\<rbrakk>\<^sub>\<sim> = \<lbrakk>X\<rbrakk>\<^sub>\<sim> /\<^sub>S Y"
by (metis lens_quotient_comp lens_quotient_vwb lens_scene_comp scene_comp_quotient sublens_pres_vwb vwb_lens_def wb_lens_weak)
lemma scene_union_quotient: "\<lbrakk> A ##\<^sub>S B; A \<le> \<lbrakk>X\<rbrakk>\<^sub>\<sim>; B \<le> \<lbrakk>X\<rbrakk>\<^sub>\<sim> \<rbrakk> \<Longrightarrow> (A \<squnion>\<^sub>S B) /\<^sub>S X = (A /\<^sub>S X) \<squnion>\<^sub>S (B /\<^sub>S X)"
unfolding less_eq_scene_def
by (case_tac "vwb_lens X"; transfer, auto simp add: lens_create_def lens_override_def)
lemma lens_scene_comp_eq [simp]:
assumes "vwb_lens x" "vwb_lens y" "x \<subseteq>\<^sub>L y"
shows "\<lbrakk>x /\<^sub>L y\<rbrakk>\<^sub>\<sim> ;\<^sub>S y = \<lbrakk>x\<rbrakk>\<^sub>\<sim>"
by (metis assms(1,2,3) lens_quotient_vwb scene_comp_quot_eq scene_comp_top_scene)
text \<open> Equality on scenes is sound and complete with respect to lens equivalence. \<close>
lemma lens_equiv_scene:
assumes "vwb_lens X" "vwb_lens Y"
shows "X \<approx>\<^sub>L Y \<longleftrightarrow> \<lbrakk>X\<rbrakk>\<^sub>\<sim> = \<lbrakk>Y\<rbrakk>\<^sub>\<sim>"
proof
assume a: "X \<approx>\<^sub>L Y"
show "\<lbrakk>X\<rbrakk>\<^sub>\<sim> = \<lbrakk>Y\<rbrakk>\<^sub>\<sim>"
by (meson a assms lens_equiv_def sublens_iff_subscene subscene_antisym vwb_impl_idem_scene)
next
assume b: "\<lbrakk>X\<rbrakk>\<^sub>\<sim> = \<lbrakk>Y\<rbrakk>\<^sub>\<sim>"
show "X \<approx>\<^sub>L Y"
by (simp add: assms b lens_equiv_def sublens_iff_subscene subscene_refl)
qed
lemma scene_lens_indep_neq:
fixes x :: "'a::two \<Longrightarrow> 's" and y :: "'b::two \<Longrightarrow> 's"
assumes "vwb_lens x" "vwb_lens y" "x \<bowtie> y"
shows "\<lbrakk>x\<rbrakk>\<^sub>\<sim> \<noteq> \<lbrakk>y\<rbrakk>\<^sub>\<sim>"
using assms(1,2,3) indep_eff_implies_not_equiv lens_equiv_scene vwb_lens_wb by blast
lemma lens_scene_top_iff_bij_lens: "mwb_lens x \<Longrightarrow> \<lbrakk>x\<rbrakk>\<^sub>\<sim> = \<top>\<^sub>S \<longleftrightarrow> bij_lens x"
apply (transfer)
apply (auto simp add: fun_eq_iff lens_override_def)
apply (unfold_locales)
apply auto
done
lemma scene_equiv_get_eq:
assumes "vwb_lens x"
shows "s \<approx>\<^sub>S s' on \<lbrakk>x\<rbrakk>\<^sub>\<sim> \<longleftrightarrow> get\<^bsub>x\<^esub> s = get\<^bsub>x\<^esub> s'"
by (metis assms get_scene_override_le lens_override_def lens_override_idem lens_scene_override
scene_equiv_def subscene_refl vwb_lens_def)
lemma scene_lens_equiv_iff:
assumes "mwb_lens x"
shows "s \<approx>\<^sub>S s' on (- \<lbrakk>x\<rbrakk>\<^sub>\<sim>) \<longleftrightarrow> s \<simeq>\<^bsub>x\<^esub> s'"
by (auto simp add: assms scene_equiv_def lens_obs_eq_def lens_override_def lens_scene_override scene_override_commute)
lemma scene_put_preserved_iff:
assumes "vwb_lens x" "y \<bowtie>\<^sub>S \<lbrakk>x\<rbrakk>\<^sub>\<sim>"
shows "(put\<^bsub>x\<^esub> s v \<approx>\<^sub>S s' on y) \<longleftrightarrow> s \<approx>\<^sub>S s' on y"
by (metis assms(1,2) put_scene_override_indep scene_equiv_def scene_indep_sym vwb_lens.put_eq)
lemma scene_le_equiv:
assumes "idem_scene B" "s \<approx>\<^sub>S s' on A" "B \<le> A"
shows "s \<approx>\<^sub>S s' on B"
by (metis assms(1,2,3) less_eq_scene_def scene_equiv_def scene_override_idem)
lemma scene_equiv_union_decomp:
assumes "a ##\<^sub>S b"
shows "s \<approx>\<^sub>S s' on (a \<squnion>\<^sub>S b) \<longleftrightarrow> (s \<approx>\<^sub>S s' on a \<and> s \<approx>\<^sub>S s' on b)"
by (metis assms scene_compat_refl scene_compat_sym scene_equiv_def scene_override_union scene_union_commute scene_union_idem)
lemma state_eq_iff_partition:
assumes "idem_scene a"
shows "s = s' \<longleftrightarrow> (s \<approx>\<^sub>S s' on a \<and> s \<approx>\<^sub>S s' on -a)"
by (metis assms scene_equiv_def scene_equiv_refl scene_equiv_sym
scene_override_commute)
subsection \<open> Function Domain Scene \<close>
lift_definition fun_dom_scene :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b::two) scene" ("fds") is
"\<lambda> A f g. override_on f g A" by (unfold_locales, simp_all add: override_on_def fun_eq_iff)
lemma fun_dom_scene_empty: "fds({}) = \<bottom>\<^sub>S"
by (transfer, simp)
lemma fun_dom_scene_union: "fds(A \<union> B) = fds(A) \<squnion>\<^sub>S fds(B)"
by (transfer, auto simp add: fun_eq_iff override_on_def)
lemma fun_dom_scene_compl: "fds(- A) = - fds(A)"
by (transfer, auto simp add: fun_eq_iff override_on_def)
lemma fun_dom_scene_inter: "fds(A \<inter> B) = fds(A) \<sqinter>\<^sub>S fds(B)"
by (simp add: inf_scene_def fun_dom_scene_union[THEN sym] fun_dom_scene_compl[THEN sym])
lemma fun_dom_scene_UNIV: "fds(UNIV) = \<top>\<^sub>S"
by (transfer, auto simp add: fun_eq_iff override_on_def)
lemma fun_dom_scene_indep [simp]:
"fds(A) \<bowtie>\<^sub>S fds(B) \<longleftrightarrow> A \<inter> B = {}"
by (transfer, auto simp add: override_on_def fun_eq_iff, meson two_diff)
lemma fun_dom_scene_always_compat [simp]: "fds(A) ##\<^sub>S fds(B)"
by (transfer, simp add: override_on_def fun_eq_iff)
lemma fun_dom_scene_le [simp]: "fds(A) \<subseteq>\<^sub>S fds(B) \<longleftrightarrow> A \<subseteq> B"
unfolding less_eq_scene_def
by (transfer, auto simp add: override_on_def fun_eq_iff, meson two_diff)
text \<open> Hide implementation details for scenes \<close>
lifting_update scene.lifting
lifting_forget scene.lifting
end