Fixpoint nb_judgements (proof_tree : cbv) : nat :=
match proof_tree with
| cbv_constr lp _ _ => 1 + suml (map nb_judgements lp)
| cbv_split lp p _ _ => 1 + nb_judgements p + suml (map nb_judgements lp)
| cbv_function _ _ p _ _ => 1 + nb_judgements p
end.
Fixpoint nb_judgements_sub_rec (proof_tree : cbv) : nat :=
match proof_tree with
| cbv_constr lp _ _ => 1 + suml (map nb_judgements_sub_rec lp)
| cbv_split lp p _ _ => 1 + nb_judgements_sub_rec p + suml (map nb_judgements_sub_rec lp)
| cbv_function _ _ _ _ _ => 0
end.
Definition nb_judgements_sub (proof_tree : cbv) : nat :=
match proof_tree with
| cbv_constr _ _ _ => 0
| cbv_split _ _ _ _ => 0
| cbv_function _ _ p _ _ => nb_judgements_sub_rec p
end.

Lemma nb_judgements_sub_rec_bound p :
wf p -> nb_judgements_sub_rec p <= term_size (proj_left p).