ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Introduction to the Coq Software for Type Theory

Updated on November 29, 2013

Coq is a program designed to have type theory, or similar foundational mathematics written into it. You can define functions and objects, and write out proofs. To read this some idea about type theory might be preferable for the theory, but it is not strictly necessary. I here use excerpts from a program I wrote in which I tried to explain Euclidean Geometry as type theory.

First, a quick note : Coq works very much like a programming software, and like programming languages it has several libraries with notations and functions available. If you make a new Coq file it will start out with the library of natural numbers and functions related to them, some basic operations and such. I am not going to use them in these examples, so they are removed.

Also, if anyone is wondering about the name, it comes from French, where the unfortunate assosiations you get in English do not apply.

An example from my first real Coq program.
An example from my first real Coq program. | Source

Defining Types

Now, the first thing you will use both in Coq and in type theory is a type. Type is here defined the same way as in type theory, any term, or object, used is of some type, and of only one type. For example:

Variable Point : Type.

This line defines a type called Point, and we can now create objects with this type. The types defined this way are primitive type, they are not made in relation to anything else.

Second, a dependent type, for example :

Variable LineThrough : Point -> Point -> Type.

Here Linethrough would geometrically be the line segment between two points. Defined this way any LineThrough is created by two points, and depends on these points. In a similar fasion, I define:

Definition Triangle := Point * Point * Point.

Here, a triangle is defined as a collection of three points, which intuitively would be the corners of the triangle. By using this, we can always match a triangle two three points which define this, and often it is more useful to work with the points than the triangle itself.

Another quick note, notice that much like any line of code has to end with ; in Java, in Coq any statement must end with a punctuation mark.

The Identity Type and Functions

Next, the identity type. Identity types are not a necessity in all type theory, but in my building of geometry it is very useful. It is simply the statement that two terms are equal. Coq has the idea programmed in, so it is easy define. Note that an identity type is only defined on one type. For example:

Definition EqualPoint (P Q : Point) := identity P Q.

Definition is used to rename the identity type. := means that we define the left side a the right side. Inside the parenthesis we clarify that P and Q are of the type Point.

Let us define:

Variable Angle : Type.

We can now create a function:

Variable CreateAngle : Point -> Point -> Point -> Angle.

This will allow us to take three points and map them to an angle. Note that all points here are taken as parameters of the function, and an angle is the result. Also, the variable CreateAngle is actually of the dependent type Point*Point*Point*Angle. Next comes another variable:

Variable AngleSym : (forall P Q R : Point, EqualAngle (CreateAngle P Q R) (CreateAngle P R Q)).

This one has more in common with a definition or axiom from our understanding of mathematics, but is here a variable or a conversion rule. Now, the only statement made is what is to the right of the last comma, in this case EqualAngle (CreateAngle P Q R) (CreateAngle P R Q)

Everything to the left are requirements for this statement to apply. As you might guess, forall means for all, and after that we define three points P, Q, R. CreateAngle is the same function as earlier, note that the points are simply written after the name of the function with no parenthesis. AngleSym tells us that for any three points, it does not matter in which order you put the two last points in the CreateAngle function, the two terms are equal. This is not true for changing the point P, the first is here intuitively the point at the base of the angle, and changing it may change the angle.

Adding requirements

Next I am going to define a ray, so we may look at a slightly more complicated version of such a variable :

Variable Ray : Type.

Variable CreateRay : Point -> Point -> Ray.

Variable StartingPointRay : Ray -> Point.

Definition EqualRay (R S : Ray) := (identity R S).

The startingpoint of the ray is obviously exactly what it seems to mean. Now, look at this variable:

Variable StartingPointRayDef : (forall R : Ray, forall P Q : Point, forall p_q_makeR : EqualRay R (CreateRay P Q), EqualPoint P (StartingPointRay R)).

This one is a little longer, but most of it is obvious, we have any ray and any two points, but another requirement is put in, namely:

forall p_q_makeR : EqualRay R (CreateRay P Q)

The first part is just a name of the requirement and is not important, what the other part states is that the ray R is equal to the ray made by P and Q. With this we can add requirements beyond just what type the different objects should have, and only if this statement is true do we have:

EqualPoint P (StartingPointRay R)

That is to say that P is the starting point of the R if R equals CreateRay P Q.

And that is the basic of writing axioms, functions and types in Coq. Next time I will write about how to prove statements in Coq relying only on previously defined types and variables.

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)