Equazione di 2° grado


Quante soluzioni?


numSoluzioni a b c
    | disc >  0 = 2
    | disc == 0 = 1
    | otherwise = 0
          where
              disc = b^2-4*a*c

Le soluzioni?


solEquazione2 a b c = ((-b-sqrt(b^2-4*a*c))/(2*a),(-b+sqrt(b^2-4*a*c))/(2*a))

Con un’espressione locale where

solEquazione2 a b c = ((-b-d)/(2*a),(-b+d)/(2*a))
    where 
        d = sqrt(b^2-4*a*c)

Con un’espressione locale let

solEquazione2 a b c = 
    let 
        d = sqrt(b^2-4*a*c)
    in  
        ((-b-d)/(2*a),(-b+d)/(2*a))
solEquazione2 a b c =
    let 
        d   = sqrt(b^2-4*a*c) 
        a_2 = 2*a
    in 
        ((-b-d)/a_2,(-b+d)/a_2)