@@ -12,6 +12,42 @@ public section
1212
1313namespace Bool
1414
15+ /--
16+ Boolean “logical or”. `lor x y`.
17+
18+ `land x y` is `true` when both of `x` or `y` are `true`. It is functionally the same as
19+ `x && y` but it does not have short-circuiting behavior: any call to `land` will evaluate both
20+ arguments.
21+
22+ Examples:
23+ * `land false false = false`
24+ * `land true false = false`
25+ * `land false true = false`
26+ * `land true true = true`
27+ -/
28+ @[expose, extern "lean_bool_land"]
29+ def land (x y : Bool) : Bool := x && y
30+
31+ @[simp] theorem land_eq_and (x y : Bool) : land x y = (x && y) := rfl
32+
33+ /--
34+ Boolean “logical or”. `lor x y`.
35+
36+ `lor x y` is `true` when at least one of `x` or `y` is `true`. It is functionally the same as
37+ `x || y` but it does not have short-circuiting behavior: any call to `lor` will evaluate both
38+ arguments.
39+
40+ Examples:
41+ * `lor false false = false`
42+ * `lor true false = true`
43+ * `lor false true = true`
44+ * `lor true true = true`
45+ -/
46+ @[expose, extern "lean_bool_lor"]
47+ def lor (x y : Bool) : Bool := x || y
48+
49+ @[simp] theorem lor_eq_or (x y : Bool) : lor x y = (x || y) := rfl
50+
1551/--
1652Boolean “exclusive or”. `xor x y` can be written `x ^^ y`.
1753
@@ -25,11 +61,14 @@ Examples:
2561 * `false ^^ true = true`
2662 * `true ^^ true = false`
2763 -/
28- abbrev xor : Bool → Bool → Bool := bne
64+ @[expose, reducible, extern "lean_bool_xor"]
65+ def xor : Bool → Bool → Bool := bne
66+
67+ @[inherit_doc] infixl :33 " ^^ " => Bool.xor
2968
30- @[inherit_doc] infixl : 33 " ^^ " => xor
69+ recommended_spelling "xor" for "^^" in [Bool. xor, « term_^^_ »]
3170
32- recommended_spelling "xor" for "^^" in [xor, « term_^^_ »]
71+ theorem xor_eq_bne (x y : Bool) : (x ^^ y) = (x != y) := rfl
3372
3473instance (p : Bool → Prop ) [inst : DecidablePred p] : Decidable (∀ x, p x) :=
3574 match inst true , inst false with
@@ -48,11 +87,13 @@ instance (p : Bool → Prop) [inst : DecidablePred p] : Decidable (∃ x, p x) :
4887instance : LE Bool := ⟨(. → .)⟩
4988instance : LT Bool := ⟨(!. && .)⟩
5089
90+ @[extern "lean_bool_dec_le"]
5191instance (x y : Bool) : Decidable (x ≤ y) := inferInstanceAs (Decidable (x → y))
92+ @[extern "lean_bool_dec_lt"]
5293instance (x y : Bool) : Decidable (x < y) := inferInstanceAs (Decidable (!x && y))
5394
54- instance : Max Bool := ⟨or ⟩
55- instance : Min Bool := ⟨and ⟩
95+ instance : Max Bool := ⟨lor ⟩
96+ instance : Min Bool := ⟨land ⟩
5697
5798theorem false_ne_true : false ≠ true := Bool.noConfusion
5899
@@ -385,7 +426,8 @@ theorem and_or_inj_left_iff :
385426/--
386427Converts `true` to `1` and `false` to `0`.
387428-/
388- @[expose] def toNat (b : Bool) : Nat := cond b 1 0
429+ @[expose, extern "lean_bool_to_nat"]
430+ def toNat (b : Bool) : Nat := cond b 1 0
389431
390432@[simp, bitvec_to_nat, grind =] theorem toNat_false : false .toNat = 0 := rfl
391433
0 commit comments