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

Commit

Permalink
feat(data/matrix): has_repr instances for fin vectors and matrices (
Browse files Browse the repository at this point in the history
#7953)

This PR provides `has_repr` instances for the types `fin n → α` and `matrix (fin m) (fin n) α`, displaying in the `![...]` matrix notation. This is especially useful if you want to `#eval` a calculation involving matrices.

[Based on this Zulip post.](https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/Matrix.20operations/near/242766110)



Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com>
  • Loading branch information
Vierkantor and Vierkantor committed Jun 17, 2021
1 parent 641a9d3 commit dc5d0c1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/data/matrix/notation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ v 0
def vec_tail {n : ℕ} (v : fin n.succ → α) : fin n → α :=
v ∘ fin.succ

variables {m n : ℕ}

/-- Use `![...]` notation for displaying a vector `fin n → α`, for example:
```
#eval ![1, 2] + ![3, 4] -- ![4, 6]
```
-/
instance [has_repr α] : has_repr (fin n → α) :=
{ repr := λ f, "![" ++ (string.intercalate ", " ((list.fin_range n).map (λ n, repr (f n)))) ++ "]" }

/-- Use `![...]` notation for displaying a `fin`-indexed matrix, for example:
```
#eval ![![1, 2], ![3, 4]] + ![![3, 4], ![5, 6]] -- ![![4, 6], ![8, 10]]
```
-/
instance [has_repr α] : has_repr (matrix (fin m) (fin n) α) :=
(by apply_instance : has_repr (fin m → fin n → α))

end matrix_notation

variables {m n o : ℕ} {m' n' o' : Type*} [fintype m'] [fintype n'] [fintype o']
Expand Down

0 comments on commit dc5d0c1

Please sign in to comment.