首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >求解目标中的等式/不等式,coq码

求解目标中的等式/不等式,coq码
EN

Stack Overflow用户
提问于 2016-09-14 03:02:15
回答 1查看 451关注 0票数 0

我如何证明这两种说法是平等的:

  1. Val.shru (Val.and a (Vint b)) (Vint c) = Vint ?3434 /\ ?3434 <> d
  2. Val.shru (Val.and a (Vint b)) (Vint c) <> d

这个概念很简单,但却停留在寻找正确的策略来解决它上。这就是我要证明的引理:

代码语言:javascript
复制
Require Import compcert.common.Values.
Require Import compcert.lib.Coqlib.
Require Import compcert.lib.Integers.

Lemma val_remains_int:
forall (a : val) (b c d: int),
(Val.shru (Val.and a (Vint b)) (Vint c)) <> (Vint d) ->
(exists (e : int), (Val.shru (Val.and a (Vint b)) (Vint c)) = (Vint e) /\ e <> d).

Proof.
  intros.
  eexists.
  ...
Admitted.

谢谢,

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-14 08:54:46

如果可以构造int类型的值(下面示例中的i0),则此引理不适用:

代码语言:javascript
复制
Require Import compcert.lib.Coqlib.
Require Import compcert.lib.Integers.
Require Import compcert.common.Values.

Variable i0 : int.

Fact counter_example_to_val_remains_int:
  ~ forall (a : val) (b c d: int),
      (Val.shru (Val.and a (Vint b)) (Vint c)) <> (Vint d) ->
      (exists (e : int),
          (Val.shru (Val.and a (Vint b)) (Vint c)) = (Vint e)
        /\ e <> d).
Proof.
  intro H.
  assert (Vundef <> Vint i0) as H0 by easy.
  specialize (H Vundef i0 i0 i0 H0); clear H0.
  simpl in H.
  destruct H as (? & contra & _).
  discriminate contra.
Qed.

至少有两个原因:

  • Val.andVal.shru对所有不是Vint的参数返回Vundef (这是GIGO原则的一个实例);
  • 而且,在C中不能将位移得太远--结果是未定义的(这是关于Val.shru的)。

对于您在评论中提到的修改后的引理,简单的reflexivity可以做到:

代码语言:javascript
复制
Lemma val_remains_int: forall a b c d: int,
    Vint (Int.shru (Int.and a b) c) <> Vint d ->
    exists (e : int), Vint (Int.shru (Int.and a b) c) = Vint e /\ e <> d.
Proof.
  intros a b c d Hneq.
  eexists. split.
  - reflexivity.
  - intro Heq. subst. auto.
Qed.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39481864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档