Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(data/{fin,unsigned}/*): remove unused {fin/unsigned} ops #527

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions library/init/data/fin/basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ lemma ne_of_vne {i j : fin n} (h : i.val ≠ j.val) : i ≠ j :=
lemma vne_of_ne {i j : fin n} (h : i ≠ j) : i.val ≠ j.val :=
λ h', absurd (eq_of_veq h') h

protected def succ : fin n → fin (succ n)
| ⟨a, h⟩ := ⟨nat.succ a, succ_le_succ h⟩

instance : has_zero (fin (succ n)) := ⟨⟨0, succ_pos n⟩⟩

end fin

open fin
Expand Down
2 changes: 1 addition & 1 deletion library/init/data/fin/default.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import init.data.fin.basic init.data.fin.ops
import init.data.fin.basic
104 changes: 0 additions & 104 deletions library/init/data/fin/ops.lean

This file was deleted.

3 changes: 3 additions & 0 deletions library/init/data/unsigned/basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ zero_lt_succ _
protected def of_nat' (n : nat) : unsigned :=
if h : n < unsigned_sz then ⟨n, h⟩ else ⟨0, zero_lt_unsigned_sz⟩

instance : has_zero unsigned := ⟨⟨0, succ_pos _⟩⟩
instance : has_one unsigned := ⟨⟨1, succ_le_succ (succ_pos _)⟩⟩

def to_nat (c : unsigned) : nat := c.val

end unsigned
Expand Down
27 changes: 16 additions & 11 deletions library/init/data/unsigned/ops.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.data.unsigned.basic init.data.fin.ops
import init.data.unsigned.basic init.data.nat

namespace unsigned
def of_nat (n : nat) : unsigned := fin.of_nat n
instance : has_zero unsigned := ⟨fin.of_nat 0⟩
instance : has_one unsigned := ⟨fin.of_nat 1⟩
instance : has_add unsigned := ⟨fin.add⟩
instance : has_sub unsigned := ⟨fin.sub⟩
instance : has_mul unsigned := ⟨fin.mul⟩
instance : has_mod unsigned := ⟨fin.mod⟩
instance : has_div unsigned := ⟨fin.div⟩
instance : has_lt unsigned := ⟨fin.lt⟩
instance : has_le unsigned := ⟨fin.le⟩

def of_nat (n : nat) : unsigned :=
⟨n % nat.succ _, nat.mod_lt _ (nat.zero_lt_succ _)⟩

private lemma mlt {n b : nat} : ∀ {a}, n > a → b % n < n
| 0 h := nat.mod_lt _ h
| (a+1) h :=
have n > 0, from lt_trans (nat.zero_lt_succ _) h,
nat.mod_lt _ this

protected def add : unsigned → unsigned → unsigned
| ⟨a, h⟩ ⟨b, _⟩ := ⟨(a + b) % _, mlt h⟩

instance : has_add unsigned := ⟨unsigned.add⟩

end unsigned
10 changes: 4 additions & 6 deletions tests/lean/397c.lean.expected.out
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[class_instances] class-instance resolution trace
[class_instances] (0) ?x_0 : has_one α := native.float.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := unsigned.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := @fin.has_one ?x_1
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := int.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := unsigned.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := nat.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := @ring.to_has_one ?x_2 ?x_3
[class_instances] (1) ?x_3 : ring α := _inst_1
[class_instances] (0) ?x_0 : has_one α := @ring.to_has_one ?x_1 ?x_2
[class_instances] (1) ?x_2 : ring α := _inst_1
[class_instances] caching instance for ring α
_inst_1
[class_instances] caching instance for has_one α
Expand Down
10 changes: 4 additions & 6 deletions tests/lean/398c.lean.expected.out
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[class_instances] class-instance resolution trace
[class_instances] (0) ?x_0 : has_one α := native.float.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := unsigned.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := @fin.has_one ?x_1
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := int.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := unsigned.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := nat.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one α := @ring.to_has_one ?x_2 ?x_3
[class_instances] (1) ?x_3 : ring α := _inst_1
[class_instances] (0) ?x_0 : has_one α := @ring.to_has_one ?x_1 ?x_2
[class_instances] (1) ?x_2 : ring α := _inst_1
[class_instances] caching instance for ring α
_inst_1
[class_instances] caching instance for has_one α
Expand Down
4 changes: 2 additions & 2 deletions tests/lean/run/array1.lean
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ a^.foldl 0 (+)
#eval array_sum (mk_array 10 1)

#eval (mk_array 10 1)^.data ⟨1, dec_trivial⟩ + 20
#eval (mk_array 10 1)^.data 2
#eval (mk_array 10 3)^.data 2
#eval (mk_array 10 1)^.data ⟨2, dec_trivial⟩
#eval (mk_array 10 3)^.data ⟨2, dec_trivial⟩
8 changes: 2 additions & 6 deletions tests/lean/tc_caching.lean.expected.out
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
[class_instances] class-instance resolution trace
[class_instances] (0) ?x_0 : has_one ℕ := native.float.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one ℕ := unsigned.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one ℕ := @fin.has_one ?x_1
failed is_def_eq
[class_instances] (0) ?x_0 : has_one ℕ := int.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one ℕ := unsigned.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_one ℕ := nat.has_one
[class_instances] caching instance for has_one ℕ
nat.has_one
Expand All @@ -50,8 +48,6 @@ nat.has_one
failed is_def_eq
[class_instances] (0) ?x_0 : has_add ℕ := unsigned.has_add
failed is_def_eq
[class_instances] (0) ?x_0 : has_add ℕ := @fin.has_add ?x_1
failed is_def_eq
[class_instances] (0) ?x_0 : has_add ℕ := int.has_add
failed is_def_eq
[class_instances] (0) ?x_0 : has_add ℕ := options.has_add
Expand Down