-
Notifications
You must be signed in to change notification settings - Fork 350
/
Bool.lean
525 lines (359 loc) Β· 21.2 KB
/
Bool.lean
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
/-
Copyright (c) 2023 F. G. Dorais. No rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: F. G. Dorais
-/
prelude
import Init.BinderPredicates
/-- Boolean exclusive or -/
abbrev xor : Bool β Bool β Bool := bne
namespace Bool
/- Namespaced versions that can be used instead of prefixing `_root_` -/
@[inherit_doc not] protected abbrev not := not
@[inherit_doc or] protected abbrev or := or
@[inherit_doc and] protected abbrev and := and
@[inherit_doc xor] protected abbrev xor := xor
instance (p : Bool β Prop) [inst : DecidablePred p] : Decidable (β x, p x) :=
match inst true, inst false with
| isFalse ht, _ => isFalse fun h => absurd (h _) ht
| _, isFalse hf => isFalse fun h => absurd (h _) hf
| isTrue ht, isTrue hf => isTrue fun | true => ht | false => hf
instance (p : Bool β Prop) [inst : DecidablePred p] : Decidable (β x, p x) :=
match inst true, inst false with
| isTrue ht, _ => isTrue β¨_, htβ©
| _, isTrue hf => isTrue β¨_, hfβ©
| isFalse ht, isFalse hf => isFalse fun | β¨true, hβ© => absurd h ht | β¨false, hβ© => absurd h hf
@[simp] theorem default_bool : default = false := rfl
instance : LE Bool := β¨(. β .)β©
instance : LT Bool := β¨(!. && .)β©
instance (x y : Bool) : Decidable (x β€ y) := inferInstanceAs (Decidable (x β y))
instance (x y : Bool) : Decidable (x < y) := inferInstanceAs (Decidable (!x && y))
instance : Max Bool := β¨orβ©
instance : Min Bool := β¨andβ©
theorem false_ne_true : false β true := Bool.noConfusion
theorem eq_false_or_eq_true : (b : Bool) β b = true β¨ b = false := by decide
theorem eq_false_iff : {b : Bool} β b = false β b β true := by decide
theorem ne_false_iff : {b : Bool} β b β false β b = true := by decide
theorem eq_iff_iff {a b : Bool} : a = b β (a β b) := by cases b <;> simp
@[simp] theorem decide_eq_true {b : Bool} [Decidable (b = true)] : decide (b = true) = b := by cases b <;> simp
@[simp] theorem decide_eq_false {b : Bool} [Decidable (b = false)] : decide (b = false) = !b := by cases b <;> simp
@[simp] theorem decide_true_eq {b : Bool} [Decidable (true = b)] : decide (true = b) = b := by cases b <;> simp
@[simp] theorem decide_false_eq {b : Bool} [Decidable (false = b)] : decide (false = b) = !b := by cases b <;> simp
/-! ### and -/
@[simp] theorem and_self_left : β(a b : Bool), (a && (a && b)) = (a && b) := by decide
@[simp] theorem and_self_right : β(a b : Bool), ((a && b) && b) = (a && b) := by decide
@[simp] theorem not_and_self : β (x : Bool), (!x && x) = false := by decide
@[simp] theorem and_not_self : β (x : Bool), (x && !x) = false := by decide
/-
Added for confluence with `not_and_self` `and_not_self` on term
`(b && !b) = true` due to reductions:
1. `(b = true β¨ !b = true)` via `Bool.and_eq_true`
2. `false = true` via `Bool.and_not_self`
-/
@[simp] theorem eq_true_and_eq_false_self : β(b : Bool), (b = true β§ b = false) β False := by decide
@[simp] theorem eq_false_and_eq_true_self : β(b : Bool), (b = false β§ b = true) β False := by decide
theorem and_comm : β (x y : Bool), (x && y) = (y && x) := by decide
instance : Std.Commutative (Β· && Β·) := β¨and_commβ©
theorem and_left_comm : β (x y z : Bool), (x && (y && z)) = (y && (x && z)) := by decide
theorem and_right_comm : β (x y z : Bool), ((x && y) && z) = ((x && z) && y) := by decide
/-
Bool version `and_iff_left_iff_imp`.
Needed for confluence of term `(a && b) β a` which reduces to `(a && b) = a` via
`Bool.coe_iff_coe` and `a β b` via `Bool.and_eq_true` and
`and_iff_left_iff_imp`.
-/
@[simp] theorem and_iff_left_iff_imp : β(a b : Bool), ((a && b) = a) β (a β b) := by decide
@[simp] theorem and_iff_right_iff_imp : β(a b : Bool), ((a && b) = b) β (b β a) := by decide
@[simp] theorem iff_self_and : β(a b : Bool), (a = (a && b)) β (a β b) := by decide
@[simp] theorem iff_and_self : β(a b : Bool), (b = (a && b)) β (b β a) := by decide
/-! ### or -/
@[simp] theorem or_self_left : β(a b : Bool), (a || (a || b)) = (a || b) := by decide
@[simp] theorem or_self_right : β(a b : Bool), ((a || b) || b) = (a || b) := by decide
@[simp] theorem not_or_self : β (x : Bool), (!x || x) = true := by decide
@[simp] theorem or_not_self : β (x : Bool), (x || !x) = true := by decide
/-
Added for confluence with `not_or_self` `or_not_self` on term
`(b || !b) = true` due to reductions:
1. `(b = true β¨ !b = true)` via `Bool.or_eq_true`
2. `true = true` via `Bool.or_not_self`
-/
@[simp] theorem eq_true_or_eq_false_self : β(b : Bool), (b = true β¨ b = false) β True := by decide
@[simp] theorem eq_false_or_eq_true_self : β(b : Bool), (b = false β¨ b = true) β True := by decide
/-
Bool version `or_iff_left_iff_imp`.
Needed for confluence of term `(a || b) β a` which reduces to `(a || b) = a` via
`Bool.coe_iff_coe` and `a β b` via `Bool.or_eq_true` and
`and_iff_left_iff_imp`.
-/
@[simp] theorem or_iff_left_iff_imp : β(a b : Bool), ((a || b) = a) β (b β a) := by decide
@[simp] theorem or_iff_right_iff_imp : β(a b : Bool), ((a || b) = b) β (a β b) := by decide
@[simp] theorem iff_self_or : β(a b : Bool), (a = (a || b)) β (b β a) := by decide
@[simp] theorem iff_or_self : β(a b : Bool), (b = (a || b)) β (a β b) := by decide
theorem or_comm : β (x y : Bool), (x || y) = (y || x) := by decide
instance : Std.Commutative (Β· || Β·) := β¨or_commβ©
theorem or_left_comm : β (x y z : Bool), (x || (y || z)) = (y || (x || z)) := by decide
theorem or_right_comm : β (x y z : Bool), ((x || y) || z) = ((x || z) || y) := by decide
/-! ### distributivity -/
theorem and_or_distrib_left : β (x y z : Bool), (x && (y || z)) = (x && y || x && z) := by decide
theorem and_or_distrib_right : β (x y z : Bool), ((x || y) && z) = (x && z || y && z) := by decide
theorem or_and_distrib_left : β (x y z : Bool), (x || y && z) = ((x || y) && (x || z)) := by decide
theorem or_and_distrib_right : β (x y z : Bool), (x && y || z) = ((x || z) && (y || z)) := by decide
theorem and_xor_distrib_left : β (x y z : Bool), (x && xor y z) = xor (x && y) (x && z) := by decide
theorem and_xor_distrib_right : β (x y z : Bool), (xor x y && z) = xor (x && z) (y && z) := by decide
/-- De Morgan's law for boolean and -/
@[simp] theorem not_and : β (x y : Bool), (!(x && y)) = (!x || !y) := by decide
/-- De Morgan's law for boolean or -/
@[simp] theorem not_or : β (x y : Bool), (!(x || y)) = (!x && !y) := by decide
theorem and_eq_true_iff (x y : Bool) : (x && y) = true β x = true β§ y = true :=
Iff.of_eq (and_eq_true x y)
theorem and_eq_false_iff : β (x y : Bool), (x && y) = false β x = false β¨ y = false := by decide
/-
New simp rule that replaces `Bool.and_eq_false_eq_eq_false_or_eq_false` in
Mathlib due to confluence:
Consider the term: `Β¬((b && c) = true)`:
1. Reduces to `((b && c) = false)` via `Bool.not_eq_true`
2. Reduces to `Β¬(b = true β§ c = true)` via `Bool.and_eq_true`.
1. Further reduces to `b = false β¨ c = false` via `Bool.and_eq_false_eq_eq_false_or_eq_false`.
2. Further reduces to `b = true β c = false` via `not_and` and `Bool.not_eq_true`.
-/
@[simp] theorem and_eq_false_imp : β (x y : Bool), (x && y) = false β (x = true β y = false) := by decide
@[simp] theorem or_eq_true_iff : β (x y : Bool), (x || y) = true β x = true β¨ y = true := by decide
@[simp] theorem or_eq_false_iff : β (x y : Bool), (x || y) = false β x = false β§ y = false := by decide
/-! ### eq/beq/bne -/
/--
These two rules follow trivially by simp, but are needed to avoid non-termination
in false_eq and true_eq.
-/
@[simp] theorem false_eq_true : (false = true) = False := by simp
@[simp] theorem true_eq_false : (true = false) = False := by simp
-- The two lemmas below normalize terms with a constant to the
-- right-hand side but risk non-termination if `false_eq_true` and
-- `true_eq_false` are disabled.
@[simp low] theorem false_eq (b : Bool) : (false = b) = (b = false) := by
cases b <;> simp
@[simp low] theorem true_eq (b : Bool) : (true = b) = (b = true) := by
cases b <;> simp
@[simp] theorem true_beq : βb, (true == b) = b := by decide
@[simp] theorem false_beq : βb, (false == b) = !b := by decide
@[simp] theorem beq_true : βb, (b == true) = b := by decide
instance : Std.LawfulIdentity (Β· == Β·) true where
left_id := true_beq
right_id := beq_true
@[simp] theorem beq_false : βb, (b == false) = !b := by decide
@[simp] theorem true_bne : β(b : Bool), (true != b) = !b := by decide
@[simp] theorem false_bne : β(b : Bool), (false != b) = b := by decide
@[simp] theorem bne_true : β(b : Bool), (b != true) = !b := by decide
@[simp] theorem bne_false : β(b : Bool), (b != false) = b := by decide
instance : Std.LawfulIdentity (Β· != Β·) false where
left_id := false_bne
right_id := bne_false
@[simp] theorem not_beq_self : β (x : Bool), ((!x) == x) = false := by decide
@[simp] theorem beq_not_self : β (x : Bool), (x == !x) = false := by decide
@[simp] theorem not_bne_self : β (x : Bool), ((!x) != x) = true := by decide
@[simp] theorem bne_not_self : β (x : Bool), (x != !x) = true := by decide
/-
Added for equivalence with `Bool.not_beq_self` and needed for confluence
due to `beq_iff_eq`.
-/
@[simp] theorem not_eq_self : β(b : Bool), ((!b) = b) β False := by decide
@[simp] theorem eq_not_self : β(b : Bool), (b = (!b)) β False := by decide
@[simp] theorem beq_self_left : β(a b : Bool), (a == (a == b)) = b := by decide
@[simp] theorem beq_self_right : β(a b : Bool), ((a == b) == b) = a := by decide
@[simp] theorem bne_self_left : β(a b : Bool), (a != (a != b)) = b := by decide
@[simp] theorem bne_self_right : β(a b : Bool), ((a != b) != b) = a := by decide
@[simp] theorem not_bne_not : β (x y : Bool), ((!x) != (!y)) = (x != y) := by decide
@[simp] theorem bne_assoc : β (x y z : Bool), ((x != y) != z) = (x != (y != z)) := by decide
instance : Std.Associative (Β· != Β·) := β¨bne_assocβ©
@[simp] theorem bne_left_inj : β (x y z : Bool), (x != y) = (x != z) β y = z := by decide
@[simp] theorem bne_right_inj : β (x y z : Bool), (x != z) = (y != z) β x = y := by decide
theorem eq_not_of_ne : β {x y : Bool}, x β y β x = !y := by decide
/-! ### coercision related normal forms -/
theorem beq_eq_decide_eq [BEq Ξ±] [LawfulBEq Ξ±] [DecidableEq Ξ±] (a b : Ξ±) :
(a == b) = decide (a = b) := by
cases h : a == b
Β· simp [ne_of_beq_false h]
Β· simp [eq_of_beq h]
@[simp] theorem not_eq_not : β {a b : Bool}, Β¬a = !b β a = b := by decide
@[simp] theorem not_not_eq : β {a b : Bool}, Β¬(!a) = b β a = b := by decide
@[simp] theorem coe_iff_coe : β(a b : Bool), (a β b) β a = b := by decide
@[simp] theorem coe_true_iff_false : β(a b : Bool), (a β b = false) β a = (!b) := by decide
@[simp] theorem coe_false_iff_true : β(a b : Bool), (a = false β b) β (!a) = b := by decide
@[simp] theorem coe_false_iff_false : β(a b : Bool), (a = false β b = false) β (!a) = (!b) := by decide
/-! ### beq properties -/
theorem beq_comm {Ξ±} [BEq Ξ±] [LawfulBEq Ξ±] {a b : Ξ±} : (a == b) = (b == a) :=
(Bool.coe_iff_coe (a == b) (b == a)).mp (by simp [@eq_comm Ξ±])
/-! ### xor -/
theorem false_xor : β (x : Bool), xor false x = x := false_bne
theorem xor_false : β (x : Bool), xor x false = x := bne_false
theorem true_xor : β (x : Bool), xor true x = !x := true_bne
theorem xor_true : β (x : Bool), xor x true = !x := bne_true
theorem not_xor_self : β (x : Bool), xor (!x) x = true := not_bne_self
theorem xor_not_self : β (x : Bool), xor x (!x) = true := bne_not_self
theorem not_xor : β (x y : Bool), xor (!x) y = !(xor x y) := by decide
theorem xor_not : β (x y : Bool), xor x (!y) = !(xor x y) := by decide
theorem not_xor_not : β (x y : Bool), xor (!x) (!y) = (xor x y) := not_bne_not
theorem xor_self : β (x : Bool), xor x x = false := by decide
theorem xor_comm : β (x y : Bool), xor x y = xor y x := by decide
theorem xor_left_comm : β (x y z : Bool), xor x (xor y z) = xor y (xor x z) := by decide
theorem xor_right_comm : β (x y z : Bool), xor (xor x y) z = xor (xor x z) y := by decide
theorem xor_assoc : β (x y z : Bool), xor (xor x y) z = xor x (xor y z) := bne_assoc
theorem xor_left_inj : β (x y z : Bool), xor x y = xor x z β y = z := bne_left_inj
theorem xor_right_inj : β (x y z : Bool), xor x z = xor y z β x = y := bne_right_inj
/-! ### le/lt -/
@[simp] protected theorem le_true : β (x : Bool), x β€ true := by decide
@[simp] protected theorem false_le : β (x : Bool), false β€ x := by decide
@[simp] protected theorem le_refl : β (x : Bool), x β€ x := by decide
@[simp] protected theorem lt_irrefl : β (x : Bool), Β¬ x < x := by decide
protected theorem le_trans : β {x y z : Bool}, x β€ y β y β€ z β x β€ z := by decide
protected theorem le_antisymm : β {x y : Bool}, x β€ y β y β€ x β x = y := by decide
protected theorem le_total : β (x y : Bool), x β€ y β¨ y β€ x := by decide
protected theorem lt_asymm : β {x y : Bool}, x < y β Β¬ y < x := by decide
protected theorem lt_trans : β {x y z : Bool}, x < y β y < z β x < z := by decide
protected theorem lt_iff_le_not_le : β {x y : Bool}, x < y β x β€ y β§ Β¬ y β€ x := by decide
protected theorem lt_of_le_of_lt : β {x y z : Bool}, x β€ y β y < z β x < z := by decide
protected theorem lt_of_lt_of_le : β {x y z : Bool}, x < y β y β€ z β x < z := by decide
protected theorem le_of_lt : β {x y : Bool}, x < y β x β€ y := by decide
protected theorem le_of_eq : β {x y : Bool}, x = y β x β€ y := by decide
protected theorem ne_of_lt : β {x y : Bool}, x < y β x β y := by decide
protected theorem lt_of_le_of_ne : β {x y : Bool}, x β€ y β x β y β x < y := by decide
protected theorem le_of_lt_or_eq : β {x y : Bool}, x < y β¨ x = y β x β€ y := by decide
protected theorem eq_true_of_true_le : β {x : Bool}, true β€ x β x = true := by decide
protected theorem eq_false_of_le_false : β {x : Bool}, x β€ false β x = false := by decide
/-! ### min/max -/
@[simp] protected theorem max_eq_or : max = or := rfl
@[simp] protected theorem min_eq_and : min = and := rfl
/-! ### injectivity lemmas -/
theorem not_inj : β {x y : Bool}, (!x) = (!y) β x = y := by decide
theorem not_inj_iff : β {x y : Bool}, (!x) = (!y) β x = y := by decide
theorem and_or_inj_right : β {m x y : Bool}, (x && m) = (y && m) β (x || m) = (y || m) β x = y := by
decide
theorem and_or_inj_right_iff :
β {m x y : Bool}, (x && m) = (y && m) β§ (x || m) = (y || m) β x = y := by decide
theorem and_or_inj_left : β {m x y : Bool}, (m && x) = (m && y) β (m || x) = (m || y) β x = y := by
decide
theorem and_or_inj_left_iff :
β {m x y : Bool}, (m && x) = (m && y) β§ (m || x) = (m || y) β x = y := by decide
/-! ## toNat -/
/-- convert a `Bool` to a `Nat`, `false -> 0`, `true -> 1` -/
def toNat (b:Bool) : Nat := cond b 1 0
@[simp] theorem toNat_false : false.toNat = 0 := rfl
@[simp] theorem toNat_true : true.toNat = 1 := rfl
theorem toNat_le (c : Bool) : c.toNat β€ 1 := by
cases c <;> trivial
@[deprecated toNat_le (since := "2024-02-23")]
abbrev toNat_le_one := toNat_le
theorem toNat_lt (b : Bool) : b.toNat < 2 :=
Nat.lt_succ_of_le (toNat_le _)
@[simp] theorem toNat_eq_zero (b : Bool) : b.toNat = 0 β b = false := by
cases b <;> simp
@[simp] theorem toNat_eq_one (b : Bool) : b.toNat = 1 β b = true := by
cases b <;> simp
/-! ### ite -/
@[simp] theorem if_true_left (p : Prop) [h : Decidable p] (f : Bool) :
(ite p true f) = (p || f) := by cases h with | _ p => simp [p]
@[simp] theorem if_false_left (p : Prop) [h : Decidable p] (f : Bool) :
(ite p false f) = (!p && f) := by cases h with | _ p => simp [p]
@[simp] theorem if_true_right (p : Prop) [h : Decidable p] (t : Bool) :
(ite p t true) = (!(p : Bool) || t) := by cases h with | _ p => simp [p]
@[simp] theorem if_false_right (p : Prop) [h : Decidable p] (t : Bool) :
(ite p t false) = (p && t) := by cases h with | _ p => simp [p]
@[simp] theorem ite_eq_true_distrib (p : Prop) [h : Decidable p] (t f : Bool) :
(ite p t f = true) = ite p (t = true) (f = true) := by
cases h with | _ p => simp [p]
@[simp] theorem ite_eq_false_distrib (p : Prop) [h : Decidable p] (t f : Bool) :
(ite p t f = false) = ite p (t = false) (f = false) := by
cases h with | _ p => simp [p]
/-
`not_ite_eq_true_eq_true` and related theorems below are added for
non-confluence. A motivating example is
`Β¬((if u then b else c) = true)`.
This reduces to:
1. `Β¬((if u then (b = true) else (c = true))` via `ite_eq_true_distrib`
2. `(if u then b c) = false)` via `Bool.not_eq_true`.
Similar logic holds for `Β¬((if u then b else c) = false)` and related
lemmas.
-/
@[simp]
theorem not_ite_eq_true_eq_true (p : Prop) [h : Decidable p] (b c : Bool) :
Β¬(ite p (b = true) (c = true)) β (ite p (b = false) (c = false)) := by
cases h with | _ p => simp [p]
@[simp]
theorem not_ite_eq_false_eq_false (p : Prop) [h : Decidable p] (b c : Bool) :
Β¬(ite p (b = false) (c = false)) β (ite p (b = true) (c = true)) := by
cases h with | _ p => simp [p]
@[simp]
theorem not_ite_eq_true_eq_false (p : Prop) [h : Decidable p] (b c : Bool) :
Β¬(ite p (b = true) (c = false)) β (ite p (b = false) (c = true)) := by
cases h with | _ p => simp [p]
@[simp]
theorem not_ite_eq_false_eq_true (p : Prop) [h : Decidable p] (b c : Bool) :
Β¬(ite p (b = false) (c = true)) β (ite p (b = true) (c = false)) := by
cases h with | _ p => simp [p]
/-
Added for confluence between `if_true_left` and `ite_false_same` on
`if b = true then True else b = true`
-/
@[simp] theorem eq_false_imp_eq_true : β(b:Bool), (b = false β b = true) β (b = true) := by decide
/-
Added for confluence between `if_true_left` and `ite_false_same` on
`if b = false then True else b = false`
-/
@[simp] theorem eq_true_imp_eq_false : β(b:Bool), (b = true β b = false) β (b = false) := by decide
/-! ### cond -/
theorem cond_eq_ite {Ξ±} (b : Bool) (t e : Ξ±) : cond b t e = if b then t else e := by
cases b <;> simp
theorem cond_eq_if : (bif b then x else y) = (if b then x else y) := cond_eq_ite b x y
@[simp] theorem cond_not (b : Bool) (t e : Ξ±) : cond (!b) t e = cond b e t := by
cases b <;> rfl
@[simp] theorem cond_self (c : Bool) (t : Ξ±) : cond c t t = t := by cases c <;> rfl
/-
This is a simp rule in Mathlib, but results in non-confluence that is difficult
to fix as decide distributes over propositions. As an example, observe that
`cond (decide (p β§ q)) t f` could simplify to either:
* `if p β§ q then t else f` via `Bool.cond_decide` or
* `cond (decide p && decide q) t f` via `Bool.decide_and`.
A possible approach to improve normalization between `cond` and `ite` would be
to completely simplify away `cond` by making `cond_eq_ite` a `simp` rule, but
that has not been taken since it could surprise users to migrate pure `Bool`
operations like `cond` to a mix of `Prop` and `Bool`.
-/
theorem cond_decide {Ξ±} (p : Prop) [Decidable p] (t e : Ξ±) :
cond (decide p) t e = if p then t else e := by
simp [cond_eq_ite]
@[simp] theorem cond_eq_ite_iff (a : Bool) (p : Prop) [h : Decidable p] (x y u v : Ξ±) :
(cond a x y = ite p u v) β ite a x y = ite p u v := by
simp [Bool.cond_eq_ite]
@[simp] theorem ite_eq_cond_iff (p : Prop) [h : Decidable p] (a : Bool) (x y u v : Ξ±) :
(ite p x y = cond a u v) β ite p x y = ite a u v := by
simp [Bool.cond_eq_ite]
@[simp] theorem cond_eq_true_distrib : β(c t f : Bool),
(cond c t f = true) = ite (c = true) (t = true) (f = true) := by
decide
@[simp] theorem cond_eq_false_distrib : β(c t f : Bool),
(cond c t f = false) = ite (c = true) (t = false) (f = false) := by decide
protected theorem cond_true {Ξ± : Type u} {a b : Ξ±} : cond true a b = a := cond_true a b
protected theorem cond_false {Ξ± : Type u} {a b : Ξ±} : cond false a b = b := cond_false a b
@[simp] theorem cond_true_left : β(c f : Bool), cond c true f = ( c || f) := by decide
@[simp] theorem cond_false_left : β(c f : Bool), cond c false f = (!c && f) := by decide
@[simp] theorem cond_true_right : β(c t : Bool), cond c t true = (!c || t) := by decide
@[simp] theorem cond_false_right : β(c t : Bool), cond c t false = ( c && t) := by decide
@[simp] theorem cond_true_same : β(c b : Bool), cond c c b = (c || b) := by decide
@[simp] theorem cond_false_same : β(c b : Bool), cond c b c = (c && b) := by decide
/-# decidability -/
protected theorem decide_coe (b : Bool) [Decidable (b = true)] : decide (b = true) = b := decide_eq_true
@[simp] theorem decide_and (p q : Prop) [dpq : Decidable (p β§ q)] [dp : Decidable p] [dq : Decidable q] :
decide (p β§ q) = (p && q) := by
cases dp with | _ p => simp [p]
@[simp] theorem decide_or (p q : Prop) [dpq : Decidable (p β¨ q)] [dp : Decidable p] [dq : Decidable q] :
decide (p β¨ q) = (p || q) := by
cases dp with | _ p => simp [p]
@[simp] theorem decide_iff_dist (p q : Prop) [dpq : Decidable (p β q)] [dp : Decidable p] [dq : Decidable q] :
decide (p β q) = (decide p == decide q) := by
cases dp with | _ p => simp [p]
end Bool
export Bool (cond_eq_if)
/-! ### decide -/
@[simp] theorem false_eq_decide_iff {p : Prop} [h : Decidable p] : false = decide p β Β¬p := by
cases h with | _ q => simp [q]
@[simp] theorem true_eq_decide_iff {p : Prop} [h : Decidable p] : true = decide p β p := by
cases h with | _ q => simp [q]