coq


Why is it impossible to perform induction on a term that is used in conclusion?


Suppose the following particular scenario.
We have a definition of equality:
Inductive eqwal {A : Type} (x : A) : A -> Prop :=
eqw_refl : eqwal x x.
And peano nats:
Inductive nawt : Prop :=
| zewro : nawt
| sawc : nawt -> nawt.
We define addition on nats:
Fixpoint plaws (m n : nawt) : nawt :=
match m with
| zewro => n
| sawc m' => sawc (plaws m' n)
end.
And now we want to prove that zero is neutral from right wrt. summing:
Theorem neutral_r : forall n : nawt, eqwal (plaws n zewro) n.
Sadly the last line of the following proofscripts says "Error: n is used in conclusion.".
Proof.
intros.
induction n. - this is the culprit
There is not much about the error in official documentation and I am somewhat confused - why does this error occur?
Using the standard library, I can prove the theorem easily:
Theorem neutral_r : forall n : nat,
n + 0 = n.
Proof.
induction n; try reflexivity.
cbn; rewrite IHn; reflexivity.
Qed.
The problem is that you defined nawt with sort Prop instead of Type or Set. By default, the induction principles generated for propositions do not allow us to prove anything about proofs of those propositions. Consider the default induction principle generated for nawt:
Check nawt_ind.
> nawt_ind : forall P : Prop, P -> (nawt -> P -> P) -> nawt -> P
Because nawt_ind quantifies over Prop, and not over nat -> Prop, we cannot use it to prove your goal.
The solution is to set a few options that change Coq's default behavior, as in the following script.
Inductive eqwal {A : Type} (x : A) : A -> Prop :=
eqw_refl : eqwal x x.
Unset Elimination Schemes.
Inductive nawt : Prop :=
| zewro : nawt
| sawc : nawt -> nawt.
Scheme nawt_ind := Induction for nawt Sort Prop.
Set Elimination Schemes.
Fixpoint plaws (m n : nawt) : nawt :=
match m with
| zewro => n
| sawc m' => sawc (plaws m' n)
end.
Theorem eqwal_sym {A : Type} (x y : A) : eqwal x y -> eqwal y x.
Proof. intros H. destruct H. constructor. Qed.
Theorem neutral_r : forall n : nawt, eqwal (plaws n zewro) n.
Proof.
intros. induction n as [|n IH]; simpl.
- constructor.
- apply eqwal_sym in IH. destruct IH. constructor.
Qed.
The Elimination Schemes option causes Coq to automatically generate induction principles for data types and propositions. In this script, I merely turned it off, and used the Scheme command to generate the correct induction principle for nawt. For the induction tactic to work, it is important to give this principle the name nawt_ind: this is the default name that is generated by Coq, and is the one that induction looks for when called.
That being said, I would generally advise against defining a type of natural numbers in Prop instead of Type, because Coq imposes restrictions on how you can use things that live in Prop. For instance, it is impossible to show that zewro is different from sawc zewro.

Related Links

MSets of different types interact badly
Defining interval function in Coq
How to introduce a new variable in Coq?
How do I check for convertibility in a tactic producing terms?
Abstracting over the term … leads to a term … which is ill-typed
Calling a functor in with declaration
Coq: How do I create a bool from a decidable Prop?
Can destruct used in implication in Coq?
How to apply a function once during simplification in Coq?
Cannot rewrite subterm in Coq
Termination implies existence of normal form
Is there a minimal complete set of tactics in Coq?
Proving x >= a /\ x <= a -> x = a
How to prove excluded middle is irrefutable in Coq?
How to make a Coq formalisation reusable?
Applying functional extensionality to functions with 2 arguments in Coq

Categories

HOME
maven
testing
vim
wso2-am
coq
single-sign-on
paw-app
youtube-api-v3
rdf
callback
alpha
virtualization
dacpac
gorm
ssl-client-authentication
offline
quickfix
circuit
graphlab
apache-metamodel
sms-gateway
django-cms
dbext
physics-engine
errorlevel
excel-2007
wijmo
underflow
status
info.plist
srcset
frame
stormpath
typed.js
mmenu
sequential
appfabric
disassembling
withings
occlusion
streamsets
opshub
user-controls
spring-security-kerberos
revapi
jedis
hendrix
pnotify
clean-architecture
ionicons
elgg
knockout-components
np-complete
sqlbulkcopy
django-scheduler
infix-notation
flash-cs5
pickadate
yaws
suffix-tree
ford-fulkerson
reactive-banana
execute
google-places
mutation-observers
security-testing
service-accounts
method-parameters
appfabric-cache
fluid-dynamics
composite
system.reflection
angularjs-ng-click
cdt
applescript-objc
navigationservice
elliptic-curve
jquery-layout
htmlcleaner
transcoding
resty-gwt
message-driven-bean
opcache
plasma
specification-pattern
distutils
chuck
jquery-ui-layout
boost-filesystem
mod-auth
appender
file-comparison
locate
xfbml
sef
putchar

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App