Zulip Chat Archive

Stream: lean4

Topic: argument order in`count_cons_of_ne`


Jovan Gerbscheid (Mar 23 2025 at 00:08):

count_cons_of_ne (h : a  b) (l : List α) : count a (b :: l) = count a l

I think that a and b should be swapped in h. This is because of the convention is to put the "more variable" argument on the left, in this case b is the more variable argument.

I ran into this because I was following this convention, and the simp lemma didn't apply.

Eric Wieser (Mar 23 2025 at 00:25):

My initial reaction is that the order there is correct with a hypothetical "keep things in a consistent order through the statement" rule.

Jovan Gerbscheid (Mar 23 2025 at 02:25):

Well, it can also be stated as

theorem count_cons_of_ne (h : a  b) (l : List α) : (b :: l).count a = l.count a := sorry

which would give the opposite order with that rule.

Jovan Gerbscheid (Mar 23 2025 at 02:50):

The thing is that the definition of List.count does follow the "more variable of the left" convention.

def count [BEq α] (a : α) : List α  Nat := countP (· == a)

So I think it's weird that this lemma flips the equality around.

Kim Morrison (Mar 24 2025 at 01:28):

I'd merge such a PR.

Jovan Gerbscheid (Mar 24 2025 at 01:52):

lean#7650

Kim Morrison (Mar 24 2025 at 09:51):

If you want to fix the lean-pr-testing-7650 branch at Batteries that would be great, but it's probably easy for me to do when the nightly lands.

Jovan Gerbscheid (Mar 24 2025 at 10:11):

I won't have time for it today


Last updated: May 02 2025 at 03:31 UTC