This PR provides more lemmas about sums of lists/arrays/vectors,
especially sums of `Nat` or `Int` lists/arrays/vectors.
This change has been motivated by my experience solving
`human-eval-lean` problems. Sums, minima and maxima are frequently
required and the improvements provided in this PR make it easier to
verify such programming tasks.
Changes:
* Added lemmas that `sum` equals `foldl`/`foldr`.
* Generalized `sum_append_nat` and `sum_reverse_nat` lemmas so that they
are polymorphic, requiring only some type class instances about the list
elements' type. The polymorphic lemmas aren't simp- or grind-annotated
because I fear the instance synthesis overhead. However, the `Nat` and
`Int` specializations are annotated (see below). Note that as
`{Array,Vector}.min` do not exist, some lemmas can't be stated and were
omitted.
* Added `List.min_singleton` and `List.max_singleton` lemmas as they
were needed for some proofs.
* `Nat`-related:
* Moved all `{List,Array,Vector}.sum` lemmas that are specific for `Nat`
into their own module: `Init.Data.List.Nat.Sum`, `Init.Data.Array.Nat`
and `Int.Data.Vector.Nat`.
* Notably, moved `Nat.sum_pos_iff_exists_pos` and renamed it to
`List.sum_pos_iff_exists_pos_nat`. This is more consistent and made it
possible to add `Array` and `Vector` variants of this lemma.
* Added lemmas proving that `l.sum / l.length` lies between the minimum
and the maximum of a list.
* Added analogous lemmas for `Int` lists/arrays/vectors to parallel
modules: `Init.Data.List.Int.Sum`, `Init.Data.Array.Int` and
`Int.Data.Vector.Int`.
* Renamed `sum_eq_sum_toList` to `sum_toList`, which better represents
the theorem's content.
28 lines
913 B
Text
28 lines
913 B
Text
/-
|
|
Copyright (c) 2024 Lean FRO. All rights reserved.
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
Authors: Kim Morrison
|
|
-/
|
|
module
|
|
|
|
prelude
|
|
public import Init.Data.Vector.Basic
|
|
public import Init.Data.Vector.Lemmas
|
|
public import Init.Data.Vector.Lex
|
|
public import Init.Data.Vector.MapIdx
|
|
public import Init.Data.Vector.Count
|
|
public import Init.Data.Vector.DecidableEq
|
|
public import Init.Data.Vector.Zip
|
|
public import Init.Data.Vector.OfFn
|
|
public import Init.Data.Vector.Range
|
|
public import Init.Data.Vector.Erase
|
|
public import Init.Data.Vector.Monadic
|
|
public import Init.Data.Vector.InsertIdx
|
|
public import Init.Data.Vector.FinRange
|
|
public import Init.Data.Vector.Extract
|
|
public import Init.Data.Vector.Perm
|
|
public import Init.Data.Vector.Find
|
|
public import Init.Data.Vector.Algebra
|
|
public import Init.Data.Vector.Stream
|
|
public import Init.Data.Vector.Nat
|
|
public import Init.Data.Vector.Int
|