Friday, November 15, 2024

COQ PROOF TECHNIQUES; REFLEXIVITY, REWRITE, AND DESTRUCT

COQ PROOF TECHNIQUES; REFLEXIVITY, REWRITE, AND DESTRUCT

REVISED: Saturday, November 16, 2024




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.

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 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: Tuesday, November 12, 2024





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.




Friday, November 8, 2024

COQIDE PROOF BY INDUCTION

COQ PROOF BY INDUCTION

REVISED: Sunday, November 17, 2024






1. COQIDE PROOF BY INDUCTION

If [P(n)] is some proposition P, involving a natural number [n], and we want to show that [P] holds for all numbers, we can reason like this:

  - Show that [P(O)], the base case,  holds.
  
  - Show that, if [P(n')] holds, then so does [P(S n')], the successor of n', 1+n'. The inductive case holds.
  
  - Conclude by the principle of induction that [P(n)] holds for all [n]. All cases hold.

Example:

Theorem add_O_r : forall n : nat,
     n + O = n.
Proof.
     intros n. induction n as [ | n' IHn' ].
      - (* n = O *) reflexivity.
      - (* n = S n' *) simpl. rewrite -> IHn'. reflexivity.
Qed.

Compile:

Theorem add_O_r : forall n:nat,
     n + O = n.

As you can see, the above Theorem named add_O_r says that for all n that are Natural Numbers n + O = n, (Recall, if you will, Coq represents the number zero as O.)

Depending on the selections you made in your CoqIDE "view" drop-down tab, when the above Theorem compiles in the CoqIDE and turns green, the goals window will show the following:

1 goal
______________________________________(1/1)
forall n : nat, n + 0 = n

Compile:

Proof.
   intros n. 

After Proof. and intros n. compile and turn green the goals window will show the following:

1 goal
n : nat
______________________________________(1/1)
n + 0 = n

The tactic intros n. is used to introduce new variables, in this case, n.  When compiled, n : nat moves above the line as an assumption.

Compile:

 induction as [ | n' IHn'].

The induction n. tactic takes an as... clause that specifies the names of the variables to be introduced in the subgoals. Since there are two subgoals, the as... clause has two parts, separated by |

Coq uses IHn' (i.e., the Induction Hypothesis for n').

When induction as [ | n' IHn']. compiles the goals window will show the following:

2 goals
______________________________________(1/2)
0 + 0 = 0
______________________________________(2/2)
S n' + 0 = S n'

Compile:

     - (* n = O *) reflexivity.

The - is a bullet used to separate the induction subgoal cases. 

Coq comments are shown using (* ... *) with the comment typed, as shown above, between the two *. 

The above shows we are using the tactic reflexivity to work on the first goal which is n = O.

When the above tactic reflexivity code compiles the goals window will show the following:

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

______________________________________(1/1)
S n' + 0 = S n'

The goal window comments above the line shows we have proved the first goal; however, information below the line shows we have another subgoal to complete.

Compile:

     - (* n = S n' *) simpl.

As shown in the above comment (* n = S n' *)we are working on the second goal n = S n' using simpl. After it is compiled, the goal window shows. 

1 goal
n' : nat
IHn' : n' + 0 = n'
______________________________________(1/1)
S (n' + 0) = S n'

As shown above IHn' : n' + 0 = n' has moved above the line as an assumption named IHn' which equals n'.

Compile:

 rewrite -> IHn'.

When the rewrite -> IHn'. code compiles,  (n' + 0) below the line becomes n' and the goals window will show the following:

1 goal
n' : nat
IHn' : n' + 0 = n'
______________________________________(1/1)
S n' = S n'

Compile:

reflexivity.

Notice below the line S n' = S n' ; we can now compile reflexivity and the goals window will show:

No more goals.

When Qed. compiles the goals window will be blank and the proof is complete.

2. CONCLUSION

To prove interesting facts about numbers, lists, and other inductively defined sets, we often need a more powerful reasoning principle: induction.

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: Sunday, November 10, 2024





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. 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: Wednesday, October 30, 2024





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: Sunday, November 29, 2024




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.




Sunday, October 27, 2024

HASKELL TO AGDA AND COQ

 

HASKELL TO AGDA AND COQ

REVISED: Wednesday, November 20, 2024




1. INTRODUCTION

As software systems become more complex and critical, the demand for rigorous verification methods will grow. Agda and Coq, with their ability to formally prove the correctness of programs, are well-positioned to play a significant role in this domain.

These languages are excellent tools for teaching and research in computer science and mathematics. They provide a solid foundation for understanding complex concepts and developing formal reasoning skills.

Agda and Coq's strengths in expressing complex specifications and proofs make them suitable for specialized domains such as cryptography, security, and systems programming.

There's potential for integrating ideas from dependent type theory into mainstream programming languages. This could lead to more reliable and secure software development practices.

2. OVERVIEW

Agda:

Dependent Types: Agda allows you to define types that depend on values, making it possible to express complex relationships between data and functions.

Proofs as Programs: In Agda, proofs are written as programs, and programs are verified proofs. This principle, known as the Curry-Howard isomorphism, enables you to write code that is both correct and formally verified.

Interactive Development: Agda provides an interactive development environment where you can define functions, prove theorems, and experiment with different approaches.

Coq:

Coq is French for Rooster. Coq is free, open-source software. Coq itself can be viewed as a combination of a small but extremely expressive functional programming language plus a set of tools for stating and proving logical assertions.

Coq is an interactive theorem prover, development started in 1983 and was first released in 1989.
Implemented in the OCaml programming language.
Reference Manual  https://coq.inria.fr/doc/V8.20.0/refman/

Calculus of Inductive Constructions: Coq is based on a powerful type theory called the Calculus of Inductive Constructions, which allows for higher-order reasoning and the definition of complex mathematical structures.

Tactics: Coq uses tactics to guide the proof process, allowing you to break down complex proofs into smaller, more manageable steps.

Formal Verification: Coq is widely used for formal verification of software and hardware, ensuring that systems are correct by construction.

3. Learning Resources:

Agda:

Official Tutorial:

https://agda.readthedocs.io/en/v2.6.0.1/getting-started/tutorial-list.html

Software Foundations in Agda:

 https://softwarefoundations.cis.upenn.edu/

Type-Driven Development with Idris:

https://www.amazon.com/Type-driven-Development-Idris-Edwin-Brady/dp/1617293024 (While this book is about Idris, it covers many concepts relevant to Agda)

Coq:

Software Foundations: 

The Coq system contains the functional programming language Gallina.

https://softwarefoundations.cis.upenn.edu/

https://www.youtube.com/watch?v=BGg-gxhsV4E&list=PLre5AT9JnKShFK9l9HYzkZugkJSsXioFs

Certified Programming with Coq:

https://www.amazon.com/Certified-Programming-Dependent-Types-Introduction/dp/0262026651

Coq'Art: The Art of Proof and Programming: 

https://link.springer.com/book/10.1007/978-3-662-07964-5

4. Getting Started:

Install: Download and install Agda or Coq for your operating system.

Learn the Basics: Start with the official tutorials or books to understand the syntax and basic concepts.

Practice: Work through exercises and examples to gain practical experience.

Explore Libraries: Use existing libraries to learn from others and build upon their work.

Join the Community: Participate in online forums and communities to ask questions and get help.

Remember, learning Agda and Coq requires patience and persistence. Don't be afraid to experiment and make mistakes. The more you practice, the better you'll become.

3. CONCLUSION

While Agda and Coq may not become mainstream programming languages like Python or JavaScript, their impact on the software development landscape is likely to grow. As the demand for rigorous verification and formal methods increases, these languages have the potential to become indispensable tools for developers and researchers alike.

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.