Library rt.util.ssromega

Require Import Omega.

(* Taken from http://github.com/pi8027/formalized-postscript/blob/master/stdlib_ext.v *)

Ltac arith_hypo_ssrnat2coqnat :=
  match goal with
    | H : context [andb _ _] |- _let H0 := fresh in case/andP: HH H0
    | H : context [orb _ _] |- _case/orP: HH
    | H : context [?L ?R] |- _move/leP: HH
    | H : context [?L < ?R] |- _move/ltP : HH
    | H : context [?L == ?R] |- _move/eqP : HH
    | H : context [addn ?L ?R] |- _rewrite -plusE in H
    | H : context [muln ?L ?R] |- _rewrite -multE in H
    | H : context [subn ?L ?R] |- _rewrite -minusE in H
  end.

Ltac arith_goal_ssrnat2coqnat :=
  rewrite ?NatTrec.trecE -?plusE -?minusE -?multE -?leqNgt -?ltnNge;
  repeat match goal with
    | |- is_true (andb _ _) ⇒ apply/andP; split
    | |- is_true (orb _ _) ⇒ try apply/orP
    | |- is_true (_ _) ⇒ try apply/leP
    | |- is_true (_ < _) ⇒ try apply/ltP
  end.

Ltac ssromega :=
  repeat arith_hypo_ssrnat2coqnat;
  arith_goal_ssrnat2coqnat; simpl;
  omega.