7

I need to use the part of the standard library called Coq.Arith.PeanoNat (https://coq.inria.fr/library/Coq.Arith.PeanoNat.html).

I've tried either importing the entire Arith library or just this module, but I can't use it either way.

Every other library I've tried works just fine. When I do Require Import Bool. I compile and I can use it correctly. Upon Print Bool. I can take a look at all the functions inside in the next format:

Module
Bool
:= Struct
Definition...
.
.
.
End

When I do either Require Import Arith.PeanoNat. or Require Import Arith. I get this as immediate output:

[Loading ML file z_syntax_plugin.cmxs ... done]
[Loading ML file quote_plugin.cmxs ... done]
[Loading ML file newring_plugin.cmxs ... done]
<W> Grammar extension: in [tactic:simple_tactic], some rule has been     masked
<W> Grammar extension: in [tactic:simple_tactic], some rule has been masked
<W> Grammar extension: in [tactic:simple_tactic], some rule has been masked
<W> Grammar extension: in [tactic:simple_tactic], some rule has been masked
<W> Grammar extension: in [tactic:simple_tactic], some rule has been masked

When I ask Coq Print Arith.PeanoNat it outputs: Module Arith := Struct End, it seems to be empty. When I try to use anything from the library, for example le_le under boolean comparisons, I get the standard Error: leb_le not a defined object. I have updated Coq and the libraries, and I have no idea of what might be going on here. I'd appreciate your input in fixing this library problem.

Sara
  • 339
  • 1
  • 8
  • Are you importing any other modules at the same time that might cause conflicts? – ichistmeinname Apr 14 '16 at 12:08
  • @ichistmeinname, I'm only importing Bool and Arith. For testing purposes I imported other ones, and deleted them from my file when I saw they worked just fine. – Sara Apr 14 '16 at 12:24

2 Answers2

15

If I am not mistaken, Require is the keyword to load a file. Import has to do with managing name spaces. Often they are used together, as in Require Import PeanoNat., but they are really doing two different things.

When coq files (DirName/FileName.vo) are loaded with Require, it is as if the contents of FileName.vo is wrapped in Module DirName.FileName ... End. Everyting defined in the file is then accessed with DirName.FileName.Name.

The file can itself have modules M inside of it, and to get to M's contents, one has to type DirName.FileName.ModuleName.Name1 etc.

Import is used to get all the definitions up to the top level. By doing Import DirName.FileName.ModuleName the module Name1 is now imported to the top level, and can be referenced without the long path.

In your example above, the file Arith/PeanoNat.vo defines the module Nat. Actually, that is all it defines. So if you do Require Import Arith.PeanoNat you get PeanoNat.Nat at the top level. And then Import PeanoNat.Nat will bring Nat to the top level. Note that you can't do Require Import PeanoNat.Nat because it is no .vo file.

Coq can sometimes find a .vo file without you having to specify the whole path, so you can also do Require Import PeanoNat. and coq will find the file. If you wonder where it found it, do Locate PeanoNat.

Coq < Require Import PeanoNat.

Coq < Locate PeanoNat.
Module Coq.Arith.PeanoNat

Another Nat is also available from another place than PeanoNat.

Coq < Require Import Nat.
Warning: Notation _ + _ was already used in scope nat_scope
Warning: Notation _ * _ was already used in scope nat_scope
Warning: Notation _ - _ was already used in scope nat_scope

Coq < Locate Nat.
Module Coq.Init.Nat

So, you don't Import a library, you Require it. You use Import to not have to use the full path name. I hope this helps you debug what is happening.

larsr
  • 5,447
  • 19
  • 38
  • Thank you for the detailed explanation, I think I won't have issues importing anymore. – Sara Apr 21 '16 at 15:23
  • 1
    @Sara If this answer resolves your issue, a nice thing to do is to accept the answer. – Anton Trunov Apr 21 '16 at 19:38
  • This answer is the closest to my issue, so I post a question here: I first type `Require Import Coq.Numbers.Natural.Abstract.NDiv.` Then command `Print NDiv.` returns `Module NDiv := Struct Module Type NDivProp End`, command `Print NDivProp` prints a list of lemmas, one of which I want to use. But `Import NDivProp.` throws an error `NDivProp is not a module`, `Print add_mod` (the lemma I want to use) throws an error `Error: add_mod not a defined object.`, commands `NDiv.add_mod`, `NDivProp.add_mod`, `NDivProp.NDiv.add_mod` also print errors. So how to access the `add_mod` lemma? – mercury0114 Jun 14 '20 at 19:36
  • I think the preferred way on SO is to post a new question. – larsr Jun 14 '20 at 21:50
0

When I try Print Arith.PeanoNat, the output is slightly different: I get Module PeanoNat := Struct Module Nat End and then even though leb_le is not in scope, Nat.leb_le is.

(I run 8.5beta2 in case that's relevant).

gallais
  • 11,823
  • 2
  • 30
  • 63
  • I think it does make the difference. I tried checking if Nat.leb_le as well, and I get the same "not a defined object". – Sara Apr 14 '16 at 12:26
  • Hi @gallais. Somehow, Nat.leb_le is in scope now (I only closed coq for the day, when I tried running the same file again today it was working better...), but I'm still having issues. I have that Nat.leb_le is scope. How can I now use, on a proof? "apply leb_le" yields "Te reference leb_le was not found in current environment" – Sara Apr 15 '16 at 10:07
  • @Sara Great news! If `leb_le` is not in scope but `Nat.leb_le` is then you have to either use the long name `Nat.leb_le` or `Import Nat` first in order to bring its content (including `leb_le`) into scope (cf. [the bit of the manual about modules](https://coq.inria.fr/distrib/current/refman/Reference-Manual004.html#hevea_command54)). – gallais Apr 15 '16 at 11:35
  • Thank you, this fixed it! I realised I was also importing things in the wrong order (I was not aware that it would make a difference!). Now everything seems to be running. – Sara Apr 15 '16 at 12:02