
(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 10 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 -7e-70)
(/ c (- b))
(if (<= b 6.5e+52)
(/ (+ b (sqrt (- (* b b) (* (* c 4.0) a)))) (* a (- 2.0)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-70) {
tmp = c / -b;
} else if (b <= 6.5e+52) {
tmp = (b + sqrt(((b * b) - ((c * 4.0) * a)))) / (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 <= (-7d-70)) then
tmp = c / -b
else if (b <= 6.5d+52) then
tmp = (b + sqrt(((b * b) - ((c * 4.0d0) * a)))) / (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 <= -7e-70) {
tmp = c / -b;
} else if (b <= 6.5e+52) {
tmp = (b + Math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-70: tmp = c / -b elif b <= 6.5e+52: tmp = (b + math.sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7e-70) tmp = Float64(c / Float64(-b)); elseif (b <= 6.5e+52) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * Float64(-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 <= -7e-70) tmp = c / -b; elseif (b <= 6.5e+52) tmp = (b + sqrt(((b * b) - ((c * 4.0) * a)))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e-70], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6.5e+52], N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $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 -7 \cdot 10^{-70}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{+52}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.99999999999999949e-70Initial program 18.3%
div-sub16.7%
sub-neg16.7%
neg-mul-116.7%
*-commutative16.7%
associate-/l*15.4%
distribute-neg-frac15.4%
neg-mul-115.4%
*-commutative15.4%
associate-/l*16.5%
distribute-rgt-out18.3%
associate-/r*18.3%
metadata-eval18.3%
sub-neg18.3%
+-commutative18.3%
Simplified18.4%
Taylor expanded in b around -inf 84.7%
mul-1-neg84.7%
distribute-neg-frac284.7%
Simplified84.7%
if -6.99999999999999949e-70 < b < 6.49999999999999996e52Initial program 79.0%
*-commutative79.0%
*-commutative79.0%
sqr-neg79.0%
*-commutative79.0%
sqr-neg79.0%
*-commutative79.0%
associate-*r*79.1%
Simplified79.1%
if 6.49999999999999996e52 < b Initial program 72.6%
div-sub72.6%
sub-neg72.6%
neg-mul-172.6%
*-commutative72.6%
associate-/l*72.5%
distribute-neg-frac72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.5%
distribute-rgt-out72.5%
associate-/r*72.5%
metadata-eval72.5%
sub-neg72.5%
+-commutative72.5%
Simplified72.5%
Taylor expanded in c around 0 98.2%
+-commutative98.2%
mul-1-neg98.2%
unsub-neg98.2%
Simplified98.2%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1e-69)
(/ c (- b))
(if (<= b 6.5e+52)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-69) {
tmp = c / -b;
} else if (b <= 6.5e+52) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (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 <= (-1d-69)) then
tmp = c / -b
else if (b <= 6.5d+52) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (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 <= -1e-69) {
tmp = c / -b;
} else if (b <= 6.5e+52) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-69: tmp = c / -b elif b <= 6.5e+52: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-69) tmp = Float64(c / Float64(-b)); elseif (b <= 6.5e+52) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / 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 <= -1e-69) tmp = c / -b; elseif (b <= 6.5e+52) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-69], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6.5e+52], 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[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-69}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{+52}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.9999999999999996e-70Initial program 18.3%
div-sub16.7%
sub-neg16.7%
neg-mul-116.7%
*-commutative16.7%
associate-/l*15.4%
distribute-neg-frac15.4%
neg-mul-115.4%
*-commutative15.4%
associate-/l*16.5%
distribute-rgt-out18.3%
associate-/r*18.3%
metadata-eval18.3%
sub-neg18.3%
+-commutative18.3%
Simplified18.4%
Taylor expanded in b around -inf 84.7%
mul-1-neg84.7%
distribute-neg-frac284.7%
Simplified84.7%
if -9.9999999999999996e-70 < b < 6.49999999999999996e52Initial program 79.0%
if 6.49999999999999996e52 < b Initial program 72.6%
div-sub72.6%
sub-neg72.6%
neg-mul-172.6%
*-commutative72.6%
associate-/l*72.5%
distribute-neg-frac72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.5%
distribute-rgt-out72.5%
associate-/r*72.5%
metadata-eval72.5%
sub-neg72.5%
+-commutative72.5%
Simplified72.5%
Taylor expanded in c around 0 98.2%
+-commutative98.2%
mul-1-neg98.2%
unsub-neg98.2%
Simplified98.2%
Final simplification84.9%
(FPCore (a b c)
:precision binary64
(if (<= b -5.4e-70)
(/ c (- b))
(if (<= b 1.15e-122)
(- (/ (* b -0.5) a) (* (sqrt (* a (* c -4.0))) (/ 0.5 a)))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.4e-70) {
tmp = c / -b;
} else if (b <= 1.15e-122) {
tmp = ((b * -0.5) / a) - (sqrt((a * (c * -4.0))) * (0.5 / 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 <= (-5.4d-70)) then
tmp = c / -b
else if (b <= 1.15d-122) then
tmp = ((b * (-0.5d0)) / a) - (sqrt((a * (c * (-4.0d0)))) * (0.5d0 / 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 <= -5.4e-70) {
tmp = c / -b;
} else if (b <= 1.15e-122) {
tmp = ((b * -0.5) / a) - (Math.sqrt((a * (c * -4.0))) * (0.5 / a));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.4e-70: tmp = c / -b elif b <= 1.15e-122: tmp = ((b * -0.5) / a) - (math.sqrt((a * (c * -4.0))) * (0.5 / a)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.4e-70) tmp = Float64(c / Float64(-b)); elseif (b <= 1.15e-122) tmp = Float64(Float64(Float64(b * -0.5) / a) - Float64(sqrt(Float64(a * Float64(c * -4.0))) * Float64(0.5 / 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 <= -5.4e-70) tmp = c / -b; elseif (b <= 1.15e-122) tmp = ((b * -0.5) / a) - (sqrt((a * (c * -4.0))) * (0.5 / a)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.4e-70], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.15e-122], N[(N[(N[(b * -0.5), $MachinePrecision] / a), $MachinePrecision] - N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.4 \cdot 10^{-70}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-122}:\\
\;\;\;\;\frac{b \cdot -0.5}{a} - \sqrt{a \cdot \left(c \cdot -4\right)} \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.4000000000000003e-70Initial program 18.3%
div-sub16.7%
sub-neg16.7%
neg-mul-116.7%
*-commutative16.7%
associate-/l*15.4%
distribute-neg-frac15.4%
neg-mul-115.4%
*-commutative15.4%
associate-/l*16.5%
distribute-rgt-out18.3%
associate-/r*18.3%
metadata-eval18.3%
sub-neg18.3%
+-commutative18.3%
Simplified18.4%
Taylor expanded in b around -inf 84.7%
mul-1-neg84.7%
distribute-neg-frac284.7%
Simplified84.7%
if -5.4000000000000003e-70 < b < 1.15000000000000003e-122Initial program 69.1%
div-sub69.1%
sub-neg69.1%
neg-mul-169.1%
*-commutative69.1%
associate-/l*69.1%
distribute-neg-frac69.1%
neg-mul-169.1%
*-commutative69.1%
associate-/l*69.0%
distribute-rgt-out69.0%
associate-/r*69.0%
metadata-eval69.0%
sub-neg69.0%
+-commutative69.0%
Simplified69.0%
Applied egg-rr69.1%
Taylor expanded in a around inf 65.5%
*-commutative65.5%
associate-*r*65.6%
Simplified65.6%
if 1.15000000000000003e-122 < b Initial program 83.4%
div-sub83.4%
sub-neg83.4%
neg-mul-183.4%
*-commutative83.4%
associate-/l*83.3%
distribute-neg-frac83.3%
neg-mul-183.3%
*-commutative83.3%
associate-/l*83.2%
distribute-rgt-out83.2%
associate-/r*83.2%
metadata-eval83.2%
sub-neg83.2%
+-commutative83.2%
Simplified83.2%
Taylor expanded in c around 0 84.1%
+-commutative84.1%
mul-1-neg84.1%
unsub-neg84.1%
Simplified84.1%
Final simplification79.0%
(FPCore (a b c)
:precision binary64
(if (<= b -8.5e-70)
(/ c (- b))
(if (<= b 1.15e-122)
(* (/ -0.5 a) (+ b (sqrt (* (* c a) -4.0))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-70) {
tmp = c / -b;
} else if (b <= 1.15e-122) {
tmp = (-0.5 / a) * (b + sqrt(((c * a) * -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 <= (-8.5d-70)) then
tmp = c / -b
else if (b <= 1.15d-122) then
tmp = ((-0.5d0) / a) * (b + sqrt(((c * a) * (-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 <= -8.5e-70) {
tmp = c / -b;
} else if (b <= 1.15e-122) {
tmp = (-0.5 / a) * (b + Math.sqrt(((c * a) * -4.0)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.5e-70: tmp = c / -b elif b <= 1.15e-122: tmp = (-0.5 / a) * (b + math.sqrt(((c * a) * -4.0))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.5e-70) tmp = Float64(c / Float64(-b)); elseif (b <= 1.15e-122) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * a) * -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 <= -8.5e-70) tmp = c / -b; elseif (b <= 1.15e-122) tmp = (-0.5 / a) * (b + sqrt(((c * a) * -4.0))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.5e-70], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.15e-122], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.5 \cdot 10^{-70}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-122}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.5000000000000002e-70Initial program 18.3%
div-sub16.7%
sub-neg16.7%
neg-mul-116.7%
*-commutative16.7%
associate-/l*15.4%
distribute-neg-frac15.4%
neg-mul-115.4%
*-commutative15.4%
associate-/l*16.5%
distribute-rgt-out18.3%
associate-/r*18.3%
metadata-eval18.3%
sub-neg18.3%
+-commutative18.3%
Simplified18.4%
Taylor expanded in b around -inf 84.7%
mul-1-neg84.7%
distribute-neg-frac284.7%
Simplified84.7%
if -8.5000000000000002e-70 < b < 1.15000000000000003e-122Initial program 69.1%
div-sub69.1%
sub-neg69.1%
neg-mul-169.1%
*-commutative69.1%
associate-/l*69.1%
distribute-neg-frac69.1%
neg-mul-169.1%
*-commutative69.1%
associate-/l*69.0%
distribute-rgt-out69.0%
associate-/r*69.0%
metadata-eval69.0%
sub-neg69.0%
+-commutative69.0%
Simplified69.0%
Taylor expanded in a around inf 65.5%
*-commutative65.5%
Simplified65.5%
if 1.15000000000000003e-122 < b Initial program 83.4%
div-sub83.4%
sub-neg83.4%
neg-mul-183.4%
*-commutative83.4%
associate-/l*83.3%
distribute-neg-frac83.3%
neg-mul-183.3%
*-commutative83.3%
associate-/l*83.2%
distribute-rgt-out83.2%
associate-/r*83.2%
metadata-eval83.2%
sub-neg83.2%
+-commutative83.2%
Simplified83.2%
Taylor expanded in c around 0 84.1%
+-commutative84.1%
mul-1-neg84.1%
unsub-neg84.1%
Simplified84.1%
Final simplification78.9%
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e-70)
(/ c (- b))
(if (<= b 7.4e-174)
(* -0.5 (/ (sqrt (* a (* c -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e-70) {
tmp = c / -b;
} else if (b <= 7.4e-174) {
tmp = -0.5 * (sqrt((a * (c * -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 <= (-2.8d-70)) then
tmp = c / -b
else if (b <= 7.4d-174) then
tmp = (-0.5d0) * (sqrt((a * (c * (-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 <= -2.8e-70) {
tmp = c / -b;
} else if (b <= 7.4e-174) {
tmp = -0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e-70: tmp = c / -b elif b <= 7.4e-174: tmp = -0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e-70) tmp = Float64(c / Float64(-b)); elseif (b <= 7.4e-174) tmp = Float64(-0.5 * Float64(sqrt(Float64(a * Float64(c * -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 <= -2.8e-70) tmp = c / -b; elseif (b <= 7.4e-174) tmp = -0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e-70], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 7.4e-174], N[(-0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $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 -2.8 \cdot 10^{-70}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 7.4 \cdot 10^{-174}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.7999999999999999e-70Initial program 18.3%
div-sub16.7%
sub-neg16.7%
neg-mul-116.7%
*-commutative16.7%
associate-/l*15.4%
distribute-neg-frac15.4%
neg-mul-115.4%
*-commutative15.4%
associate-/l*16.5%
distribute-rgt-out18.3%
associate-/r*18.3%
metadata-eval18.3%
sub-neg18.3%
+-commutative18.3%
Simplified18.4%
Taylor expanded in b around -inf 84.7%
mul-1-neg84.7%
distribute-neg-frac284.7%
Simplified84.7%
if -2.7999999999999999e-70 < b < 7.40000000000000019e-174Initial program 69.3%
*-commutative69.3%
*-commutative69.3%
sqr-neg69.3%
*-commutative69.3%
sqr-neg69.3%
*-commutative69.3%
associate-*r*69.4%
Simplified69.4%
add-cube-cbrt68.6%
pow368.5%
*-commutative68.5%
associate-*l*67.2%
Applied egg-rr67.2%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt67.3%
rem-cube-cbrt67.7%
Simplified67.7%
associate-/l*67.7%
Applied egg-rr67.7%
associate-*r/67.7%
*-commutative67.7%
times-frac67.7%
metadata-eval67.7%
Simplified67.7%
if 7.40000000000000019e-174 < b Initial program 82.4%
div-sub82.4%
sub-neg82.4%
neg-mul-182.4%
*-commutative82.4%
associate-/l*82.3%
distribute-neg-frac82.3%
neg-mul-182.3%
*-commutative82.3%
associate-/l*82.2%
distribute-rgt-out82.2%
associate-/r*82.2%
metadata-eval82.2%
sub-neg82.2%
+-commutative82.2%
Simplified82.2%
Taylor expanded in c around 0 81.2%
+-commutative81.2%
mul-1-neg81.2%
unsub-neg81.2%
Simplified81.2%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(c / Float64(-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 <= -4e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 36.3%
div-sub35.3%
sub-neg35.3%
neg-mul-135.3%
*-commutative35.3%
associate-/l*34.4%
distribute-neg-frac34.4%
neg-mul-134.4%
*-commutative34.4%
associate-/l*35.1%
distribute-rgt-out36.2%
associate-/r*36.2%
metadata-eval36.2%
sub-neg36.2%
+-commutative36.2%
Simplified36.3%
Taylor expanded in b around -inf 60.8%
mul-1-neg60.8%
distribute-neg-frac260.8%
Simplified60.8%
if -3.999999999999988e-310 < b Initial program 81.1%
div-sub81.1%
sub-neg81.1%
neg-mul-181.1%
*-commutative81.1%
associate-/l*81.0%
distribute-neg-frac81.0%
neg-mul-181.0%
*-commutative81.0%
associate-/l*80.9%
distribute-rgt-out80.9%
associate-/r*80.9%
metadata-eval80.9%
sub-neg80.9%
+-commutative80.9%
Simplified80.9%
Taylor expanded in c around 0 70.0%
+-commutative70.0%
mul-1-neg70.0%
unsub-neg70.0%
Simplified70.0%
(FPCore (a b c) :precision binary64 (if (<= b -3.1e-287) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.1e-287) {
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 <= (-3.1d-287)) 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 <= -3.1e-287) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.1e-287: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.1e-287) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.1e-287) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.1e-287], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.1 \cdot 10^{-287}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.1000000000000001e-287Initial program 36.5%
div-sub35.5%
sub-neg35.5%
neg-mul-135.5%
*-commutative35.5%
associate-/l*34.6%
distribute-neg-frac34.6%
neg-mul-134.6%
*-commutative34.6%
associate-/l*35.3%
distribute-rgt-out36.5%
associate-/r*36.5%
metadata-eval36.5%
sub-neg36.5%
+-commutative36.5%
Simplified36.5%
Taylor expanded in b around -inf 61.2%
mul-1-neg61.2%
distribute-neg-frac261.2%
Simplified61.2%
if -3.1000000000000001e-287 < b Initial program 80.4%
div-sub80.4%
sub-neg80.4%
neg-mul-180.4%
*-commutative80.4%
associate-/l*80.3%
distribute-neg-frac80.3%
neg-mul-180.3%
*-commutative80.3%
associate-/l*80.2%
distribute-rgt-out80.2%
associate-/r*80.2%
metadata-eval80.2%
sub-neg80.2%
+-commutative80.2%
Simplified80.2%
Taylor expanded in a around 0 69.2%
associate-*r/69.2%
mul-1-neg69.2%
Simplified69.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 / Float64(-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 56.4%
div-sub55.8%
sub-neg55.8%
neg-mul-155.8%
*-commutative55.8%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.7%
distribute-rgt-out56.3%
associate-/r*56.3%
metadata-eval56.3%
sub-neg56.3%
+-commutative56.3%
Simplified56.3%
Taylor expanded in b around -inf 34.4%
mul-1-neg34.4%
distribute-neg-frac234.4%
Simplified34.4%
(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 56.4%
div-sub55.8%
sub-neg55.8%
neg-mul-155.8%
*-commutative55.8%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.7%
distribute-rgt-out56.3%
associate-/r*56.3%
metadata-eval56.3%
sub-neg56.3%
+-commutative56.3%
Simplified56.3%
Taylor expanded in b around -inf 34.4%
mul-1-neg34.4%
distribute-neg-frac234.4%
Simplified34.4%
add-sqr-sqrt19.7%
sqrt-unprod16.1%
distribute-frac-neg216.1%
distribute-frac-neg216.1%
sqr-neg16.1%
sqrt-unprod6.8%
add-sqr-sqrt8.2%
*-un-lft-identity8.2%
Applied egg-rr8.2%
*-lft-identity8.2%
Simplified8.2%
(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(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 56.4%
div-sub55.8%
sub-neg55.8%
neg-mul-155.8%
*-commutative55.8%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.7%
distribute-rgt-out56.3%
associate-/r*56.3%
metadata-eval56.3%
sub-neg56.3%
+-commutative56.3%
Simplified56.3%
Taylor expanded in a around 0 32.7%
associate-*r/32.7%
mul-1-neg32.7%
Simplified32.7%
add-sqr-sqrt1.4%
sqrt-unprod1.9%
sqr-neg1.9%
sqrt-prod0.6%
add-sqr-sqrt2.8%
div-inv2.8%
Applied egg-rr2.8%
associate-*r/2.8%
*-rgt-identity2.8%
Simplified2.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{t\_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t\_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2024130
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ c (- sqtD (/ b 2))) (/ (+ (/ b 2) sqtD) (- a)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))