Get the i
-th element (interpreted as 0
if the list is not long enough).
Equations
- IntList.get xs i = Option.getD (List.get? xs i) 0
Instances For
@[simp]
theorem
IntList.get_cons_succ
{x : Int}
{xs : List Int}
{i : Nat}
:
IntList.get (x :: xs) (i + 1) = IntList.get xs i
theorem
IntList.get_map
{f : Int → Int}
{i : Nat}
{xs : IntList}
(h : f 0 = 0)
:
IntList.get (List.map f xs) i = f (IntList.get xs i)
theorem
IntList.get_of_length_le
{i : Nat}
{xs : IntList}
(h : List.length xs ≤ i)
:
IntList.get xs i = 0
theorem
IntList.lt_length_of_get_nonzero
{i : Nat}
{xs : IntList}
(h : IntList.get xs i ≠ 0)
:
i < List.length xs
Like List.set
, but right-pad with zeroes as necessary first.
Equations
- IntList.set [] 0 y = [y]
- IntList.set [] (Nat.succ i_2) y = 0 :: IntList.set [] i_2 y
- IntList.set (head :: xs_2) 0 y = y :: xs_2
- IntList.set (x :: xs_2) (Nat.succ i_2) y = x :: IntList.set xs_2 i_2 y
Instances For
@[simp]
theorem
IntList.set_nil_succ
{i : Nat}
{y : Int}
:
IntList.set [] (i + 1) y = 0 :: IntList.set [] i y
@[simp]
theorem
IntList.set_cons_zero
{x : Int}
{xs : List Int}
{y : Int}
:
IntList.set (x :: xs) 0 y = y :: xs
@[simp]
theorem
IntList.set_cons_succ
{x : Int}
{xs : List Int}
{i : Nat}
{y : Int}
:
IntList.set (x :: xs) (i + 1) y = x :: IntList.set xs i y
theorem
IntList.set_get_eq
{xs : IntList}
{i : Nat}
{y : Int}
{j : Nat}
:
IntList.get (IntList.set xs i y) j = if i = j then y else IntList.get xs j
@[simp]
theorem
IntList.set_get_self
{xs : IntList}
{i : Nat}
{y : Int}
:
IntList.get (IntList.set xs i y) i = y
@[simp]
theorem
IntList.set_get_of_ne
{i : Nat}
{j : Nat}
{xs : IntList}
{y : Int}
(h : i ≠ j)
:
IntList.get (IntList.set xs i y) j = IntList.get xs j
Returns the leading coefficient, i.e. the first non-zero entry.
Equations
- IntList.leading xs = Option.getD (List.find? (fun (x : Int) => !x == 0) xs) 0
Instances For
Implementation of +
on IntList
.
Equations
- IntList.add xs ys = List.zipWithAll (fun (x y : Option Int) => Option.getD x 0 + Option.getD y 0) xs ys
Instances For
Equations
- IntList.instAddIntList = { add := IntList.add }
theorem
IntList.add_def
(xs : IntList)
(ys : IntList)
:
xs + ys = List.zipWithAll (fun (x y : Option Int) => Option.getD x 0 + Option.getD y 0) xs ys
@[simp]
theorem
IntList.add_get
(xs : IntList)
(ys : IntList)
(i : Nat)
:
IntList.get (xs + ys) i = IntList.get xs i + IntList.get ys i
Implementation of *
on IntList
.
Equations
- IntList.mul xs ys = List.zipWith (fun (x x_1 : Int) => x * x_1) xs ys
Instances For
Equations
- IntList.instMulIntList = { mul := IntList.mul }
theorem
IntList.mul_def
(xs : IntList)
(ys : IntList)
:
xs * ys = List.zipWith (fun (x x_1 : Int) => x * x_1) xs ys
@[simp]
theorem
IntList.mul_get
(xs : IntList)
(ys : IntList)
(i : Nat)
:
IntList.get (xs * ys) i = IntList.get xs i * IntList.get ys i
Equations
- IntList.instNegIntList = { neg := IntList.neg }
@[simp]
Implementation of subtraction on IntList
.
Equations
- IntList.sub xs ys = List.zipWithAll (fun (x y : Option Int) => Option.getD x 0 - Option.getD y 0) xs ys
Instances For
Equations
- IntList.instSubIntList = { sub := IntList.sub }
theorem
IntList.sub_def
(xs : IntList)
(ys : IntList)
:
xs - ys = List.zipWithAll (fun (x y : Option Int) => Option.getD x 0 - Option.getD y 0) xs ys
Equations
- IntList.instHMulIntIntList = { hMul := fun (i : Int) (xs : IntList) => IntList.smul xs i }
@[simp]
theorem
IntList.smul_get
(xs : IntList)
(a : Int)
(i : Nat)
:
IntList.get (a * xs) i = a * IntList.get xs i
A linear combination of two IntList
s.
Equations
- IntList.combo a xs b ys = List.zipWithAll (fun (x y : Option Int) => a * Option.getD x 0 + b * Option.getD y 0) xs ys
Instances For
theorem
IntList.combo_def
{a : Int}
{b : Int}
(xs : IntList)
(ys : IntList)
:
IntList.combo a xs b ys = List.zipWithAll (fun (x y : Option Int) => a * Option.getD x 0 + b * Option.getD y 0) xs ys
@[simp]
theorem
IntList.combo_get
{a : Int}
{b : Int}
(xs : IntList)
(ys : IntList)
(i : Nat)
:
IntList.get (IntList.combo a xs b ys) i = a * IntList.get xs i + b * IntList.get ys i
@[simp]
theorem
IntList.sub_get
(xs : IntList)
(ys : IntList)
(i : Nat)
:
IntList.get (xs - ys) i = IntList.get xs i - IntList.get ys i
The sum of the entries of an IntList
.
Equations
- IntList.sum xs = List.foldr (fun (x x_1 : Int) => x + x_1) 0 xs
Instances For
@[simp]
theorem
IntList.sum_add
(xs : IntList)
(ys : IntList)
:
IntList.sum (xs + ys) = IntList.sum xs + IntList.sum ys
@[simp]
@[simp]
theorem
IntList.dot_cons₂
{x : Int}
{xs : List Int}
{y : Int}
{ys : List Int}
:
IntList.dot (x :: xs) (y :: ys) = x * y + IntList.dot xs ys
@[simp]
theorem
IntList.dot_set_left
(xs : IntList)
(ys : IntList)
(i : Nat)
(z : Int)
:
IntList.dot (IntList.set xs i z) ys = IntList.dot xs ys + (z - IntList.get xs i) * IntList.get ys i
@[simp]
theorem
IntList.dot_set_right
(xs : IntList)
(ys : IntList)
(i : Nat)
(z : Int)
:
IntList.dot xs (IntList.set ys i z) = IntList.dot xs ys + IntList.get xs i * (z - IntList.get ys i)
theorem
IntList.dot_distrib_left
(xs : IntList)
(ys : IntList)
(zs : IntList)
:
IntList.dot (xs + ys) zs = IntList.dot xs zs + IntList.dot ys zs
@[simp]
theorem
IntList.dot_neg_left
(xs : IntList)
(ys : IntList)
:
IntList.dot (-xs) ys = -IntList.dot xs ys
@[simp]
theorem
IntList.dot_smul_left
(xs : IntList)
(ys : IntList)
(i : Int)
:
IntList.dot (i * xs) ys = i * IntList.dot xs ys
theorem
IntList.dot_sub_left
(xs : IntList)
(ys : IntList)
(zs : IntList)
:
IntList.dot (xs - ys) zs = IntList.dot xs zs - IntList.dot ys zs
theorem
IntList.dot_of_left_zero
{xs : IntList}
{ys : IntList}
(w : ∀ (x : Int), x ∈ xs → x = 0)
:
IntList.dot xs ys = 0
theorem
IntList.dvd_dot_of_dvd_left
{xs : IntList}
{m : Int}
{ys : IntList}
(w : ∀ (x : Int), x ∈ xs → m ∣ x)
:
m ∣ IntList.dot xs ys
@[simp]
theorem
IntList.sdiv_cons
{x : Int}
{xs : List Int}
{g : Int}
:
IntList.sdiv (x :: xs) g = x / g :: IntList.sdiv xs g
@[simp]
theorem
IntList.sdiv_get
{xs : IntList}
{g : Int}
{i : Nat}
:
IntList.get (IntList.sdiv xs g) i = IntList.get xs i / g
The gcd of the absolute values of the entries of an IntList
.
Equations
- IntList.gcd xs = List.foldr (fun (x : Int) (g : Nat) => Nat.gcd (Int.natAbs x) g) 0 xs
Instances For
@[simp]
theorem
IntList.gcd_cons
{x : Int}
{xs : List Int}
:
IntList.gcd (x :: xs) = Nat.gcd (Int.natAbs x) (IntList.gcd xs)
theorem
IntList.gcd_cons_div_right
{x : Int}
{xs : List Int}
:
IntList.gcd (x :: xs) ∣ IntList.gcd xs
theorem
IntList.gcd_cons_div_right'
{x : Int}
{xs : List Int}
:
↑(IntList.gcd (x :: xs)) ∣ ↑(IntList.gcd xs)
theorem
IntList.dvd_gcd
(xs : IntList)
(c : Nat)
(w : ∀ {a : Int}, a ∈ xs → ↑c ∣ a)
:
c ∣ IntList.gcd xs
@[simp]
@[simp]
theorem
IntList.dot_mod_gcd_left
(xs : IntList)
(ys : IntList)
:
IntList.dot xs ys % ↑(IntList.gcd xs) = 0
theorem
IntList.gcd_dvd_dot_left
(xs : IntList)
(ys : IntList)
:
↑(IntList.gcd xs) ∣ IntList.dot xs ys
@[simp]
theorem
IntList.dot_eq_zero_of_left_eq_zero
{xs : IntList}
{ys : IntList}
(h : ∀ (x : Int), x ∈ xs → x = 0)
:
IntList.dot xs ys = 0
theorem
IntList.dot_eq_zero_of_gcd_left_eq_zero
{xs : IntList}
{ys : IntList}
(h : IntList.gcd xs = 0)
:
IntList.dot xs ys = 0
theorem
IntList.dot_sdiv_left
(xs : IntList)
(ys : IntList)
{d : Int}
(h : d ∣ ↑(IntList.gcd xs))
:
IntList.dot (IntList.sdiv xs d) ys = IntList.dot xs ys / d
@[simp]
theorem
IntList.dot_sdiv_gcd_left
(xs : IntList)
(ys : IntList)
:
IntList.dot (IntList.sdiv xs ↑(IntList.gcd xs)) ys = IntList.dot xs ys / ↑(IntList.gcd xs)
The leading sign in an IntList
.
Equations
- IntList.leadingSign [] = 0
- IntList.leadingSign (Int.ofNat 0 :: xs_2) = IntList.leadingSign xs_2
- IntList.leadingSign (x :: tail) = Int.sign x
Instances For
@[simp]
theorem
IntList.leadingSign_cons_zero
{xs : List Int}
:
IntList.leadingSign (0 :: xs) = IntList.leadingSign xs
theorem
IntList.leadingSign_cons
{x : Int}
{xs : List Int}
:
IntList.leadingSign (x :: xs) = if x = 0 then IntList.leadingSign xs else Int.sign x
Trim trailing zeroes from a List Int
, returning none
if none were removed.
Equations
- IntList.trim? xs = match List.reverse xs with | [] => none | Int.ofNat 0 :: xs => some (List.reverse (List.dropWhile (fun (x : Int) => x == 0) xs)) | head :: tail => none
Instances For
theorem
IntList.trim?_isSome
{xs : IntList}
:
(Option.isSome (IntList.trim? xs) = true) = (List.getLast? xs = some 0)
Trailing trailing zeroes from a List Int
.
Equations
- IntList.trim xs = Option.getD (IntList.trim? xs) xs
Instances For
theorem
IntList.trim?_eq_some
{t : IntList}
{xs : IntList}
(w : IntList.trim? xs = some t)
:
IntList.trim xs = t
theorem
IntList.trim_spec
{xs : IntList}
:
IntList.trim xs = List.reverse (List.dropWhile (fun (x : Int) => x == 0) (List.reverse xs))
@[simp]
@[inline, reducible]
The difference between the balanced mod of a dot product, and the dot product with balanced mod applied to each entry of the left factor.
Equations
- IntList.bmod_dot_sub_dot_bmod m a b = Int.bmod (IntList.dot a b) m - IntList.dot (IntList.bmod a m) b
Instances For
theorem
IntList.dvd_bmod_dot_sub_dot_bmod
(m : Nat)
(xs : IntList)
(ys : IntList)
:
↑m ∣ IntList.bmod_dot_sub_dot_bmod m xs ys