Section Fin.
Global Coercion fin_to_nat (n : nat) (i : Fin.t n) : nat := proj1_sig (Fin.to_nat i).
Global Set Printing Coercions.
Fixpoint finMax (n : nat) {struct n} : n <> 0 -> Fin.t n.
(* Arguments finMax (n) H : clear implicits. *)
(* Compute finMax (ltac:(congruence) : 1 <> 0). *)
(* Compute finMax (ltac:(congruence) : 10 <> 0). *)
(* Compute finMax' 99. *)
Definition finMin (n : nat) : n <> 0 -> Fin.t n.
Definition finMin_opt (n : nat) : option (Fin.t n).
End Fin.
Fixpoint map_vect_list (X Y : Type) (f : X -> Y -> X) (n : nat) (vs : Vector.t Y n) (ls : list X) {struct ls} : list X :=
match ls with
| nil => nil
| x :: ls' =>
match vs with
| [| |] => ls
| y ::: vs' =>
f x y :: map_vect_list f vs' ls'
end
end.
Definition insertKnownSymbol {n : nat} (readSymbols : Vector.t (option sig) n) (i : Fin.t n) (s : option sig) : Vector.t (option sig) n :=
Vector.replace readSymbols i s.
Fixpoint insertKnownSymbols {n : nat} (readSymbols : Vector.t (option sig) n) (i : Fin.t n) (newSymbols : list (option sig)) :
Vector.t (option sig) n :=
match newSymbols with
| nil => readSymbols
| s :: newSymbols' =>
match finSucc_opt i with
| Some i' => insertKnownSymbols (insertKnownSymbol readSymbols i s) i' newSymbols'
| None => insertKnownSymbol readSymbols i s
end
end.

Lemma insertKnownSymbol_correct (n : nat) (readSymbols : Vector.t (option sig) n) (i : Fin.t n) tps tp :
length tps = fin_to_nat i ->
knowsFirstSymbols readSymbols tps ->
knowsFirstSymbols (insertKnownSymbol readSymbols i (current tp)) (tps ++ [tp]).