@@ -1402,6 +1402,13 @@ by cases l; refl
1402
1402
theorem map₂_nil (f : α → β → γ) (l : list α) : map₂ f l [] = [] :=
1403
1403
by cases l; refl
1404
1404
1405
+ @[simp] theorem map₂_flip (f : α → β → γ) :
1406
+ ∀ as bs, map₂ (flip f) bs as = map₂ f as bs
1407
+ | [] [] := rfl
1408
+ | [] (b :: bs) := rfl
1409
+ | (a :: as) [] := rfl
1410
+ | (a :: as) (b :: bs) := by { simp! [map₂_flip], refl }
1411
+
1405
1412
/-! ### take, drop -/
1406
1413
@[simp] theorem take_zero (l : list α) : take 0 l = [] := rfl
1407
1414
@@ -4024,7 +4031,218 @@ lemma choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) := (choo
4024
4031
4025
4032
end choose
4026
4033
4027
- -- A jumble of lost lemmas:
4034
+ /-! ### map₂_left' -/
4035
+
4036
+ section map₂_left'
4037
+
4038
+ -- The definitional equalities for `map₂_left'` can already be used by the
4039
+ -- simplifie because `map₂_left'` is marked `@[simp]`.
4040
+
4041
+ @[simp] theorem map₂_left'_nil_right (f : α → option β → γ) (as) :
4042
+ map₂_left' f as [] = (as.map (λ a, f a none), []) :=
4043
+ by cases as; refl
4044
+
4045
+ end map₂_left'
4046
+
4047
+ /-! ### map₂_right' -/
4048
+
4049
+ section map₂_right'
4050
+
4051
+ variables (f : option α → β → γ) (a : α) (as : list α) (b : β) (bs : list β)
4052
+
4053
+ @[simp] theorem map₂_right'_nil_left :
4054
+ map₂_right' f [] bs = (bs.map (f none), []) :=
4055
+ by cases bs; refl
4056
+
4057
+ @[simp] theorem map₂_right'_nil_right :
4058
+ map₂_right' f as [] = ([], as) :=
4059
+ rfl
4060
+
4061
+ @[simp] theorem map₂_right'_nil_cons :
4062
+ map₂_right' f [] (b :: bs) = (f none b :: bs.map (f none), []) :=
4063
+ rfl
4064
+
4065
+ @[simp] theorem map₂_right'_cons_cons :
4066
+ map₂_right' f (a :: as) (b :: bs) =
4067
+ let rec := map₂_right' f as bs in
4068
+ (f (some a) b :: rec.fst, rec.snd) :=
4069
+ rfl
4070
+
4071
+ end map₂_right'
4072
+
4073
+ /-! ### zip_left' -/
4074
+
4075
+ section zip_left'
4076
+
4077
+ variables (a : α) (as : list α) (b : β) (bs : list β)
4078
+
4079
+ @[simp] theorem zip_left'_nil_right :
4080
+ zip_left' as ([] : list β) = (as.map (λ a, (a, none)), []) :=
4081
+ by cases as; refl
4082
+
4083
+ @[simp] theorem zip_left'_nil_left :
4084
+ zip_left' ([] : list α) bs = ([], bs) :=
4085
+ rfl
4086
+
4087
+ @[simp] theorem zip_left'_cons_nil :
4088
+ zip_left' (a :: as) ([] : list β) = ((a, none) :: as.map (λ a, (a, none)), []) :=
4089
+ rfl
4090
+
4091
+ @[simp] theorem zip_left'_cons_cons :
4092
+ zip_left' (a :: as) (b :: bs) =
4093
+ let rec := zip_left' as bs in
4094
+ ((a, some b) :: rec.fst, rec.snd) :=
4095
+ rfl
4096
+
4097
+ end zip_left'
4098
+
4099
+ /-! ### zip_right' -/
4100
+
4101
+ section zip_right'
4102
+
4103
+ variables (a : α) (as : list α) (b : β) (bs : list β)
4104
+
4105
+ @[simp] theorem zip_right'_nil_left :
4106
+ zip_right' ([] : list α) bs = (bs.map (λ b, (none, b)), []) :=
4107
+ by cases bs; refl
4108
+
4109
+ @[simp] theorem zip_right'_nil_right :
4110
+ zip_right' as ([] : list β) = ([], as) :=
4111
+ rfl
4112
+
4113
+ @[simp] theorem zip_right'_nil_cons :
4114
+ zip_right' ([] : list α) (b :: bs) = ((none, b) :: bs.map (λ b, (none, b)), []) :=
4115
+ rfl
4116
+
4117
+ @[simp] theorem zip_right'_cons_cons :
4118
+ zip_right' (a :: as) (b :: bs) =
4119
+ let rec := zip_right' as bs in
4120
+ ((some a, b) :: rec.fst, rec.snd) :=
4121
+ rfl
4122
+
4123
+ end zip_right'
4124
+
4125
+ /-! ### map₂_left -/
4126
+
4127
+ section map₂_left
4128
+
4129
+ variables (f : α → option β → γ) (as : list α)
4130
+
4131
+ -- The definitional equalities for `map₂_left` can already be used by the
4132
+ -- simplifier because `map₂_left` is marked `@[simp]`.
4133
+
4134
+ @[simp] theorem map₂_left_nil_right :
4135
+ map₂_left f as [] = as.map (λ a, f a none) :=
4136
+ by cases as; refl
4137
+
4138
+ theorem map₂_left_eq_map₂_left' : ∀ as bs,
4139
+ map₂_left f as bs = (map₂_left' f as bs).fst
4140
+ | [] bs := by simp!
4141
+ | (a :: as) [] := by simp!
4142
+ | (a :: as) (b :: bs) := by simp! [*]
4143
+
4144
+ theorem map₂_left_eq_map₂ : ∀ as bs,
4145
+ length as ≤ length bs →
4146
+ map₂_left f as bs = map₂ (λ a b, f a (some b)) as bs
4147
+ | [] [] h := by simp!
4148
+ | [] (b :: bs) h := by simp!
4149
+ | (a :: as) [] h := by { simp at h, contradiction }
4150
+ | (a :: as) (b :: bs) h := by { simp at h, simp! [*] }
4151
+
4152
+ end map₂_left
4153
+
4154
+ /-! ### map₂_right -/
4155
+
4156
+ section map₂_right
4157
+
4158
+ variables (f : option α → β → γ) (a : α) (as : list α) (b : β) (bs : list β)
4159
+
4160
+ @[simp] theorem map₂_right_nil_left :
4161
+ map₂_right f [] bs = bs.map (f none) :=
4162
+ by cases bs; refl
4163
+
4164
+ @[simp] theorem map₂_right_nil_right :
4165
+ map₂_right f as [] = [] :=
4166
+ rfl
4167
+
4168
+ @[simp] theorem map₂_right_nil_cons :
4169
+ map₂_right f [] (b :: bs) = f none b :: bs.map (f none) :=
4170
+ rfl
4171
+
4172
+ @[simp] theorem map₂_right_cons_cons :
4173
+ map₂_right f (a :: as) (b :: bs) = f (some a) b :: map₂_right f as bs :=
4174
+ rfl
4175
+
4176
+ theorem map₂_right_eq_map₂_right' :
4177
+ map₂_right f as bs = (map₂_right' f as bs).fst :=
4178
+ by simp only [map₂_right, map₂_right', map₂_left_eq_map₂_left']
4179
+
4180
+ theorem map₂_right_eq_map₂ (h : length bs ≤ length as) :
4181
+ map₂_right f as bs = map₂ (λ a b, f (some a) b) as bs :=
4182
+ begin
4183
+ have : (λ a b, flip f a (some b)) = (flip (λ a b, f (some a) b)) := rfl,
4184
+ simp only [map₂_right, map₂_left_eq_map₂, map₂_flip, *]
4185
+ end
4186
+
4187
+ end map₂_right
4188
+
4189
+ /-! ### zip_left -/
4190
+
4191
+ section zip_left
4192
+
4193
+ variables (a : α) (as : list α) (b : β) (bs : list β)
4194
+
4195
+ @[simp] theorem zip_left_nil_right :
4196
+ zip_left as ([] : list β) = as.map (λ a, (a, none)) :=
4197
+ by cases as; refl
4198
+
4199
+ @[simp] theorem zip_left_nil_left :
4200
+ zip_left ([] : list α) bs = [] :=
4201
+ rfl
4202
+
4203
+ @[simp] theorem zip_left_cons_nil :
4204
+ zip_left (a :: as) ([] : list β) = (a, none) :: as.map (λ a, (a, none)) :=
4205
+ rfl
4206
+
4207
+ @[simp] theorem zip_left_cons_cons :
4208
+ zip_left (a :: as) (b :: bs) = (a, some b) :: zip_left as bs :=
4209
+ rfl
4210
+
4211
+ theorem zip_left_eq_zip_left' :
4212
+ zip_left as bs = (zip_left' as bs).fst :=
4213
+ by simp only [zip_left, zip_left', map₂_left_eq_map₂_left']
4214
+
4215
+ end zip_left
4216
+
4217
+ /-! ### zip_right -/
4218
+
4219
+ section zip_right
4220
+
4221
+ variables (a : α) (as : list α) (b : β) (bs : list β)
4222
+
4223
+ @[simp] theorem zip_right_nil_left :
4224
+ zip_right ([] : list α) bs = bs.map (λ b, (none, b)) :=
4225
+ by cases bs; refl
4226
+
4227
+ @[simp] theorem zip_right_nil_right :
4228
+ zip_right as ([] : list β) = [] :=
4229
+ rfl
4230
+
4231
+ @[simp] theorem zip_right_nil_cons :
4232
+ zip_right ([] : list α) (b :: bs) = (none, b) :: bs.map (λ b, (none, b)) :=
4233
+ rfl
4234
+
4235
+ @[simp] theorem zip_right_cons_cons :
4236
+ zip_right (a :: as) (b :: bs) = (some a, b) :: zip_right as bs :=
4237
+ rfl
4238
+
4239
+ theorem zip_right_eq_zip_right' :
4240
+ zip_right as bs = (zip_right' as bs).fst :=
4241
+ by simp only [zip_right, zip_right', map₂_right_eq_map₂_right']
4242
+
4243
+ end zip_right
4244
+
4245
+ /-! ### Miscellaneous lemmas -/
4028
4246
4029
4247
theorem ilast'_mem : ∀ a l, @ilast' α a l ∈ a :: l
4030
4248
| a [] := or.inl rfl
0 commit comments