如何使用不同的bin定义来证明二进制commutavity?

时间:2016-11-10 11:44:06

标签: coq

// Collacoq link: https://x80.org/collacoq/qezicaroni.coq

Inductive bin : Type :=
| Zero : bin
| One : bin
| ZeroP : bin -> bin
| OneP : bin -> bin.

Inductive bin_carry : Type :=
| ZeroC : bin_carry
| OneC : bin_carry.

(*returns carry, new_state*)
Fixpoint incr' (x : bin) : bin_carry * bin :=
  match x with
  | Zero => (ZeroC, One)
  | One => (OneC, Zero)
  | ZeroP x =>
    match incr' x with
    | (OneC, x') => (ZeroC, OneP x')
    | (ZeroC, x') => (ZeroC, ZeroP x')
    end
  | OneP x =>
    match incr' x with
    | (OneC, x') => (OneC, ZeroP x')
    | (ZeroC, x') => (ZeroC, OneP x')
    end
  end.


Definition incr (x : bin): bin :=
  match incr' x with
  | (ZeroC,x) => x
  | (OneC,x) => OneP x
  end.

(*index_multiplier * result*)
Fixpoint bin_to_nat' (x : bin): nat * nat :=
  match x with
  | Zero => (2,0)
  | One => (2,1)
  | ZeroP x =>
    match bin_to_nat' x with
    | (multiplier,result) => (multiplier * 2,result)
    end
  | OneP x =>
    match bin_to_nat' x with
    | (multiplier,result) => (multiplier * 2,result + multiplier)
    end
  end.


Definition bin_to_nat (x : bin): nat :=
  match bin_to_nat' x with
  | (_,r) => r
  end.

Example bin_test1: bin_to_nat Zero = 0.
Proof. reflexivity. Qed.
Example bin_test2: bin_to_nat (incr Zero) = 1.
Proof. reflexivity. Qed.
Example bin_test3: bin_to_nat (incr (incr Zero)) = 2.
Proof. reflexivity. Qed.
Example bin_test4: bin_to_nat (incr (incr (incr Zero))) = 3.
Proof. reflexivity. Qed.
Example bin_test5: bin_to_nat (incr (incr (incr (incr Zero)))) = 4.
Proof. reflexivity. Qed.

Theorem binary_commute :
  forall (x: bin),
    bin_to_nat(incr x) = S (bin_to_nat x).
Proof. induction x.
       - reflexivity.
       - reflexivity.
       - replace (ZeroP x) with x.
         + rewrite -> IHx. reflexivity.
         + induction x.
           * Abort.

我正在阅读软件基础书,并对上述内容感到困惑。我在网上环顾四周,找到了the solution用于不同种类的垃圾箱配方,但我认为这里没有适用的解决方案。

问题在于,第三个-项目符号bin_to_nat (incr (ZeroP x)) = S (bin_to_nat (ZeroP x)不会简化,也不能直接重写。所以在了解了替换之后,我认为这可能有用,但后来我试图证明Zero = ZeroP Zero

我知道这个问题表明我可以自由地改变bin的表达方式来证明它的交换性更容易,但我的预感是,如果我遇到上述定义,我不会对Coq有所了解。虽然与过去几次不同,但我认为我还没有工具可以解决这个问题。

我在这里缺少什么?

1 个答案:

答案 0 :(得分:3)

<?php $host="localhost"; $dbuser="root"; $pass=""; $dbname="online_exam"; $conn=mysqli_connect($host,$dbuser,$pass,$dbname); // echo "$conn"; if(mysqli_connect_errno()) {die("connection Failed!".mysqli_connect_error()); } ?> <html> <body background="bg/hero8.jpg" text="white"> <table cellspacing="15px" border="0px" align="center"> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <tr></tr> <form action="loginS.php" method="POST"> <tr> <td>STUDENTS LOGIN</td></tr> <tr> <td>Enter the user name:<input type="text" name="uname"></td></tr> <tr> <td>Enter the Password:<input type="password" name="pwd"></td></tr> <tr><td><input type="submit" name="submit" value="LOGIN"></td></tr> </table> </body> </html> <?php if(isset($_POST['submit'])){ $uname = $_POST['uname']; $pswd=$_POST['pwd']; if(empty($uname) || empty($pswd)) {echo"OOPs! Your are suppose to not leave any of the constrains empty ";} else{ $sql="SELECT * FROM student WHERE Email='{$uname}'AND Pass='{$pswd}';"; //Q_no, Ques, Op_1, Op_2, Op_3, Op_4, Ans $res=mysqli_query($conn,$sql); if(!$res){ //die("query failed".mysqli_error($conn)); echo "User name or password is wrong"; } else{$flag=0; while($row=mysqli_fetch_array($res)){ //$course = $row['Course']; //$question_array[$i]=$row['Ques']; $name = $row['Name']; $lastresult= $row['Lastresult']; $USN=$row['USN']; $flag=1; } if($flag==0) {echo "Wrong Password or Username"; exit;} session_start(); $_SESSION['myValue']=$lastresult; $_SESSION['myValue1']=$name; $_SESSION['myValue2']=$USN; header("Location: Student_menu.php"); exit; } } } ?> 无法成功:因为持有replace (ZeroP x) with x.这样的等式需要是一个等于x的无限项。您可能首先要证明的是ZeroP (ZeroP (ZeroP (...)))是语义扩展 。即。

incr