(* partial version of compatible QI *)

Definition p_assignment_function := function -> option(list nat -> nat).(* partial assignment of a term*)
Fixpoint p_term_assignment (qic:assignment_constructor) (qif:p_assignment_function)
(t:term) {struct t} : option nat:=
   match t with
  | var v=> Some 0 (* pas necessaire. Les QI sont toujours appliquées sur des termes clots. *)
  | capply c lt => option_map (qic c) (option_list_map(map (p_term_assignment qic qif) lt))
  | fapply f lt=> option_bind (fun g => option_map g (option_list_map(map (p_term_assignment qic qif)  lt)))
                              (qif f)
end.Definition complete_p_QI (qif : p_assignment_function) f := 
  complete_option maxl (qif f).

(* Specifications: *)
Lemma p_term_assignment_term_assignment qic qif t v: p_term_assignment qic qif t = Some v -> term_assignment qic (complete_p_QI qif) t = v.
Lemma p_compatible_compatible qic: {pqif | p_compatible_QI qic pqif} -> {qif | compatible_QI qic qif}.
Lemma p_term_assignment_ext qic f f': (forall x, f x = f' x) -> forall t, p_term_assignment qic f t= p_term_assignment qic f' t.
Lemma p_compatible_QI_ext qic f f': (forall x, f x = f' x) -> p_compatible_QI qic f -> p_compatible_QI qic f'.
Lemma value_as_p_term_assignment qic qif: forall v:value, (p_term_assignment qic qif (term_from_value v)) = Some (value_assignment qic v).