
(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 11 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 (* a (* c -4.0))))
(if (<= b -3.5e+43)
(/ (- c) b)
(if (<= b -2.75e-304)
(* -0.5 (/ (* c 4.0) (- b (sqrt (fma b b t_0)))))
(if (<= b 4.2e+114)
(* -0.5 (+ (/ b a) (/ (sqrt (+ t_0 (* b b))) a)))
(/ (- b) a))))))
double code(double a, double b, double c) {
double t_0 = a * (c * -4.0);
double tmp;
if (b <= -3.5e+43) {
tmp = -c / b;
} else if (b <= -2.75e-304) {
tmp = -0.5 * ((c * 4.0) / (b - sqrt(fma(b, b, t_0))));
} else if (b <= 4.2e+114) {
tmp = -0.5 * ((b / a) + (sqrt((t_0 + (b * b))) / a));
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(a * Float64(c * -4.0)) tmp = 0.0 if (b <= -3.5e+43) tmp = Float64(Float64(-c) / b); elseif (b <= -2.75e-304) tmp = Float64(-0.5 * Float64(Float64(c * 4.0) / Float64(b - sqrt(fma(b, b, t_0))))); elseif (b <= 4.2e+114) tmp = Float64(-0.5 * Float64(Float64(b / a) + Float64(sqrt(Float64(t_0 + Float64(b * b))) / a))); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -3.5e+43], N[((-c) / b), $MachinePrecision], If[LessEqual[b, -2.75e-304], N[(-0.5 * N[(N[(c * 4.0), $MachinePrecision] / N[(b - N[Sqrt[N[(b * b + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.2e+114], N[(-0.5 * N[(N[(b / a), $MachinePrecision] + N[(N[Sqrt[N[(t$95$0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(c \cdot -4\right)\\
\mathbf{if}\;b \leq -3.5 \cdot 10^{+43}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq -2.75 \cdot 10^{-304}:\\
\;\;\;\;-0.5 \cdot \frac{c \cdot 4}{b - \sqrt{\mathsf{fma}\left(b, b, t_0\right)}}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{+114}:\\
\;\;\;\;-0.5 \cdot \left(\frac{b}{a} + \frac{\sqrt{t_0 + b \cdot b}}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.5000000000000001e43Initial program 4.2%
Taylor expanded in b around -inf 95.3%
associate-*r/95.3%
neg-mul-195.3%
Simplified95.3%
if -3.5000000000000001e43 < b < -2.75000000000000017e-304Initial program 57.7%
Simplified57.7%
fma-udef57.7%
associate-*r*57.7%
metadata-eval57.7%
distribute-rgt-neg-in57.7%
*-commutative57.7%
+-commutative57.7%
sub-neg57.7%
*-commutative57.7%
associate-*l*57.7%
Applied egg-rr57.7%
div-inv57.6%
Applied egg-rr57.6%
*-commutative57.6%
flip-+57.2%
add-sqr-sqrt57.1%
frac-times46.1%
Applied egg-rr63.6%
times-frac83.9%
*-inverses83.9%
*-lft-identity83.9%
Simplified83.9%
if -2.75000000000000017e-304 < b < 4.2000000000000001e114Initial program 90.4%
Simplified90.4%
fma-udef90.4%
associate-*r*90.4%
metadata-eval90.4%
distribute-rgt-neg-in90.4%
*-commutative90.4%
+-commutative90.4%
sub-neg90.4%
*-commutative90.4%
associate-*l*90.4%
Applied egg-rr90.4%
div-inv90.2%
Applied egg-rr90.2%
*-commutative90.2%
distribute-rgt-in90.3%
div-inv90.3%
fma-neg90.3%
distribute-rgt-neg-in90.3%
distribute-rgt-neg-in90.3%
metadata-eval90.3%
Applied egg-rr90.3%
associate-*r/90.4%
*-rgt-identity90.4%
Simplified90.4%
fma-udef90.4%
Applied egg-rr90.4%
if 4.2000000000000001e114 < b Initial program 61.9%
Taylor expanded in b around inf 94.4%
associate-*r/94.4%
mul-1-neg94.4%
Simplified94.4%
Final simplification90.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* (* c 4.0) a)))
(if (<= b -1e-26)
(/ (- c) b)
(if (<= b -9.6e-100)
(* -0.5 (/ (/ t_0 (- b (sqrt (- (* b b) t_0)))) a))
(if (<= b 8.5e+114)
(* -0.5 (+ (/ b a) (/ (sqrt (+ (* a (* c -4.0)) (* b b))) a)))
(/ (- b) a))))))
double code(double a, double b, double c) {
double t_0 = (c * 4.0) * a;
double tmp;
if (b <= -1e-26) {
tmp = -c / b;
} else if (b <= -9.6e-100) {
tmp = -0.5 * ((t_0 / (b - sqrt(((b * b) - t_0)))) / a);
} else if (b <= 8.5e+114) {
tmp = -0.5 * ((b / a) + (sqrt(((a * (c * -4.0)) + (b * b))) / 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) :: t_0
real(8) :: tmp
t_0 = (c * 4.0d0) * a
if (b <= (-1d-26)) then
tmp = -c / b
else if (b <= (-9.6d-100)) then
tmp = (-0.5d0) * ((t_0 / (b - sqrt(((b * b) - t_0)))) / a)
else if (b <= 8.5d+114) then
tmp = (-0.5d0) * ((b / a) + (sqrt(((a * (c * (-4.0d0))) + (b * b))) / a))
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (c * 4.0) * a;
double tmp;
if (b <= -1e-26) {
tmp = -c / b;
} else if (b <= -9.6e-100) {
tmp = -0.5 * ((t_0 / (b - Math.sqrt(((b * b) - t_0)))) / a);
} else if (b <= 8.5e+114) {
tmp = -0.5 * ((b / a) + (Math.sqrt(((a * (c * -4.0)) + (b * b))) / a));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): t_0 = (c * 4.0) * a tmp = 0 if b <= -1e-26: tmp = -c / b elif b <= -9.6e-100: tmp = -0.5 * ((t_0 / (b - math.sqrt(((b * b) - t_0)))) / a) elif b <= 8.5e+114: tmp = -0.5 * ((b / a) + (math.sqrt(((a * (c * -4.0)) + (b * b))) / a)) else: tmp = -b / a return tmp
function code(a, b, c) t_0 = Float64(Float64(c * 4.0) * a) tmp = 0.0 if (b <= -1e-26) tmp = Float64(Float64(-c) / b); elseif (b <= -9.6e-100) tmp = Float64(-0.5 * Float64(Float64(t_0 / Float64(b - sqrt(Float64(Float64(b * b) - t_0)))) / a)); elseif (b <= 8.5e+114) tmp = Float64(-0.5 * Float64(Float64(b / a) + Float64(sqrt(Float64(Float64(a * Float64(c * -4.0)) + Float64(b * b))) / a))); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (c * 4.0) * a; tmp = 0.0; if (b <= -1e-26) tmp = -c / b; elseif (b <= -9.6e-100) tmp = -0.5 * ((t_0 / (b - sqrt(((b * b) - t_0)))) / a); elseif (b <= 8.5e+114) tmp = -0.5 * ((b / a) + (sqrt(((a * (c * -4.0)) + (b * b))) / a)); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]}, If[LessEqual[b, -1e-26], N[((-c) / b), $MachinePrecision], If[LessEqual[b, -9.6e-100], N[(-0.5 * N[(N[(t$95$0 / N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8.5e+114], N[(-0.5 * N[(N[(b / a), $MachinePrecision] + N[(N[Sqrt[N[(N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(c \cdot 4\right) \cdot a\\
\mathbf{if}\;b \leq -1 \cdot 10^{-26}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq -9.6 \cdot 10^{-100}:\\
\;\;\;\;-0.5 \cdot \frac{\frac{t_0}{b - \sqrt{b \cdot b - t_0}}}{a}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{+114}:\\
\;\;\;\;-0.5 \cdot \left(\frac{b}{a} + \frac{\sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b}}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1e-26Initial program 7.1%
Taylor expanded in b around -inf 92.1%
associate-*r/92.1%
neg-mul-192.1%
Simplified92.1%
if -1e-26 < b < -9.600000000000001e-100Initial program 45.9%
Simplified45.9%
fma-udef45.9%
associate-*r*45.9%
metadata-eval45.9%
distribute-rgt-neg-in45.9%
*-commutative45.9%
+-commutative45.9%
sub-neg45.9%
*-commutative45.9%
associate-*l*45.9%
Applied egg-rr45.9%
flip-+45.1%
add-sqr-sqrt45.1%
Applied egg-rr45.1%
add-log-exp2.9%
associate--r-2.9%
exp-sum2.9%
+-inverses2.9%
1-exp2.9%
*-un-lft-identity2.9%
add-log-exp75.0%
*-commutative75.0%
Applied egg-rr75.0%
if -9.600000000000001e-100 < b < 8.5000000000000001e114Initial program 87.1%
Simplified87.1%
fma-udef87.1%
associate-*r*87.1%
metadata-eval87.1%
distribute-rgt-neg-in87.1%
*-commutative87.1%
+-commutative87.1%
sub-neg87.1%
*-commutative87.1%
associate-*l*87.1%
Applied egg-rr87.1%
div-inv86.9%
Applied egg-rr86.9%
*-commutative86.9%
distribute-rgt-in87.0%
div-inv87.0%
fma-neg87.0%
distribute-rgt-neg-in87.0%
distribute-rgt-neg-in87.0%
metadata-eval87.0%
Applied egg-rr87.0%
associate-*r/87.1%
*-rgt-identity87.1%
Simplified87.1%
fma-udef87.1%
Applied egg-rr87.1%
if 8.5000000000000001e114 < b Initial program 61.9%
Taylor expanded in b around inf 94.4%
associate-*r/94.4%
mul-1-neg94.4%
Simplified94.4%
Final simplification89.2%
(FPCore (a b c)
:precision binary64
(if (<= b -7.8e-63)
(/ (- c) b)
(if (<= b 9.5e+113)
(* -0.5 (+ (/ b a) (/ (sqrt (+ (* a (* c -4.0)) (* b b))) a)))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.8e-63) {
tmp = -c / b;
} else if (b <= 9.5e+113) {
tmp = -0.5 * ((b / a) + (sqrt(((a * (c * -4.0)) + (b * b))) / 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 <= (-7.8d-63)) then
tmp = -c / b
else if (b <= 9.5d+113) then
tmp = (-0.5d0) * ((b / a) + (sqrt(((a * (c * (-4.0d0))) + (b * b))) / 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 <= -7.8e-63) {
tmp = -c / b;
} else if (b <= 9.5e+113) {
tmp = -0.5 * ((b / a) + (Math.sqrt(((a * (c * -4.0)) + (b * b))) / a));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.8e-63: tmp = -c / b elif b <= 9.5e+113: tmp = -0.5 * ((b / a) + (math.sqrt(((a * (c * -4.0)) + (b * b))) / a)) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.8e-63) tmp = Float64(Float64(-c) / b); elseif (b <= 9.5e+113) tmp = Float64(-0.5 * Float64(Float64(b / a) + Float64(sqrt(Float64(Float64(a * Float64(c * -4.0)) + Float64(b * b))) / a))); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.8e-63) tmp = -c / b; elseif (b <= 9.5e+113) tmp = -0.5 * ((b / a) + (sqrt(((a * (c * -4.0)) + (b * b))) / a)); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.8e-63], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 9.5e+113], N[(-0.5 * N[(N[(b / a), $MachinePrecision] + N[(N[Sqrt[N[(N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.8 \cdot 10^{-63}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{+113}:\\
\;\;\;\;-0.5 \cdot \left(\frac{b}{a} + \frac{\sqrt{a \cdot \left(c \cdot -4\right) + b \cdot b}}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -7.80000000000000044e-63Initial program 11.5%
Taylor expanded in b around -inf 87.2%
associate-*r/87.2%
neg-mul-187.2%
Simplified87.2%
if -7.80000000000000044e-63 < b < 9.5000000000000001e113Initial program 84.7%
Simplified84.7%
fma-udef84.7%
associate-*r*84.7%
metadata-eval84.7%
distribute-rgt-neg-in84.7%
*-commutative84.7%
+-commutative84.7%
sub-neg84.7%
*-commutative84.7%
associate-*l*84.7%
Applied egg-rr84.7%
div-inv84.6%
Applied egg-rr84.6%
*-commutative84.6%
distribute-rgt-in84.6%
div-inv84.6%
fma-neg84.6%
distribute-rgt-neg-in84.6%
distribute-rgt-neg-in84.6%
metadata-eval84.6%
Applied egg-rr84.6%
associate-*r/84.8%
*-rgt-identity84.8%
Simplified84.8%
fma-udef84.8%
Applied egg-rr84.8%
if 9.5000000000000001e113 < b Initial program 61.9%
Taylor expanded in b around inf 94.4%
associate-*r/94.4%
mul-1-neg94.4%
Simplified94.4%
Final simplification87.4%
(FPCore (a b c)
:precision binary64
(if (<= b -9.2e-62)
(/ (- c) b)
(if (<= b 2e+114)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* (* c 4.0) a)))) a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.2e-62) {
tmp = -c / b;
} else if (b <= 2e+114) {
tmp = -0.5 * ((b + sqrt(((b * b) - ((c * 4.0) * a)))) / 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.2d-62)) then
tmp = -c / b
else if (b <= 2d+114) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) - ((c * 4.0d0) * a)))) / 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.2e-62) {
tmp = -c / b;
} else if (b <= 2e+114) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) - ((c * 4.0) * a)))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.2e-62: tmp = -c / b elif b <= 2e+114: tmp = -0.5 * ((b + math.sqrt(((b * b) - ((c * 4.0) * a)))) / a) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.2e-62) tmp = Float64(Float64(-c) / b); elseif (b <= 2e+114) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.2e-62) tmp = -c / b; elseif (b <= 2e+114) tmp = -0.5 * ((b + sqrt(((b * b) - ((c * 4.0) * a)))) / a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.2e-62], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2e+114], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.2 \cdot 10^{-62}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+114}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -9.20000000000000002e-62Initial program 11.5%
Taylor expanded in b around -inf 87.2%
associate-*r/87.2%
neg-mul-187.2%
Simplified87.2%
if -9.20000000000000002e-62 < b < 2e114Initial program 84.7%
Simplified84.7%
fma-udef84.7%
associate-*r*84.7%
metadata-eval84.7%
distribute-rgt-neg-in84.7%
*-commutative84.7%
+-commutative84.7%
sub-neg84.7%
*-commutative84.7%
associate-*l*84.7%
Applied egg-rr84.7%
if 2e114 < b Initial program 61.9%
Taylor expanded in b around inf 94.4%
associate-*r/94.4%
mul-1-neg94.4%
Simplified94.4%
Final simplification87.4%
(FPCore (a b c)
:precision binary64
(if (<= b -4.4e-70)
(/ (- c) b)
(if (<= b 2.25e-130)
(* -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 <= -4.4e-70) {
tmp = -c / b;
} else if (b <= 2.25e-130) {
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 <= (-4.4d-70)) then
tmp = -c / b
else if (b <= 2.25d-130) 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 <= -4.4e-70) {
tmp = -c / b;
} else if (b <= 2.25e-130) {
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 <= -4.4e-70: tmp = -c / b elif b <= 2.25e-130: 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 <= -4.4e-70) tmp = Float64(Float64(-c) / b); elseif (b <= 2.25e-130) 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 <= -4.4e-70) tmp = -c / b; elseif (b <= 2.25e-130) 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, -4.4e-70], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.25e-130], 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 -4.4 \cdot 10^{-70}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.25 \cdot 10^{-130}:\\
\;\;\;\;-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 < -4.3999999999999998e-70Initial program 12.3%
Taylor expanded in b around -inf 85.3%
associate-*r/85.3%
neg-mul-185.3%
Simplified85.3%
if -4.3999999999999998e-70 < b < 2.25e-130Initial program 77.9%
Simplified77.9%
Taylor expanded in a around inf 76.5%
*-commutative76.5%
associate-*r*76.5%
Simplified76.5%
if 2.25e-130 < b Initial program 79.6%
Taylor expanded in b around inf 84.8%
mul-1-neg84.8%
unsub-neg84.8%
Simplified84.8%
Final simplification82.9%
(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 31.9%
Taylor expanded in b around -inf 63.1%
associate-*r/63.1%
neg-mul-163.1%
Simplified63.1%
if -4.999999999999985e-310 < b Initial program 79.7%
Taylor expanded in b around inf 70.9%
mul-1-neg70.9%
unsub-neg70.9%
Simplified70.9%
Final simplification67.2%
(FPCore (a b c) :precision binary64 (if (<= b -7.5e-292) 0.0 (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-292) {
tmp = 0.0;
} 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 <= (-7.5d-292)) then
tmp = 0.0d0
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-292) {
tmp = 0.0;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.5e-292: tmp = 0.0 else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.5e-292) tmp = 0.0; else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.5e-292) tmp = 0.0; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.5e-292], 0.0, N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.5 \cdot 10^{-292}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -7.5000000000000002e-292Initial program 31.0%
Simplified31.0%
Taylor expanded in a around 0 4.1%
unpow24.1%
Simplified4.1%
Taylor expanded in b around -inf 12.6%
if -7.5000000000000002e-292 < b Initial program 79.4%
Taylor expanded in b around inf 69.3%
associate-*r/69.3%
mul-1-neg69.3%
Simplified69.3%
Final simplification43.2%
(FPCore (a b c) :precision binary64 (if (<= b -9e-292) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-292) {
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 <= (-9d-292)) 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 <= -9e-292) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-292: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-292) 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 <= -9e-292) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-292], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-292}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -8.99999999999999913e-292Initial program 31.0%
Taylor expanded in b around -inf 64.6%
associate-*r/64.6%
neg-mul-164.6%
Simplified64.6%
if -8.99999999999999913e-292 < b Initial program 79.4%
Taylor expanded in b around inf 69.3%
associate-*r/69.3%
mul-1-neg69.3%
Simplified69.3%
Final simplification67.1%
(FPCore (a b c) :precision binary64 -1.0)
double code(double a, double b, double c) {
return -1.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -1.0d0
end function
public static double code(double a, double b, double c) {
return -1.0;
}
def code(a, b, c): return -1.0
function code(a, b, c) return -1.0 end
function tmp = code(a, b, c) tmp = -1.0; end
code[a_, b_, c_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 57.1%
Simplified57.1%
Taylor expanded in a around 0 32.3%
unpow232.3%
Simplified32.3%
Taylor expanded in b around -inf 7.3%
Simplified3.3%
Final simplification3.3%
(FPCore (a b c) :precision binary64 -0.5)
double code(double a, double b, double c) {
return -0.5;
}
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
end function
public static double code(double a, double b, double c) {
return -0.5;
}
def code(a, b, c): return -0.5
function code(a, b, c) return -0.5 end
function tmp = code(a, b, c) tmp = -0.5; end
code[a_, b_, c_] := -0.5
\begin{array}{l}
\\
-0.5
\end{array}
Initial program 57.1%
Simplified57.1%
fma-udef57.1%
associate-*r*57.1%
metadata-eval57.1%
distribute-rgt-neg-in57.1%
*-commutative57.1%
+-commutative57.1%
sub-neg57.1%
*-commutative57.1%
associate-*l*57.1%
Applied egg-rr57.1%
div-inv57.0%
Applied egg-rr57.0%
Taylor expanded in b around inf 38.6%
expm1-log1p-u24.4%
expm1-udef21.5%
Applied egg-rr0.0%
Simplified3.3%
Final simplification3.3%
(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 57.1%
Simplified57.1%
Taylor expanded in a around 0 32.3%
unpow232.3%
Simplified32.3%
Taylor expanded in b around -inf 7.3%
Final simplification7.3%
(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 2023257
(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)))