This might not be the most efficient way to do it.
At the step induction c.
(where it's stuck):
______________________________________(1/2)
b && true = b || true -> b = true
______________________________________(2/2)
b && false = b || false -> b = false
You can use rewrite
and basic theorems in [bool][1] to simplify terms such as b && true
to b
, and b || true
to true
.
This can reduce it to two "trivial" sub goals:
b : bool
______________________________________(1/2)
b = true -> b = true
______________________________________(2/2)
false = b -> b = false
This is almost trivial proof using assumption
, except it is one symmetry
away. You can try
if symmetry
will make them match using:
try (symmetry;assumption); try assumption.
(Someone who really knows Coq may enlighten me how to try
this more succinctly)
Putting it together:
Require Import Bool.
Theorem andb_eq_orb : forall b c, andb b c = orb b c -> b = c.
Proof.
destruct c;
try (rewrite andb_true_r);
try (rewrite orb_true_r);
try (rewrite andb_false_r);
try (rewrite orb_false_r);
intro H;
try (symmetry;assumption); try assumption.
Qed.
A second approach is to brute-force it and using the "Truth table" method. This means you can break down all variables to their truth values, and simplify: destruct b, c; simpl.
. This again gives four trivial implications, up to one symmetry
to try
:
4 subgoal
______________________________________(1/4)
true = true -> true = true
______________________________________(2/4)
false = true -> true = false
______________________________________(3/4)
false = true -> false = true
______________________________________(4/4)
false = false -> false = false
Putting it together:
Theorem andb_eq_orb1 : forall b c, andb b c = orb b c -> b = c.
Proof.
destruct b, c; simpl; intro; try (symmetry;assumption); try assumption.
Qed.
The first approach is more troublesome but it does not involve enumerating all truth table rows (I think).
b
and then usesimpl
andreflexivity
? like, hypothesizeb=true
then prove it, then hypothesizeb=false
and prove it. – Chris Beck