Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ltac: get hypotesis' type from name

I am looking for a way to get an hypotesis by it's name in order to match it. Like this :

Ltac mytactic h_name :=
let h := hyp_from_name h_name in
    match h with
    | _ /\ _ => do_something
    | _ => print_error_message
    end
.

Which would be used like this :

H0 : A /\ B
==================
A

Coq < mytactic H0.

Thanks.

like image 621
L. Soret Avatar asked Apr 10 '26 16:04

L. Soret


1 Answers

I'm not sure I completely understand your question, but I'll try. You can use the type of <term> construction like so:

Ltac mytactic H :=
  match type of H with
  | _ /\ _ =>
    let H1 := fresh in
    let H2 := fresh in
    destruct H as [H1 H2]; try (inversion H1; inversion H2; subst)
  | _ => fail "Algo salió mal, mi amigo"
  end.

Example por_ejemplo x : x >= 0 /\ x <= 0 -> x = 0.
Proof.
  intros H.
  now mytactic H.
Qed.
like image 182
Anton Trunov Avatar answered Apr 12 '26 11:04

Anton Trunov