Proving Mathematical Identities Using Haskell and Set Arithmetic

Proving Mathematical Identities Using Haskell and Set Arithmetic

Introduction

In this article, we will explore how to prove mathematical identities using Haskell, particularly focusing on the identity of Wall's continued fraction representation of the inverse tangent function. We will discuss the process step-by-step, from understanding the identity to writing a Haskell program to verify it.

Understanding the Identity

The identity we aim to prove is related to the continued fraction representation of the inverse tangent function, as described in the book Analytic Theory of Continued Fractions by H.S. Wall, published in 1948. A key trigonometric identity involved is arcsin(x) 2 arctan(x / (√(1 - x^2) - x)). This identity will play a crucial role in our proof.

Program Development

To prove this identity programmatically, we need to represent the involved sets and their operations using Haskell. We will define a data type for expressions and implement functions to evaluate these expressions under specific conditions.

Defining the Expression Data Type

data Expr     Union Expr Expr    | Intersect Expr Expr    | Complement Expr    | Variable String    deriving Show

This data type represents basic set operations such as union, intersection, complement, and variables. We will extend this with functions to evaluate the expressions.

Evaluating Expressions

type VariableAssignment  String - BoolevalExpr :: VariableAssignment - Expr - BoolevalExpr va Union e1 e2  (evalExpr va e1)  (evalExpr va e2)evalExpr va Intersect e1 e2  (evalExpr va e1)  (evalExpr va e2)evalExpr va Complement e  not $ (evalExpr va e)evalExpr va (Variable v)  va v

The above functions evalExpr are designed to evaluate boolean expressions based on the given assignment of variables. Here, VariableAssignment is a mapping from a set of strings (variables) to booleans (true or false).

Checking Expression Equivalence

equivExprs :: Expr - Expr - BoolequivExprs e1 e2      let uniqVars  nub $ allVars e1    allVars e2    in  all (uncurry (uniqVars  where    allVars :: Expr - [String]    allVars Union e1 e2  allVars e1    allVars e2    allVars Intersect e1 e2  allVars e1    allVars e2    allVars Complement e  allVars e    allVars Variable v  [v]

The function equivExprs determines if two expressions are equivalent by evaluating them under all possible variable assignments. The function subsequences generates all possible combinations of variables, and the function all ensures that for every combination, the two expressions evaluate to the same boolean value.

Parsing Expressions

exprParser :: GenParser Char ExprexprParser      do        lhs do            op oneOf "∪"            rhs return if op  "∪" then Union else Intersect lhs rhs        do            return lhsexprParser1 :: GenParser Char ExprexprParser1     do        char        exprParser        char "∪"        char        exprParser        do        char        char        do        Variable .: [] oneOf acceptableVarNames        Complement  char U  char  exprParser1  where    acceptableVarNames   :: String - ExprparseExpr s  case parse exprParser eof s               of Left er - error er                  Right res - res

The parser uses the Parsec library to parse strings into Expr data types. This allows us to easily input expressions and parse them into a data structure for evaluation.

Running the Program

main  putStrLn $ show $ equivExprs >> parseExpr >> parseExpr 

The main function runs the expression equivalence check and prints the result. In this case, the program will output True, confirming the identity.

Conclusion

Using Haskell for set arithmetic and programmatic proof of mathematical identities provides a powerful and elegant approach. This method not only verifies the given identity but also offers a general framework for proving other mathematical identities involving set operations.

References

Wall, H.S. (1948). Analytic Theory of Continued Fractions. New York: Chelsea.