
(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
(let* ((t_0 (/ (- c) b)))
(if (<= b -7e+29)
t_0
(if (<= b -1.05e-79)
(*
-0.5
(/ (/ (* c (* a 4.0)) (- b (sqrt (fma c (* a -4.0) (* b b))))) a))
(if (<= b -1e-122)
t_0
(if (<= b 5e+99)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* a (* c 4.0))))) a))
(/ (- b) a)))))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double tmp;
if (b <= -7e+29) {
tmp = t_0;
} else if (b <= -1.05e-79) {
tmp = -0.5 * (((c * (a * 4.0)) / (b - sqrt(fma(c, (a * -4.0), (b * b))))) / a);
} else if (b <= -1e-122) {
tmp = t_0;
} else if (b <= 5e+99) {
tmp = -0.5 * ((b + sqrt(((b * b) - (a * (c * 4.0))))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(Float64(-c) / b) tmp = 0.0 if (b <= -7e+29) tmp = t_0; elseif (b <= -1.05e-79) tmp = Float64(-0.5 * Float64(Float64(Float64(c * Float64(a * 4.0)) / Float64(b - sqrt(fma(c, Float64(a * -4.0), Float64(b * b))))) / a)); elseif (b <= -1e-122) tmp = t_0; elseif (b <= 5e+99) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, If[LessEqual[b, -7e+29], t$95$0, If[LessEqual[b, -1.05e-79], N[(-0.5 * N[(N[(N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision] / N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1e-122], t$95$0, If[LessEqual[b, 5e+99], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
\mathbf{if}\;b \leq -7 \cdot 10^{+29}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -1.05 \cdot 10^{-79}:\\
\;\;\;\;-0.5 \cdot \frac{\frac{c \cdot \left(a \cdot 4\right)}{b - \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a}\\
\mathbf{elif}\;b \leq -1 \cdot 10^{-122}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+99}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -6.99999999999999958e29 or -1.05e-79 < b < -1.00000000000000006e-122Initial program 14.7%
Taylor expanded in b around -inf 94.3%
associate-*r/94.3%
neg-mul-194.3%
Simplified94.3%
if -6.99999999999999958e29 < b < -1.05e-79Initial program 37.4%
/-rgt-identity37.4%
metadata-eval37.4%
associate-/l*37.3%
associate-/r/37.3%
*-commutative37.3%
metadata-eval37.3%
metadata-eval37.3%
associate-*l/37.3%
associate-/r/37.3%
times-frac37.4%
*-commutative37.4%
times-frac37.4%
metadata-eval37.4%
associate-/r/37.4%
*-commutative37.4%
div-sub37.2%
Simplified37.4%
fma-udef37.4%
associate-*r*37.4%
metadata-eval37.4%
distribute-rgt-neg-in37.4%
*-commutative37.4%
+-commutative37.4%
sub-neg37.4%
*-commutative37.4%
associate-*l*37.4%
Applied egg-rr37.4%
flip-+37.0%
add-sqr-sqrt37.1%
Applied egg-rr37.1%
associate--r-83.8%
+-inverses83.8%
associate-*r*83.1%
*-commutative83.1%
associate-*l*83.8%
*-commutative83.8%
cancel-sign-sub-inv83.8%
distribute-rgt-neg-in83.8%
metadata-eval83.8%
*-commutative83.8%
associate-*r*83.8%
+-commutative83.8%
*-commutative83.8%
associate-*l*83.8%
fma-udef83.8%
Simplified83.8%
if -1.00000000000000006e-122 < b < 5.00000000000000008e99Initial program 79.7%
/-rgt-identity79.7%
metadata-eval79.7%
associate-/l*79.6%
associate-/r/79.6%
*-commutative79.6%
metadata-eval79.6%
metadata-eval79.6%
associate-*l/79.6%
associate-/r/79.6%
times-frac79.7%
*-commutative79.7%
times-frac79.7%
metadata-eval79.7%
associate-/r/79.7%
*-commutative79.7%
div-sub79.7%
Simplified79.7%
fma-udef79.7%
associate-*r*79.7%
metadata-eval79.7%
distribute-rgt-neg-in79.7%
*-commutative79.7%
+-commutative79.7%
sub-neg79.7%
*-commutative79.7%
associate-*l*79.7%
Applied egg-rr79.7%
if 5.00000000000000008e99 < b Initial program 58.2%
Taylor expanded in b around inf 95.7%
associate-*r/95.7%
mul-1-neg95.7%
Simplified95.7%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(if (<= b -9.5e-115)
(/ (- c) b)
(if (<= b 1.25e+97)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* a (* c 4.0))))) a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-115) {
tmp = -c / b;
} else if (b <= 1.25e+97) {
tmp = -0.5 * ((b + sqrt(((b * b) - (a * (c * 4.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 <= (-9.5d-115)) then
tmp = -c / b
else if (b <= 1.25d+97) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) - (a * (c * 4.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 <= -9.5e-115) {
tmp = -c / b;
} else if (b <= 1.25e+97) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) - (a * (c * 4.0))))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-115: tmp = -c / b elif b <= 1.25e+97: tmp = -0.5 * ((b + math.sqrt(((b * b) - (a * (c * 4.0))))) / a) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-115) tmp = Float64(Float64(-c) / b); elseif (b <= 1.25e+97) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.5e-115) tmp = -c / b; elseif (b <= 1.25e+97) tmp = -0.5 * ((b + sqrt(((b * b) - (a * (c * 4.0))))) / a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-115], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.25e+97], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{-115}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{+97}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -9.4999999999999996e-115Initial program 19.9%
Taylor expanded in b around -inf 85.8%
associate-*r/85.8%
neg-mul-185.8%
Simplified85.8%
if -9.4999999999999996e-115 < b < 1.25e97Initial program 79.7%
/-rgt-identity79.7%
metadata-eval79.7%
associate-/l*79.6%
associate-/r/79.6%
*-commutative79.6%
metadata-eval79.6%
metadata-eval79.6%
associate-*l/79.6%
associate-/r/79.6%
times-frac79.7%
*-commutative79.7%
times-frac79.7%
metadata-eval79.7%
associate-/r/79.7%
*-commutative79.7%
div-sub79.7%
Simplified79.7%
fma-udef79.7%
associate-*r*79.7%
metadata-eval79.7%
distribute-rgt-neg-in79.7%
*-commutative79.7%
+-commutative79.7%
sub-neg79.7%
*-commutative79.7%
associate-*l*79.7%
Applied egg-rr79.7%
if 1.25e97 < b Initial program 58.2%
Taylor expanded in b around inf 95.7%
associate-*r/95.7%
mul-1-neg95.7%
Simplified95.7%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(if (<= b -9.5e-119)
(/ (- c) b)
(if (<= b 1.36e-46)
(* -0.5 (* (+ b (sqrt (* c (* a -4.0)))) (/ 1.0 a)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-119) {
tmp = -c / b;
} else if (b <= 1.36e-46) {
tmp = -0.5 * ((b + sqrt((c * (a * -4.0)))) * (1.0 / a));
} 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 <= (-9.5d-119)) then
tmp = -c / b
else if (b <= 1.36d-46) then
tmp = (-0.5d0) * ((b + sqrt((c * (a * (-4.0d0))))) * (1.0d0 / a))
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 <= -9.5e-119) {
tmp = -c / b;
} else if (b <= 1.36e-46) {
tmp = -0.5 * ((b + Math.sqrt((c * (a * -4.0)))) * (1.0 / a));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-119: tmp = -c / b elif b <= 1.36e-46: tmp = -0.5 * ((b + math.sqrt((c * (a * -4.0)))) * (1.0 / a)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-119) tmp = Float64(Float64(-c) / b); elseif (b <= 1.36e-46) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) * Float64(1.0 / a))); 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 <= -9.5e-119) tmp = -c / b; elseif (b <= 1.36e-46) tmp = -0.5 * ((b + sqrt((c * (a * -4.0)))) * (1.0 / a)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-119], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.36e-46], N[(-0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{-119}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.36 \cdot 10^{-46}:\\
\;\;\;\;-0.5 \cdot \left(\left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{1}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.5000000000000002e-119Initial program 19.9%
Taylor expanded in b around -inf 85.8%
associate-*r/85.8%
neg-mul-185.8%
Simplified85.8%
if -9.5000000000000002e-119 < b < 1.3600000000000001e-46Initial program 74.9%
/-rgt-identity74.9%
metadata-eval74.9%
associate-/l*74.8%
associate-/r/74.9%
*-commutative74.9%
metadata-eval74.9%
metadata-eval74.9%
associate-*l/74.9%
associate-/r/74.9%
times-frac74.9%
*-commutative74.9%
times-frac74.9%
metadata-eval74.9%
associate-/r/74.9%
*-commutative74.9%
div-sub74.9%
Simplified74.9%
fma-udef74.9%
associate-*r*74.9%
metadata-eval74.9%
distribute-rgt-neg-in74.9%
*-commutative74.9%
+-commutative74.9%
sub-neg74.9%
*-commutative74.9%
associate-*l*74.9%
Applied egg-rr74.9%
div-inv75.0%
Applied egg-rr75.0%
Taylor expanded in b around 0 66.8%
*-commutative66.8%
associate-*l*66.9%
Simplified66.9%
if 1.3600000000000001e-46 < b Initial program 72.1%
Taylor expanded in b around inf 86.4%
mul-1-neg86.4%
unsub-neg86.4%
Simplified86.4%
Final simplification80.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.4e-114)
(/ (- c) b)
(if (<= b 1.05e-46)
(* -0.5 (/ (+ b (sqrt (* c (* a -4.0)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e-114) {
tmp = -c / b;
} else if (b <= 1.05e-46) {
tmp = -0.5 * ((b + sqrt((c * (a * -4.0)))) / a);
} 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 <= (-1.4d-114)) then
tmp = -c / b
else if (b <= 1.05d-46) then
tmp = (-0.5d0) * ((b + sqrt((c * (a * (-4.0d0))))) / a)
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 <= -1.4e-114) {
tmp = -c / b;
} else if (b <= 1.05e-46) {
tmp = -0.5 * ((b + Math.sqrt((c * (a * -4.0)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.4e-114: tmp = -c / b elif b <= 1.05e-46: tmp = -0.5 * ((b + math.sqrt((c * (a * -4.0)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.4e-114) tmp = Float64(Float64(-c) / b); elseif (b <= 1.05e-46) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / a)); 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 <= -1.4e-114) tmp = -c / b; elseif (b <= 1.05e-46) tmp = -0.5 * ((b + sqrt((c * (a * -4.0)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.4e-114], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.05e-46], N[(-0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4 \cdot 10^{-114}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{-46}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.4000000000000001e-114Initial program 19.9%
Taylor expanded in b around -inf 85.8%
associate-*r/85.8%
neg-mul-185.8%
Simplified85.8%
if -1.4000000000000001e-114 < b < 1.04999999999999994e-46Initial program 74.9%
/-rgt-identity74.9%
metadata-eval74.9%
associate-/l*74.8%
associate-/r/74.9%
*-commutative74.9%
metadata-eval74.9%
metadata-eval74.9%
associate-*l/74.9%
associate-/r/74.9%
times-frac74.9%
*-commutative74.9%
times-frac74.9%
metadata-eval74.9%
associate-/r/74.9%
*-commutative74.9%
div-sub74.9%
Simplified74.9%
Taylor expanded in a around inf 66.8%
*-commutative66.8%
associate-*r*66.9%
Simplified66.9%
if 1.04999999999999994e-46 < b Initial program 72.1%
Taylor expanded in b around inf 86.4%
mul-1-neg86.4%
unsub-neg86.4%
Simplified86.4%
Final simplification80.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 32.2%
Taylor expanded in b around -inf 68.1%
associate-*r/68.1%
neg-mul-168.1%
Simplified68.1%
if -9.999999999999969e-311 < b Initial program 73.2%
Taylor expanded in b around inf 62.8%
mul-1-neg62.8%
unsub-neg62.8%
Simplified62.8%
Final simplification65.6%
(FPCore (a b c) :precision binary64 (if (<= b -4e+56) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e+56) {
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 <= (-4d+56)) 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 <= -4e+56) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e+56: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e+56) tmp = 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 <= -4e+56) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e+56], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{+56}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.00000000000000037e56Initial program 14.2%
/-rgt-identity14.2%
metadata-eval14.2%
associate-/l*14.2%
associate-/r/14.2%
*-commutative14.2%
metadata-eval14.2%
metadata-eval14.2%
associate-*l/14.2%
associate-/r/14.2%
times-frac14.2%
*-commutative14.2%
times-frac14.2%
metadata-eval14.2%
associate-/r/14.2%
*-commutative14.2%
div-sub12.0%
Simplified14.2%
fma-udef14.2%
associate-*r*14.2%
metadata-eval14.2%
distribute-rgt-neg-in14.2%
*-commutative14.2%
+-commutative14.2%
sub-neg14.2%
*-commutative14.2%
associate-*l*14.2%
Applied egg-rr14.2%
Taylor expanded in b around inf 2.4%
associate-/l*2.5%
Simplified2.5%
Taylor expanded in b around 0 42.2%
if -4.00000000000000037e56 < b Initial program 64.7%
Taylor expanded in b around inf 40.7%
associate-*r/40.7%
mul-1-neg40.7%
Simplified40.7%
Final simplification41.1%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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 <= (-1d-310)) 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 <= -1e-310) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) 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 <= -1e-310) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 32.2%
Taylor expanded in b around -inf 68.1%
associate-*r/68.1%
neg-mul-168.1%
Simplified68.1%
if -9.999999999999969e-311 < b Initial program 73.2%
Taylor expanded in b around inf 62.5%
associate-*r/62.5%
mul-1-neg62.5%
Simplified62.5%
Final simplification65.5%
(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 51.3%
/-rgt-identity51.3%
metadata-eval51.3%
associate-/l*51.2%
associate-/r/51.2%
*-commutative51.2%
metadata-eval51.2%
metadata-eval51.2%
associate-*l/51.2%
associate-/r/51.2%
times-frac51.3%
*-commutative51.3%
times-frac51.3%
metadata-eval51.3%
associate-/r/51.3%
*-commutative51.3%
div-sub50.7%
Simplified51.3%
fma-udef51.3%
associate-*r*51.3%
metadata-eval51.3%
distribute-rgt-neg-in51.3%
*-commutative51.3%
+-commutative51.3%
sub-neg51.3%
*-commutative51.3%
associate-*l*51.3%
Applied egg-rr51.3%
Taylor expanded in b around inf 29.6%
associate-/l*30.3%
Simplified30.3%
Taylor expanded in b around 0 13.4%
Final simplification13.4%
(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 2023171
(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)))