Skip to content

Instantly share code, notes, and snippets.

@ComFreek
Created October 9, 2020 09:50
Show Gist options
  • Save ComFreek/ec5a4df31e5d46c767c39d98b51f5c1a to your computer and use it in GitHub Desktop.
Save ComFreek/ec5a4df31e5d46c767c39d98b51f5c1a to your computer and use it in GitHub Desktop.
A right-recursive variant of plus: nat -> nat -> nat in Coq
From Coq Require Import ssreflect ssrfun ssrbool.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Fixpoint plus' (n m: nat): nat := match n with | S n' => plus' n' (S m) | 0 => m end.
Lemma helper_lemma: forall n m, plus' n (S m) = S (plus' n m).
Proof.
elim => // [n IHn m].
by simpl; do ! rewrite IHn.
Qed.
Theorem plus_plus'_ext_eqv: forall n m, plus n m = plus' n m.
Proof.
elim => // [n IHn m].
by simpl; rewrite helper_lemma; rewrite IHn.
Qed.
Require Import Coq.Logic.FunctionalExtensionality.
Theorem plus_plus'_eqv: plus = plus'.
Proof.
do 2! [apply: functional_extensionality; move => ?].
by apply: plus_plus'_ext_eqv.
Qed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment