Definition invariant s r i (e : A) := onth r i = Some e /\ prefix s r.(* Tagging for controlling the search of instances *)
Structure xtagged := XTag {xuntag :> A}.(* Tagging for controlling the search of instances *)
Structure xtagged := XTag {xuntag :> A}.(* Tagging for controlling the search of instances *)
Structure xtagged := XTag {xuntag :> A}.Definition extend_tag := XTag.Definition recurse_tag := extend_tag.Canonical Structure found_tag x := recurse_tag x.(* Main structure
   s : input sequence
   r : output sequence. If elem_of is in the sequence, then it's equal to s,
       otherwise it's equal to (elem_of :: s)
   i : output index of elem_of in r *)
Structure xfind (s r : seq A) (i : nat) := XFind {
  elem_of :> xtagged;
  _ : invariant s r i elem_of}.(* Main structure
   s : input sequence
   r : output sequence. If elem_of is in the sequence, then it's equal to s,
       otherwise it's equal to (elem_of :: s)
   i : output index of elem_of in r *)
Structure xfind (s r : seq A) (i : nat) := XFind {
  elem_of :> xtagged;
  _ : invariant s r i elem_of}.(* Main structure
   s : input sequence
   r : output sequence. If elem_of is in the sequence, then it's equal to s,
       otherwise it's equal to (elem_of :: s)
   i : output index of elem_of in r *)
Structure xfind (s r : seq A) (i : nat) := XFind {
  elem_of :> xtagged;
  _ : invariant s r i elem_of}.

Lemma found_pf x t : invariant (x :: t) (x :: t) 0 x.