
(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 9 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 -15500000.0)
(- (/ c b) (/ b a))
(if (<= b 4e-77)
(* (/ -0.5 a) (- b (hypot b (sqrt (* (* c a) -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -15500000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 4e-77) {
tmp = (-0.5 / a) * (b - hypot(b, sqrt(((c * a) * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -15500000.0) {
tmp = (c / b) - (b / a);
} else if (b <= 4e-77) {
tmp = (-0.5 / a) * (b - Math.hypot(b, Math.sqrt(((c * a) * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -15500000.0: tmp = (c / b) - (b / a) elif b <= 4e-77: tmp = (-0.5 / a) * (b - math.hypot(b, math.sqrt(((c * a) * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -15500000.0) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4e-77) tmp = Float64(Float64(-0.5 / a) * Float64(b - hypot(b, sqrt(Float64(Float64(c * a) * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -15500000.0) tmp = (c / b) - (b / a); elseif (b <= 4e-77) tmp = (-0.5 / a) * (b - hypot(b, sqrt(((c * a) * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -15500000.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4e-77], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[b ^ 2 + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -15500000:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-77}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \mathsf{hypot}\left(b, \sqrt{\left(c \cdot a\right) \cdot -4}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.55e7Initial program 67.0%
neg-sub067.0%
associate-+l-67.0%
sub0-neg67.0%
neg-mul-167.0%
associate-*l/67.0%
*-commutative67.0%
associate-/r*67.0%
/-rgt-identity67.0%
metadata-eval67.0%
Simplified67.1%
Taylor expanded in b around -inf 97.9%
mul-1-neg97.9%
unsub-neg97.9%
Simplified97.9%
if -1.55e7 < b < 3.9999999999999997e-77Initial program 75.7%
neg-sub075.7%
associate-+l-75.7%
sub0-neg75.7%
neg-mul-175.7%
associate-*l/75.5%
*-commutative75.5%
associate-/r*75.6%
/-rgt-identity75.6%
metadata-eval75.6%
Simplified75.6%
fma-udef75.6%
*-commutative75.6%
associate-*r*75.6%
metadata-eval75.6%
distribute-rgt-neg-in75.6%
*-commutative75.6%
distribute-lft-neg-in75.6%
+-commutative75.6%
sub-neg75.6%
add-cbrt-cube60.3%
pow360.4%
pow1/357.0%
Applied egg-rr56.9%
unpow1/360.4%
fma-def60.4%
+-commutative60.4%
fma-def60.4%
Simplified60.4%
expm1-log1p-u38.8%
expm1-udef19.7%
*-commutative19.7%
pow1/319.6%
pow-pow27.4%
metadata-eval27.4%
pow1/227.4%
fma-udef27.4%
add-sqr-sqrt27.4%
hypot-def28.2%
Applied egg-rr28.2%
expm1-def52.8%
expm1-log1p78.1%
associate-*r*78.0%
*-commutative78.0%
Simplified78.0%
if 3.9999999999999997e-77 < b Initial program 17.5%
neg-sub017.5%
associate-+l-17.5%
sub0-neg17.5%
neg-mul-117.5%
associate-*l/17.5%
*-commutative17.5%
associate-/r*17.5%
/-rgt-identity17.5%
metadata-eval17.5%
Simplified17.5%
Taylor expanded in b around inf 87.3%
mul-1-neg87.3%
distribute-neg-frac87.3%
Simplified87.3%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(if (<= b -2.2e+150)
(- (/ c b) (/ b a))
(if (<= b 4e-77)
(* (/ -0.5 a) (- b (sqrt (+ (* b b) (* a (* c -4.0))))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.2e+150) {
tmp = (c / b) - (b / a);
} else if (b <= 4e-77) {
tmp = (-0.5 / a) * (b - sqrt(((b * b) + (a * (c * -4.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.2d+150)) then
tmp = (c / b) - (b / a)
else if (b <= 4d-77) then
tmp = ((-0.5d0) / a) * (b - sqrt(((b * b) + (a * (c * (-4.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.2e+150) {
tmp = (c / b) - (b / a);
} else if (b <= 4e-77) {
tmp = (-0.5 / a) * (b - Math.sqrt(((b * b) + (a * (c * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.2e+150: tmp = (c / b) - (b / a) elif b <= 4e-77: tmp = (-0.5 / a) * (b - math.sqrt(((b * b) + (a * (c * -4.0))))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.2e+150) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4e-77) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.2e+150) tmp = (c / b) - (b / a); elseif (b <= 4e-77) tmp = (-0.5 / a) * (b - sqrt(((b * b) + (a * (c * -4.0))))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.2e+150], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4e-77], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.2 \cdot 10^{+150}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-77}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.19999999999999999e150Initial program 34.1%
neg-sub034.1%
associate-+l-34.1%
sub0-neg34.1%
neg-mul-134.1%
associate-*l/34.1%
*-commutative34.1%
associate-/r*34.1%
/-rgt-identity34.1%
metadata-eval34.1%
Simplified34.4%
Taylor expanded in b around -inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
if -2.19999999999999999e150 < b < 3.9999999999999997e-77Initial program 82.9%
neg-sub082.9%
associate-+l-82.9%
sub0-neg82.9%
neg-mul-182.9%
associate-*l/82.8%
*-commutative82.8%
associate-/r*82.8%
/-rgt-identity82.8%
metadata-eval82.8%
Simplified82.8%
fma-udef82.8%
*-commutative82.8%
associate-*r*82.8%
metadata-eval82.8%
distribute-rgt-neg-in82.8%
*-commutative82.8%
distribute-lft-neg-in82.8%
+-commutative82.8%
sub-neg82.8%
add-cbrt-cube64.0%
pow364.0%
pow1/360.5%
Applied egg-rr60.5%
unpow1/364.0%
fma-def64.0%
+-commutative64.0%
fma-def64.0%
Simplified64.0%
pow1/360.5%
pow-pow82.8%
metadata-eval82.8%
pow1/282.8%
add-exp-log78.0%
fma-udef78.0%
add-sqr-sqrt66.1%
hypot-def68.3%
Applied egg-rr68.3%
add-exp-log72.6%
hypot-udef70.2%
add-sqr-sqrt82.8%
Applied egg-rr82.8%
if 3.9999999999999997e-77 < b Initial program 17.5%
neg-sub017.5%
associate-+l-17.5%
sub0-neg17.5%
neg-mul-117.5%
associate-*l/17.5%
*-commutative17.5%
associate-/r*17.5%
/-rgt-identity17.5%
metadata-eval17.5%
Simplified17.5%
Taylor expanded in b around inf 87.3%
mul-1-neg87.3%
distribute-neg-frac87.3%
Simplified87.3%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1e+155)
(- (/ c b) (/ b a))
(if (<= b 3.2e-77)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+155) {
tmp = (c / b) - (b / a);
} else if (b <= 3.2e-77) {
tmp = (sqrt(((b * b) - (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 <= (-1d+155)) then
tmp = (c / b) - (b / a)
else if (b <= 3.2d-77) then
tmp = (sqrt(((b * b) - (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 <= -1e+155) {
tmp = (c / b) - (b / a);
} else if (b <= 3.2e-77) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+155: tmp = (c / b) - (b / a) elif b <= 3.2e-77: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+155) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.2e-77) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e+155) tmp = (c / b) - (b / a); elseif (b <= 3.2e-77) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+155], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.2e-77], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $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 -1 \cdot 10^{+155}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.2 \cdot 10^{-77}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.00000000000000001e155Initial program 34.1%
neg-sub034.1%
associate-+l-34.1%
sub0-neg34.1%
neg-mul-134.1%
associate-*l/34.1%
*-commutative34.1%
associate-/r*34.1%
/-rgt-identity34.1%
metadata-eval34.1%
Simplified34.4%
Taylor expanded in b around -inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
if -1.00000000000000001e155 < b < 3.2e-77Initial program 82.9%
if 3.2e-77 < b Initial program 17.5%
neg-sub017.5%
associate-+l-17.5%
sub0-neg17.5%
neg-mul-117.5%
associate-*l/17.5%
*-commutative17.5%
associate-/r*17.5%
/-rgt-identity17.5%
metadata-eval17.5%
Simplified17.5%
Taylor expanded in b around inf 87.3%
mul-1-neg87.3%
distribute-neg-frac87.3%
Simplified87.3%
Final simplification87.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.66e-195)
(- (/ c b) (/ b a))
(if (<= b 5.8e-78)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.66e-195) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-78) {
tmp = (sqrt((a * (c * -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 <= (-1.66d-195)) then
tmp = (c / b) - (b / a)
else if (b <= 5.8d-78) then
tmp = (sqrt((a * (c * (-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 <= -1.66e-195) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-78) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.66e-195: tmp = (c / b) - (b / a) elif b <= 5.8e-78: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.66e-195) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.8e-78) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.66e-195) tmp = (c / b) - (b / a); elseif (b <= 5.8e-78) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.66e-195], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.8e-78], N[(N[(N[Sqrt[N[(a * N[(c * -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 -1.66 \cdot 10^{-195}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{-78}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.66e-195Initial program 71.7%
neg-sub071.7%
associate-+l-71.7%
sub0-neg71.7%
neg-mul-171.7%
associate-*l/71.5%
*-commutative71.5%
associate-/r*71.6%
/-rgt-identity71.6%
metadata-eval71.6%
Simplified71.7%
Taylor expanded in b around -inf 85.2%
mul-1-neg85.2%
unsub-neg85.2%
Simplified85.2%
if -1.66e-195 < b < 5.8000000000000001e-78Initial program 71.0%
Taylor expanded in b around 0 69.3%
*-commutative69.3%
*-commutative69.3%
associate-*r*69.4%
Simplified69.4%
if 5.8000000000000001e-78 < b Initial program 17.5%
neg-sub017.5%
associate-+l-17.5%
sub0-neg17.5%
neg-mul-117.5%
associate-*l/17.5%
*-commutative17.5%
associate-/r*17.5%
/-rgt-identity17.5%
metadata-eval17.5%
Simplified17.5%
Taylor expanded in b around inf 87.3%
mul-1-neg87.3%
distribute-neg-frac87.3%
Simplified87.3%
Final simplification82.5%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 72.1%
neg-sub072.1%
associate-+l-72.1%
sub0-neg72.1%
neg-mul-172.1%
associate-*l/72.0%
*-commutative72.0%
associate-/r*72.0%
/-rgt-identity72.0%
metadata-eval72.0%
Simplified72.1%
Taylor expanded in b around -inf 71.0%
mul-1-neg71.0%
unsub-neg71.0%
Simplified71.0%
if -3.999999999999988e-310 < b Initial program 30.5%
neg-sub030.5%
associate-+l-30.5%
sub0-neg30.5%
neg-mul-130.5%
associate-*l/30.5%
*-commutative30.5%
associate-/r*30.5%
/-rgt-identity30.5%
metadata-eval30.5%
Simplified30.5%
Taylor expanded in b around inf 71.6%
mul-1-neg71.6%
distribute-neg-frac71.6%
Simplified71.6%
Final simplification71.3%
(FPCore (a b c) :precision binary64 (if (<= b 7.2e-84) (/ (- b) a) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.2e-84) {
tmp = -b / a;
} else {
tmp = 0.0;
}
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-84) then
tmp = -b / a
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 7.2e-84) {
tmp = -b / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.2e-84: tmp = -b / a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.2e-84) tmp = Float64(Float64(-b) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 7.2e-84) tmp = -b / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.2e-84], N[((-b) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.2 \cdot 10^{-84}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < 7.20000000000000007e-84Initial program 71.0%
neg-sub071.0%
associate-+l-71.0%
sub0-neg71.0%
neg-mul-171.0%
associate-*l/70.9%
*-commutative70.9%
associate-/r*70.9%
/-rgt-identity70.9%
metadata-eval70.9%
Simplified71.0%
Taylor expanded in b around -inf 60.9%
associate-*r/60.9%
mul-1-neg60.9%
Simplified60.9%
if 7.20000000000000007e-84 < b Initial program 20.5%
neg-sub020.5%
associate-+l-20.5%
sub0-neg20.5%
neg-mul-120.5%
associate-*l/20.5%
*-commutative20.5%
associate-/r*20.5%
/-rgt-identity20.5%
metadata-eval20.5%
Simplified20.5%
*-commutative20.5%
sub-neg20.5%
distribute-lft-in17.5%
Applied egg-rr17.5%
Taylor expanded in c around 0 18.3%
distribute-rgt-out18.3%
metadata-eval18.3%
mul0-rgt26.4%
Simplified26.4%
Final simplification49.6%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 72.1%
neg-sub072.1%
associate-+l-72.1%
sub0-neg72.1%
neg-mul-172.1%
associate-*l/72.0%
*-commutative72.0%
associate-/r*72.0%
/-rgt-identity72.0%
metadata-eval72.0%
Simplified72.1%
Taylor expanded in b around -inf 70.6%
associate-*r/70.6%
mul-1-neg70.6%
Simplified70.6%
if -3.999999999999988e-310 < b Initial program 30.5%
neg-sub030.5%
associate-+l-30.5%
sub0-neg30.5%
neg-mul-130.5%
associate-*l/30.5%
*-commutative30.5%
associate-/r*30.5%
/-rgt-identity30.5%
metadata-eval30.5%
Simplified30.5%
Taylor expanded in b around inf 71.6%
mul-1-neg71.6%
distribute-neg-frac71.6%
Simplified71.6%
Final simplification71.1%
(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 54.4%
neg-sub054.4%
associate-+l-54.4%
sub0-neg54.4%
neg-mul-154.4%
associate-*l/54.3%
*-commutative54.3%
associate-/r*54.4%
/-rgt-identity54.4%
metadata-eval54.4%
Simplified54.4%
Taylor expanded in b around -inf 41.7%
mul-1-neg41.7%
unsub-neg41.7%
Simplified41.7%
Taylor expanded in c around inf 10.7%
Final simplification10.7%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 54.4%
neg-sub054.4%
associate-+l-54.4%
sub0-neg54.4%
neg-mul-154.4%
associate-*l/54.3%
*-commutative54.3%
associate-/r*54.4%
/-rgt-identity54.4%
metadata-eval54.4%
Simplified54.4%
*-commutative54.4%
sub-neg54.4%
distribute-lft-in53.5%
Applied egg-rr53.5%
Taylor expanded in c around 0 7.8%
distribute-rgt-out7.8%
metadata-eval7.8%
mul0-rgt10.6%
Simplified10.6%
Final simplification10.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- b) t_0) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b < 0.0d0) then
tmp = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-b - t_0) / (2.0d0 * a)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b < 0.0: tmp = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b < 0.0) tmp = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-b - t_0) / (2.0 * a))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023213
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))