A functional and menu-driven polynomial calculator written in Haskell.
It supports normalization, addition, multiplication, and derivation of polynomials written in standard algebraic form (e.g. 2x + 5x^2 + 3).
Simplifies a polynomial by combining like terms and ordering them by degree.
Examples
Input: 2x + 5x^2 + 3 + 4x^2 + x
Output: 9x^2 + 3x + 3
Input: x^3 + 2x^3 - x + 4 - 4
Output: 3x^3 - x
Sums two polynomials.
Examples
Input:
First polynomial: 2x^2 + 3x + 1
Second polynomial: x^2 + 5
Output: 3x^2 + 3x + 6
Input:
First polynomial: 4x^3 + x
Second polynomial: 2x^3 + 3x^2 + 5
Output: 6x^3 + 3x^2 + x + 5
Multiplies two polynomials.
Examples
Input:
First polynomial: x + 1
Second polynomial: x + 2
Output: x^2 + 3x + 2
Input:
First polynomial: 2x^2 + 3
Second polynomial: x + 4
Output: 2x^3 + 8x^2 + 3x + 12
Computes the derivative of a polynomial.
Examples
Input: 3x^3 + 2x + 1
Output: 9x^2 + 2
Input: 5x^4 + x^2 + 7x
Output: 20x^3 + 2x + 7
When you run the program, a text menu appears:
What operation do you want to do?
1) Normalize
2) Add
3) Multiply
4) Derivate
0) Exit
Enter the number corresponding to the operation you want to perform, then provide the polynomial(s) as prompted.
Compile and run using GHC:
runghc main.hs