Greg Nisbet
Greg Nisbet

Reputation: 6994

Coq prove that arithmetic expressions involving real number literals are equal

I have a pretty basic expression involving real number literals and +, namely the fact that 4 = 1 + 1 + 1 + 1.

I'm trying to figure out how to prove this fact using as little cleverness as possible.

Require Export RIneq. (* probably overkill, but it pulls in
                         enough real number stuff to be useful *)

Open Scope R_scope.

Lemma test_sum2 : 4 = 1 + 1 + 1 + 1.

I attempted to prove it by using strategically chosen assertions and spamming intuition, but I can't seem to build integral reals above 3 using that technique.

Require Export RIneq.

Open Scope R_scope.

Lemma test_sum2 : 4 = 1 + 1 + 1 + 1.
Proof.
assert (1 + 1 = 2).
intuition.
rewrite H.
assert (1 + 2 = 3).
intuition.
assert (1 + 2 = 2 + 1).
intuition.
rewrite H1 in H0.
rewrite H0.
assert (1 + 3 = 3 + 1).
intuition.

leaves me in the proof state

1 subgoal
H : 1 + 1 = 2
H0 : 2 + 1 = 3
H1 : 1 + 2 = 2 + 1
H2 : 1 + 3 = 3 + 1
______________________________________(1/1)
4 = 3 + 1

Upvotes: 2

Views: 123

Answers (1)

SCappella
SCappella

Reputation: 10414

Based on this answer, it looks like the field tactic will work. I'm not sure if that's too much cleverness.

Require Export RIneq.

Open Scope R_scope.

Lemma test_sum2 : 4 = 1 + 1 + 1 + 1.
Proof.
  field.
Qed.

(Tested in Coq 8.9+beta1)

Upvotes: 2

Related Questions