是否存在一种“适用”式的策略,可以在Coq中实现“存在”目标?

时间:2015-12-11 04:33:11

标签: coq coq-tactic

在证明目标是存在主义的情况下,我有以下内容,目标属性是其中一个假设。

H : x ==> y
...
______________________________________(1/2)
exists t : tm, x ==> t

我知道我可以exists y. apply H.来证明目前的目标,但我想知道是否有更智能的策略可以直接使用假设证明存在目标,例如eapply H

由于这是一个统一,所以不必在X中编写exists X.部分会很好。

如果不存在这样的策略,我该怎么写呢?

1 个答案:

答案 0 :(得分:4)

存在这样的策略,它被称为Variable T : Type. Variable R : T -> T -> Prop. Theorem test : forall x y, R x y -> exists t, R x t. Proof. intros. eexists. apply H. Qed. 。 它完全符合您的期望。

https://coq.inria.fr/distrib/current/refman/Reference-Manual010.html#hevea_tactic23

使用示例:

program poly;

type
    polynomial = record
                 a, b, c : real;
                end;

procedure readPolynomial (var p : polynomial);
      begin
        writeln ('Input 1st coefficient: ');
        readln (p.a);

        writeln ('Input 2nd coefficient: ');
        readln (p.b);

        writeln ('Input 3rd coefficient: ');
        readln (p.c);
      end;


function square (x : real) : real;
     begin
        square := x * x; 
     end;

procedure roots (p : polynomial; var rP, rN : real);
      begin
        rP := (-p.b + (sqrt((square(p.b)) - (4 * p.a * p.c)))) / (2 * p.a); 
        rN := (-p.b - (sqrt((square(p.b)) - (4 * p.a * p.c)))) / (2 * p.a);

        writeln('The roots are: ', rP:0:3, ' y ' ,rN:0:3);
      end;

var
myPolynomial : polynomial;
r1, r2      : real;

begin
    writeln ('Enter the coefficients: ');
    readPolynomial (myPolynomial);

    roots (myPolynomial, r1, r2);

end.
相关问题