
(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 -3e-120)
(/ c (- b))
(if (<= b 1.7e+41)
(/ (- (- b) (sqrt (- (* b b) (* (* c 4.0) a)))) (* a 2.0))
(* (/ -0.5 a) (+ b (* b (sqrt (fma -4.0 (* a (/ (/ c b) b)) 1.0))))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-120) {
tmp = c / -b;
} else if (b <= 1.7e+41) {
tmp = (-b - sqrt(((b * b) - ((c * 4.0) * a)))) / (a * 2.0);
} else {
tmp = (-0.5 / a) * (b + (b * sqrt(fma(-4.0, (a * ((c / b) / b)), 1.0))));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -3e-120) tmp = Float64(c / Float64(-b)); elseif (b <= 1.7e+41) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * 2.0)); else tmp = Float64(Float64(-0.5 / a) * Float64(b + Float64(b * sqrt(fma(-4.0, Float64(a * Float64(Float64(c / b) / b)), 1.0))))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -3e-120], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.7e+41], 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[(-0.5 / a), $MachinePrecision] * N[(b + N[(b * N[Sqrt[N[(-4.0 * N[(a * N[(N[(c / b), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-120}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{+41}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + b \cdot \sqrt{\mathsf{fma}\left(-4, a \cdot \frac{\frac{c}{b}}{b}, 1\right)}\right)\\
\end{array}
\end{array}
if b < -3.00000000000000011e-120Initial program 18.7%
div-sub18.4%
sub-neg18.4%
neg-mul-118.4%
*-commutative18.4%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*18.3%
distribute-rgt-out18.7%
associate-/r*18.7%
metadata-eval18.7%
sub-neg18.7%
+-commutative18.7%
Simplified18.7%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
distribute-neg-frac281.4%
Simplified81.4%
if -3.00000000000000011e-120 < b < 1.69999999999999999e41Initial program 87.8%
*-commutative87.8%
*-commutative87.8%
sqr-neg87.8%
*-commutative87.8%
sqr-neg87.8%
*-commutative87.8%
associate-*r*87.8%
Simplified87.8%
if 1.69999999999999999e41 < b Initial program 57.2%
div-sub57.2%
sub-neg57.2%
neg-mul-157.2%
*-commutative57.2%
associate-/l*57.2%
distribute-neg-frac57.2%
neg-mul-157.2%
*-commutative57.2%
associate-/l*57.1%
distribute-rgt-out57.1%
associate-/r*57.1%
metadata-eval57.1%
sub-neg57.1%
+-commutative57.1%
Simplified57.2%
Taylor expanded in b around inf 56.9%
associate-/l*57.2%
Simplified57.2%
pow257.2%
*-commutative57.2%
sqrt-prod61.0%
+-commutative61.0%
fma-define61.0%
pow261.0%
div-inv61.0%
pow261.0%
pow-flip61.0%
metadata-eval61.0%
sqrt-prod98.4%
add-sqr-sqrt98.6%
Applied egg-rr98.6%
add-sqr-sqrt78.9%
pow278.9%
sqrt-prod42.0%
sqrt-pow142.0%
metadata-eval42.0%
inv-pow42.0%
Applied egg-rr42.0%
unpow242.0%
associate-*r/42.0%
*-rgt-identity42.0%
associate-*r/42.0%
associate-*r/42.0%
*-rgt-identity42.0%
associate-*l/42.0%
rem-square-sqrt99.7%
Simplified99.7%
Final simplification89.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.9e-120)
(/ c (- b))
(if (<= b 2.65e+72)
(/ (- (- 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 <= -2.9e-120) {
tmp = c / -b;
} else if (b <= 2.65e+72) {
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 <= (-2.9d-120)) then
tmp = c / -b
else if (b <= 2.65d+72) 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 <= -2.9e-120) {
tmp = c / -b;
} else if (b <= 2.65e+72) {
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 <= -2.9e-120: tmp = c / -b elif b <= 2.65e+72: 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 <= -2.9e-120) tmp = Float64(c / Float64(-b)); elseif (b <= 2.65e+72) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * 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 <= -2.9e-120) tmp = c / -b; elseif (b <= 2.65e+72) 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, -2.9e-120], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.65e+72], 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 -2.9 \cdot 10^{-120}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.65 \cdot 10^{+72}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.9e-120Initial program 18.7%
div-sub18.4%
sub-neg18.4%
neg-mul-118.4%
*-commutative18.4%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*18.3%
distribute-rgt-out18.7%
associate-/r*18.7%
metadata-eval18.7%
sub-neg18.7%
+-commutative18.7%
Simplified18.7%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
distribute-neg-frac281.4%
Simplified81.4%
if -2.9e-120 < b < 2.6500000000000001e72Initial program 88.0%
*-commutative88.0%
*-commutative88.0%
sqr-neg88.0%
*-commutative88.0%
sqr-neg88.0%
*-commutative88.0%
associate-*r*88.0%
Simplified88.0%
if 2.6500000000000001e72 < b Initial program 52.2%
div-sub52.2%
sub-neg52.2%
neg-mul-152.2%
*-commutative52.2%
associate-/l*52.2%
distribute-neg-frac52.2%
neg-mul-152.2%
*-commutative52.2%
associate-/l*52.2%
distribute-rgt-out52.2%
associate-/r*52.2%
metadata-eval52.2%
sub-neg52.2%
+-commutative52.2%
Simplified52.3%
Taylor expanded in c around 0 95.9%
+-commutative95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
Final simplification87.9%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-120)
(/ c (- b))
(if (<= b 2.7e+72)
(/ (- (- 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 <= -3e-120) {
tmp = c / -b;
} else if (b <= 2.7e+72) {
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 <= (-3d-120)) then
tmp = c / -b
else if (b <= 2.7d+72) 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 <= -3e-120) {
tmp = c / -b;
} else if (b <= 2.7e+72) {
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 <= -3e-120: tmp = c / -b elif b <= 2.7e+72: 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 <= -3e-120) tmp = Float64(c / Float64(-b)); elseif (b <= 2.7e+72) 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 <= -3e-120) tmp = c / -b; elseif (b <= 2.7e+72) 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, -3e-120], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.7e+72], 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 -3 \cdot 10^{-120}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.7 \cdot 10^{+72}:\\
\;\;\;\;\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 < -3.00000000000000011e-120Initial program 18.7%
div-sub18.4%
sub-neg18.4%
neg-mul-118.4%
*-commutative18.4%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*18.3%
distribute-rgt-out18.7%
associate-/r*18.7%
metadata-eval18.7%
sub-neg18.7%
+-commutative18.7%
Simplified18.7%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
distribute-neg-frac281.4%
Simplified81.4%
if -3.00000000000000011e-120 < b < 2.7000000000000001e72Initial program 88.0%
if 2.7000000000000001e72 < b Initial program 52.2%
div-sub52.2%
sub-neg52.2%
neg-mul-152.2%
*-commutative52.2%
associate-/l*52.2%
distribute-neg-frac52.2%
neg-mul-152.2%
*-commutative52.2%
associate-/l*52.2%
distribute-rgt-out52.2%
associate-/r*52.2%
metadata-eval52.2%
sub-neg52.2%
+-commutative52.2%
Simplified52.3%
Taylor expanded in c around 0 95.9%
+-commutative95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
Final simplification87.8%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-120)
(/ c (- b))
(if (<= b 1.9e-92)
(* (/ -0.5 a) (+ b (sqrt (* -4.0 (* c a)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-120) {
tmp = c / -b;
} else if (b <= 1.9e-92) {
tmp = (-0.5 / a) * (b + sqrt((-4.0 * (c * 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 <= (-3d-120)) then
tmp = c / -b
else if (b <= 1.9d-92) then
tmp = ((-0.5d0) / a) * (b + sqrt(((-4.0d0) * (c * 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 <= -3e-120) {
tmp = c / -b;
} else if (b <= 1.9e-92) {
tmp = (-0.5 / a) * (b + Math.sqrt((-4.0 * (c * a))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-120: tmp = c / -b elif b <= 1.9e-92: tmp = (-0.5 / a) * (b + math.sqrt((-4.0 * (c * a)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-120) tmp = Float64(c / Float64(-b)); elseif (b <= 1.9e-92) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(-4.0 * Float64(c * 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 <= -3e-120) tmp = c / -b; elseif (b <= 1.9e-92) tmp = (-0.5 / a) * (b + sqrt((-4.0 * (c * a)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-120], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.9e-92], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(-4.0 * N[(c * a), $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 \cdot 10^{-120}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-92}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{-4 \cdot \left(c \cdot a\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.00000000000000011e-120Initial program 18.7%
div-sub18.4%
sub-neg18.4%
neg-mul-118.4%
*-commutative18.4%
associate-/l*17.0%
distribute-neg-frac17.0%
neg-mul-117.0%
*-commutative17.0%
associate-/l*18.3%
distribute-rgt-out18.7%
associate-/r*18.7%
metadata-eval18.7%
sub-neg18.7%
+-commutative18.7%
Simplified18.7%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
distribute-neg-frac281.4%
Simplified81.4%
if -3.00000000000000011e-120 < b < 1.9e-92Initial program 84.9%
div-sub84.9%
sub-neg84.9%
neg-mul-184.9%
*-commutative84.9%
associate-/l*84.9%
distribute-neg-frac84.9%
neg-mul-184.9%
*-commutative84.9%
associate-/l*84.8%
distribute-rgt-out84.8%
associate-/r*84.8%
metadata-eval84.8%
sub-neg84.8%
+-commutative84.8%
Simplified84.9%
Taylor expanded in a around inf 82.0%
*-commutative82.0%
Simplified82.0%
if 1.9e-92 < b Initial program 67.8%
div-sub67.8%
sub-neg67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.7%
distribute-neg-frac67.7%
neg-mul-167.7%
*-commutative67.7%
associate-/l*67.6%
distribute-rgt-out67.6%
associate-/r*67.6%
metadata-eval67.6%
sub-neg67.6%
+-commutative67.6%
Simplified67.6%
Taylor expanded in c around 0 86.7%
+-commutative86.7%
mul-1-neg86.7%
unsub-neg86.7%
Simplified86.7%
Final simplification83.8%
(FPCore (a b c) :precision binary64 (if (<= b -5e-311) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
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-311)) 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-311) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-311: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-311) 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 <= -5e-311) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-311], 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^{-311}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.00000000000023e-311Initial program 30.6%
div-sub30.3%
sub-neg30.3%
neg-mul-130.3%
*-commutative30.3%
associate-/l*29.2%
distribute-neg-frac29.2%
neg-mul-129.2%
*-commutative29.2%
associate-/l*30.2%
distribute-rgt-out30.5%
associate-/r*30.5%
metadata-eval30.5%
sub-neg30.5%
+-commutative30.5%
Simplified30.5%
Taylor expanded in b around -inf 67.4%
mul-1-neg67.4%
distribute-neg-frac267.4%
Simplified67.4%
if -5.00000000000023e-311 < b Initial program 74.2%
div-sub74.2%
sub-neg74.2%
neg-mul-174.2%
*-commutative74.2%
associate-/l*74.1%
distribute-neg-frac74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.0%
distribute-rgt-out74.0%
associate-/r*74.0%
metadata-eval74.0%
sub-neg74.0%
+-commutative74.0%
Simplified74.1%
Taylor expanded in c around 0 65.1%
+-commutative65.1%
mul-1-neg65.1%
unsub-neg65.1%
Simplified65.1%
(FPCore (a b c) :precision binary64 (if (<= b -2.5e-299) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.5e-299) {
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.5d-299)) 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.5e-299) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.5e-299: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.5e-299) 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 <= -2.5e-299) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.5e-299], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.5 \cdot 10^{-299}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.49999999999999978e-299Initial program 29.9%
div-sub29.6%
sub-neg29.6%
neg-mul-129.6%
*-commutative29.6%
associate-/l*28.5%
distribute-neg-frac28.5%
neg-mul-128.5%
*-commutative28.5%
associate-/l*29.6%
distribute-rgt-out29.9%
associate-/r*29.9%
metadata-eval29.9%
sub-neg29.9%
+-commutative29.9%
Simplified29.9%
Taylor expanded in b around -inf 68.0%
mul-1-neg68.0%
distribute-neg-frac268.0%
Simplified68.0%
if -2.49999999999999978e-299 < b Initial program 74.4%
div-sub74.4%
sub-neg74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.3%
distribute-neg-frac74.3%
neg-mul-174.3%
*-commutative74.3%
associate-/l*74.2%
distribute-rgt-out74.2%
associate-/r*74.2%
metadata-eval74.2%
sub-neg74.2%
+-commutative74.2%
Simplified74.2%
Taylor expanded in a around 0 64.1%
associate-*r/64.1%
mul-1-neg64.1%
Simplified64.1%
(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 55.8%
div-sub55.7%
sub-neg55.7%
neg-mul-155.7%
*-commutative55.7%
associate-/l*55.2%
distribute-neg-frac55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*55.5%
distribute-rgt-out55.7%
associate-/r*55.7%
metadata-eval55.7%
sub-neg55.7%
+-commutative55.7%
Simplified55.7%
Taylor expanded in b around -inf 29.8%
mul-1-neg29.8%
distribute-neg-frac229.8%
Simplified29.8%
(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 55.8%
div-sub55.7%
sub-neg55.7%
neg-mul-155.7%
*-commutative55.7%
associate-/l*55.2%
distribute-neg-frac55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*55.5%
distribute-rgt-out55.7%
associate-/r*55.7%
metadata-eval55.7%
sub-neg55.7%
+-commutative55.7%
Simplified55.7%
Taylor expanded in a around 0 36.0%
Taylor expanded in a around inf 12.0%
(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 55.8%
div-sub55.7%
sub-neg55.7%
neg-mul-155.7%
*-commutative55.7%
associate-/l*55.2%
distribute-neg-frac55.2%
neg-mul-155.2%
*-commutative55.2%
associate-/l*55.5%
distribute-rgt-out55.7%
associate-/r*55.7%
metadata-eval55.7%
sub-neg55.7%
+-commutative55.7%
Simplified55.7%
Taylor expanded in a around 0 38.3%
associate-*r/38.3%
mul-1-neg38.3%
Simplified38.3%
div-inv38.2%
add-sqr-sqrt1.0%
sqrt-unprod1.9%
sqr-neg1.9%
sqrt-unprod1.0%
add-sqr-sqrt2.7%
Applied egg-rr2.7%
associate-*r/2.7%
*-rgt-identity2.7%
Simplified2.7%
(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 2024137
(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)))