Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

coq - Printing ssrnat's ".+1" definition

In Ilya Sergey's Programs and Proofs, ssrnat's command .+1 is introduced and used for defining some functions on the natural numbers. Although its usage is well explained there, I'm also interested in how it is defined and, more importantly, how it works. Earlier in that chapter the nat type is introduced, which we can verify the definition with "Print nat.", which yields:

Inductive nat : Set :=  O : nat | S : nat -> nat

For .+1 however, the commands "Print .+1." or "Print +1." yield:

Syntax error: 'Fields' or 'Rings' or 'Hint' 'View' expected after 'Print' (in [command]).

Even trying to circumvent this by adding a natural number before it, such as in "Definition one: nat := 1." followed by "Print one.+1." yields:

Syntax error: '.' expected after [command] (in [vernac_aux]).

However, I imagine this command is defined in the library and is not a primitive of the language, so it feels like one should be able to examine its definition as any other.

If that's the case, why is the command not working and how may the definition of .+1 be printed?

Note: In case that is impossible, an explanation of why is also acceptable as an answer (and a resource for the code/workings of the command appreciated).

question from:https://stackoverflow.com/questions/65931381/printing-ssrnats-1-definition

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To print a notation such as .+1 you have to use quotation marks.

Print ".+1".

If you do so you will end up with the same result as Print nat. because that's what happens when you print a constructor of an inductive type. In fact you get the result of Print S. because .+1 is a notation for it.

For notations, usually you want to use Locate:

Locate ".+1'.

And this time the output is more informative:

Notation
"n .+1" := S n : nat_scope (default interpretation)

A notation, is not the same as a definition. It's just a way to write and print an expression, but underneath it's the same.

To clarify, .+1 is a notation, not a command. Commands are things such as Definition, Print etc. I encourage you to have a look at the documentation if you want to know more about those.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...