Haskell Program to find the hyperbolic arcsine of the given value


This tutorial will help us in finding hyperbolic arcsine of the given value. The hyperbolic arcsine (also known as "area hyperbolic sine" or "inverse hyperbolic sine") of a value, denoted as asinh(x), is the inverse function of the hyperbolic sine function (sinh(x)), which is defined as −

asinh(x) = ln(x + sqrt(x^2 + 1))

Syntax

asinh(angle)

Here, asinh() is a function to compute the hyperbolic arcsine of the given value and value is passed as parameter to compute the hyperbolic arcsine of the value passed. It is included in the Prelude module, which is automatically imported into all Haskell programs, so it can be used without importing any additional modules.

Method 1: Using asinh() function

In this method, the asinh() function calculates the value of the hyperbolic arcsine,this means that it takes a value, x, and returns the value, y, such that sinh(y) = x. The calculation is done using the formula asinh(x) = ln(x + sqrt(x^2 + 1))

Algorithm

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

  • Step 2 − 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 3 − The hyperbolic arcsine function, asinh() is called. The hyperbolic arcsine, asinh() function is not a built-in function in Haskell, but it is a part of the Prelude module. Here, the asinh() function is defined using ln and sqrt function.

  • Step 4 − “value” variable that contains the value, is passed as parameter to the asinh() function from Prelude module.

  • Step 5 − The result is assigned to the “result” variable after asinh() function computes the final resultant value and final output is displayed by printing the result value.

Example

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

main = do
let value = 3.14
let result = asinh(value) 
print (result)

Output

1.8618125572133835 

Method 2: Using log function for asinh()

In this method, the hyperbolic arcsine of a given value in Haskell would be calculated using the log function from the Prelude module instead of the ln function, and the sqrt function from the Math.Functions module, along with the ^ operator to raise a number to a power. And this definition is defined under asinh(), which is then called and used to compute the result. The result is then displayed on the screen.

Algorithm

  • Step 1 − The “Prelude” module is imported on hiding asinh() function. This module has already included asinh() function.

  • Step 2 − The definition of hyperbolic arcsine function under Prelude module using log functions is defined as, asinh x = log (x + sqrt (x^2 + 1)). This definition is defined main function and can be used under main, once the function is being called.

  • 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 − A variable named, ‘value’ that will contain the angle value, is being initialized. And a constant value is assigned to it using assignment operator.

  • Step 5 − The hyperbolic arcsine function asinh() that contains the above defined log function definition to compute the hyperbolic arcsine of the angle value passed, is called.

  • Step 6 − The angle value is passed as parameter to the asinh() function, by simply writing variable name along with the function called.

  • Step 7 − The result is assigned to the “result” variable after asinh() function computes the final resultant value and final output is displayed by printing the result value. To print the result, we can use ‘putStrLn’ as putStrLn $ "asinh(" ++ show value ++ ") = " ++ show result. Instead, we can also use print (result).

Example

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

import Prelude hiding (asinh)
asinh :: Double -> Double
asinh x = log (x + sqrt (x^2 + 1)) 
main :: IO ()
main = do  
let value = 2.5 
let result = asinh value 
putStrLn $ "asinh(" ++ show value ++ ") = " ++ show result  

Output

asinh(2.5) = 1.6472311463710958

Conclusion

The hyperbolic arcsine value for the given value in Haskell can be calculated by using the asinh() function. The hyperbolic arcsine, asinh() function is not a built-in function in Haskell, but it is a part of the Prelude module. The hyperbolic arcsine function is defined for all real values of x and it returns a value between negative infinity and positive infinity. It is useful in various fields such as mathematics, physics, and engineering.

Updated on: 20-Jan-2023

88 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements