Project 'mayero/coq-num-analysis' was moved to 'mayero/rocq-num-analysis'. Please update any links and bookmarks that may still have the old path.
Newer
Older
(**
This file is part of the Elfic library
Copyright (C) Boldo, Clément, Faissole, Martin, Mayero
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
COPYING file for more details.
*)
Subsets of the type U are represented by their belonging function,
of type U -> Prop.
Most of the properties are tautologies that can be found on Wikipedia:
https://en.wikipedia.org/wiki/List_of_set_identities_and_relations *)
From Coq Require Import Classical.
From Coq Require Import PropExtensionality FunctionalExtensionality.
Definition emptyset : U -> Prop := fun _ => False.
Definition fullset : U -> Prop := fun _ => True.
Definition singleton : U -> Prop := fun x => x = a.
Definition empty : Prop := forall x, A x -> False.
Definition full : Prop := forall x, A x.
Definition compl : U -> Prop := fun x => ~ A x.
Definition incl : Prop := forall x, A x -> B x.
Definition same : Prop := forall x, A x <-> B x.
Definition disj : Prop :=forall x, A x -> B x -> False.
(** Binary operations on subsets. *)
Definition union : U -> Prop := fun x => A x \/ B x.
Definition inter : U -> Prop := fun x => A x /\ B x.
End Base_Def1.
Section Base_Def2.
Context {U : Type}. (* Universe. *)
(** Sesquary operation on subsets. *)
Variable A : U -> Prop. (* Subset. *)
Variable a : U. (* Element. *)
Definition add : U -> Prop := union A (singleton a).
(** More binary operation on subsets. *)
Variable B : U -> Prop. (* Subset. *)
Definition diff : U -> Prop := inter A (compl B).
Variable C : U -> Prop. (* Subset. *)
Definition partition : Prop := A = union B C /\ disj B C.
End Base_Def2.
Section Base_Def3.
Context {U : Type}. (* Universe. *)
(** Binary constructor of subsets. *)
Variable a b : U. (* Elements. *)
Definition pair : U -> Prop := add (singleton a) b.
(** More binary operation on subsets. *)
Variable A B : U -> Prop. (* Subsets. *)
Definition sym_diff : U -> Prop := union (diff A B) (diff B A).
Context {U1 U2 : Type}. (* Universes. *)
Variable A1 : U1 -> Prop. (* Subset. *)
Variable A2 : U2 -> Prop. (* Subset. *)
Definition prod : U1 * U2 -> Prop :=
inter (fun x => A1 (fst x)) (fun x => A2 (snd x)).
Definition swap : forall {U : Type}, (U1 * U2 -> U) -> U2 * U1 -> U :=
fun U f x => f (snd x, fst x).
unfold partition, disj, same, incl, full, empty, (* Predicates. *)
pair,
swap, prod, sym_diff, diff, add, inter, union, compl, (* Operators. *)
singleton, fullset, emptyset. (* Constructors. *)
Ltac subset_auto :=
subset_unfold; try tauto; try easy.
Section Prop_Facts.
Context {U : Type}. (* Universe. *)
(** Extensionality of subsets. *)
Lemma subset_ext :
forall (A B : U -> Prop),
same A B -> A = B.
Proof.
intros.
apply functional_extensionality;
intros x; now apply propositional_extensionality.
Qed.

François Clément
committed
Lemma subset_ext_equiv :
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
forall (A B : U -> Prop),
A = B <-> incl A B /\ incl B A.
Proof.
intros; split.
intros H; split; now rewrite H.
intros [H1 H2]; apply subset_ext; split; [apply H1 | apply H2].
Qed.
(** Facts about emptyset and fullset. *)
Lemma empty_emptyset :
forall (A : U -> Prop),
empty A <-> A = emptyset.
Proof.
intros; split; intros H.
intros; apply subset_ext; intros x; split; try easy; intros; now apply (H x).
now rewrite H.
Qed.
Lemma full_fullset :
forall (A : U -> Prop),
full A <-> A = fullset.
Proof.
intros; split; intros H.
now apply subset_ext.
now rewrite H.
Qed.
(** Facts about singleton. *)
Lemma singleton_in :
forall a : U, singleton a a.
Proof.
subset_auto.
Qed.
Lemma singleton_out :
forall a x : U, x <> a -> compl (singleton a) x.
Proof.
subset_auto.
Qed.
(** Facts about incl. *)
(** It is an order binary relation. *)
Lemma incl_refl :
forall (A B : U -> Prop),
same A B -> incl A B.
Proof.
intros A B H x; now rewrite (H x).
Qed.
Lemma incl_antisym :
forall (A B : U -> Prop),
incl A B -> incl B A -> A = B.
Proof.

François Clément
committed
intros; now rewrite subset_ext_equiv.
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
Qed.
Lemma incl_trans :
forall (A B C : U -> Prop),
incl A B -> incl B C -> incl A C.
Proof.
intros; intros x Hx; auto.
Qed.
Lemma full_not_empty :
inhabited U <-> ~ incl (@fullset U) emptyset.
Proof.
subset_unfold; split.
intros [x]; auto.
intros H; apply exists_inhabited with (fun x => ~ (True -> False)).
now apply not_all_ex_not in H.
Qed.
Lemma incl_empty :
forall (A : U -> Prop),
incl A emptyset -> A = emptyset.
Proof.
intros A H; apply subset_ext; split; [apply H | easy].
Qed.
Lemma full_incl :
forall (A : U -> Prop),
incl fullset A -> A = fullset.
Proof.
intros A H; apply subset_ext; split; [easy | apply H].
Qed.
(** Facts about same. *)
(** It is an equivalence binary relation. *)
(* Useless?
Lemma same_refl :
forall (A : U -> Prop),
same A A.
Proof.
easy.
Qed.*)
(* This one is used! *)
Lemma same_sym :
forall (A B : U -> Prop),
same A B -> same B A.
Proof.
easy.
Qed.
Lemma same_trans :
forall (A B C : U -> Prop),
same A B -> same B C -> same A C.
Proof.
intros A B C H1 H2 x; now rewrite (H1 x).
Qed.
(** Facts about disj. *)
Lemma disj_equiv_def :
forall (A B : U -> Prop),
disj A B <-> inter A B = emptyset.
Proof.
intros; rewrite <- empty_emptyset; subset_unfold; split;
intros H x; intros; now apply (H x).
Qed.
Lemma disj_irrefl :
forall (A : U -> Prop),
disj A A <-> A = emptyset.
Proof.
intros; rewrite <- empty_emptyset; split; intros H x Hx; now apply (H x).
Qed.
Lemma disj_sym :
forall (A B : U -> Prop),
disj A B <-> disj B A.
Proof.
intros; split; intros H x Hx1 Hx2; now apply (H x).
Qed.
Lemma disj_full_l :
forall (A : U -> Prop),
disj fullset A -> A = emptyset.
Proof.
intros A H; apply empty_emptyset; intros x Hx; now apply (H x).
Qed.
Lemma disj_full_r :
forall (A : U -> Prop),
disj A fullset -> A = emptyset.
Proof.
intros A; rewrite disj_sym; apply disj_full_l.
Qed.
Lemma disj_monot_l :
forall (A B C : U -> Prop),
incl A B ->
disj B C -> disj A C.
Proof.
intros A B C H1 H2 x Hx1 Hx2; apply (H2 x); auto.
Qed.
Lemma disj_monot_r :
forall (A B C : U -> Prop),
incl A B ->
disj C B -> disj C A.
Proof.
intros A B C H1 H2 x Hx1 Hx2; apply (H2 x); auto.
Qed.
Lemma incl_disj :
forall (A B : U -> Prop),
incl A B ->
disj A B <-> A = emptyset.
Proof.
intros; split; intros H2.
apply empty_emptyset; intros x Hx; apply (H2 x); auto.
now rewrite H2.
Qed.
End Prop_Facts.
Section Compl_Facts.
(** Facts about complement. *)
Context {U : Type}. (* Universe. *)
Lemma compl_empty :
compl (@emptyset U) = fullset.
Proof.
now apply subset_ext.
Qed.
Lemma compl_full :
compl (@fullset U) = emptyset.
Proof.
apply subset_ext; subset_auto.
Qed.
Lemma compl_invol :
forall (A : U -> Prop),
compl (compl A) = A.
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.

François Clément
committed
Lemma incl_compl :
forall (A B : U -> Prop),
incl A B -> incl (compl B) (compl A).
Proof.
subset_auto; intros; intuition.
Qed.

François Clément
committed
Lemma incl_compl_equiv :
forall (A B : U -> Prop),
incl (compl B) (compl A) <-> incl A B.
Proof.
intros; split.
rewrite <- (compl_invol A) at 2; rewrite <- (compl_invol B) at 2.

François Clément
committed
apply incl_compl.
apply incl_compl.

François Clément
committed
Lemma same_compl :
forall (A B : U -> Prop),
same A B -> same (compl A) (compl B).
Proof.
subset_unfold; intros; now apply not_iff_compat.
Qed.

François Clément
committed
Lemma same_compl_equiv :
forall (A B : U -> Prop),
same (compl A) (compl B) <-> same A B.
Proof.
intros; split.
rewrite <- (compl_invol A) at 2; rewrite <- (compl_invol B) at 2.

François Clément
committed
apply same_compl.
apply same_compl.
Qed.
Lemma compl_reg :
forall (A B : U -> Prop),
same (compl A) (compl B) -> A = B.
Proof.

François Clément
committed
intros; now apply subset_ext, same_compl_equiv.
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
Qed.
Lemma compl_ext :
forall (A B : U -> Prop),
compl A = compl B -> A = B.
Proof.
intros A B H; apply compl_reg; now rewrite H.
Qed.
Lemma disj_incl_compl_r :
forall (A B : U -> Prop),
disj A B <-> incl A (compl B).
Proof.
subset_auto.
Qed.
Lemma disj_incl_compl_l :
forall (A B : U -> Prop),
disj A B <-> incl B (compl A).
Proof.
intros A B; rewrite disj_sym; apply disj_incl_compl_r.
Qed.
End Compl_Facts.
Section Union_Facts.
(** Facts about union. *)
Context {U : Type}. (* Universe. *)
Lemma union_assoc :
forall (A B C : U -> Prop),
union (union A B) C = union A (union B C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma union_comm :
forall (A B : U -> Prop),
union A B = union B A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma union_idem :
forall (A : U -> Prop),
union A A = A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma union_empty_l :
forall (A : U -> Prop),
union emptyset A = A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma union_empty_r :
forall (A : U -> Prop),
union A emptyset = A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma empty_union :
forall (A B : U -> Prop),
union A B = emptyset <-> A = emptyset /\ B = emptyset.
Proof.
intros; do 3 rewrite <- empty_emptyset; split.
intros H; split; intros x Hx; apply (H x); [now left | now right].
intros [H1 H2] x [Hx | Hx]; [now apply (H1 x) | now apply (H2 x)].
Qed.
Lemma union_full_l :
forall (A : U -> Prop),
union fullset A = fullset.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma union_full_r :
forall (A : U -> Prop),
union A fullset = fullset.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma union_ub_l :
forall (A B : U -> Prop),
incl A (union A B).
Proof.
subset_auto.
Qed.
Lemma union_ub_r :
forall (A B : U -> Prop),
incl B (union A B).
Proof.
subset_auto.
Qed.
Lemma union_lub :
forall (A B C : U -> Prop),
incl A C -> incl B C ->
incl (union A B) C.
Proof.
intros; intros x [H3 | H3]; auto.
Qed.
Lemma incl_union :
forall (A B C : U -> Prop),
incl (union A B) C -> incl A C /\ incl B C.
Proof.
intros A B C H; split; intros x Hx; apply (H x); [now left | now right].
Qed.
Lemma union_left :
forall (A B : U -> Prop),
incl A B <-> union B A = B.
Proof.
intros; split.
(* *)

François Clément
committed
intros; rewrite subset_ext_equiv; split; intros x.
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
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
intros [Hx | Hx]; auto.
intros Hx; now left.
(* *)
intros H x Hx; rewrite <- H; now right.
Qed.
Lemma union_right :
forall (A B : U -> Prop),
incl A B <-> union A B = B.
Proof.
intros A B; rewrite union_comm; apply union_left.
Qed.
Lemma union_monot_l :
forall (A B C : U -> Prop),
incl A B -> incl (union C A) (union C B).
Proof.
intros A B C H x [Hx | Hx]; [now left | right; now apply H].
Qed.
Lemma union_monot_r :
forall (A B C : U -> Prop),
incl A B -> incl (union A C) (union B C).
Proof.
intros; rewrite (union_comm A), (union_comm B); now apply union_monot_l.
Qed.
Lemma disj_union_l :
forall (A B C : U -> Prop),
disj (union A B) C <-> disj A C /\ disj B C.
Proof.
intros; split.
intros H; split; intros x Hx1 Hx2; apply (H x); try easy; [now left | now right].
intros [H1 H2] x [Hx1 | Hx1] Hx2; [now apply (H1 x) | now apply (H2 x)].
Qed.
Lemma disj_union_r :
forall (A B C : U -> Prop),
disj A (union B C) <-> disj A B /\ disj A C.
Proof.
intros A B C; now rewrite disj_sym, disj_union_l, (disj_sym B), (disj_sym C).
Qed.
Lemma union_compl_l :
forall (A : U -> Prop),
union (compl A) A = fullset.
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma union_compl_r :
forall (A : U -> Prop),
union A (compl A) = fullset.
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
End Union_Facts.
Section Inter_Facts.
(** Facts about intersection. *)
Context {U : Type}. (* Universe. *)
Lemma inter_assoc :
forall (A B C : U -> Prop),
inter (inter A B) C = inter A (inter B C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma inter_comm :
forall (A B : U -> Prop),
inter A B = inter B A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma inter_idem :
forall (A : U -> Prop),
inter A A = A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma inter_full_l :
forall (A : U -> Prop),
inter fullset A = A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma inter_full_r :
forall (A : U -> Prop),
inter A fullset = A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma full_inter :
forall (A B : U -> Prop),
inter A B = fullset <-> A = fullset /\ B = fullset.
Proof.
intros; do 3 rewrite <- full_fullset; split.
intros H; split; intros x; now destruct (H x).
intros [H1 H2] x; split; [apply (H1 x) | apply (H2 x)].
Qed.
Lemma inter_empty_l :
forall (A : U -> Prop),
inter emptyset A = emptyset.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma inter_empty_r :
forall (A : U -> Prop),
inter A emptyset = emptyset.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma inter_lb_l :
forall (A B : U -> Prop),
incl (inter A B) A.
Proof.
subset_auto.
Qed.
Lemma inter_lb_r :
forall (A B : U -> Prop),
incl (inter A B) B.
Proof.
subset_auto.
Qed.
Lemma inter_glb :
forall (A B C : U -> Prop),
incl C A -> incl C B ->
incl C (inter A B).
Proof.
intros; intros x Hx; split; auto.
Qed.
Lemma incl_inter :
forall (A B C : U -> Prop),
incl A (inter B C) -> incl A B /\ incl A C.
Proof.
intros A B C H; split; intros x Hx; now apply (H x).
Qed.
Lemma inter_left :
forall (A B : U -> Prop),
incl A B <-> inter A B = A.
Proof.
intros; split.
(* *)

François Clément
committed
rewrite subset_ext_equiv; split; intros x.
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
intros [Hx1 Hx2]; auto.
intros Hx; split; auto.
(* *)
intros H x Hx; rewrite <- H in Hx; now destruct Hx as [_ Hx].
Qed.
Lemma inter_right :
forall (A B : U -> Prop),
incl B A <-> inter A B = B.
Proof.
intros; rewrite inter_comm; apply inter_left.
Qed.
Lemma inter_monot_l :
forall (A B C : U -> Prop),
incl A B -> incl (inter C A) (inter C B).
Proof.
intros A B C H x [Hx1 Hx2]; split; [easy | now apply H].
Qed.
Lemma inter_monot_r :
forall (A B C : U -> Prop),
incl A B -> incl (inter A C) (inter B C).
Proof.
intros; rewrite (inter_comm A), (inter_comm B); now apply inter_monot_l.
Qed.
Lemma disj_inter_l :
forall (A B C : U -> Prop),
disj A B -> disj (inter C A) (inter C B).
Proof.
intros A B C H; rewrite disj_equiv_def in H; rewrite disj_equiv_def.
rewrite <- empty_emptyset in H; rewrite <- empty_emptyset.
intros x [[_ Hx1] [_ Hx2]]; now apply (H x).
Qed.
Lemma disj_inter_r :
forall (A B C : U -> Prop),
disj A B -> disj (inter A C) (inter B C).
Proof.
intros; rewrite (inter_comm A), (inter_comm B); now apply disj_inter_l.
Qed.
Lemma inter_compl_l :
forall (A : U -> Prop),
inter (compl A) A = emptyset.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma inter_compl_r :
forall (A : U -> Prop),
inter A (compl A) = emptyset.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
End Inter_Facts.
Section Union_Inter_Facts.
(** Facts about union and intersection. *)
Context {U : Type}. (* Universe. *)
Lemma incl_inter_union :
forall (A B : U -> Prop),
incl (inter A B) (union A B).
Proof.
intros; intros x [Hx _]; now left.
Qed.
Lemma disj_inter_union :
forall (A B : U -> Prop),
disj (inter A B) (union A B) <-> disj A B.
Proof.
intros; split; intros H x.
intros Hx1 Hx2; apply (H x); [easy | now left].
intros [Hx1 Hx2] _; now apply (H x).
Qed.
(** De Morgan's laws. *)
Lemma compl_union :
forall (A B : U -> Prop),
compl (union A B) = inter (compl A) (compl B).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma compl_inter :
forall (A B : U -> Prop),
compl (inter A B) = union (compl A) (compl B).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
(** Distributivity. *)
Lemma distrib_union_union_l :
forall (A B C : U -> Prop),
union A (union B C) = union (union A B) (union A C).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma distrib_union_union_r :
forall (A B C : U -> Prop),
union (union A B) C = union (union A C) (union B C).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma distrib_union_inter_l :
forall (A B C : U -> Prop),
union A (inter B C) = inter (union A B) (union A C).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma distrib_union_inter_r :
forall (A B C : U -> Prop),
union (inter A B) C = inter (union A C) (union B C).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma distrib_union_inter :
forall (A B C D : U -> Prop),
union (inter A B) (inter C D) =
inter (inter (union A C) (union B C)) (inter (union A D) (union B D)).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma distrib_inter_union_l :
forall (A B C : U -> Prop),
inter A (union B C) = union (inter A B) (inter A C).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma distrib_inter_union_r :
forall (A B C : U -> Prop),
inter (union A B) C = union (inter A C) (inter B C).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma distrib_inter_union :
forall (A B C D : U -> Prop),
inter (union A B) (union C D) =
union (union (inter A C) (inter B C)) (union (inter A D) (inter B D)).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma distrib_inter_inter_l :
forall (A B C : U -> Prop),
inter A (inter B C) = inter (inter A B) (inter A C).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma distrib_inter_inter_r :
forall (A B C : U -> Prop),
inter (inter A B) C = inter (inter A C) (inter B C).
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split; subset_auto.
Qed.
Lemma disj_compl_l :
forall (A B : U -> Prop),
disj (compl A) B -> ~ empty B -> ~ disj A B.
Proof.
intros A B H1 H2 H3; rewrite disj_equiv_def in H1, H3.
contradict H2; apply empty_emptyset.
rewrite <- (inter_full_l B).
rewrite <- (union_compl_l A), distrib_inter_union_r, H1, H3.
now apply empty_union.
Qed.
Lemma disj_compl_r :
forall (A B : U -> Prop),
disj A (compl B) -> ~ empty A -> ~ disj A B.
Proof.
intros A B H1 H2.
rewrite disj_sym in H1; rewrite disj_sym.
now apply disj_compl_l.
Qed.
End Union_Inter_Facts.
Section Add_Facts.
(** Facts about addition of one element. *)
Context {U : Type}. (* Universe. *)
Lemma add_incl :
forall A (a : U), incl A (add A a).
Proof.
intros; apply union_ub_l.
Qed.
Lemma add_in :
forall A (a : U), add A a a.
Proof.
intros; apply union_ub_r, singleton_in.
Qed.
End Add_Facts.
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
Section Diff_Facts.
(** Facts about set difference. *)
Context {U : Type}. (* Universe. *)
Lemma diff_equiv_def_inter :
forall (A B : U -> Prop),
diff A B = inter A (compl B).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_equiv_def_union :
forall (A B : U -> Prop),
diff A B = compl (union (compl A) B).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma compl_equiv_def_diff :
forall (A : U -> Prop),
compl A = diff fullset A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma inter_equiv_def_diff :
forall (A B : U -> Prop),
inter A B = diff A (diff A B).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma union_equiv_def_diff :
forall (A B : U -> Prop),
union A B = compl (diff (compl A) B).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma diff_lb_l :
forall (A B : U -> Prop),
incl (diff A B) A.
Proof.
intros; apply inter_lb_l.
Qed.
Lemma diff_lb_r :
forall (A B : U -> Prop),
incl (diff A B) (compl B).
Proof.
intros; apply inter_lb_r.
Qed.
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
Lemma partition_diff_l :
forall (A B : U -> Prop),
partition (union A B) (diff A B) B.
Proof.
intros; split.
apply subset_ext; intros x; subset_auto.
subset_auto.
Qed.
Lemma partition_diff_r :
forall (A B : U -> Prop),
partition (union A B) A (diff B A).
Proof.
intros; split.
apply subset_ext; intros x; subset_auto.
subset_auto.
Qed.
Lemma diff_monot_l :
forall (A B C : U -> Prop),
incl B C -> incl (diff A C) (diff A B).
Proof.
intros A B C H x [Hx1 Hx2]; split; [easy | intros Hx3; now apply Hx2, H].
Qed.
Lemma diff_monot_r :
forall (A B C : U -> Prop),
incl A B -> incl (diff A C) (diff B C).
Proof.
intros A B C H x [Hx1 Hx2]; split; [now apply H | easy].
Qed.
Lemma disj_diff :
forall (A B : U -> Prop),
disj A B <-> diff A B = A.
Proof.

François Clément
committed
intros; rewrite subset_ext_equiv; split.
intros H; split; subset_unfold; intros x Hx1; specialize (H x); intuition.
intros [_ H] x Hx1 Hx2; specialize (H x Hx1); now destruct H as [_ H].
Qed.
Lemma disj_diff_r :
forall (A B C : U -> Prop),
disj A B -> disj (diff A C) (diff B C).
Proof.
intros A B C H x HAx HBx; apply (H x); now apply (diff_lb_l _ C).
Qed.

François Clément
committed
Lemma diff_empty :
forall (A B : U -> Prop),
diff A B = emptyset <-> incl A B.
Proof.
intros; rewrite <- empty_emptyset; split; intros H.
intros x Hx1; apply NNPP; intros Hx2; now apply (H x).
intros x [Hx1 Hx2]; auto.
Qed.

François Clément
committed
Lemma diff_empty_diag :
forall (A : U -> Prop),
diff A A = emptyset.
Proof.

François Clément
committed
intros; now rewrite diff_empty.
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
Qed.
Lemma full_diff :
forall (A B : U -> Prop),
diff A B = fullset <-> A = fullset /\ B = emptyset.
Proof.
intros; do 2 rewrite <- full_fullset; rewrite <- empty_emptyset.
split; intros H.
split; intros x; now destruct (H x) as [H1 H2].
intros x; destruct H as [H1 H2]; split; [apply H1 | exact (H2 x)].
Qed.
Lemma compl_diff :
forall (A B : U -> Prop),
compl (diff A B) = union (compl A) B.
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma diff_empty_l :
forall (A : U -> Prop),
diff emptyset A = emptyset.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_empty_r :
forall (A : U -> Prop),
diff A emptyset = A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_full_l:
forall (A : U -> Prop),
diff fullset A = compl A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_full_r:
forall (A : U -> Prop),
diff A fullset = emptyset.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_compl_l :
forall (A B : U -> Prop),
diff (compl A) B = diff (compl B) A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_compl_r :
forall (A B : U -> Prop),
diff A (compl B) = diff B (compl A).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma diff_compl :
forall (A B : U -> Prop),
diff (compl A) (compl B) = diff B A.
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma diff_union_l :
forall (A B C : U -> Prop),
diff (union A B) C = union (diff A C) (diff B C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_union_r :
forall (A B C : U -> Prop),
diff A (union B C) = inter (diff A B) (diff A C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_inter_l :
forall (A B C : U -> Prop),
diff (inter A B) C = inter (diff A C) (diff B C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_inter_r :
forall (A B C : U -> Prop),
diff A (inter B C) = union (diff A B) (diff A C).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.

François Clément
committed
Lemma diff_union_l_diag :
forall (A B : U -> Prop),
diff (union A B) A = diff B A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.

François Clément
committed
Lemma diff_union_r_diag :
forall (A B : U -> Prop),
diff (union A B) B = diff A B.
Proof.
intros; apply subset_ext; subset_auto.
Qed.

François Clément
committed
Lemma diff_inter_l_diag :
forall (A B : U -> Prop),
diff A (inter A B) = diff A B.
Proof.
intros; apply subset_ext; subset_auto.
Qed.

François Clément
committed
Lemma diff_inter_r_diag :
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
forall (A B : U -> Prop),
diff B (inter A B) = diff B A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma union_diff_l :
forall (A B C : U -> Prop),
union (diff A B) C = diff (union A C) (diff B C).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma union_diff_r :
forall (A B C : U -> Prop),
union A (diff B C) = diff (union A B) (diff C A).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma distrib_inter_diff_l :
forall (A B C : U -> Prop),
inter A (diff B C) = diff (inter A B) (inter A C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma distrib_inter_diff_r :
forall (A B C : U -> Prop),
inter (diff A B) C = diff (inter A C) (inter B C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff2_l :
forall (A B C : U -> Prop),
diff (diff A B) C = diff A (union B C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff2_r :
forall (A B C : U -> Prop),
diff A (diff B C) = union (inter A C) (diff A B).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma diff2_r_inter :
forall (A B C : U -> Prop),
incl A B ->
diff A (diff B C) = inter A C.
Proof.

François Clément
committed
intros A B C H; apply diff_empty in H.
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
rewrite diff2_r, H; apply union_empty_r.
Qed.
Lemma diff2 :
forall (A B C D : U -> Prop),
diff (diff A B) (diff C D) =
union (diff (inter A (compl C)) B)
(diff (inter A D) B).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma diff2_diag_l :
forall (A B C : U -> Prop),
diff (diff A B) (diff A C) = diff (inter A C) B.
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma diff2_cancel_left :
forall (A B C : U -> Prop),
incl A B ->
diff (diff B C) (diff B A) = diff A C.
Proof.
intros; now rewrite diff2_diag_l, inter_comm, (proj1 (inter_left _ _)).
Qed.
Lemma diff2_diag_r :
forall (A B C : U -> Prop),
diff (diff A C) (diff B C) = diff (inter A (compl B)) C.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
End Diff_Facts.
Section Sym_diff_Facts.
(** Facts about symmetric difference. *)
Context {U : Type}. (* Universe. *)
Lemma sym_diff_equiv_def_union :
forall (A B : U -> Prop),
sym_diff A B = union (diff A B) (diff B A).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma sym_diff_equiv_def_diff :
forall (A B : U -> Prop),
sym_diff A B = diff (union A B) (inter A B).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma union_equiv_def_sym_diff :
forall (A B : U -> Prop),
union A B = sym_diff (sym_diff A B) (inter A B).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma inter_equiv_def_sym_diff :
forall (A B : U -> Prop),
inter A B = diff (union A B) (sym_diff A B).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma diff_equiv_def_sym_diff_inter :
forall (A B : U -> Prop),
diff A B = sym_diff A (inter A B).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma diff_equiv_def_sym_diff_union :
forall (A B : U -> Prop),
diff A B = sym_diff (union A B) B.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
(* ((U -> Prop) -> Prop, sym_diff) is a Boolean group,
ie an abelian group with the emptyset as neutral, and inv = id. *)
Lemma sym_diff_assoc :
forall (A B C : U -> Prop),
sym_diff (sym_diff A B) C = sym_diff A (sym_diff B C).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma sym_diff_comm :
forall (A B : U -> Prop),
sym_diff A B = sym_diff B A.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma sym_diff_inv :
forall (A : U -> Prop),
sym_diff A A = emptyset.
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma sym_diff_empty_l :
forall (A : U -> Prop),
sym_diff emptyset A = A.
Proof.
intros; rewrite sym_diff_equiv_def_union, diff_empty_l, diff_empty_r.
apply union_empty_l.
Qed.
Lemma sym_diff_empty_r :
forall (A : U -> Prop),
sym_diff A emptyset = A.
Proof.
intros; rewrite sym_diff_comm; apply sym_diff_empty_l.
Qed.
Lemma sym_diff_full_l :
forall (A : U -> Prop),
sym_diff fullset A = compl A.
Proof.
intros; rewrite sym_diff_equiv_def_diff, union_full_l, inter_full_l.
symmetry; apply compl_equiv_def_diff.
Qed.
Lemma sym_diff_full_r :
forall (A : U -> Prop),
sym_diff A fullset = compl A.
Proof.
intros; rewrite sym_diff_comm; apply sym_diff_full_l.
Qed.
Lemma sym_diff_eq_reg_l :
forall (A B C : U -> Prop),
sym_diff A B = sym_diff A C -> B = C.
Proof.
intros A B C H.
rewrite <- (sym_diff_empty_l B), <- (sym_diff_empty_l C), <- (sym_diff_inv A).
do 2 rewrite sym_diff_assoc.
now f_equal.
Qed.
Lemma sym_diff_eq_reg_r :
forall (A B C : U -> Prop),
sym_diff A B = sym_diff C B -> A = C.
Proof.
intros A B C H; apply sym_diff_eq_reg_l with B.
now rewrite (sym_diff_comm _ A), (sym_diff_comm _ C).
Qed.
Lemma sym_diff_compl_l :
forall (A : U -> Prop),
sym_diff (compl A) A = fullset.
Proof.
intros; rewrite <- sym_diff_full_l, sym_diff_assoc, sym_diff_inv.
apply sym_diff_empty_r.
Qed.
Lemma sym_diff_compl_r :
forall (A : U -> Prop),
sym_diff A (compl A) = fullset.
Proof.
intros; rewrite sym_diff_comm; apply sym_diff_compl_l.
Qed.
Lemma sym_diff_compl :
forall (A B : U -> Prop),
sym_diff (compl A) (compl B) = sym_diff A B.
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma super_distrib_union_sym_diff_l :
forall (A B C : U -> Prop),
incl (sym_diff (union A C) (union B C))
(union (sym_diff A B) C).
Proof.
intros; subset_auto.
Qed.
Lemma super_distrib_union_sym_diff_r :
forall (A B C : U -> Prop),
incl (sym_diff (union A B) (union A C))
(union A (sym_diff B C)).
Proof.
intros; subset_auto.
Qed.
Lemma super_distrib_union_sym_diff :
forall (A B C D : U -> Prop),
incl (sym_diff (union A C) (union B D))
(union (sym_diff A B) (sym_diff C D)).
Proof.
intros; subset_auto.
Qed.
Lemma sub_distrib_sym_diff_union_l :
forall (A B C : U -> Prop),
incl (sym_diff (union A B) C)
(union (sym_diff A C) (sym_diff B C)).
Proof.
intros; subset_auto.
Qed.
Lemma sub_distrib_sym_diff_union_r :
forall (A B C : U -> Prop),
incl (sym_diff A (union B C))
(union (sym_diff A B) (sym_diff A C)).
Proof.
intros; subset_auto.
Qed.
Lemma sub_distrib_sym_diff_union :
forall (A B C D : U -> Prop),
incl (sym_diff (union A B) (union C D))
(union (sym_diff A C) (sym_diff B D)).
Proof.
intros; subset_auto.
Qed.
(* ((U -> Prop) -> Prop, sym_diff, inter) is a Boolean ring,
ie an abelian ring with fullset as neutral for intersection. *)
Lemma distrib_inter_sym_diff_l :
forall (A B C : U -> Prop),
inter (sym_diff A B) C = sym_diff (inter A C) (inter B C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma distrib_inter_sym_diff_r :
forall (A B C : U -> Prop),
inter A (sym_diff B C) = sym_diff (inter A B) (inter A C).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma distrib_inter_sym_diff :
forall (A B C D : U -> Prop),
inter (sym_diff A B) (sym_diff C D) =
sym_diff (sym_diff (inter A C) (inter A D))
(sym_diff (inter B C) (inter B D)).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma super_distrib_sym_diff_inter_l :
forall (A B C : U -> Prop),
incl (inter (sym_diff A C) (sym_diff B C))
(sym_diff (inter A B) C).
Proof.
intros; subset_auto.
Qed.
Lemma super_distrib_sym_diff_inter_r :
forall (A B C : U -> Prop),
incl (inter (sym_diff A B) (sym_diff A C))
(sym_diff A (inter B C)).
Proof.
intros; subset_auto.
Qed.
Lemma super_distrib_sym_diff_inter :
forall (A B C D : U -> Prop),
incl (inter (inter (sym_diff A C) (sym_diff A D))
(inter (sym_diff B C) (sym_diff B D)))
(sym_diff (inter A B) (inter C D)).
Proof.
intros; subset_auto.
Qed.
(* ((U -> Prop) -> Prop, sym_diff, inter) is a Boolean algebra. *)
Lemma sym_diff_union :
forall (A B : U -> Prop),
sym_diff A B = union A B <-> disj A B.
Proof.
intros; rewrite sym_diff_equiv_def_diff, <- disj_diff, (disj_sym (union _ _)).
apply disj_inter_union.
Qed.
Lemma disj_sym_diff_inter :
forall (A B : U -> Prop),
disj (sym_diff A B) (inter A B).
Proof.
intros; subset_auto.
Qed.
Lemma union_sym_diff_inter :
forall (A B : U -> Prop),
union (sym_diff A B) (inter A B) = union A B.
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma partition_sym_diff_inter :
forall (A B : U -> Prop),
partition (union A B) (sym_diff A B) (inter A B).
Proof.
intros; split.
symmetry; apply union_sym_diff_inter.
apply disj_sym_diff_inter.
Qed.
Lemma sym_diff_cancel_middle :
forall (A B C : U -> Prop),
sym_diff (sym_diff A B) (sym_diff B C) = sym_diff A C.
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma sym_diff2 :
forall (A B C D : U -> Prop),
sym_diff (sym_diff A B) (sym_diff C D) =
sym_diff A (sym_diff B (sym_diff C D)).
Proof.
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma sym_diff_triangle_ineq :
forall (A B C : U -> Prop),
incl (sym_diff A C) (union (sym_diff A B) (sym_diff B C)).
Proof.
intros; intros x; subset_auto.
Qed.
Lemma sym_diff_diff_diag_l :
forall (A B C : U -> Prop),
incl (union B C) A ->
sym_diff (diff A B) (diff A C) = sym_diff B C.
Proof.
intros A B C H; apply incl_union in H.
rewrite sym_diff_equiv_def_union.
repeat rewrite diff2_cancel_left; try easy.
now rewrite <- sym_diff_equiv_def_union, sym_diff_comm.
Qed.
End Sym_diff_Facts.
Section Partition_Facts.
(** Facts about partition. *)
Context {U : Type}. (* Universe. *)
Lemma partition_sym :
forall (A B C : U -> Prop),
partition A B C -> partition A C B.
Proof.
intros A B C; unfold partition.
now rewrite union_comm, disj_sym.
Qed.
Lemma partition_inter_l :
forall (A B C D : U -> Prop),
partition A B C -> partition (inter D A) (inter D B) (inter D C).
Proof.
intros A B C D [H1 H2]; split.
rewrite H1; apply distrib_inter_union_l.
now apply disj_inter_l.
Qed.
Lemma partition_inter_r :
forall (A B C D : U -> Prop),
partition A B C -> partition (inter A D) (inter B D) (inter C D).
Proof.
intros A B C D.
rewrite (inter_comm A), (inter_comm B), (inter_comm C).
apply partition_inter_l.
Qed.
Lemma partition_diff :
forall (A B C D : U -> Prop),
partition A B C -> partition (diff A D) (diff B D) (diff C D).
Proof.
intros; now apply partition_inter_r.
Qed.
Section Prod_Facts.
(** Facts about Cartesian product. *)
Context {U1 U2 : Type}. (* Universes. *)
Lemma inhabited_prod :
inhabited U1 -> inhabited U2 -> inhabited (U1 * U2).
Proof.
intros [x1] [x2]; apply (inhabits (x1, x2)).
Qed.
Lemma prod_emptyset_l :
forall A2, prod emptyset A2 = @emptyset (U1 * U2).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma prod_emptyset_r :
forall A1, prod A1 emptyset = @emptyset (U1 * U2).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma prod_fullset :
prod fullset fullset = @fullset (U1 * U2).
Proof.
apply subset_ext; subset_auto.
Qed.
Lemma prod_fullset_l :
forall A2, prod fullset A2 = fun x : U1 * U2 => A2 (snd x).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma prod_fullset_r :
forall A1, prod A1 fullset = fun x : U1 * U2 => A1 (fst x).
Proof.
intros; apply subset_ext; subset_auto.
Qed.
Lemma prod_inter :
forall (A1 B1 : U1 -> Prop) (A2 B2 : U2 -> Prop),
inter (prod A1 A2) (prod B1 B2) = prod (inter A1 B1) (inter A2 B2).
intros; apply subset_ext; subset_auto.
Qed.
Lemma prod_compl_union :
forall (A1 : U1 -> Prop) (A2 : U2 -> Prop),
compl (prod A1 A2) = union (prod (compl A1) A2) (prod fullset (compl A2)).
intros; apply subset_ext; intros x; subset_auto.
Qed.
Lemma prod_compl_disj :
forall (A1 : U1 -> Prop) (A2 : U2 -> Prop),
disj (prod (compl A1) A2) (prod fullset (compl A2)).
Proof.
subset_auto.
Qed.
Lemma prod_compl_partition :
forall (A1 : U1 -> Prop) (A2 : U2 -> Prop),
partition (compl (prod A1 A2))
(prod (compl A1) A2) (prod fullset (compl A2)).
Proof.
intros; split.
apply prod_compl_union.
apply prod_compl_disj.
Qed.
Lemma prod_swap :
forall (A1 : U1 -> Prop) (A2 : U2 -> Prop),
(fun x21 : U2 * U1 => prod A1 A2 (swap (fun x : U1 * U2 => x) x21)) = prod A2 A1.
Proof.
intros; apply subset_ext; subset_auto.
Qed.