1

The Coq docs say that the ring of booleans is predefined, and that all one has to do is Require Ring.

The docs also say that the ring tactic works by normalizing w.r.t. associativity and commutativity.

However, the ring tactic fails for this trivial proof that relies only on commutativity of || (orb):

Lemma ors: forall (a b: bool), a || b = b || a.
Proof.
intros.
ring.
Error: Tactic failure: not a valid ring equation.

What went wrong?

Max Heiber
  • 14,346
  • 12
  • 59
  • 97

1 Answers1

1

That happens because Coq's standard library defines a Boolean ring structure for andb and xorb operations. But to prove your lemma with the ring tactic you need a Boolean semiring. Here is how you can define it using Add Ring vernacular:

From Coq Require Import Ring.
Open Scope bool_scope.

Lemma boolSRth : semi_ring_theory false true orb andb (@eq bool).
Proof.
constructor.
exact Bool.orb_false_l.
exact Bool.orb_comm.
exact Bool.orb_assoc.
exact Bool.andb_true_l.
exact Bool.andb_false_l.
exact Bool.andb_comm.
exact Bool.andb_assoc.
exact Bool.andb_orb_distrib_l.
Qed.

Add Ring boolsr : boolSRth (decidable bool_eq_ok, constants [bool_cst]).

Lemma ors a b : a || b = b || a.
Proof. ring. Qed.

Unfortunately, now this breaks using ring for goals involving xorb function.

Anton Trunov
  • 15,074
  • 2
  • 23
  • 43