First, the function [foldc] should be defined, using the supplementary [eqfx].
Definition eq_corx {X : Type} (eqfx : X -> X -> bool) :=
forall (x y : X), x = y <-> eqfx x y = true.
Definition foldc {X: Type} {eqfx} : @eq_corx X eqfx -> X -> list X -> nat :=
With [foldc], I would like to prove these 2 theorems below.
First:
Theorem foldc1 {X : Type} {eqfx} (eqx: eq_corx eqfx):
forall (l : list X),
(forall (x:X), foldc eqfx x l = 0) <-> l = nil.
I tried to prove by induction on l, but I'm stuck.
Second:
Theorem foldc2 {X : Type} {eqfx} :
forall (l : list X) (eqx: eq_corx eqfx) (x y : X),
x = y <-> foldc eqx y (x::l) = S (foldc eqx y l).
I tried unfolding [foldc], it didn't help unfortunately.
By the way, this is how [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
count_fold
, you get stuck on someeqf x y
. In general, this does not help, but if you are stuck oneqf x x
then by your hypothesis oneqf
, this should betrue
, which would unblock the computation. Equivalently, try and prove whatcount_fold eq x (x::l)
is equal to. $\endgroup$