Here's a countFirst, the function [foldc] should be defined via fold, using the supplementary [eqf][eqfx].
Definition eq_coreq_corx {X : Type} (eqfeqfx : X -> X -> bool) :=
forall (x y : X), x = y <-> eqfeqfx x y = true.
Definition count_foldfoldc {X: Type} {eqfeqfx} : @eq_cor@eq_corx X eqfeqfx -> X -> list X -> nat :=
fun _ x l => (fold X nat (fun y n => if eqf x y then n + 1 else n) l 0).
With [count_fold][foldc], I would like to prove these 2 theorems below.
First:
Theorem count_fold_nilfoldc1 {X : Type} {eqfeqfx} (eqx: eq_corx eqfx):
forall (l : list X) (eq: eq_cor eqf),
(forall (x:X), count_foldfoldc eqeqfx x l = 0) <-> l = nil.
I have a hint, but not sure if it's for the first, or the second theorem:
I might need to prove a little lemma for one of directions: for example, that n <> S n for any n. Of course, it may also be the case that there is such a lemma in the standard library. What I tried, is to prove by induction on l, but I'm stuck.
Second:
Theorem count_occ_cons_eqfoldc2 {X : Type} {eqfeqfx} :
forall (l : list X) (eqeqx: eq_coreq_corx eqfeqfx) (x y : X),
x = y <-> count_foldfoldc eqeqx y (x::l) = S (count_foldfoldc eqeqx y l).
I tried unfolding [count_fold][foldc], it didn't help unfortunately.
By the way, this is how [fold][fold_right] is defined, which should help defining [foldc]:
Print fold_right.
fun (A B : Type) (f : B -> A -> A) (a0 : A) =>
fix fold_right (l : list B) : A :=
match l with
| [] => a0
| b :: t => f b (fold_right t)
end
: forall A B : Type, (B -> A -> A) -> A -> list B -> A
Definition fold (A B: Type) f l b:= @fold_right B A f b l.