
(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 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(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 -1.1e-95)
(/ (- c) b)
(if (<= b 9e+129)
(/ (- (- b) (sqrt (- (* b b) (* c (* 4.0 a))))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e-95) {
tmp = -c / b;
} else if (b <= 9e+129) {
tmp = (-b - sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.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 <= (-1.1d-95)) then
tmp = -c / b
else if (b <= 9d+129) then
tmp = (-b - sqrt(((b * b) - (c * (4.0d0 * a))))) / (a * 2.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 <= -1.1e-95) {
tmp = -c / b;
} else if (b <= 9e+129) {
tmp = (-b - Math.sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.1e-95: tmp = -c / b elif b <= 9e+129: tmp = (-b - math.sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.1e-95) tmp = Float64(Float64(-c) / b); elseif (b <= 9e+129) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.1e-95) tmp = -c / b; elseif (b <= 9e+129) tmp = (-b - sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.1e-95], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 9e+129], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{-95}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 9 \cdot 10^{+129}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.0999999999999999e-95Initial program 10.2%
*-commutative10.2%
sqr-neg10.2%
*-commutative10.2%
sqr-neg10.2%
associate-*r*10.2%
*-commutative10.2%
Simplified10.2%
Taylor expanded in b around -inf 91.8%
associate-*r/91.8%
neg-mul-191.8%
Simplified91.8%
if -1.0999999999999999e-95 < b < 9.0000000000000003e129Initial program 81.1%
*-commutative81.1%
sqr-neg81.1%
*-commutative81.1%
sqr-neg81.1%
associate-*r*81.1%
*-commutative81.1%
Simplified81.1%
if 9.0000000000000003e129 < b Initial program 44.7%
*-commutative44.7%
sqr-neg44.7%
*-commutative44.7%
sqr-neg44.7%
associate-*r*44.7%
*-commutative44.7%
Simplified44.7%
Taylor expanded in b around inf 95.6%
associate-*r/95.6%
mul-1-neg95.6%
Simplified95.6%
Final simplification87.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (- b) (sqrt (* c (* a -4.0)))) (* a 2.0))))
(if (<= b -2.1e-94)
(/ (- c) b)
(if (<= b 1.6e-94)
t_0
(if (<= b 2.65e-79)
(- (/ b a))
(if (<= b 3.1e+38) t_0 (- (/ c b) (/ b a))))))))
double code(double a, double b, double c) {
double t_0 = (-b - sqrt((c * (a * -4.0)))) / (a * 2.0);
double tmp;
if (b <= -2.1e-94) {
tmp = -c / b;
} else if (b <= 1.6e-94) {
tmp = t_0;
} else if (b <= 2.65e-79) {
tmp = -(b / a);
} else if (b <= 3.1e+38) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (-b - sqrt((c * (a * (-4.0d0))))) / (a * 2.0d0)
if (b <= (-2.1d-94)) then
tmp = -c / b
else if (b <= 1.6d-94) then
tmp = t_0
else if (b <= 2.65d-79) then
tmp = -(b / a)
else if (b <= 3.1d+38) then
tmp = t_0
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (-b - Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
double tmp;
if (b <= -2.1e-94) {
tmp = -c / b;
} else if (b <= 1.6e-94) {
tmp = t_0;
} else if (b <= 2.65e-79) {
tmp = -(b / a);
} else if (b <= 3.1e+38) {
tmp = t_0;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): t_0 = (-b - math.sqrt((c * (a * -4.0)))) / (a * 2.0) tmp = 0 if b <= -2.1e-94: tmp = -c / b elif b <= 1.6e-94: tmp = t_0 elif b <= 2.65e-79: tmp = -(b / a) elif b <= 3.1e+38: tmp = t_0 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) t_0 = Float64(Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -4.0)))) / Float64(a * 2.0)) tmp = 0.0 if (b <= -2.1e-94) tmp = Float64(Float64(-c) / b); elseif (b <= 1.6e-94) tmp = t_0; elseif (b <= 2.65e-79) tmp = Float64(-Float64(b / a)); elseif (b <= 3.1e+38) tmp = t_0; else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (-b - sqrt((c * (a * -4.0)))) / (a * 2.0); tmp = 0.0; if (b <= -2.1e-94) tmp = -c / b; elseif (b <= 1.6e-94) tmp = t_0; elseif (b <= 2.65e-79) tmp = -(b / a); elseif (b <= 3.1e+38) tmp = t_0; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[((-b) - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.1e-94], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.6e-94], t$95$0, If[LessEqual[b, 2.65e-79], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 3.1e+38], t$95$0, N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{if}\;b \leq -2.1 \cdot 10^{-94}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{-94}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 2.65 \cdot 10^{-79}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 3.1 \cdot 10^{+38}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.1000000000000001e-94Initial program 10.2%
*-commutative10.2%
sqr-neg10.2%
*-commutative10.2%
sqr-neg10.2%
associate-*r*10.2%
*-commutative10.2%
Simplified10.2%
Taylor expanded in b around -inf 91.8%
associate-*r/91.8%
neg-mul-191.8%
Simplified91.8%
if -2.1000000000000001e-94 < b < 1.59999999999999998e-94 or 2.6499999999999999e-79 < b < 3.10000000000000018e38Initial program 77.2%
*-commutative77.2%
sqr-neg77.2%
*-commutative77.2%
sqr-neg77.2%
associate-*r*77.3%
*-commutative77.3%
Simplified77.3%
Taylor expanded in b around 0 66.2%
*-commutative66.2%
*-commutative66.2%
associate-*r*66.2%
Simplified66.2%
if 1.59999999999999998e-94 < b < 2.6499999999999999e-79Initial program 100.0%
*-commutative100.0%
sqr-neg100.0%
*-commutative100.0%
sqr-neg100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if 3.10000000000000018e38 < b Initial program 59.4%
*-commutative59.4%
sqr-neg59.4%
*-commutative59.4%
sqr-neg59.4%
associate-*r*59.4%
*-commutative59.4%
Simplified59.4%
Taylor expanded in b around inf 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
Simplified91.1%
Final simplification83.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.1e-94)
(/ (- c) b)
(if (<= b 1.2e+130)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-94) {
tmp = -c / b;
} else if (b <= 1.2e+130) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.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 <= (-2.1d-94)) then
tmp = -c / b
else if (b <= 1.2d+130) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.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 <= -2.1e-94) {
tmp = -c / b;
} else if (b <= 1.2e+130) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-94: tmp = -c / b elif b <= 1.2e+130: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-94) tmp = Float64(Float64(-c) / b); elseif (b <= 1.2e+130) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.1e-94) tmp = -c / b; elseif (b <= 1.2e+130) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-94], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.2e+130], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.1 \cdot 10^{-94}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{+130}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.1000000000000001e-94Initial program 10.2%
*-commutative10.2%
sqr-neg10.2%
*-commutative10.2%
sqr-neg10.2%
associate-*r*10.2%
*-commutative10.2%
Simplified10.2%
Taylor expanded in b around -inf 91.8%
associate-*r/91.8%
neg-mul-191.8%
Simplified91.8%
if -2.1000000000000001e-94 < b < 1.20000000000000012e130Initial program 81.1%
if 1.20000000000000012e130 < b Initial program 44.7%
*-commutative44.7%
sqr-neg44.7%
*-commutative44.7%
sqr-neg44.7%
associate-*r*44.7%
*-commutative44.7%
Simplified44.7%
Taylor expanded in b around inf 95.6%
associate-*r/95.6%
mul-1-neg95.6%
Simplified95.6%
Final simplification87.8%
(FPCore (a b c)
:precision binary64
(if (<= b -3.4e-94)
(/ (- c) b)
(if (<= b 2.2e-94)
(* (/ 0.5 a) (- b (sqrt (* a (* c -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.4e-94) {
tmp = -c / b;
} else if (b <= 2.2e-94) {
tmp = (0.5 / a) * (b - sqrt((a * (c * -4.0))));
} 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 <= (-3.4d-94)) then
tmp = -c / b
else if (b <= 2.2d-94) then
tmp = (0.5d0 / a) * (b - sqrt((a * (c * (-4.0d0)))))
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 <= -3.4e-94) {
tmp = -c / b;
} else if (b <= 2.2e-94) {
tmp = (0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.4e-94: tmp = -c / b elif b <= 2.2e-94: tmp = (0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.4e-94) tmp = Float64(Float64(-c) / b); elseif (b <= 2.2e-94) tmp = Float64(Float64(0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); 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 <= -3.4e-94) tmp = -c / b; elseif (b <= 2.2e-94) tmp = (0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.4e-94], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.2e-94], N[(N[(0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $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 -3.4 \cdot 10^{-94}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-94}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.3999999999999998e-94Initial program 10.2%
*-commutative10.2%
sqr-neg10.2%
*-commutative10.2%
sqr-neg10.2%
associate-*r*10.2%
*-commutative10.2%
Simplified10.2%
Taylor expanded in b around -inf 91.8%
associate-*r/91.8%
neg-mul-191.8%
Simplified91.8%
if -3.3999999999999998e-94 < b < 2.20000000000000001e-94Initial program 76.0%
*-commutative76.0%
sqr-neg76.0%
*-commutative76.0%
sqr-neg76.0%
associate-*r*76.1%
*-commutative76.1%
Simplified76.1%
Taylor expanded in b around 0 73.2%
*-commutative73.2%
*-commutative73.2%
associate-*r*73.2%
Simplified73.2%
div-sub73.2%
add-sqr-sqrt33.0%
sqrt-unprod72.3%
sqr-neg72.3%
sqrt-prod39.3%
add-sqr-sqrt72.2%
Applied egg-rr72.2%
div-sub72.2%
*-lft-identity72.2%
associate-*l/72.2%
*-commutative72.2%
associate-/r*72.2%
metadata-eval72.2%
associate-*r*72.1%
*-commutative72.1%
associate-*l*72.2%
Simplified72.2%
if 2.20000000000000001e-94 < b Initial program 67.7%
*-commutative67.7%
sqr-neg67.7%
*-commutative67.7%
sqr-neg67.7%
associate-*r*67.7%
*-commutative67.7%
Simplified67.7%
Taylor expanded in b around inf 74.7%
+-commutative74.7%
mul-1-neg74.7%
unsub-neg74.7%
Simplified74.7%
Final simplification80.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.25e-94)
(/ (- c) b)
(if (<= b 1e-94)
(/ (- b (sqrt (* c (* a -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.25e-94) {
tmp = -c / b;
} else if (b <= 1e-94) {
tmp = (b - sqrt((c * (a * -4.0)))) / (a * 2.0);
} 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.25d-94)) then
tmp = -c / b
else if (b <= 1d-94) then
tmp = (b - sqrt((c * (a * (-4.0d0))))) / (a * 2.0d0)
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.25e-94) {
tmp = -c / b;
} else if (b <= 1e-94) {
tmp = (b - Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.25e-94: tmp = -c / b elif b <= 1e-94: tmp = (b - math.sqrt((c * (a * -4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.25e-94) tmp = Float64(Float64(-c) / b); elseif (b <= 1e-94) tmp = Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) / Float64(a * 2.0)); 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.25e-94) tmp = -c / b; elseif (b <= 1e-94) tmp = (b - sqrt((c * (a * -4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.25e-94], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1e-94], N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.25 \cdot 10^{-94}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 10^{-94}:\\
\;\;\;\;\frac{b - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.2499999999999999e-94Initial program 10.2%
*-commutative10.2%
sqr-neg10.2%
*-commutative10.2%
sqr-neg10.2%
associate-*r*10.2%
*-commutative10.2%
Simplified10.2%
Taylor expanded in b around -inf 91.8%
associate-*r/91.8%
neg-mul-191.8%
Simplified91.8%
if -1.2499999999999999e-94 < b < 9.9999999999999996e-95Initial program 76.0%
*-commutative76.0%
sqr-neg76.0%
*-commutative76.0%
sqr-neg76.0%
associate-*r*76.1%
*-commutative76.1%
Simplified76.1%
Taylor expanded in b around 0 73.2%
*-commutative73.2%
*-commutative73.2%
associate-*r*73.2%
Simplified73.2%
div-sub73.2%
add-sqr-sqrt33.0%
sqrt-unprod72.3%
sqr-neg72.3%
sqrt-prod39.3%
add-sqr-sqrt72.2%
Applied egg-rr72.2%
div-sub72.2%
Simplified72.2%
if 9.9999999999999996e-95 < b Initial program 67.7%
*-commutative67.7%
sqr-neg67.7%
*-commutative67.7%
sqr-neg67.7%
associate-*r*67.7%
*-commutative67.7%
Simplified67.7%
Taylor expanded in b around inf 74.7%
+-commutative74.7%
mul-1-neg74.7%
unsub-neg74.7%
Simplified74.7%
Final simplification80.9%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 23.3%
*-commutative23.3%
sqr-neg23.3%
*-commutative23.3%
sqr-neg23.3%
associate-*r*23.4%
*-commutative23.4%
Simplified23.4%
Taylor expanded in b around -inf 76.4%
associate-*r/76.4%
neg-mul-176.4%
Simplified76.4%
if -1.999999999999994e-310 < b Initial program 70.1%
*-commutative70.1%
sqr-neg70.1%
*-commutative70.1%
sqr-neg70.1%
associate-*r*70.1%
*-commutative70.1%
Simplified70.1%
Taylor expanded in b around inf 58.5%
+-commutative58.5%
mul-1-neg58.5%
unsub-neg58.5%
Simplified58.5%
Final simplification67.5%
(FPCore (a b c) :precision binary64 (if (<= b -2.6e-34) (/ c b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-34) {
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 <= (-2.6d-34)) 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 <= -2.6e-34) {
tmp = c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.6e-34: tmp = c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.6e-34) 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 <= -2.6e-34) tmp = c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.6e-34], N[(c / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.6 \cdot 10^{-34}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -2.5999999999999999e-34Initial program 7.6%
*-commutative7.6%
sqr-neg7.6%
*-commutative7.6%
sqr-neg7.6%
associate-*r*7.6%
*-commutative7.6%
Simplified7.6%
Taylor expanded in b around inf 2.3%
Taylor expanded in b around 0 18.8%
if -2.5999999999999999e-34 < b Initial program 69.8%
*-commutative69.8%
sqr-neg69.8%
*-commutative69.8%
sqr-neg69.8%
associate-*r*69.8%
*-commutative69.8%
Simplified69.8%
Taylor expanded in b around inf 46.7%
associate-*r/46.7%
mul-1-neg46.7%
Simplified46.7%
Final simplification36.4%
(FPCore (a b c) :precision binary64 (if (<= b -6.8e-262) (/ (- c) b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.8e-262) {
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 <= (-6.8d-262)) 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 <= -6.8e-262) {
tmp = -c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.8e-262: tmp = -c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.8e-262) 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 <= -6.8e-262) tmp = -c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.8e-262], N[((-c) / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.8 \cdot 10^{-262}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -6.7999999999999998e-262Initial program 22.9%
*-commutative22.9%
sqr-neg22.9%
*-commutative22.9%
sqr-neg22.9%
associate-*r*22.9%
*-commutative22.9%
Simplified22.9%
Taylor expanded in b around -inf 77.6%
associate-*r/77.6%
neg-mul-177.6%
Simplified77.6%
if -6.7999999999999998e-262 < b Initial program 69.8%
*-commutative69.8%
sqr-neg69.8%
*-commutative69.8%
sqr-neg69.8%
associate-*r*69.8%
*-commutative69.8%
Simplified69.8%
Taylor expanded in b around inf 57.2%
associate-*r/57.2%
mul-1-neg57.2%
Simplified57.2%
Final simplification67.2%
(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 46.7%
*-commutative46.7%
sqr-neg46.7%
*-commutative46.7%
sqr-neg46.7%
associate-*r*46.7%
*-commutative46.7%
Simplified46.7%
Taylor expanded in b around inf 29.1%
Taylor expanded in b around 0 9.2%
Final simplification9.2%
(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 2023279
(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)))