
(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
(let* ((t_0 (* a (* c 4.0))))
(if (<= b -6.8e+69)
(/ -1.0 (* b (- (/ 1.0 c) (/ (/ a b) b))))
(if (<= b -1.3e-106)
(/
-1.0
(/ a (* -0.5 (/ t_0 (- (sqrt (fma a (* c -4.0) (pow b 2.0))) b)))))
(if (<= b 4.1e+151)
(/ (- (- b) (sqrt (- (* b b) t_0))) (* a 2.0))
(- (/ c b) (/ b a)))))))
double code(double a, double b, double c) {
double t_0 = a * (c * 4.0);
double tmp;
if (b <= -6.8e+69) {
tmp = -1.0 / (b * ((1.0 / c) - ((a / b) / b)));
} else if (b <= -1.3e-106) {
tmp = -1.0 / (a / (-0.5 * (t_0 / (sqrt(fma(a, (c * -4.0), pow(b, 2.0))) - b))));
} else if (b <= 4.1e+151) {
tmp = (-b - sqrt(((b * b) - t_0))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
function code(a, b, c) t_0 = Float64(a * Float64(c * 4.0)) tmp = 0.0 if (b <= -6.8e+69) tmp = Float64(-1.0 / Float64(b * Float64(Float64(1.0 / c) - Float64(Float64(a / b) / b)))); elseif (b <= -1.3e-106) tmp = Float64(-1.0 / Float64(a / Float64(-0.5 * Float64(t_0 / Float64(sqrt(fma(a, Float64(c * -4.0), (b ^ 2.0))) - b))))); elseif (b <= 4.1e+151) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - t_0))) / Float64(a * 2.0)); else tmp = Float64(Float64(c / b) - 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, -6.8e+69], N[(-1.0 / N[(b * N[(N[(1.0 / c), $MachinePrecision] - N[(N[(a / b), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.3e-106], N[(-1.0 / N[(a / N[(-0.5 * N[(t$95$0 / N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.1e+151], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $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}
t_0 := a \cdot \left(c \cdot 4\right)\\
\mathbf{if}\;b \leq -6.8 \cdot 10^{+69}:\\
\;\;\;\;\frac{-1}{b \cdot \left(\frac{1}{c} - \frac{\frac{a}{b}}{b}\right)}\\
\mathbf{elif}\;b \leq -1.3 \cdot 10^{-106}:\\
\;\;\;\;\frac{-1}{\frac{a}{-0.5 \cdot \frac{t\_0}{\sqrt{\mathsf{fma}\left(a, c \cdot -4, {b}^{2}\right)} - b}}}\\
\mathbf{elif}\;b \leq 4.1 \cdot 10^{+151}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - t\_0}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.79999999999999973e69Initial program 10.6%
div-sub10.0%
sub-neg10.0%
neg-mul-110.0%
*-commutative10.0%
associate-/l*5.5%
distribute-neg-frac5.5%
neg-mul-15.5%
*-commutative5.5%
associate-/l*10.0%
distribute-rgt-out10.6%
associate-/r*10.6%
metadata-eval10.6%
sub-neg10.6%
+-commutative10.6%
Simplified10.6%
associate-*l/10.6%
clear-num10.6%
*-commutative10.6%
pow210.6%
Applied egg-rr10.6%
Taylor expanded in b around -inf 93.5%
associate-*r*93.5%
mul-1-neg93.5%
+-commutative93.5%
mul-1-neg93.5%
unsub-neg93.5%
Simplified93.5%
*-un-lft-identity93.5%
pow293.5%
times-frac94.0%
Applied egg-rr94.0%
associate-*l/94.0%
*-lft-identity94.0%
Simplified94.0%
if -6.79999999999999973e69 < b < -1.3e-106Initial program 40.8%
div-sub40.8%
sub-neg40.8%
neg-mul-140.8%
*-commutative40.8%
associate-/l*40.7%
distribute-neg-frac40.7%
neg-mul-140.7%
*-commutative40.7%
associate-/l*40.7%
distribute-rgt-out40.7%
associate-/r*40.7%
metadata-eval40.7%
sub-neg40.7%
+-commutative40.7%
Simplified40.7%
associate-*l/40.8%
clear-num40.8%
*-commutative40.8%
pow240.8%
Applied egg-rr40.8%
flip-+40.4%
pow240.4%
add-sqr-sqrt40.6%
Applied egg-rr40.6%
fma-undefine40.6%
metadata-eval40.6%
distribute-rgt-neg-in40.6%
distribute-rgt-neg-in40.6%
+-commutative40.6%
sub-neg40.6%
associate--r-81.6%
+-inverses81.6%
+-lft-identity81.6%
Simplified81.6%
if -1.3e-106 < b < 4.0999999999999998e151Initial program 77.4%
*-commutative77.4%
*-commutative77.4%
sqr-neg77.4%
*-commutative77.4%
sqr-neg77.4%
*-commutative77.4%
associate-*r*77.5%
Simplified77.5%
if 4.0999999999999998e151 < b Initial program 44.1%
div-sub44.1%
sub-neg44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-neg-frac44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-rgt-out44.1%
associate-/r*44.1%
metadata-eval44.1%
sub-neg44.1%
+-commutative44.1%
Simplified44.4%
Taylor expanded in c around 0 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification85.6%
(FPCore (a b c)
:precision binary64
(if (<= b -1.25e-63)
(/ -1.0 (- (/ b c) (/ a b)))
(if (<= b 5e+151)
(/ (- (- b) (sqrt (- (* b b) (* a (* c 4.0))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.25e-63) {
tmp = -1.0 / ((b / c) - (a / b));
} else if (b <= 5e+151) {
tmp = (-b - sqrt(((b * b) - (a * (c * 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-63)) then
tmp = (-1.0d0) / ((b / c) - (a / b))
else if (b <= 5d+151) then
tmp = (-b - sqrt(((b * b) - (a * (c * 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-63) {
tmp = -1.0 / ((b / c) - (a / b));
} else if (b <= 5e+151) {
tmp = (-b - Math.sqrt(((b * b) - (a * (c * 4.0))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.25e-63: tmp = -1.0 / ((b / c) - (a / b)) elif b <= 5e+151: tmp = (-b - math.sqrt(((b * b) - (a * (c * 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-63) tmp = Float64(-1.0 / Float64(Float64(b / c) - Float64(a / b))); elseif (b <= 5e+151) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 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-63) tmp = -1.0 / ((b / c) - (a / b)); elseif (b <= 5e+151) tmp = (-b - sqrt(((b * b) - (a * (c * 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-63], N[(-1.0 / N[(N[(b / c), $MachinePrecision] - N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e+151], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $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.25 \cdot 10^{-63}:\\
\;\;\;\;\frac{-1}{\frac{b}{c} - \frac{a}{b}}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+151}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.25e-63Initial program 15.9%
div-sub15.5%
sub-neg15.5%
neg-mul-115.5%
*-commutative15.5%
associate-/l*12.1%
distribute-neg-frac12.1%
neg-mul-112.1%
*-commutative12.1%
associate-/l*15.4%
distribute-rgt-out15.8%
associate-/r*15.8%
metadata-eval15.8%
sub-neg15.8%
+-commutative15.8%
Simplified15.8%
associate-*l/15.9%
clear-num15.8%
*-commutative15.8%
pow215.8%
Applied egg-rr15.8%
Taylor expanded in b around -inf 86.9%
associate-*r*86.9%
mul-1-neg86.9%
+-commutative86.9%
mul-1-neg86.9%
unsub-neg86.9%
Simplified86.9%
Taylor expanded in c around inf 87.3%
+-commutative87.3%
mul-1-neg87.3%
unsub-neg87.3%
Simplified87.3%
if -1.25e-63 < b < 5.0000000000000002e151Initial program 76.7%
*-commutative76.7%
*-commutative76.7%
sqr-neg76.7%
*-commutative76.7%
sqr-neg76.7%
*-commutative76.7%
associate-*r*76.8%
Simplified76.8%
if 5.0000000000000002e151 < b Initial program 44.1%
div-sub44.1%
sub-neg44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-neg-frac44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-rgt-out44.1%
associate-/r*44.1%
metadata-eval44.1%
sub-neg44.1%
+-commutative44.1%
Simplified44.4%
Taylor expanded in c around 0 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification83.8%
(FPCore (a b c)
:precision binary64
(if (<= b -2.5e-55)
(/ -1.0 (- (/ b c) (/ a b)))
(if (<= b 5e+151)
(/ (- (- 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 <= -2.5e-55) {
tmp = -1.0 / ((b / c) - (a / b));
} else if (b <= 5e+151) {
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 <= (-2.5d-55)) then
tmp = (-1.0d0) / ((b / c) - (a / b))
else if (b <= 5d+151) 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 <= -2.5e-55) {
tmp = -1.0 / ((b / c) - (a / b));
} else if (b <= 5e+151) {
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 <= -2.5e-55: tmp = -1.0 / ((b / c) - (a / b)) elif b <= 5e+151: 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 <= -2.5e-55) tmp = Float64(-1.0 / Float64(Float64(b / c) - Float64(a / b))); elseif (b <= 5e+151) 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 <= -2.5e-55) tmp = -1.0 / ((b / c) - (a / b)); elseif (b <= 5e+151) 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, -2.5e-55], N[(-1.0 / N[(N[(b / c), $MachinePrecision] - N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e+151], 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 -2.5 \cdot 10^{-55}:\\
\;\;\;\;\frac{-1}{\frac{b}{c} - \frac{a}{b}}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+151}:\\
\;\;\;\;\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 < -2.5000000000000001e-55Initial program 15.9%
div-sub15.5%
sub-neg15.5%
neg-mul-115.5%
*-commutative15.5%
associate-/l*12.1%
distribute-neg-frac12.1%
neg-mul-112.1%
*-commutative12.1%
associate-/l*15.4%
distribute-rgt-out15.8%
associate-/r*15.8%
metadata-eval15.8%
sub-neg15.8%
+-commutative15.8%
Simplified15.8%
associate-*l/15.9%
clear-num15.8%
*-commutative15.8%
pow215.8%
Applied egg-rr15.8%
Taylor expanded in b around -inf 86.9%
associate-*r*86.9%
mul-1-neg86.9%
+-commutative86.9%
mul-1-neg86.9%
unsub-neg86.9%
Simplified86.9%
Taylor expanded in c around inf 87.3%
+-commutative87.3%
mul-1-neg87.3%
unsub-neg87.3%
Simplified87.3%
if -2.5000000000000001e-55 < b < 5.0000000000000002e151Initial program 76.7%
if 5.0000000000000002e151 < b Initial program 44.1%
div-sub44.1%
sub-neg44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-neg-frac44.1%
neg-mul-144.1%
*-commutative44.1%
associate-/l*44.1%
distribute-rgt-out44.1%
associate-/r*44.1%
metadata-eval44.1%
sub-neg44.1%
+-commutative44.1%
Simplified44.4%
Taylor expanded in c around 0 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification83.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.7e-66)
(/ -1.0 (- (/ b c) (/ a b)))
(if (<= b 1e-59)
(/ (+ 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.7e-66) {
tmp = -1.0 / ((b / c) - (a / b));
} else if (b <= 1e-59) {
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.7d-66)) then
tmp = (-1.0d0) / ((b / c) - (a / b))
else if (b <= 1d-59) 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.7e-66) {
tmp = -1.0 / ((b / c) - (a / b));
} else if (b <= 1e-59) {
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.7e-66: tmp = -1.0 / ((b / c) - (a / b)) elif b <= 1e-59: 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.7e-66) tmp = Float64(-1.0 / Float64(Float64(b / c) - Float64(a / b))); elseif (b <= 1e-59) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / 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 <= -1.7e-66) tmp = -1.0 / ((b / c) - (a / b)); elseif (b <= 1e-59) 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.7e-66], N[(-1.0 / N[(N[(b / c), $MachinePrecision] - N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1e-59], 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.7 \cdot 10^{-66}:\\
\;\;\;\;\frac{-1}{\frac{b}{c} - \frac{a}{b}}\\
\mathbf{elif}\;b \leq 10^{-59}:\\
\;\;\;\;\frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.69999999999999999e-66Initial program 15.9%
div-sub15.5%
sub-neg15.5%
neg-mul-115.5%
*-commutative15.5%
associate-/l*12.1%
distribute-neg-frac12.1%
neg-mul-112.1%
*-commutative12.1%
associate-/l*15.4%
distribute-rgt-out15.8%
associate-/r*15.8%
metadata-eval15.8%
sub-neg15.8%
+-commutative15.8%
Simplified15.8%
associate-*l/15.9%
clear-num15.8%
*-commutative15.8%
pow215.8%
Applied egg-rr15.8%
Taylor expanded in b around -inf 86.9%
associate-*r*86.9%
mul-1-neg86.9%
+-commutative86.9%
mul-1-neg86.9%
unsub-neg86.9%
Simplified86.9%
Taylor expanded in c around inf 87.3%
+-commutative87.3%
mul-1-neg87.3%
unsub-neg87.3%
Simplified87.3%
if -1.69999999999999999e-66 < b < 1e-59Initial program 69.6%
*-commutative69.6%
*-commutative69.6%
sqr-neg69.6%
*-commutative69.6%
sqr-neg69.6%
*-commutative69.6%
associate-*r*69.7%
Simplified69.7%
Taylor expanded in b around 0 62.0%
associate-*r*62.0%
*-commutative62.0%
Simplified62.0%
if 1e-59 < b Initial program 69.5%
div-sub69.5%
sub-neg69.5%
neg-mul-169.5%
*-commutative69.5%
associate-/l*69.4%
distribute-neg-frac69.4%
neg-mul-169.4%
*-commutative69.4%
associate-/l*69.4%
distribute-rgt-out69.4%
associate-/r*69.4%
metadata-eval69.4%
sub-neg69.4%
+-commutative69.4%
Simplified69.5%
Taylor expanded in c around 0 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
Final simplification79.8%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ -1.0 (- (/ b c) (/ a b))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -1.0 / ((b / c) - (a / 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 = (-1.0d0) / ((b / c) - (a / 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 = -1.0 / ((b / c) - (a / b));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -1.0 / ((b / c) - (a / b)) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(-1.0 / Float64(Float64(b / c) - Float64(a / 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 = -1.0 / ((b / c) - (a / b)); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(-1.0 / N[(N[(b / c), $MachinePrecision] - N[(a / b), $MachinePrecision]), $MachinePrecision]), $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{-1}{\frac{b}{c} - \frac{a}{b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 29.4%
div-sub29.1%
sub-neg29.1%
neg-mul-129.1%
*-commutative29.1%
associate-/l*26.7%
distribute-neg-frac26.7%
neg-mul-126.7%
*-commutative26.7%
associate-/l*29.0%
distribute-rgt-out29.3%
associate-/r*29.3%
metadata-eval29.3%
sub-neg29.3%
+-commutative29.3%
Simplified29.3%
associate-*l/29.4%
clear-num29.4%
*-commutative29.4%
pow229.4%
Applied egg-rr29.4%
Taylor expanded in b around -inf 66.5%
associate-*r*66.5%
mul-1-neg66.5%
+-commutative66.5%
mul-1-neg66.5%
unsub-neg66.5%
Simplified66.5%
Taylor expanded in c around inf 67.1%
+-commutative67.1%
mul-1-neg67.1%
unsub-neg67.1%
Simplified67.1%
if -1.999999999999994e-310 < b Initial program 71.8%
div-sub71.8%
sub-neg71.8%
neg-mul-171.8%
*-commutative71.8%
associate-/l*71.8%
distribute-neg-frac71.8%
neg-mul-171.8%
*-commutative71.8%
associate-/l*71.7%
distribute-rgt-out71.7%
associate-/r*71.7%
metadata-eval71.7%
sub-neg71.7%
+-commutative71.7%
Simplified71.8%
Taylor expanded in c around 0 65.8%
+-commutative65.8%
mul-1-neg65.8%
unsub-neg65.8%
Simplified65.8%
Final simplification66.4%
(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 29.4%
div-sub29.1%
sub-neg29.1%
neg-mul-129.1%
*-commutative29.1%
associate-/l*26.7%
distribute-neg-frac26.7%
neg-mul-126.7%
*-commutative26.7%
associate-/l*29.0%
distribute-rgt-out29.3%
associate-/r*29.3%
metadata-eval29.3%
sub-neg29.3%
+-commutative29.3%
Simplified29.3%
Taylor expanded in b around -inf 66.2%
mul-1-neg66.2%
distribute-neg-frac266.2%
Simplified66.2%
if -1.999999999999994e-310 < b Initial program 71.8%
div-sub71.8%
sub-neg71.8%
neg-mul-171.8%
*-commutative71.8%
associate-/l*71.8%
distribute-neg-frac71.8%
neg-mul-171.8%
*-commutative71.8%
associate-/l*71.7%
distribute-rgt-out71.7%
associate-/r*71.7%
metadata-eval71.7%
sub-neg71.7%
+-commutative71.7%
Simplified71.8%
Taylor expanded in c around 0 65.8%
+-commutative65.8%
mul-1-neg65.8%
unsub-neg65.8%
Simplified65.8%
Final simplification66.0%
(FPCore (a b c) :precision binary64 (if (<= b -3e-308) (- (/ c b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-308) {
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 <= (-3d-308)) 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 <= -3e-308) {
tmp = -(c / b);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-308: tmp = -(c / b) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-308) tmp = Float64(-Float64(c / b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3e-308) tmp = -(c / b); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-308], (-N[(c / b), $MachinePrecision]), N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-308}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -3.00000000000000022e-308Initial program 29.4%
div-sub29.1%
sub-neg29.1%
neg-mul-129.1%
*-commutative29.1%
associate-/l*26.7%
distribute-neg-frac26.7%
neg-mul-126.7%
*-commutative26.7%
associate-/l*29.0%
distribute-rgt-out29.3%
associate-/r*29.3%
metadata-eval29.3%
sub-neg29.3%
+-commutative29.3%
Simplified29.3%
Taylor expanded in b around -inf 66.2%
mul-1-neg66.2%
distribute-neg-frac266.2%
Simplified66.2%
if -3.00000000000000022e-308 < b Initial program 71.8%
div-sub71.8%
sub-neg71.8%
neg-mul-171.8%
*-commutative71.8%
associate-/l*71.8%
distribute-neg-frac71.8%
neg-mul-171.8%
*-commutative71.8%
associate-/l*71.7%
distribute-rgt-out71.7%
associate-/r*71.7%
metadata-eval71.7%
sub-neg71.7%
+-commutative71.7%
Simplified71.8%
Taylor expanded in a around 0 65.0%
associate-*r/65.0%
mul-1-neg65.0%
Simplified65.0%
Final simplification65.6%
(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(-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 50.3%
div-sub50.1%
sub-neg50.1%
neg-mul-150.1%
*-commutative50.1%
associate-/l*48.9%
distribute-neg-frac48.9%
neg-mul-148.9%
*-commutative48.9%
associate-/l*50.0%
distribute-rgt-out50.2%
associate-/r*50.2%
metadata-eval50.2%
sub-neg50.2%
+-commutative50.2%
Simplified50.2%
Taylor expanded in b around -inf 34.7%
mul-1-neg34.7%
distribute-neg-frac234.7%
Simplified34.7%
Final simplification34.7%
(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 50.3%
div-sub50.1%
sub-neg50.1%
neg-mul-150.1%
*-commutative50.1%
associate-/l*48.9%
distribute-neg-frac48.9%
neg-mul-148.9%
*-commutative48.9%
associate-/l*50.0%
distribute-rgt-out50.2%
associate-/r*50.2%
metadata-eval50.2%
sub-neg50.2%
+-commutative50.2%
Simplified50.2%
Taylor expanded in b around -inf 12.1%
mul-1-neg12.1%
Simplified12.1%
Taylor expanded in a around 0 12.1%
(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 2024118
(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)))