I'm proving a simple fact about ternary relations in Coq as an exercise.
I'm interested in ternary relations at the moment because they are a simple thing that can represent a finitary consequence relation, i.e. a consequence relation $\vdash : \mathsf{Set}[\mathsf{Wff}] \times \mathsf{Wff} \to 2$ with the property that $\Gamma \vdash \varphi$ implies that some finite $\Gamma_0 \subset \Gamma$ exists such that $\Gamma_0 \vdash \varphi$. For finitary consequence relations, I can always rework my system to only have binary inference rules (provided I have something that works like conjunction (I think)).
Anyway, I want to prove some basic facts about ternary relations first. I decided to formalize this in Coq in the simplest way possible, defining a new type $T * T * T \to 2$.
I'm curious how this can be done better. The proof script below is extremely naive. It makes no use of implicit arguments and CommutativeTernaryRelation
and the like are encoded as propositions rather than as new types.
The way the proof itself is done is also bad; it does the one line per tactic thing and makes liberal use of assert where other tactics would probably be more idiomatic.
(* TernaryRelation is a relation between three elements of the same type.
Represented here as a decidable procedure giving us back a boolean. *)
Definition TernaryRelation (T : Type) : Type := (T * T * T) -> bool.
(* A ternary relation is commutative if and only if Rabc holds iff Rbac holds. *)
Definition CommutativeTernaryRelation (T: Type) (R: TernaryRelation T) : Prop :=
forall a b c : T, R (a, b, c) = R (b, a, c).
(* A ternary relation R is cyclic if and only if the truth value of R is not changed by permuting its arguments with a permutation of positive sign *)
Definition CyclicTernaryRelation (T: Type) (R: TernaryRelation T) : Prop :=
forall a b c : T, R (a, b, c) = R (b, c, a).
(* We want to show that cyclic and commutative ternary relations are invariant
under reversing the arguments too. *)
Theorem CommutativeAndCyclicImpliesReversible: forall T: Type, forall R: TernaryRelation T, CommutativeTernaryRelation T R /\ CyclicTernaryRelation T R -> (forall a b c : T, R (a, b, c) = R (c, b, a)).
Proof.
intros.
intuition.
unfold CyclicTernaryRelation in H1.
unfold CommutativeTernaryRelation in H0.
assert (R (a, b, c) = R (b, a, c)).
intuition.
assert (R (b, a, c) = R (a, c, b)).
intuition.
assert (R (a, c, b) = R (b, c, a)).
symmetry in H2.
rewrite H2.
symmetry in H.
rewrite H.
intuition.
intuition.
rewrite H.
rewrite H2.
rewrite H3.
assert (R (b, c, a) = R (b, c, a)).
tauto.
intuition.
Qed.
```