Showing posts with label Coq. Show all posts
Showing posts with label Coq. Show all posts

Sunday, November 24, 2024

COQ INDUCTION ON LISTS

COQ INDUCTION ON LISTS

REVISED: Saturday, September 6, 2025





1. INTRODUCTION

ASSOCIATIVITY OF LIST CONCATENATION 

A list can be either nil or else cons applied to a number and a list. 

Applications of the declared constructors to one another are the only possible shapes that elements of an inductively defined set can have.

This last fact directly gives rise to a way of reasoning about inductively defined sets. A number is either O or S applied to some smaller number. A list is either nil or is cons applied to some number and some smaller list; etc. Thus, if we have in mind some proposition P that mentions a list l and we want to argue that P holds for all lists, we can reason as follows:

First, show that P is true of l when l is nil.

Then show that P is true of l when l is cons n l' for some number n and some smaller list l', assuming that P is true for l'.

Since larger lists can always be broken down into smaller ones, eventually reaching nil, these two arguments establish the truth of P for all lists l.

2. EXAMPLE

(* ++ is constructor for append *)
Theorem app_assoc : forall l1 l2 l3 : list Type,
  (l1 ++ l2) ++ l3 = l1 ++ (l2 ++ l3).
Proof.
  intros l1 l2 l3. induction l1 as [| n l1' IHl1'].
  - (* l1 = nil *)
    simpl. (* Unfold the ++ operator *)
    reflexivity.
  - (* l1 = cons n l1' *)
    simpl.
    rewrite IHl1'.
    reflexivity.
Qed.

Compiling:

(* ++ is constructor for append *)
Theorem app_assoc : forall l1 l2 l3 : list Type,
  (l1 ++ l2) ++ l3 = l1 ++ (l2 ++ l3).

The Goal window of CoqIDE shows:

1 goal
A, B, C : Prop
______________________________________(1/1)
forall l1 l2 l3 : list Type,
(l1 ++ l2) ++ l3 = l1 ++ l2 ++ l3

Theorem Declaration:

Theorem app_assoc : ... : Declares a theorem named app_assoc.

forall l1 l2 l3 : list Type,: Specifies that the theorem holds for any three lists of any type.

(l1 ++ l2) ++ l3 = l1 ++ (l2 ++ l3).: States the property to be proven: associativity of list concatenation.

Compiling:

Proof.

The Goal window of CoqIDE shows:

1 goal
A, B, C : Prop
______________________________________(1/1)
forall l1 l2 l3 : list Type,
(l1 ++ l2) ++ l3 = l1 ++ l2 ++ l3

Proof Initiation:

Proof.: Starts the proof.

Compiling:

  intros l1 l2 l3.

The Goal window of CoqIDE shows:

1 goal
A, B, C : Prop
l1 : list Type
l2 : list Type
l3 : list Type
______________________________________(1/1)
(l1 ++ l2) ++ l3 = l1 ++ l2 ++ l3

Induction Hypothesis:

intros l1 l2 l3.: Introduces the variables l1, l2, and l3 for the three lists.

Compiling:

 induction l1 as [| n l1' IHl1'].

The Goal window of CoqIDE shows:

2 goals
A, B, C : Prop
l2 : list Type
l3 : list Type
______________________________________(1/2)
([] ++ l2) ++ l3 = [] ++ l2 ++ l3
______________________________________(2/2)
((n :: l1') ++ l2) ++ l3 = (n :: l1') ++ l2 ++ l3

induction l1 as [| n l1' IHl1'].: Inducts on the first list l1.

Base Case: l1 = nil

Inductive Case: l1 = cons n l1' with the induction hypothesis IHl1'.

Compiling:

 - (* l1 = nil *)
    simpl. (* Unfold the ++ operator *)

The Goal window of CoqIDE shows:

1 goal
A, B, C : Prop
l2 : list Type
l3 : list Type
______________________________________(1/1)
l2 ++ l3 = l2 ++ l3

Base Case:

simpl.: Simplifies the expression by unfolding the ++ operator.

Compiling:

    reflexivity.

The Goal window of CoqIDE shows:

This subproof is complete, but there are some unfocused goals:

______________________________________(1/1)
((n :: l1') ++ l2) ++ l3 = (n :: l1') ++ l2 ++ l3

reflexivity.: Directly proves the equality by reflexivity, as both sides reduce to the same expression.

Compiling:

(* l1 = cons n l1' *)
    simpl.

The Goal window of CoqIDE shows:

1 goal
A, B, C : Prop
n : Type
l1' : list Type
l2 : list Type
l3 : list Type
IHl1' : (l1' ++ l2) ++ l3 = l1' ++ l2 ++ l3
______________________________________(1/1)
((n :: l1') ++ l2) ++ l3 = (n :: l1') ++ l2 ++ l3

Inductive Case:

simpl.: Simplifies the expression, again unfolding the ++ operator.

Compiling:

rewrite IHl1'.

The Goal window of CoqIDE shows:

1 goal
A, B, C : Prop
n : Type
l1' : list Type
l2 : list Type
l3 : list Type
IHl1' : (l1' ++ l2) ++ l3 = l1' ++ l2 ++ l3
______________________________________(1/1)
n :: l1' ++ l2 ++ l3 = n :: l1' ++ l2 ++ l3

rewrite IHl1'.: Applies the induction hypothesis IHl1' to simplify the expression further.

Compiling:

  reflexivity.

The Goal window of CoqIDE shows:

No more goals.

reflexivity.: After simplification, the two sides of the equation become identical, allowing for the application of reflexivity.

Compiling:

Qed.

3. CONCLUSION

Induction: The proof uses mathematical induction on the structure of the first list.

Simplification: The simpl tactic is used to unfold definitions and reduce expressions.

Reflexivity: The reflexivity tactic is used to prove equalities directly.

Induction Hypothesis: The IHl1' represents the induction hypothesis, which is the assumption that the property holds for smaller lists.

By following these steps and applying the appropriate tactics, Coq can verify the correctness of the app_assoc theorem.

The core idea of inductive proofs is to break down a complex problem into simpler instances and then use the inductive hypothesis to solve the simpler instances. In this case, we broke down the problem for cons n l1' into a simpler problem for l1' and then used the inductive hypothesis to solve the simpler problem.

4. REFERENCES

Bird, R. (2015). Thinking Functionally with Haskell. Cambridge, England: Cambridge University Press.

Davie, A. (1992). Introduction to Functional Programming Systems Using Haskell. Cambridge, England: Cambridge University Press.

Goerzen, J. & O'Sullivan, B. &  Stewart, D. (2008). Real World Haskell. Sebastopol, CA: O'Reilly Media, Inc.

Hutton, G. (2007). Programming in Haskell. New York: Cambridge University Press.

Lipovača, M. (2011). Learn You a Haskell for Great Good!: A Beginner's Guide. San Francisco, CA: No Starch Press, Inc.

Pierce, Benjamin C., et al., editors. Logical Foundations. Vol. 1 of Software Foundations. Electronic Textbook, 2024. Version 6.7,
http://softwarefoundations.cis.upenn.edu.

Thompson, S. (2011). The Craft of Functional Programming. Edinburgh Gate, Harlow, England: Pearson Education Limited.




Friday, November 15, 2024

COQ PROOF TECHNIQUES; REFLEXIVITY, REWRITE, AND DESTRUCT

COQ PROOF TECHNIQUES; REFLEXIVITY, REWRITE, AND DESTRUCT

REVISED: Saturday, September 6, 2025




Coq is a powerful Proof Assistant that allows you to formally verify mathematical proofs. To effectively use Coq, you'll need to master a few fundamental proof tactics. Let's delve into three of the most common ones: reflexivity, rewrite, and destruct.

1. REFLEXIVITY

The reflexivity tactic is used to prove equalities where both sides of the equation are identical. In essence, it asserts that any term is equal to itself. If you are having problems understanding Coq, preceed reflexivity with simpl. simpl is not necessary; however, it might help with human readability.

Example:

Goal forall x: nat, x = x.
Proof.
  reflexivity.
Qed.

We enter the proof engine by the command Goal, followed by the conjecture we want to verify: forall x: nat, x = x.

In this example, the goal is to prove that for any natural number x, x is equal to itself. The reflexivity tactic directly proves this equality.

Compiling: 

Goal forall x: nat,
  x = x.

The CoqIDE system displays the current goal below a line, local hypotheses (there are none initially) being displayed above the line. We call the combination of local hypotheses with a goal a judgment.

The Goal window of CoqIDE shows: 

1 goal
______________________________________(1/1)
forall x : nat, x = x

Compiling: 

Proof.
  reflexivity.

The Goal window of CoqIDE shows: 

No more goals.

Qed.

2. REWRITE

The rewrite tactic is used to replace one side of an equation with another equivalent expression. This is particularly useful when you have a known equality that can be applied to simplify a proof.

Example:

Theorem plus_id_example :
  forall n m : nat,
  n = m ->
  n + n = m + m.
Proof.
  intros n m.
  intros H.
  rewrite -> H.
  reflexivity.
Qed.

Compiling: 

Theorem plus_id_example :
  forall n m : nat,
  n = m ->
  n + n = m + m.

The Goal window of CoqIDE shows: 

1 goal
______________________________________(1/1)
forall n m : nat, n = m -> n + n = m + m

Compiling: 

Proof.
  intros n m.

The Goal window of CoqIDE shows: 

1 goal
n, m : nat
______________________________________(1/1)
n = m -> n + n = m + m

forall n, m : nat are moved above the line and become assumptions to improve human readability.  Now we more clearly see we have one goal, and we are assuming n and m are both natural numbers.

Compiling: 

intros H.

The Goal window of CoqIDE shows: 

1 goal
n, m : nat
H : n = m
______________________________________(1/1)
n + n = m + m

Compiling: 

rewrite -> H.

The Coq default is left to right; therefore, we could have written rewrite H.

The Goal window of CoqIDE shows: 

1 goal
n, m : nat
H : n = m
______________________________________(1/1)
m + m = m + m

Compiling: 

reflexivity.

The Goal window of CoqIDE shows: 

No more goals.

Qed.

3. DESTRUCT

The destruct tactic is used to break down inductive data types into their constituent cases. This is essential for reasoning about recursive definitions and proofs by induction.

Example:

Theorem andb_commutative : forall b c, andb b c = andb c b.
Proof.
  intros b c.
  destruct b, c.
  - reflexivity.
  - reflexivity.
  - reflexivity.
  - reflexivity.
Qed.

Compiling: 

Theorem andb_commutative : forall b c, andb b c = andb c b.

The Goal window of CoqIDE shows: 

1 goal
______________________________________(1/1)
forall b c : bool,
(b && c)%bool = (c && b)%bool

Compiling:

Proof.
  intros b c.

The Goal window of CoqIDE shows: 

1 goal
b, c : bool
______________________________________(1/1)
(b && c)%bool = (c && b)%bool

Compiling:

destruct b, c.

The Goal window of CoqIDE shows: 

4 goals
______________________________________(1/4)
(true && true)%bool = (true && true)%bool
______________________________________(2/4)
(true && false)%bool = (false && true)%bool
______________________________________(3/4)
(false && true)%bool = (true && false)%bool
______________________________________(4/4)
(false && false)%bool = (false && false)%bool

Compiling:

  - reflexivity.

The Goal window of CoqIDE shows: 

This subproof is complete, but there are some unfocused goals:

______________________________________(1/3)
(true && false)%bool = (false && true)%bool
______________________________________(2/3)
(false && true)%bool = (true && false)%bool
______________________________________(3/3)
(false && false)%bool = (false && false)%bool

Compiling:

  - reflexivity.

The Goal window of CoqIDE shows: 

This subproof is complete, but there are some unfocused goals:

______________________________________(1/2)
(false && true)%bool = (true && false)%bool
______________________________________(2/2)
(false && false)%bool = (false && false)%bool

Compiling:

  - reflexivity.

The Goal window of CoqIDE shows: 

This subproof is complete, but there are some unfocused goals:

______________________________________(1/1)
(false && false)%bool = (false && false)%bool

Compiling:

  - reflexivity.

The Goal window of CoqIDE shows: 

No more goals.

Qed.

Additional information.

Combined Destruct:

Instead of performing two nested destructs, they can be combined into a single destruct b, c. This simultaneously breaks down both b and c into their possible cases, leading to a more concise proof.

Implicit Reflexivity:

In each case, the equality is trivial. Coq's automated tactics can often infer the necessary steps to prove such simple equalities. By simply using reflexivity without explicit argument, we let Coq fill in the details.

Key Points to Remember.

Efficient Destruct:

Use destruct judiciously to break down complex terms into simpler cases.

Leverage Automation: 

Utilize Coq's automated tactics to simplify proofs, especially for trivial equalities.

Readability: 

Write clear and concise proofs. Avoid unnecessary steps and redundant explanations.

4. CONCLUSION

By mastering these three techniques, you can tackle a wide range of proofs in Coq. 

Remember that practice is key, so don't hesitate to experiment and explore more complex examples.

5. REFERENCES

Bird, R. (2015). Thinking Functionally with Haskell. Cambridge, England: Cambridge University Press.

Davie, A. (1992). Introduction to Functional Programming Systems Using Haskell. Cambridge, England: Cambridge University Press.

Goerzen, J. & O'Sullivan, B. &  Stewart, D. (2008). Real World Haskell. Sebastopol, CA: O'Reilly Media, Inc.

Hutton, G. (2007). Programming in Haskell. New York: Cambridge University Press.

Lipovača, M. (2011). Learn You a Haskell for Great Good!: A Beginner's Guide. San Francisco, CA: No Starch Press, Inc.

Pierce, Benjamin C., et al., editors. Logical Foundations. Vol. 1 of Software Foundations. Electronic Textbook, 2024. Version 6.7, http://softwarefoundations.cis.upenn.edu.

Thompson, S. (2011). The Craft of Functional Programming. Edinburgh Gate, Harlow, England: Pearson Education Limited.




Monday, November 11, 2024

COQ RECURSIVE FUNCTION EXAMPLE

COQ RECURSIVE FUNCTION EXAMPLE

REVISED: Saturday, September 6, 2025




1. COQ RECURSIVE FUNCTION EXAMPLE

Fixpoint even (n:nat) : bool :=
  match n with
  | O => true
  | S O => false
  | S (S n') => even n'
  end.

To understand the Coq program's Vernacular Commands and Tactics let's break down the above Coq program and explain each component:

1.1. Fixpoint even (n:nat) : bool :=

Fixpoint: This keyword declares a recursively defined function. In this case, we're defining a function named even that takes a natural number n as input and returns a boolean value.

(n:nat): This specifies that the input parameter n is of type nat, which represents Natural Numbers in Coq.

: bool: This indicates that the function even returns a value of type bool, which represents boolean values (true or false).

1.2. match n with

match: This keyword introduces a pattern-matching construct. It allows us to define the behavior of the function based on different cases of the input n.

1.3. | O => true

| O: This is a pattern that matches the case when n is zero.

=> true: If the pattern matches, the function returns true.

1.4. | S O => false

| S O: This pattern matches the case when n is the successor of zero, i.e., one.

=> false: If the pattern matches, the function returns false.

1.5. | S (S n') => even n'

| S (S n'): This pattern matches the case when n is the successor of the successor of some natural number n'.

=> even n': If the pattern matches, the function recursively calls itself with the argument n'.

2. Reasoning Behind the Program

The even function is designed to determine whether a given natural number is even or odd. It works as follows:

 2.1. Base Cases:

If n is zero, it's considered even, so the function returns true.

If n is one, it's considered odd, so the function returns false.

2.2. Recursive Case:

If n is greater than one, we can express it as the successor of another natural number n'.

The parity of n is the opposite of the parity of n'. Therefore, we can recursively call the even function on n' and negate the result.

In essence, the even function recursively checks if a number is even by repeatedly subtracting 2 until it reaches 0 or 1.

2. CONCLUSION

This is a classic example of a recursive function in Coq, demonstrating how pattern matching and recursion can be used to define complex functions in a concise and elegant manner.

3. REFERENCES

Bird, R. (2015). Thinking Functionally with Haskell. Cambridge, England: Cambridge University Press.

Davie, A. (1992). Introduction to Functional Programming Systems Using Haskell. Cambridge, England: Cambridge University Press.

Goerzen, J. & O'Sullivan, B. &  Stewart, D. (2008). Real World Haskell. Sebastopol, CA: O'Reilly Media, Inc.

Hutton, G. (2007). Programming in Haskell. New York: Cambridge University Press.

Lipovača, M. (2011). Learn You a Haskell for Great Good!: A Beginner's Guide. San Francisco, CA: No Starch Press, Inc.

Pierce, Benjamin C., et al., editors. Logical Foundations. Vol. 1 of Software Foundations. Electronic Textbook, 2024. Version 6.7, http://softwarefoundations.cis.upenn.edu.

Thompson, S. (2011). The Craft of Functional Programming. Edinburgh Gate, Harlow, England: Pearson Education Limited.




Wednesday, October 30, 2024

COQ'S FUNCTIONAL PROGRAMMING LANGUAGE

COQ'S FUNCTIONAL PROGRAMMING LANGUAGE

REVISED: Saturday, September 6, 2025





1. COQ'S FUNCTIONAL PROGRAMMING LANGUAGE

We type in the CoqIDF buffer window using Coq keyword vernacular commands.

As shown below, the Inductive Type day is a new Type : defined to be := the list of day Type items or constructors separated by | vertical bars. The list of constructors ends with a period .

Inductive day : Type :=
    | monday
    | tuesday
    | wednesday
    | thursday
    | friday
    | saturday
    | sunday.

We move the cursor to the right of the period and click the CoqIDE down-arrow to compile the above Type.  If the compile is successful the line color changes to green.

After the successful compile, CoqIDE responds in the Messages' window with 

day is defined
day_rect is defined
day_ind is defined
day_rec is defined
day_sind is defined

Next, we write the function next_weekday based on the above day Type. Definition is the Vernacular command that declares Coq functions. The function name should be a short descriptive group of words connected by underscores _  reflecting the purpose of the function. The function uses pattern matching, matching the argument d and the branch or case Type it returns will be the day: Type. The branch or case is separated by right arrows pointing to the matching argument. The function ends with end and a period .

Definition next_weekday (d:day) : day :=
    match d with
    | monday    => tuesday
    | tuesday   => wednesday
    | wednesday => thursday
    | thursday  => friday
    | friday    => monday
    | saturday  => monday
    | sunday    => monday
    end.

We move the cursor to the right of the period after end and click the CoqIDE down-arrow to compile the function next_weekday.  When the compile is successful the function color changes to green.

After the successful compile, CoqIDE responds in the Messages' window with 

next_weekday is defined

To call a function, we use the vernacular command Compute.

Compute (next_weekday friday).

After the successful compile, CoqIDE responds in the Messages window with

    = monday
     : day

We test our next_weekday function using the vernacular command Example.

Example test_next_weekday :
    (next_weekday (next_weekday saturday)) = tuesday.

After a successful compile, CoqIDE responds in the Goal's window by telling us we must first prove the new test_next_weekday function before we can use it. 

1 goal
______________________________________(1/1)
next_weekday (next_weekday saturday) =
tuesday

CoqIDF wants us to prove 1 goal the test_next_weekday function.

We use the simpl tactic to simplify the goal we are trying to prove. 

Proof. simpl. reflexivity. Qed.

After Proof we compile period by period one at a time. After the successful compile of  simple,  CoqIDE responds in the Goal's window with 

1 goal
______________________________________(1/1)
tuesday = tuesday

Notice 1 goal has changed, now both sides of = below the line are the same.

When both sides of = are the same we can use the tactic reflexivityAfter the successful compile of  reflexivity, CoqIDE responds in the Goal's window with 

No more goals.

Now when we compile Qed. all windows are blank and CoqIDE accepts the Proof as proven.

Compute (next_weekday (next_weekday saturday)).

After the successful compile of Compute, CoqIDE responds in the Messages window with

    = tuesday
     : day

Notice the above Compute is passing function arguments from right to left. For example, next_weekday saturday computes to monday which is passed as an argument to the function on the left next_weekday which uses monday  to compute the final answer tuesday.

2. CONCLUSION 

The Coq functional programming Language is both logically intuitive and easy to use.

3. REFERENCES

Bird, R. (2015). Thinking Functionally with Haskell. Cambridge, England: Cambridge University Press.

Davie, A. (1992). Introduction to Functional Programming Systems Using Haskell. Cambridge, England: Cambridge University Press.

Goerzen, J. & O'Sullivan, B. &  Stewart, D. (2008). Real World Haskell. Sebastopol, CA: O'Reilly Media, Inc.

Hutton, G. (2007). Programming in Haskell. New York: Cambridge University Press.

Lipovača, M. (2011). Learn You a Haskell for Great Good!: A Beginner's Guide. San Francisco, CA: No Starch Press, Inc.

Pierce, Benjamin C., et al., editors. Logical Foundations. Vol. 1 of Software Foundations. Electronic Textbook, 2024. Version 6.7, http://softwarefoundations.cis.upenn.edu.

Thompson, S. (2011). The Craft of Functional Programming. Edinburgh Gate, Harlow, England: Pearson Education Limited.




CALCULUS of INDUCTIVE CONSTRUCTIONS (CIC) and Gallina

CLCULUS OF INDUCTIVE CONSTRUCTIONS (CIC) AND GALLINA

REVISED: Saturday, September 6, 2025





1. The Calculus of Inductive Constructions (CIC)

CIC is a powerful type of theory that serves as the foundation for the Coq proof assistant. It's a higher-order logic system where types and terms are unified, allowing for a seamless integration of logic and computation.

Key Features

Types and Terms:

In CIC, types and terms are not distinct entities. Both are represented as expressions within the same language. This means that types can be the subjects of proofs, and proofs can be the objects of computation.

Dependent Types: 

CIC supports dependent types, where the type of an expression can depend on the value of another expression. This enables fine-grained reasoning about complex data structures and algorithms.

Inductive Types: 

Inductive types allow the definition of recursive data structures, such as natural numbers, lists, and trees. This is crucial for defining algorithms and proving properties about them.

Proofs as Programs: 

The Curry-Howard isomorphism, a fundamental principle in CIC, establishes a correspondence between proofs and programs. This means that proofs can be seen as programs that construct values of a certain type, and programs can be seen as proofs of their correctness.

2. Gallina

Gallina is a high-level specification language built on top of CIC. It provides a more user-friendly syntax and a rich set of features for writing mathematical proofs and formal specifications.

Key Features

Intuitive Syntax: 

Gallina uses a more natural syntax compared to raw CIC, making it easier to read and write.

Tactics: 

Gallina provides a variety of tactics for constructing proofs interactively. These tactics automate common proof steps, reducing the amount of manual effort required.

Inductive Definitions: 

Gallina allows for the definition of inductive types and functions using a concise and intuitive syntax.

Higher-Order Logic: 

Gallina supports higher-order logic, allowing for reasoning about functions and predicates.

3. How Gallina and CIC Work Together

Key Features

Specification: 

The user writes a formal specification in Gallina, defining the properties and theorems to be proven.

Proof Development: 

The user interacts with the Coq proof assistant to construct proofs interactively. Gallina provides a convenient interface for this process.

Type Checking: 

Coq's type checker ensures the correctness of the proof by verifying that each step adheres to the rules of CIC.

Proof Completion: 

Once a proof is completed, Coq generates a formal proof object, which can be machine-checked for correctness.

4. Benefits of Using CIC and Gallina

Key Features

Formal Verification: 

CIC and Gallina enable the formal verification of software and hardware systems, ensuring their correctness and reliability.

Mathematical Reasoning: 

CIC can be used to formalize and reason about complex mathematical concepts, such as number theory, algebra, and topology.

Program Synthesis: 

The Curry-Howard isomorphism allows for the synthesis of programs from proofs, leading to the development of correct-by-construction software.

Education and Research: 

CIC and Gallina are powerful tools for teaching and researching formal methods, logic, and programming languages.

5. CONCLUSION

CIC and Gallina provide a robust framework for formal reasoning and program verification. By combining the power of higher-order logic, dependent types, and inductive definitions, they enable the development of complex mathematical theories and the rigorous verification of software systems.

6. REFERENCES

Bird, R. (2015). Thinking Functionally with Haskell. Cambridge, England: Cambridge University Press.

Davie, A. (1992). Introduction to Functional Programming Systems Using Haskell. Cambridge, England: Cambridge University Press.

Goerzen, J. & O'Sullivan, B. &  Stewart, D. (2008). Real World Haskell. Sebastopol, CA: O'Reilly Media, Inc.

Hutton, G. (2007). Programming in Haskell. New York: Cambridge University Press.

Lipovača, M. (2011). Learn You a Haskell for Great Good!: A Beginner's Guide. San Francisco, CA: No Starch Press, Inc.

Pierce, Benjamin C., et al., editors. Logical Foundations. Vol. 1 of Software Foundations. Electronic Textbook, 2024. Version 6.7, http://softwarefoundations.cis.upenn.edu.

Thompson, S. (2011). The Craft of Functional Programming. Edinburgh Gate, Harlow, England: Pearson Education Limited.




Tuesday, October 29, 2024

COQ

COQ

REVISED: Saturday, September 6, 2025



1. INTRODUCTION

Imagine you're building a really cool LEGO structure. You have all the bricks and pieces, and you have a plan (instructions) on how to build it. Coq is like a super smart friend who helps you make sure you're following the plan perfectly and that your LEGO structure is strong and sturdy.

Here's how it works:

Proof Assistant:

Coq is a proof assistant. That means it helps you write proofs, which are like arguments or explanations that show something is true.

Math and Programming:

Coq can be used for math and programming. In math, it can help you prove theorems, like proving that 2 + 2 always equals 4. In programming, it can help you write programs that are correct and work the way they should.

Formal Verification:

Coq is used for formal verification. This means it can check if your math or programming is correct, just like your friend checks your LEGO building.

So, Coq is a powerful tool that helps people be sure that their math and programming is accurate and reliable. It's like having a super-smart friend who can help

2. COQIDE

Imagine CoqIDE as a special kind of word processor, but instead of writing stories or essays, it helps you build logical arguments and proofs. It's like having a super smart friend who can check your work and tell you if your reasoning is correct.

Here's what it does:

Proof Editing:

You can type in your proofs, and CoqIDE will help you by suggesting steps or pointing out mistakes.

Auto-Completion: 

It can finish your sentences for you, just like your phone does when you text!

Highlighting: 

It highlights important parts of your proof to make it easier to read and understand.

Checking: 

CoqIDE checks your proof step-by-step to make sure it's logically sound.

So, CoqIDE is a tool that helps you build strong, accurate proofs. It's like having a helpful assistant who makes sure your logical thinking is top-notch.

3. COQ-SHELL

Imagine Coq-Shell as a magical text box where you can type in math problems and proofs. It's like having a super smart calculator that not only gives you answers but also checks if your thinking is correct.

Here's how it works:

Typing: 

You type in your math problems and proofs using special commands.

Checking: 

Coq-Shell checks your work step-by-step to make sure it's logically sound.

Feedback: 

It gives you feedback, like if you made a mistake or if your proof is correct.

So, Coq-Shell is a tool that helps you explore math and logic in a fun and interactive way. It's like having a math wizard by your side, guiding you through your calculations and helping you discover new things!

4. CONCLUSION

In this tutorial, you have received a brief overview of Coq, Coq-IDE, and Coq-Shell.

5. REFERENCES

Bird, R. (2015). Thinking Functionally with Haskell. Cambridge, England: Cambridge University Press.

Davie, A. (1992). Introduction to Functional Programming Systems Using Haskell. Cambridge, England: Cambridge University Press.

Goerzen, J. & O'Sullivan, B. &  Stewart, D. (2008). Real World Haskell. Sebastopol, CA: O'Reilly Media, Inc.

Hutton, G. (2007). Programming in Haskell. New York: Cambridge University Press.

Lipovača, M. (2011). Learn You a Haskell for Great Good!: A Beginner's Guide. San Francisco, CA: No Starch Press, Inc.

Pierce, Benjamin C., et al., editors. Logical Foundations. Vol. 1 of Software Foundations. Electronic Textbook, 2024. Version 6.7, http://softwarefoundations.cis.upenn.edu.

Thompson, S. (2011). The Craft of Functional Programming. Edinburgh Gate, Harlow, England: Pearson Education Limited.