
(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 8 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 -7.7e-59)
(/ (* c (- -1.0 (/ (* c a) (pow b 2.0)))) b)
(if (<= b 90000000000.0)
(/ (- (- 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 <= -7.7e-59) {
tmp = (c * (-1.0 - ((c * a) / pow(b, 2.0)))) / b;
} else if (b <= 90000000000.0) {
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 <= (-7.7d-59)) then
tmp = (c * ((-1.0d0) - ((c * a) / (b ** 2.0d0)))) / b
else if (b <= 90000000000.0d0) 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 <= -7.7e-59) {
tmp = (c * (-1.0 - ((c * a) / Math.pow(b, 2.0)))) / b;
} else if (b <= 90000000000.0) {
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 <= -7.7e-59: tmp = (c * (-1.0 - ((c * a) / math.pow(b, 2.0)))) / b elif b <= 90000000000.0: 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 <= -7.7e-59) tmp = Float64(Float64(c * Float64(-1.0 - Float64(Float64(c * a) / (b ^ 2.0)))) / b); elseif (b <= 90000000000.0) 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 <= -7.7e-59) tmp = (c * (-1.0 - ((c * a) / (b ^ 2.0)))) / b; elseif (b <= 90000000000.0) 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, -7.7e-59], N[(N[(c * N[(-1.0 - N[(N[(c * a), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[b, 90000000000.0], 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 -7.7 \cdot 10^{-59}:\\
\;\;\;\;\frac{c \cdot \left(-1 - \frac{c \cdot a}{{b}^{2}}\right)}{b}\\
\mathbf{elif}\;b \leq 90000000000:\\
\;\;\;\;\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 < -7.7e-59Initial program 10.3%
div-sub9.8%
sub-neg9.8%
neg-mul-19.8%
*-commutative9.8%
associate-/l*8.6%
distribute-neg-frac8.6%
neg-mul-18.6%
*-commutative8.6%
associate-/l*9.8%
distribute-rgt-out10.4%
associate-/r*10.4%
metadata-eval10.4%
sub-neg10.4%
+-commutative10.4%
Simplified10.4%
distribute-lft-in9.8%
associate-*l/8.8%
pow28.8%
Applied egg-rr8.8%
+-commutative8.8%
fma-define6.2%
associate-*r/6.2%
*-commutative6.2%
Simplified6.2%
Taylor expanded in b around -inf 80.6%
associate-*r/80.6%
mul-1-neg80.6%
associate-/l*81.6%
unpow281.6%
unpow281.6%
times-frac92.7%
unpow292.7%
Simplified92.7%
Taylor expanded in c around 0 92.9%
if -7.7e-59 < b < 9e10Initial program 78.6%
*-commutative78.6%
sqr-neg78.6%
*-commutative78.6%
sqr-neg78.6%
*-commutative78.6%
associate-*r*78.8%
*-commutative78.8%
Simplified78.8%
if 9e10 < b Initial program 66.8%
div-sub66.7%
sub-neg66.7%
neg-mul-166.7%
*-commutative66.7%
associate-/l*66.7%
distribute-neg-frac66.7%
neg-mul-166.7%
*-commutative66.7%
associate-/l*66.6%
distribute-rgt-out66.6%
associate-/r*66.6%
metadata-eval66.6%
sub-neg66.6%
+-commutative66.6%
Simplified66.6%
Taylor expanded in c around 0 97.4%
+-commutative97.4%
mul-1-neg97.4%
unsub-neg97.4%
Simplified97.4%
Final simplification89.6%
(FPCore (a b c)
:precision binary64
(if (<= b -6.5e-59)
(/ (* c (- -1.0 (/ (* c a) (pow b 2.0)))) b)
(if (<= b 90000000000.0)
(/ (- (- b) (sqrt (- (* b b) (* (* c a) 4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.5e-59) {
tmp = (c * (-1.0 - ((c * a) / pow(b, 2.0)))) / b;
} else if (b <= 90000000000.0) {
tmp = (-b - sqrt(((b * b) - ((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 <= (-6.5d-59)) then
tmp = (c * ((-1.0d0) - ((c * a) / (b ** 2.0d0)))) / b
else if (b <= 90000000000.0d0) then
tmp = (-b - sqrt(((b * b) - ((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 <= -6.5e-59) {
tmp = (c * (-1.0 - ((c * a) / Math.pow(b, 2.0)))) / b;
} else if (b <= 90000000000.0) {
tmp = (-b - Math.sqrt(((b * b) - ((c * a) * 4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.5e-59: tmp = (c * (-1.0 - ((c * a) / math.pow(b, 2.0)))) / b elif b <= 90000000000.0: tmp = (-b - math.sqrt(((b * b) - ((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 <= -6.5e-59) tmp = Float64(Float64(c * Float64(-1.0 - Float64(Float64(c * a) / (b ^ 2.0)))) / b); elseif (b <= 90000000000.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 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 <= -6.5e-59) tmp = (c * (-1.0 - ((c * a) / (b ^ 2.0)))) / b; elseif (b <= 90000000000.0) tmp = (-b - sqrt(((b * b) - ((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, -6.5e-59], N[(N[(c * N[(-1.0 - N[(N[(c * a), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[b, 90000000000.0], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * a), $MachinePrecision] * 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 -6.5 \cdot 10^{-59}:\\
\;\;\;\;\frac{c \cdot \left(-1 - \frac{c \cdot a}{{b}^{2}}\right)}{b}\\
\mathbf{elif}\;b \leq 90000000000:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -6.50000000000000017e-59Initial program 10.3%
div-sub9.8%
sub-neg9.8%
neg-mul-19.8%
*-commutative9.8%
associate-/l*8.6%
distribute-neg-frac8.6%
neg-mul-18.6%
*-commutative8.6%
associate-/l*9.8%
distribute-rgt-out10.4%
associate-/r*10.4%
metadata-eval10.4%
sub-neg10.4%
+-commutative10.4%
Simplified10.4%
distribute-lft-in9.8%
associate-*l/8.8%
pow28.8%
Applied egg-rr8.8%
+-commutative8.8%
fma-define6.2%
associate-*r/6.2%
*-commutative6.2%
Simplified6.2%
Taylor expanded in b around -inf 80.6%
associate-*r/80.6%
mul-1-neg80.6%
associate-/l*81.6%
unpow281.6%
unpow281.6%
times-frac92.7%
unpow292.7%
Simplified92.7%
Taylor expanded in c around 0 92.9%
if -6.50000000000000017e-59 < b < 9e10Initial program 78.6%
if 9e10 < b Initial program 66.8%
div-sub66.7%
sub-neg66.7%
neg-mul-166.7%
*-commutative66.7%
associate-/l*66.7%
distribute-neg-frac66.7%
neg-mul-166.7%
*-commutative66.7%
associate-/l*66.6%
distribute-rgt-out66.6%
associate-/r*66.6%
metadata-eval66.6%
sub-neg66.6%
+-commutative66.6%
Simplified66.6%
Taylor expanded in c around 0 97.4%
+-commutative97.4%
mul-1-neg97.4%
unsub-neg97.4%
Simplified97.4%
Final simplification89.5%
(FPCore (a b c)
:precision binary64
(if (<= b -8.2e-114)
(/ (* c (- -1.0 (/ (* c a) (pow b 2.0)))) b)
(if (<= b 7.5e-82)
(* (/ -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.2e-114) {
tmp = (c * (-1.0 - ((c * a) / pow(b, 2.0)))) / b;
} else if (b <= 7.5e-82) {
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.2d-114)) then
tmp = (c * ((-1.0d0) - ((c * a) / (b ** 2.0d0)))) / b
else if (b <= 7.5d-82) 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.2e-114) {
tmp = (c * (-1.0 - ((c * a) / Math.pow(b, 2.0)))) / b;
} else if (b <= 7.5e-82) {
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.2e-114: tmp = (c * (-1.0 - ((c * a) / math.pow(b, 2.0)))) / b elif b <= 7.5e-82: 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.2e-114) tmp = Float64(Float64(c * Float64(-1.0 - Float64(Float64(c * a) / (b ^ 2.0)))) / b); elseif (b <= 7.5e-82) 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.2e-114) tmp = (c * (-1.0 - ((c * a) / (b ^ 2.0)))) / b; elseif (b <= 7.5e-82) 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.2e-114], N[(N[(c * N[(-1.0 - N[(N[(c * a), $MachinePrecision] / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[b, 7.5e-82], 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.2 \cdot 10^{-114}:\\
\;\;\;\;\frac{c \cdot \left(-1 - \frac{c \cdot a}{{b}^{2}}\right)}{b}\\
\mathbf{elif}\;b \leq 7.5 \cdot 10^{-82}:\\
\;\;\;\;\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.1999999999999993e-114Initial program 12.5%
div-sub12.0%
sub-neg12.0%
neg-mul-112.0%
*-commutative12.0%
associate-/l*10.9%
distribute-neg-frac10.9%
neg-mul-110.9%
*-commutative10.9%
associate-/l*12.0%
distribute-rgt-out12.5%
associate-/r*12.5%
metadata-eval12.5%
sub-neg12.5%
+-commutative12.5%
Simplified12.5%
distribute-lft-in12.0%
associate-*l/11.1%
pow211.1%
Applied egg-rr11.1%
+-commutative11.1%
fma-define8.6%
associate-*r/8.6%
*-commutative8.6%
Simplified8.6%
Taylor expanded in b around -inf 78.4%
associate-*r/78.4%
mul-1-neg78.4%
associate-/l*79.5%
unpow279.5%
unpow279.5%
times-frac90.0%
unpow290.0%
Simplified90.0%
Taylor expanded in c around 0 90.1%
if -8.1999999999999993e-114 < b < 7.4999999999999997e-82Initial program 77.3%
div-sub77.3%
sub-neg77.3%
neg-mul-177.3%
*-commutative77.3%
associate-/l*77.2%
distribute-neg-frac77.2%
neg-mul-177.2%
*-commutative77.2%
associate-/l*77.2%
distribute-rgt-out77.3%
associate-/r*77.3%
metadata-eval77.3%
sub-neg77.3%
+-commutative77.3%
Simplified77.6%
Taylor expanded in a around inf 76.7%
*-commutative76.7%
Simplified76.7%
if 7.4999999999999997e-82 < b Initial program 72.0%
div-sub72.0%
sub-neg72.0%
neg-mul-172.0%
*-commutative72.0%
associate-/l*71.9%
distribute-neg-frac71.9%
neg-mul-171.9%
*-commutative71.9%
associate-/l*71.9%
distribute-rgt-out71.9%
associate-/r*71.9%
metadata-eval71.9%
sub-neg71.9%
+-commutative71.9%
Simplified71.9%
Taylor expanded in c around 0 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
Simplified91.1%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(if (<= b -8.2e-114)
(/ (+ c (* a (/ (/ c b) (/ b c)))) (- b))
(if (<= b 6.2e-82)
(* (/ -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.2e-114) {
tmp = (c + (a * ((c / b) / (b / c)))) / -b;
} else if (b <= 6.2e-82) {
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.2d-114)) then
tmp = (c + (a * ((c / b) / (b / c)))) / -b
else if (b <= 6.2d-82) 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.2e-114) {
tmp = (c + (a * ((c / b) / (b / c)))) / -b;
} else if (b <= 6.2e-82) {
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.2e-114: tmp = (c + (a * ((c / b) / (b / c)))) / -b elif b <= 6.2e-82: 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.2e-114) tmp = Float64(Float64(c + Float64(a * Float64(Float64(c / b) / Float64(b / c)))) / Float64(-b)); elseif (b <= 6.2e-82) 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.2e-114) tmp = (c + (a * ((c / b) / (b / c)))) / -b; elseif (b <= 6.2e-82) 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.2e-114], N[(N[(c + N[(a * N[(N[(c / b), $MachinePrecision] / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-b)), $MachinePrecision], If[LessEqual[b, 6.2e-82], 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.2 \cdot 10^{-114}:\\
\;\;\;\;\frac{c + a \cdot \frac{\frac{c}{b}}{\frac{b}{c}}}{-b}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-82}:\\
\;\;\;\;\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.1999999999999993e-114Initial program 12.5%
div-sub12.0%
sub-neg12.0%
neg-mul-112.0%
*-commutative12.0%
associate-/l*10.9%
distribute-neg-frac10.9%
neg-mul-110.9%
*-commutative10.9%
associate-/l*12.0%
distribute-rgt-out12.5%
associate-/r*12.5%
metadata-eval12.5%
sub-neg12.5%
+-commutative12.5%
Simplified12.5%
distribute-lft-in12.0%
associate-*l/11.1%
pow211.1%
Applied egg-rr11.1%
+-commutative11.1%
fma-define8.6%
associate-*r/8.6%
*-commutative8.6%
Simplified8.6%
Taylor expanded in b around -inf 78.4%
associate-*r/78.4%
mul-1-neg78.4%
associate-/l*79.5%
unpow279.5%
unpow279.5%
times-frac90.0%
unpow290.0%
Simplified90.0%
unpow290.0%
clear-num90.0%
un-div-inv90.0%
Applied egg-rr90.0%
if -8.1999999999999993e-114 < b < 6.19999999999999999e-82Initial program 77.3%
div-sub77.3%
sub-neg77.3%
neg-mul-177.3%
*-commutative77.3%
associate-/l*77.2%
distribute-neg-frac77.2%
neg-mul-177.2%
*-commutative77.2%
associate-/l*77.2%
distribute-rgt-out77.3%
associate-/r*77.3%
metadata-eval77.3%
sub-neg77.3%
+-commutative77.3%
Simplified77.6%
Taylor expanded in a around inf 76.7%
*-commutative76.7%
Simplified76.7%
if 6.19999999999999999e-82 < b Initial program 72.0%
div-sub72.0%
sub-neg72.0%
neg-mul-172.0%
*-commutative72.0%
associate-/l*71.9%
distribute-neg-frac71.9%
neg-mul-171.9%
*-commutative71.9%
associate-/l*71.9%
distribute-rgt-out71.9%
associate-/r*71.9%
metadata-eval71.9%
sub-neg71.9%
+-commutative71.9%
Simplified71.9%
Taylor expanded in c around 0 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
Simplified91.1%
Final simplification87.4%
(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 26.1%
div-sub25.7%
sub-neg25.7%
neg-mul-125.7%
*-commutative25.7%
associate-/l*24.8%
distribute-neg-frac24.8%
neg-mul-124.8%
*-commutative24.8%
associate-/l*25.7%
distribute-rgt-out26.2%
associate-/r*26.2%
metadata-eval26.2%
sub-neg26.2%
+-commutative26.2%
Simplified26.3%
Taylor expanded in b around -inf 73.5%
mul-1-neg73.5%
distribute-neg-frac273.5%
Simplified73.5%
if -3.999999999999988e-310 < b Initial program 73.4%
div-sub73.4%
sub-neg73.4%
neg-mul-173.4%
*-commutative73.4%
associate-/l*73.3%
distribute-neg-frac73.3%
neg-mul-173.3%
*-commutative73.3%
associate-/l*73.2%
distribute-rgt-out73.2%
associate-/r*73.2%
metadata-eval73.2%
sub-neg73.2%
+-commutative73.2%
Simplified73.2%
Taylor expanded in c around 0 72.5%
+-commutative72.5%
mul-1-neg72.5%
unsub-neg72.5%
Simplified72.5%
(FPCore (a b c) :precision binary64 (if (<= b -5.1e-305) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.1e-305) {
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 <= (-5.1d-305)) 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 <= -5.1e-305) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.1e-305: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.1e-305) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.1e-305) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.1e-305], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.1 \cdot 10^{-305}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -5.09999999999999959e-305Initial program 26.3%
div-sub25.9%
sub-neg25.9%
neg-mul-125.9%
*-commutative25.9%
associate-/l*25.0%
distribute-neg-frac25.0%
neg-mul-125.0%
*-commutative25.0%
associate-/l*25.9%
distribute-rgt-out26.3%
associate-/r*26.3%
metadata-eval26.3%
sub-neg26.3%
+-commutative26.3%
Simplified26.5%
Taylor expanded in b around -inf 74.1%
mul-1-neg74.1%
distribute-neg-frac274.1%
Simplified74.1%
if -5.09999999999999959e-305 < b Initial program 72.8%
div-sub72.8%
sub-neg72.8%
neg-mul-172.8%
*-commutative72.8%
associate-/l*72.8%
distribute-neg-frac72.8%
neg-mul-172.8%
*-commutative72.8%
associate-/l*72.7%
distribute-rgt-out72.7%
associate-/r*72.7%
metadata-eval72.7%
sub-neg72.7%
+-commutative72.7%
Simplified72.7%
Taylor expanded in a around 0 71.8%
associate-*r/71.8%
mul-1-neg71.8%
Simplified71.8%
Final simplification72.9%
(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 49.0%
div-sub48.8%
sub-neg48.8%
neg-mul-148.8%
*-commutative48.8%
associate-/l*48.3%
distribute-neg-frac48.3%
neg-mul-148.3%
*-commutative48.3%
associate-/l*48.7%
distribute-rgt-out49.0%
associate-/r*49.0%
metadata-eval49.0%
sub-neg49.0%
+-commutative49.0%
Simplified49.0%
Taylor expanded in b around -inf 39.0%
mul-1-neg39.0%
distribute-neg-frac239.0%
Simplified39.0%
(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 49.0%
div-sub48.8%
sub-neg48.8%
neg-mul-148.8%
*-commutative48.8%
associate-/l*48.3%
distribute-neg-frac48.3%
neg-mul-148.3%
*-commutative48.3%
associate-/l*48.7%
distribute-rgt-out49.0%
associate-/r*49.0%
metadata-eval49.0%
sub-neg49.0%
+-commutative49.0%
Simplified49.0%
Taylor expanded in b around -inf 9.5%
mul-1-neg9.5%
Simplified9.5%
Taylor expanded in a around 0 9.5%
(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 2024172
(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)))