?

Average Error: 52.5 → 0.1
Time: 13.1s
Precision: binary64
Cost: 7488

?

\[\left(\left(4.930380657631324 \cdot 10^{-32} < a \land a < 2.028240960365167 \cdot 10^{+31}\right) \land \left(4.930380657631324 \cdot 10^{-32} < b \land b < 2.028240960365167 \cdot 10^{+31}\right)\right) \land \left(4.930380657631324 \cdot 10^{-32} < c \land c < 2.028240960365167 \cdot 10^{+31}\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[0.5 \cdot \frac{-4 \cdot c}{b + \sqrt{b \cdot b + -4 \cdot \left(c \cdot a\right)}} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (* 0.5 (/ (* -4.0 c) (+ b (sqrt (+ (* b b) (* -4.0 (* c a))))))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
	return 0.5 * ((-4.0 * c) / (b + sqrt(((b * b) + (-4.0 * (c * a))))));
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = 0.5d0 * (((-4.0d0) * c) / (b + sqrt(((b * b) + ((-4.0d0) * (c * a))))))
end function
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
	return 0.5 * ((-4.0 * c) / (b + Math.sqrt(((b * b) + (-4.0 * (c * a))))));
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
def code(a, b, c):
	return 0.5 * ((-4.0 * c) / (b + math.sqrt(((b * b) + (-4.0 * (c * a))))))
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function code(a, b, c)
	return Float64(0.5 * Float64(Float64(-4.0 * c) / Float64(b + sqrt(Float64(Float64(b * b) + Float64(-4.0 * Float64(c * a)))))))
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
end
function tmp = code(a, b, c)
	tmp = 0.5 * ((-4.0 * c) / (b + sqrt(((b * b) + (-4.0 * (c * a))))));
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := N[(0.5 * N[(N[(-4.0 * c), $MachinePrecision] / N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
0.5 \cdot \frac{-4 \cdot c}{b + \sqrt{b \cdot b + -4 \cdot \left(c \cdot a\right)}}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 52.5

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
  2. Simplified52.5

    \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    Proof

    [Start]52.5

    \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]

    *-commutative [=>]52.5

    \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
  3. Applied egg-rr52.3

    \[\leadsto \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2} \]
  4. Simplified52.3

    \[\leadsto \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{a \cdot 2} \]
    Proof

    [Start]52.3

    \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2} \]

    *-commutative [=>]52.3

    \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \color{blue}{\left(c \cdot a\right)}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2} \]

    *-commutative [=>]52.3

    \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot a\right) \cdot 4}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2} \]

    fma-def [<=]52.3

    \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -4\right)}}}}{a \cdot 2} \]

    +-commutative [=>]52.3

    \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right) + b \cdot b}}}}{a \cdot 2} \]

    fma-def [=>]52.3

    \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{a \cdot 2} \]
  5. Applied egg-rr58.8

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}\right)} - 1} \]
  6. Simplified0.2

    \[\leadsto \color{blue}{0.5 \cdot \frac{\frac{c \cdot \left(-4 \cdot a\right) + 0 \cdot \left(b \cdot b\right)}{a}}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}} \]
    Proof

    [Start]58.8

    \[ e^{\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}\right)} - 1 \]

    expm1-def [=>]56.3

    \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}\right)\right)} \]

    expm1-log1p [=>]52.3

    \[ \color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}} \]

    *-lft-identity [<=]52.3

    \[ \frac{\color{blue}{1 \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right)}}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)} \]

    associate-*l/ [<=]52.3

    \[ \color{blue}{\frac{1}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)} \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right)} \]

    associate-/r* [=>]52.3

    \[ \color{blue}{\frac{\frac{1}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}} \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right) \]
  7. Taylor expanded in c around 0 0.1

    \[\leadsto 0.5 \cdot \frac{\color{blue}{-4 \cdot c}}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}} \]
  8. Applied egg-rr0.1

    \[\leadsto 0.5 \cdot \frac{-4 \cdot c}{b + \sqrt{\color{blue}{b \cdot b + -4 \cdot \left(a \cdot c\right)}}} \]
  9. Final simplification0.1

    \[\leadsto 0.5 \cdot \frac{-4 \cdot c}{b + \sqrt{b \cdot b + -4 \cdot \left(c \cdot a\right)}} \]

Alternatives

Alternative 1
Error3.0
Cost1088
\[0.5 \cdot \frac{-4 \cdot c}{b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)} \]
Alternative 2
Error3.1
Cost1024
\[\frac{-c}{b} - \frac{\frac{a \cdot \left(c \cdot c\right)}{b \cdot b}}{b} \]
Alternative 3
Error6.2
Cost256
\[\frac{-c}{b} \]

Error

Reproduce?

herbie shell --seed 2023053 
(FPCore (a b c)
  :name "Quadratic roots, wide range"
  :precision binary64
  :pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))