Haskell Program to find the hyperbolic arccosine of the given value


This article will help us in finding hyperbolic arccosine of the given value. The hyperbolic arccosine, also known as the inverse hyperbolic cosine, is the inverse function of the hyperbolic cosine. It is defined as acosh(x) = log(x + sqrt(x^2 - 1)) for x > 1, where log is the natural logarithm. The output of this function is a real number.

Syntax

acosh(angle)

Here, acosh() is a function and value is passed as parameter to compute the hyperbolic arccosine of the value passed and value passed must be greater than 1.

Method 1: Using acosh() function

In this method, the function uses the natural logarithm function (log) and the square root function (sqrt) to calculate the hyperbolic arccosine of the input value that must be greater than 1.

Algorithm

  • Step 1 − “Data.Complex” module is imported.

  • Step 2 − Program execution will be started from main function. The main() function has whole control of the program. It is written as, main = do.

  • Step 3 − A variable named, “value” is being initialized. Initially, it will have the garbage value. Then, a constant value is being assigned to it. This value is assigned to the variable “value” by using the assignment operator.

  • Step 4 − The hyperbolic arccosine function, acosh() is called from the Prelude module. The hyperbolic arccosine, acosh() function is not a built-in function in Haskell. Here, the acosh() function is defined using log and sqrt function as acosh x = log (x + sqrt (x^2 - 1)).

  • Step 5 − “value” variable that contains the value, is passed as parameter to the acosh() function, by simply writing variable name along with the function called.

  • Step 6 − The result is assigned to the “result” variable after acosh() function computes the final resultant value and final output is displayed by printing the result value. To display the output, we use print statement as, print (result).

Example

In this example, we are going to see how we can find the hyperbolic arccosine of the value passed using acosh() function.

import qualified Data.Complex as C
acosh :: Double -> Double
acosh x = log (x + sqrt (x^2 - 1)) 
main = do  
let value = 2.0 
let result = Prelude.acosh (value) 
putStrLn "The resultant hyperbolic arccosine value is:  "
print (result) 

Output

The resultant hyperbolic arccosine value is:  
1.3169578969248166 

Method 2: Using log function

In this approach, the hyperbolic arccosine of a given complex number value is computed. The function uses the log function and the sqrt function to calculate the natural logarithm of a complex number and the square root of the square of the complex number minus one respectively. And this definition is defined under acosh(), which is then called and used to compute the result.

Algorithm

  • Step 1 − The “Data.Complex” module is imported to work over complex numbers and for using log functions.

  • Step 2 − The definition of hyperbolic arccosine function using log functions is defined as, acosh z = log (z + (sqrt ((z^2) - 1))). This is defined above the main function in order to be used, once called under main function.

  • Step 3 − Program execution will be started from main function. The main() function has whole control of the program. It is written as, main = do.

  • Step 4 − The hyperbolic arccosine function acosh() that contains the above defined log function definition to compute the hyperbolic arccosine of the complex number value passed, is called from Prelude module.

  • Step 5 − The complex number value (in the form of a :+ b) is passed as parameter to the acosh() function. For example, acosh (3 :+ 4)

  • Step 6 − The result is assigned to the “result” variable after acosh() function computes the final resultant value and final output is displayed by printing the result value. To display the output, we use print statement as, print (result).

Example

In this example, we are going to see how we can find the hyperbolic arccosine of the value passed using log function

import Data.Complex 

acosh :: Complex Double -> Complex Double
acosh z = log (z + (sqrt ((z^2) - 1))) 

main :: IO ()
main = do  
let result = Prelude.acosh (3 :+ 4) 
putStrLn "The resultant hyperbolic arccosine value is:  "
print (result) 

Output

The resultant hyperbolic arccosine value is:  
2.305509031243477 :+ 0.9368124611557199

Conclusion

The hyperbolic arccosine value for the given value in Haskell can be calculated by using the acosh() function. The hyperbolic arccosine, acosh() function is not a built-in function in Haskell. The hyperbolic arccosine value can also be computed for complex numbers, where the (x :+ sqrt (x^2 - 1)) creates a complex number with the real part x and imaginary part sqrt(x^2 -1).

The hyperbolic arccosine function is useful in areas such as physics, engineering, and computer science, where it is used in the study of hyperbolic functions and their properties.

Updated on: 20-Jan-2023

85 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements