
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -150000000.0)
(- (/ (- c) b) (* (pow (/ (pow (cbrt c) 2.0) b) 3.0) a))
(if (<= b 2e-90)
(* -0.5 (/ 1.0 (* a (/ 1.0 (+ b (hypot b (sqrt (* c (* a -4.0)))))))))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -150000000.0) {
tmp = (-c / b) - (pow((pow(cbrt(c), 2.0) / b), 3.0) * a);
} else if (b <= 2e-90) {
tmp = -0.5 * (1.0 / (a * (1.0 / (b + hypot(b, sqrt((c * (a * -4.0))))))));
} else {
tmp = -b / a;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -150000000.0) {
tmp = (-c / b) - (Math.pow((Math.pow(Math.cbrt(c), 2.0) / b), 3.0) * a);
} else if (b <= 2e-90) {
tmp = -0.5 * (1.0 / (a * (1.0 / (b + Math.hypot(b, Math.sqrt((c * (a * -4.0))))))));
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -150000000.0) tmp = Float64(Float64(Float64(-c) / b) - Float64((Float64((cbrt(c) ^ 2.0) / b) ^ 3.0) * a)); elseif (b <= 2e-90) tmp = Float64(-0.5 * Float64(1.0 / Float64(a * Float64(1.0 / Float64(b + hypot(b, sqrt(Float64(c * Float64(a * -4.0))))))))); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -150000000.0], N[(N[((-c) / b), $MachinePrecision] - N[(N[Power[N[(N[Power[N[Power[c, 1/3], $MachinePrecision], 2.0], $MachinePrecision] / b), $MachinePrecision], 3.0], $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2e-90], N[(-0.5 * N[(1.0 / N[(a * N[(1.0 / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -150000000:\\
\;\;\;\;\frac{-c}{b} - {\left(\frac{{\left(\sqrt[3]{c}\right)}^{2}}{b}\right)}^{3} \cdot a\\
\mathbf{elif}\;b \leq 2 \cdot 10^{-90}:\\
\;\;\;\;-0.5 \cdot \frac{1}{a \cdot \frac{1}{b + \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.5e8Initial program 13.9%
Taylor expanded in b around -inf 79.3%
+-commutative79.3%
mul-1-neg79.3%
unsub-neg79.3%
associate-*r/79.3%
neg-mul-179.3%
associate-/l*81.8%
unpow281.8%
Simplified81.8%
add-cube-cbrt81.8%
pow281.8%
cbrt-div81.8%
cbrt-prod81.8%
pow281.8%
cbrt-div81.8%
rem-cbrt-cube81.8%
cbrt-div81.8%
cbrt-prod94.0%
pow294.0%
cbrt-div94.0%
rem-cbrt-cube94.0%
Applied egg-rr94.0%
pow-plus94.0%
metadata-eval94.0%
associate-/r/94.0%
cube-prod94.1%
rem-cube-cbrt94.1%
Simplified94.1%
if -1.5e8 < b < 1.99999999999999999e-90Initial program 67.7%
/-rgt-identity67.7%
metadata-eval67.7%
associate-/l*67.6%
associate-/r/67.6%
*-commutative67.6%
metadata-eval67.6%
metadata-eval67.6%
associate-*l/67.6%
associate-/r/67.6%
times-frac67.7%
*-commutative67.7%
times-frac67.7%
metadata-eval67.7%
associate-/r/67.7%
*-commutative67.7%
div-sub67.7%
Simplified67.7%
clear-num67.6%
inv-pow67.6%
Applied egg-rr67.6%
unpow-167.6%
fma-udef67.6%
*-commutative67.6%
associate-*l*67.6%
+-commutative67.6%
fma-def67.6%
*-commutative67.6%
Simplified67.6%
div-inv67.6%
fma-udef67.6%
add-sqr-sqrt67.6%
hypot-def69.2%
Applied egg-rr69.2%
if 1.99999999999999999e-90 < b Initial program 59.1%
Taylor expanded in b around inf 88.9%
associate-*r/88.9%
mul-1-neg88.9%
Simplified88.9%
Final simplification83.6%
(FPCore (a b c)
:precision binary64
(if (<= b -64000.0)
(/ (- c) b)
(if (<= b 2.2e-90)
(* -0.5 (/ 1.0 (* a (/ 1.0 (+ b (hypot b (sqrt (* c (* a -4.0)))))))))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -64000.0) {
tmp = -c / b;
} else if (b <= 2.2e-90) {
tmp = -0.5 * (1.0 / (a * (1.0 / (b + hypot(b, sqrt((c * (a * -4.0))))))));
} else {
tmp = -b / a;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -64000.0) {
tmp = -c / b;
} else if (b <= 2.2e-90) {
tmp = -0.5 * (1.0 / (a * (1.0 / (b + Math.hypot(b, Math.sqrt((c * (a * -4.0))))))));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -64000.0: tmp = -c / b elif b <= 2.2e-90: tmp = -0.5 * (1.0 / (a * (1.0 / (b + math.hypot(b, math.sqrt((c * (a * -4.0)))))))) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -64000.0) tmp = Float64(Float64(-c) / b); elseif (b <= 2.2e-90) tmp = Float64(-0.5 * Float64(1.0 / Float64(a * Float64(1.0 / Float64(b + hypot(b, sqrt(Float64(c * Float64(a * -4.0))))))))); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -64000.0) tmp = -c / b; elseif (b <= 2.2e-90) tmp = -0.5 * (1.0 / (a * (1.0 / (b + hypot(b, sqrt((c * (a * -4.0)))))))); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -64000.0], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.2e-90], N[(-0.5 * N[(1.0 / N[(a * N[(1.0 / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -64000:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-90}:\\
\;\;\;\;-0.5 \cdot \frac{1}{a \cdot \frac{1}{b + \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -64000Initial program 13.8%
Taylor expanded in b around -inf 93.0%
associate-*r/93.0%
neg-mul-193.0%
Simplified93.0%
if -64000 < b < 2.19999999999999986e-90Initial program 68.4%
/-rgt-identity68.4%
metadata-eval68.4%
associate-/l*68.3%
associate-/r/68.3%
*-commutative68.3%
metadata-eval68.3%
metadata-eval68.3%
associate-*l/68.3%
associate-/r/68.3%
times-frac68.4%
*-commutative68.4%
times-frac68.4%
metadata-eval68.4%
associate-/r/68.4%
*-commutative68.4%
div-sub68.5%
Simplified68.4%
clear-num68.3%
inv-pow68.4%
Applied egg-rr68.4%
unpow-168.3%
fma-udef68.3%
*-commutative68.3%
associate-*l*68.3%
+-commutative68.3%
fma-def68.3%
*-commutative68.3%
Simplified68.3%
div-inv68.3%
fma-udef68.3%
add-sqr-sqrt68.3%
hypot-def70.0%
Applied egg-rr70.0%
if 2.19999999999999986e-90 < b Initial program 59.1%
Taylor expanded in b around inf 88.9%
associate-*r/88.9%
mul-1-neg88.9%
Simplified88.9%
Final simplification83.6%
(FPCore (a b c)
:precision binary64
(if (<= b -440000.0)
(/ (- c) b)
(if (<= b 4e-40)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* 2.0 a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -440000.0) {
tmp = -c / b;
} else if (b <= 4e-40) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (2.0 * a);
} else {
tmp = -b / 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) :: tmp
if (b <= (-440000.0d0)) then
tmp = -c / b
else if (b <= 4d-40) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (2.0d0 * a)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -440000.0) {
tmp = -c / b;
} else if (b <= 4e-40) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (2.0 * a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -440000.0: tmp = -c / b elif b <= 4e-40: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (2.0 * a) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -440000.0) tmp = Float64(Float64(-c) / b); elseif (b <= 4e-40) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(2.0 * a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -440000.0) tmp = -c / b; elseif (b <= 4e-40) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (2.0 * a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -440000.0], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4e-40], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -440000:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-40}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.4e5Initial program 13.8%
Taylor expanded in b around -inf 93.0%
associate-*r/93.0%
neg-mul-193.0%
Simplified93.0%
if -4.4e5 < b < 3.9999999999999997e-40Initial program 71.6%
if 3.9999999999999997e-40 < b Initial program 53.6%
Taylor expanded in b around inf 88.7%
associate-*r/88.7%
mul-1-neg88.7%
Simplified88.7%
Final simplification83.5%
(FPCore (a b c)
:precision binary64
(if (<= b -85000.0)
(/ (- c) b)
(if (<= b 5.2e-96)
(- (/ (+ b (sqrt (* -4.0 (* c a)))) (* 2.0 a)))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -85000.0) {
tmp = -c / b;
} else if (b <= 5.2e-96) {
tmp = -((b + sqrt((-4.0 * (c * a)))) / (2.0 * a));
} else {
tmp = -b / 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) :: tmp
if (b <= (-85000.0d0)) then
tmp = -c / b
else if (b <= 5.2d-96) then
tmp = -((b + sqrt(((-4.0d0) * (c * a)))) / (2.0d0 * a))
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -85000.0) {
tmp = -c / b;
} else if (b <= 5.2e-96) {
tmp = -((b + Math.sqrt((-4.0 * (c * a)))) / (2.0 * a));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -85000.0: tmp = -c / b elif b <= 5.2e-96: tmp = -((b + math.sqrt((-4.0 * (c * a)))) / (2.0 * a)) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -85000.0) tmp = Float64(Float64(-c) / b); elseif (b <= 5.2e-96) tmp = Float64(-Float64(Float64(b + sqrt(Float64(-4.0 * Float64(c * a)))) / Float64(2.0 * a))); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -85000.0) tmp = -c / b; elseif (b <= 5.2e-96) tmp = -((b + sqrt((-4.0 * (c * a)))) / (2.0 * a)); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -85000.0], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.2e-96], (-N[(N[(b + N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -85000:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{-96}:\\
\;\;\;\;-\frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -85000Initial program 13.8%
Taylor expanded in b around -inf 93.0%
associate-*r/93.0%
neg-mul-193.0%
Simplified93.0%
if -85000 < b < 5.2000000000000003e-96Initial program 68.4%
Taylor expanded in b around 0 65.4%
*-commutative65.4%
Simplified65.4%
if 5.2000000000000003e-96 < b Initial program 59.1%
Taylor expanded in b around inf 88.9%
associate-*r/88.9%
mul-1-neg88.9%
Simplified88.9%
Final simplification82.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (* -0.5 (/ 1.0 (+ (* 0.5 (/ b c)) (* -0.5 (/ a b))))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -0.5 * (1.0 / ((0.5 * (b / c)) + (-0.5 * (a / b))));
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-5d-310)) then
tmp = (-0.5d0) * (1.0d0 / ((0.5d0 * (b / c)) + ((-0.5d0) * (a / b))))
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -0.5 * (1.0 / ((0.5 * (b / c)) + (-0.5 * (a / b))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -0.5 * (1.0 / ((0.5 * (b / c)) + (-0.5 * (a / b)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(-0.5 * Float64(1.0 / Float64(Float64(0.5 * Float64(b / c)) + Float64(-0.5 * Float64(a / b))))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -0.5 * (1.0 / ((0.5 * (b / c)) + (-0.5 * (a / b)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(-0.5 * N[(1.0 / N[(N[(0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;-0.5 \cdot \frac{1}{0.5 \cdot \frac{b}{c} + -0.5 \cdot \frac{a}{b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 36.7%
/-rgt-identity36.7%
metadata-eval36.7%
associate-/l*36.6%
associate-/r/36.7%
*-commutative36.7%
metadata-eval36.7%
metadata-eval36.7%
associate-*l/36.7%
associate-/r/36.7%
times-frac36.7%
*-commutative36.7%
times-frac36.7%
metadata-eval36.7%
associate-/r/36.7%
*-commutative36.7%
div-sub36.4%
Simplified36.7%
clear-num36.7%
inv-pow36.7%
Applied egg-rr36.7%
unpow-136.7%
fma-udef36.7%
*-commutative36.7%
associate-*l*36.7%
+-commutative36.7%
fma-def36.7%
*-commutative36.7%
Simplified36.7%
Taylor expanded in b around -inf 64.7%
if -4.999999999999985e-310 < b Initial program 61.7%
Taylor expanded in b around inf 71.1%
mul-1-neg71.1%
unsub-neg71.1%
Simplified71.1%
Final simplification67.5%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-5d-310)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 36.7%
Taylor expanded in b around -inf 64.6%
associate-*r/64.6%
neg-mul-164.6%
Simplified64.6%
if -4.999999999999985e-310 < b Initial program 61.7%
Taylor expanded in b around inf 71.1%
mul-1-neg71.1%
unsub-neg71.1%
Simplified71.1%
Final simplification67.5%
(FPCore (a b c) :precision binary64 (if (<= b -5.4e-305) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.4e-305) {
tmp = -c / b;
} else {
tmp = -b / 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) :: tmp
if (b <= (-5.4d-305)) then
tmp = -c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.4e-305) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.4e-305: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.4e-305) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.4e-305) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.4e-305], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.4 \cdot 10^{-305}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -5.3999999999999998e-305Initial program 36.3%
Taylor expanded in b around -inf 65.1%
associate-*r/65.1%
neg-mul-165.1%
Simplified65.1%
if -5.3999999999999998e-305 < b Initial program 62.0%
Taylor expanded in b around inf 70.5%
associate-*r/70.5%
mul-1-neg70.5%
Simplified70.5%
Final simplification67.5%
(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(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 47.8%
Taylor expanded in b around inf 33.1%
associate-*r/33.1%
mul-1-neg33.1%
Simplified33.1%
Final simplification33.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = 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 = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2023178
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))