Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you find function by type signature in Coq?

Tags:

coq

I'm looking for utility similar to one of Hoogle for Haskell. For the sake of example, let's say I need a function of signature forall n m:nat, n <> m -> m <> n.

When my Google searches don't yield any results, I write Definition foo: forall n m:nat, n <> m -> m <> n. and write intros; auto with arith. to prove it. But is there any way to not pollute my workspace with these temporary results and search for them based on their type? I'm sure I've seen this symmetry stated somewhere in standard library.

like image 382
SzymonPajzert Avatar asked May 17 '18 13:05

SzymonPajzert


People also ask

How does Coq know what type to use?

Like most functional programming languages, Coq can often figure out these types for itself when they are not given explicitly -- i.e., it can do type inference -- but we'll generally include them to make reading easier. Having defined a function, we should next check that it works on some examples.

Are all logical judgments in Coq typing judgments?

Then, all logical judgments in Coq are typing judgments: the very heart of Coq is in fact a type -checking algorithm. Prop is the sort for propositions, i.e. well-formed propositions are of type Prop. Typical propositions are:

What is the scope of notation in Coq?

Each notation symbol is also associated with a notation scope. Coq tries to guess what scope is meant from context, so when it sees S (O × O) it guesses nat_scope, but when it sees the product type bool × bool (which we'll see in later chapters) it guesses type_scope.

What are the argument and return types of functions in Coq?

One point to note is that the argument and return types of this function are explicitly declared. Like most functional programming languages, Coq can often figure out these types for itself when they are not given explicitly -- i.e., it can do type inference -- but we'll generally include them to make reading easier.


1 Answers

There's a Search command that's somewhat similar to Hoogle, but a bit more precise. Here are some searches you might use for symmetry of not. In practice I would use the first and fall back to the second if there were a lot of results.

Search (_ <> _). (* everything related to not equal *)
Search (?a <> ?b -> ?b <> ?a). (* exactly what you want -
    note that unlike Hoogle, you need to use ?a for a pattern variable *)
Search (?R ?a ?b -> ?R ?b ?a). (* this searches for any symmetry theorem;
    not terribly useful for it's cool that it works *)
Search not "_sym". (* if you know some of the theorem name you can use that, too *)
like image 100
Tej Chajed Avatar answered Oct 23 '22 05:10

Tej Chajed