(* QuickChick ble_n_Sn. *)

Fixpoint nth_bad (l:natlist) (n:nat) : nat :=
  match l with
  | nil => 42  (* arbitrary! *)
  | a :: l' => match beq_nat n O with
               | true => a
               | false => nth_bad l' (pred n)
               end
  end.Inductive natoption : Type :=
  | Some : nat -> natoption
  | None : natoption.Inductive natoption : Type :=
  | Some : nat -> natoption
  | None : natoption.Inductive natoption : Type :=
  | Some : nat -> natoption
  | None : natoption.Instance dec_natoption (p q : natoption) : Dec (p = q).Fixpoint nth_error (l:natlist) (n:nat) : natoption :=
  match l with
  | nil => None
  | a :: l' => match beq_nat n O with
               | true => Some a
               | false => nth_error l' (pred n)
               end
  end.Fixpoint nth_error' (l:natlist) (n:nat) : natoption :=
  match l with
  | nil => None
  | a :: l' => if beq_nat n O then Some a
               else nth_error' l' (pred n)
  end.Definition option_elim (d : nat) (o : natoption) : nat :=
  match o with
  | Some n' => n'
  | None => d
  end.(* Filled *)
Definition hd_error (l : natlist) : natoption :=
  match l with 
  | nil => None
  | a :: _ => Some a 
  end.

Theorem option_elim_hd : forall (l:natlist) (default:nat), hd default l = option_elim default (hd_error l).