Zulip Chat Archive

Stream: Is there code for X?

Topic: List.countP.mono_left but strict inequality


Aatman Supkar (Apr 17 2025 at 11:46):

This can be used to take a list, and argue that if q is satisfied by each entry that satisfies p, then the weak inequality follows. I wish to provide a hypothesis that there exists an index where q is satisfied but p is not, and obtain a strict inequality. Do we have something that does that?

Yury G. Kudryashov (Apr 19 2025 at 04:36):

@loogle List.countP, _ < _

loogle (Apr 19 2025 at 04:36):

:search: List.countP_pos, List.countP_pos_iff, and 6 more

Yury G. Kudryashov (Apr 19 2025 at 04:37):

It looks like the answer is no.

Edward van de Meent (Apr 19 2025 at 06:57):

I suspect that it will be easiest to prove the contrapositive by induction

Edward van de Meent (Apr 19 2025 at 07:00):

So assuming the counts are equal and p -> q, all elements satisfying q must satisfy p

Edward van de Meent (Apr 19 2025 at 07:32):

actually i no longer think that's true... i think an argument making use of List.countP_eq_countP_filter_add might be easier

Edward van de Meent (Apr 19 2025 at 07:45):

variable {α : Type u} {l : List α} {P Q : α  Bool}

theorem List.countP_lt_countP (hpq :  x  l, P x  Q x) {x:α} (hx: x  l) (hxP : P x = false) (hxQ : Q x):
    l.countP P < l.countP Q := by
  rw [List.countP_eq_countP_filter_add l Q P]
  have : List.countP (Q) (l.filter P) = List.countP P l := by
    rw [List.countP_filter, List.countP_attach, List.countP_attach (l := l)]
    congr
    ext x
    simp only [Bool.and_iff_right_iff_imp]
    exact hpq x.val x.property
  rw [this]
  simp only [Nat.lt_add_right_iff_pos, List.countP_pos_iff, List.mem_filter, Bool.not_eq_eq_eq_not,
    Bool.not_true]
  exact x,hx,hxP,hxQ

Kim Morrison (Apr 20 2025 at 05:35):

I can get this down to

theorem List.countP_lt_countP (hpq :  x  l, P x  Q x) (y:α) (hx: y  l) (hxP : P y = false) (hxQ : Q y) :
    l.countP P < l.countP Q := by
  induction l with
  | nil => grind
  | cons x xs ih =>
    have : xs.countP P  xs.countP Q := countP_le_countP (by grind)
    specialize ih (by grind)
    grind

(on an unreleased version of Lean, sorry).

Kim Morrison (Apr 20 2025 at 05:41):

(And I hope we can do without the specialize line later.)


Last updated: May 02 2025 at 03:31 UTC