
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * 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
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * 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 tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * 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]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * 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
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * 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 tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * 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]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -5e+125)
(/ b (- a))
(if (<= b 6.5e-107)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(* c (fma -1.0 (* a (/ c (pow b 3.0))) (/ -1.0 b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+125) {
tmp = b / -a;
} else if (b <= 6.5e-107) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c * fma(-1.0, (a * (c / pow(b, 3.0))), (-1.0 / b));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5e+125) tmp = Float64(b / Float64(-a)); elseif (b <= 6.5e-107) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(c * fma(-1.0, Float64(a * Float64(c / (b ^ 3.0))), Float64(-1.0 / b))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5e+125], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 6.5e-107], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c * N[(-1.0 * N[(a * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+125}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{-107}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \mathsf{fma}\left(-1, a \cdot \frac{c}{{b}^{3}}, \frac{-1}{b}\right)\\
\end{array}
\end{array}
if b < -4.99999999999999962e125Initial program 51.9%
*-commutative51.9%
Simplified52.0%
Taylor expanded in b around -inf 97.2%
associate-*r/97.2%
mul-1-neg97.2%
Simplified97.2%
if -4.99999999999999962e125 < b < 6.5000000000000002e-107Initial program 82.1%
if 6.5000000000000002e-107 < b Initial program 11.9%
*-commutative11.9%
Simplified11.9%
Taylor expanded in c around 0 91.9%
fmm-def91.9%
associate-/l*94.3%
distribute-neg-frac94.3%
metadata-eval94.3%
Simplified94.3%
Final simplification90.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.5e+128)
(/ b (- a))
(if (<= b 7.5e-103)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.5e+128) {
tmp = b / -a;
} else if (b <= 7.5e-103) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.5d+128)) then
tmp = b / -a
else if (b <= 7.5d-103) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.5e+128) {
tmp = b / -a;
} else if (b <= 7.5e-103) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.5e+128: tmp = b / -a elif b <= 7.5e-103: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.5e+128) tmp = Float64(b / Float64(-a)); elseif (b <= 7.5e-103) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.5e+128) tmp = b / -a; elseif (b <= 7.5e-103) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.5e+128], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 7.5e-103], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.5 \cdot 10^{+128}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 7.5 \cdot 10^{-103}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.5e128Initial program 51.9%
*-commutative51.9%
Simplified52.0%
Taylor expanded in b around -inf 97.2%
associate-*r/97.2%
mul-1-neg97.2%
Simplified97.2%
if -2.5e128 < b < 7.5e-103Initial program 82.1%
if 7.5e-103 < b Initial program 11.9%
*-commutative11.9%
Simplified11.9%
Taylor expanded in a around 0 93.9%
associate-*r/93.9%
mul-1-neg93.9%
Simplified93.9%
Final simplification90.1%
(FPCore (a b c)
:precision binary64
(if (<= b -7.2e-81)
(- (/ c b) (/ b a))
(if (<= b 3.5e-107)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-81) {
tmp = (c / b) - (b / a);
} else if (b <= 3.5e-107) {
tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-7.2d-81)) then
tmp = (c / b) - (b / a)
else if (b <= 3.5d-107) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-81) {
tmp = (c / b) - (b / a);
} else if (b <= 3.5e-107) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.2e-81: tmp = (c / b) - (b / a) elif b <= 3.5e-107: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.2e-81) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.5e-107) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.2e-81) tmp = (c / b) - (b / a); elseif (b <= 3.5e-107) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.2e-81], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.5e-107], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{-81}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.5 \cdot 10^{-107}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -7.1999999999999997e-81Initial program 65.3%
*-commutative65.3%
Simplified65.4%
Taylor expanded in b around -inf 86.2%
mul-1-neg86.2%
distribute-rgt-neg-in86.2%
+-commutative86.2%
mul-1-neg86.2%
unsub-neg86.2%
Simplified86.2%
Taylor expanded in b around 0 52.8%
associate-*r/52.8%
neg-mul-152.8%
Simplified52.8%
Taylor expanded in c around 0 86.5%
mul-1-neg86.5%
distribute-frac-neg286.5%
+-commutative86.5%
distribute-frac-neg286.5%
unsub-neg86.5%
Simplified86.5%
if -7.1999999999999997e-81 < b < 3.49999999999999985e-107Initial program 78.5%
*-commutative78.5%
Simplified78.5%
Taylor expanded in a around inf 76.1%
associate-*r*76.1%
*-commutative76.1%
Simplified76.1%
if 3.49999999999999985e-107 < b Initial program 11.9%
*-commutative11.9%
Simplified11.9%
Taylor expanded in a around 0 93.9%
associate-*r/93.9%
mul-1-neg93.9%
Simplified93.9%
Final simplification86.5%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2d-310)) then
tmp = (c / b) - (b / a)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = (c / b) - (b / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 70.4%
*-commutative70.4%
Simplified70.5%
Taylor expanded in b around -inf 62.9%
mul-1-neg62.9%
distribute-rgt-neg-in62.9%
+-commutative62.9%
mul-1-neg62.9%
unsub-neg62.9%
Simplified62.9%
Taylor expanded in b around 0 39.5%
associate-*r/39.5%
neg-mul-139.5%
Simplified39.5%
Taylor expanded in c around 0 64.6%
mul-1-neg64.6%
distribute-frac-neg264.6%
+-commutative64.6%
distribute-frac-neg264.6%
unsub-neg64.6%
Simplified64.6%
if -1.999999999999994e-310 < b Initial program 21.4%
*-commutative21.4%
Simplified21.4%
Taylor expanded in a around 0 80.3%
associate-*r/80.3%
mul-1-neg80.3%
Simplified80.3%
Final simplification71.1%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2d-310)) then
tmp = b / -a
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 70.4%
*-commutative70.4%
Simplified70.5%
Taylor expanded in b around -inf 64.5%
associate-*r/64.5%
mul-1-neg64.5%
Simplified64.5%
if -1.999999999999994e-310 < b Initial program 21.4%
*-commutative21.4%
Simplified21.4%
Taylor expanded in a around 0 80.3%
associate-*r/80.3%
mul-1-neg80.3%
Simplified80.3%
Final simplification71.0%
(FPCore (a b c) :precision binary64 (if (<= b 3.6e-36) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.6e-36) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 3.6d-36) then
tmp = b / -a
else
tmp = c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 3.6e-36) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.6e-36: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.6e-36) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 3.6e-36) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.6e-36], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.6 \cdot 10^{-36}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 3.60000000000000032e-36Initial program 68.5%
*-commutative68.5%
Simplified68.6%
Taylor expanded in b around -inf 56.4%
associate-*r/56.4%
mul-1-neg56.4%
Simplified56.4%
if 3.60000000000000032e-36 < b Initial program 11.7%
*-commutative11.7%
Simplified11.7%
Taylor expanded in b around -inf 2.4%
mul-1-neg2.4%
distribute-rgt-neg-in2.4%
+-commutative2.4%
mul-1-neg2.4%
unsub-neg2.4%
Simplified2.4%
Taylor expanded in b around 0 27.0%
Final simplification47.0%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 50.3%
*-commutative50.3%
Simplified50.4%
Taylor expanded in b around -inf 38.1%
mul-1-neg38.1%
distribute-rgt-neg-in38.1%
+-commutative38.1%
mul-1-neg38.1%
unsub-neg38.1%
Simplified38.1%
Taylor expanded in b around 0 10.9%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / 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 / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 50.3%
*-commutative50.3%
Simplified50.4%
Applied egg-rr34.8%
unpow-134.8%
associate-/l*34.8%
Simplified34.8%
Taylor expanded in a around 0 2.1%
herbie shell --seed 2024191
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))