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_bound_gen : forall i s p' t v,
let p := cbv_function i s p' t v in
let A := length (activations p) in
let S := max_active_size p in
wf p ->
nb_judgements p <= A * activation_bound prog S + A.