Definition trace_inputs (tr : list (name * (input + list output))) : nat :=
  length (filterMap (fun e => match e with
                           | (primary, inl i) => Some i
                           | _ => None
                           end) tr).

Lemma trace_outputs_app : forall tr1 tr2, trace_outputs (tr1 ++ tr2) = trace_outputs tr1 + trace_outputs tr2.