Lvc.Infra.Pos

Require Import CSet Map OrderedTypeEx Util List Get Computable DecSolve AllInRel.

Set Implicit Arguments.

Fixpoint pos X `{OrderedType X} (l:list X) (x:X) (n:nat) : option nat :=
  match l with
    | nilNone
    | y::lif [ x === y ] then Some n else pos l x (S n)
  end.

Lemma pos_add X `{OrderedType X} symb (f:X) k i
: pos symb f k = Some ipos symb f ( + k) = Some ( + i).

Lemma pos_sub X `{OrderedType X} symb (f:X) k i
: pos symb f ( + k) = Some ( + i) → pos symb f k = Some i.

Lemma pos_ge X `{OrderedType X} symb (l:X) i k
: pos symb l k = Some i
  → k i.

Lemma pos_sub´ X `{OrderedType X} symb (f:X) k i
: pos symb f k = Some i kpos symb f (k - ) = Some (i - ).

Lemma update_with_list_lookup_in_list_first X `{OrderedType X} B E n
      (Z:list X) (Y:list B) z
: length Z = length Y
  → get Z n z
  → ( , < nget Z =/= z)
  → y, get Y n y E [Z <-- Y] z === y.

Lemma list_lookup_in_list_first X `{OrderedType X} B E
      (Z:list X) (Y:list B) x y
: length Z = length Y
  → (E [Z <-- Y]) x = y
  → x of_list Z
  → n , get Y n y === ( , < nget Z =/= x).

Lemma of_list_get_first X `{OrderedType X} (Z:list X) z
: z of_list Z
  → n , get Z n z === ( , < nget Z =/= z).

Lemma get_first_pos X `{OrderedType X} n
      (Z:list X) z
: get Z n z
  → ( , < nget Z =/= z)
  → pos Z z 0 = Some n.

Lemma pos_get X `{OrderedType X} (symb:list X) v x i
: pos symb v i = x
   → , get symb (x-i) v === x i.

Lemma pos_none X `{OrderedType X} symb (x:X) k
: pos symb x k = None
  → pos symb x = None.

Lemma pos_eq X `{OrderedType X} symb y k
: pos symb y k = Some k
  → hd_error symb === Some y.

Lemma pos_indep X `{OrderedType X} symb symb´ x y k
: pos symb x k = pos symb´ y k
  → pos symb x = pos symb´ y .

Lemma pos_inc X `{OrderedType X} symb symb´ x y k
: pos symb x k = pos symb´ y k
  → pos symb x ( + k) = pos symb´ y ( + k).

Lemma pos_dec X `{OrderedType X} symb symb´ x y k
: pos symb x k = pos symb´ y k
  → pos symb x (k - ) = pos symb´ y (k - ).

Lemma pos_app_in X `{OrderedType X} x k L
: x of_list L
  → pos (L ++ ) x k = pos L x k.

Lemma pos_app_not_in X `{OrderedType X} x k L
: x of_list L
  → pos (L ++ ) x k = pos x (length L + k).