Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit e585bed

Browse files
kckennylaudigama0
authored andcommitted
feat(data/int/basic): bounded forall is decidable for integers
1 parent 489050b commit e585bed

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

data/int/basic.lean

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Jeremy Avigad
55
66
The integers, with addition, multiplication, and subtraction.
77
-/
8-
import data.nat.basic algebra.char_zero algebra.order_functions
8+
import data.nat.basic data.list.basic algebra.char_zero algebra.order_functions
99
open nat
1010

1111
namespace int
@@ -1126,4 +1126,35 @@ by simp [abs]
11261126

11271127
end cast
11281128

1129+
section decidable
1130+
1131+
def range (m n : ℤ) : list ℤ :=
1132+
(list.range (to_nat (n-m))).map $ λ r, m+r
1133+
1134+
theorem mem_range_iff {m n r : ℤ} : r ∈ range m n ↔ m ≤ r ∧ r < n :=
1135+
⟨λ H, let ⟨s, h1, h2⟩ := list.mem_map.1 H in h2 ▸
1136+
⟨le_add_of_nonneg_right trivial,
1137+
add_lt_of_lt_sub_left $ match n-m, h1 with
1138+
| (k:ℕ), h1 := by rwa [list.mem_range, to_nat_coe_nat, ← coe_nat_lt] at h1
1139+
end⟩,
1140+
λ ⟨h1, h2⟩, list.mem_map.2 ⟨to_nat (r-m),
1141+
list.mem_range.2 $ by rw [← coe_nat_lt, to_nat_of_nonneg (sub_nonneg_of_le h1),
1142+
to_nat_of_nonneg (sub_nonneg_of_le (le_of_lt (lt_of_le_of_lt h1 h2)))];
1143+
exact sub_lt_sub_right h2 _,
1144+
show m + _ = _, by rw [to_nat_of_nonneg (sub_nonneg_of_le h1), add_sub_cancel'_right]⟩⟩
1145+
1146+
instance decidable_le_lt (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m ≤ r → r < n → P r) :=
1147+
decidable_of_iff (∀ r ∈ range m n, P r) $ by simp only [mem_range_iff, and_imp]
1148+
1149+
instance decidable_le_le (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m ≤ r → r ≤ n → P r) :=
1150+
decidable_of_iff (∀ r ∈ range m (n+1), P r) $ by simp only [mem_range_iff, and_imp, lt_add_one_iff]
1151+
1152+
instance decidable_lt_lt (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m < r → r < n → P r) :=
1153+
int.decidable_le_lt P _ _
1154+
1155+
instance decidable_lt_le (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m < r → r ≤ n → P r) :=
1156+
int.decidable_le_le P _ _
1157+
1158+
end decidable
1159+
11291160
end int

0 commit comments

Comments
 (0)