
(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 -2.75e-124)
(/ c (- b))
(if (<= b 2.4e-11)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/
(-
(- b)
(* b (sqrt (fma -4.0 (pow (cbrt (* c (* a (pow b -2.0)))) 3.0) 1.0))))
(* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.75e-124) {
tmp = c / -b;
} else if (b <= 2.4e-11) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (-b - (b * sqrt(fma(-4.0, pow(cbrt((c * (a * pow(b, -2.0)))), 3.0), 1.0)))) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -2.75e-124) tmp = Float64(c / Float64(-b)); elseif (b <= 2.4e-11) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-b) - Float64(b * sqrt(fma(-4.0, (cbrt(Float64(c * Float64(a * (b ^ -2.0)))) ^ 3.0), 1.0)))) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -2.75e-124], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.4e-11], 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[((-b) - N[(b * N[Sqrt[N[(-4.0 * N[Power[N[Power[N[(c * N[(a * N[Power[b, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.75 \cdot 10^{-124}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-11}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b \cdot \sqrt{\mathsf{fma}\left(-4, {\left(\sqrt[3]{c \cdot \left(a \cdot {b}^{-2}\right)}\right)}^{3}, 1\right)}}{a \cdot 2}\\
\end{array}
\end{array}
if b < -2.75000000000000008e-124Initial program 19.6%
div-sub19.3%
sub-neg19.3%
neg-mul-119.3%
*-commutative19.3%
associate-/l*18.3%
distribute-neg-frac18.3%
neg-mul-118.3%
*-commutative18.3%
associate-/l*19.3%
distribute-rgt-out19.6%
associate-/r*19.6%
metadata-eval19.6%
sub-neg19.6%
+-commutative19.6%
Simplified19.7%
Taylor expanded in b around -inf 77.3%
mul-1-neg77.3%
distribute-neg-frac277.3%
Simplified77.3%
if -2.75000000000000008e-124 < b < 2.4000000000000001e-11Initial program 76.1%
if 2.4000000000000001e-11 < b Initial program 68.7%
*-commutative68.7%
*-commutative68.7%
sqr-neg68.7%
*-commutative68.7%
sqr-neg68.7%
*-commutative68.7%
associate-*r*68.7%
Simplified68.7%
Taylor expanded in b around inf 68.6%
associate-/l*68.7%
Simplified68.7%
sqrt-prod70.1%
sqrt-pow198.6%
metadata-eval98.6%
pow198.6%
+-commutative98.6%
fma-define98.6%
associate-*r/94.3%
div-inv94.3%
pow-flip94.3%
metadata-eval94.3%
Applied egg-rr94.3%
associate-*l*98.6%
Simplified98.6%
add-cube-cbrt98.6%
pow398.6%
associate-*r*94.3%
*-commutative94.3%
associate-*l*98.6%
Applied egg-rr98.6%
Final simplification82.8%
(FPCore (a b c)
:precision binary64
(if (<= b -2.75e-124)
(/ c (- b))
(if (<= b 2.3e+33)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/
(- (- b) (* b (sqrt (fma -4.0 (* a (* c (pow b -2.0))) 1.0))))
(* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.75e-124) {
tmp = c / -b;
} else if (b <= 2.3e+33) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (-b - (b * sqrt(fma(-4.0, (a * (c * pow(b, -2.0))), 1.0)))) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -2.75e-124) tmp = Float64(c / Float64(-b)); elseif (b <= 2.3e+33) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-b) - Float64(b * sqrt(fma(-4.0, Float64(a * Float64(c * (b ^ -2.0))), 1.0)))) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -2.75e-124], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.3e+33], 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[((-b) - N[(b * N[Sqrt[N[(-4.0 * N[(a * N[(c * N[Power[b, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.75 \cdot 10^{-124}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{+33}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b \cdot \sqrt{\mathsf{fma}\left(-4, a \cdot \left(c \cdot {b}^{-2}\right), 1\right)}}{a \cdot 2}\\
\end{array}
\end{array}
if b < -2.75000000000000008e-124Initial program 19.6%
div-sub19.3%
sub-neg19.3%
neg-mul-119.3%
*-commutative19.3%
associate-/l*18.3%
distribute-neg-frac18.3%
neg-mul-118.3%
*-commutative18.3%
associate-/l*19.3%
distribute-rgt-out19.6%
associate-/r*19.6%
metadata-eval19.6%
sub-neg19.6%
+-commutative19.6%
Simplified19.7%
Taylor expanded in b around -inf 77.3%
mul-1-neg77.3%
distribute-neg-frac277.3%
Simplified77.3%
if -2.75000000000000008e-124 < b < 2.30000000000000011e33Initial program 78.7%
if 2.30000000000000011e33 < b Initial program 64.1%
*-commutative64.1%
*-commutative64.1%
sqr-neg64.1%
*-commutative64.1%
sqr-neg64.1%
*-commutative64.1%
associate-*r*64.1%
Simplified64.1%
Taylor expanded in b around inf 64.0%
associate-/l*64.1%
Simplified64.1%
sqrt-prod65.7%
sqrt-pow198.4%
metadata-eval98.4%
pow198.4%
+-commutative98.4%
fma-define98.4%
associate-*r/93.5%
div-inv93.5%
pow-flip93.5%
metadata-eval93.5%
Applied egg-rr93.5%
associate-*l*98.4%
Simplified98.4%
Final simplification82.8%
(FPCore (a b c)
:precision binary64
(if (<= b -2.75e-124)
(/ c (- b))
(if (<= b 2.6e+120)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.75e-124) {
tmp = c / -b;
} else if (b <= 2.6e+120) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.75d-124)) then
tmp = c / -b
else if (b <= 2.6d+120) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.75e-124) {
tmp = c / -b;
} else if (b <= 2.6e+120) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.75e-124: tmp = c / -b elif b <= 2.6e+120: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.75e-124) tmp = Float64(c / Float64(-b)); elseif (b <= 2.6e+120) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.75e-124) tmp = c / -b; elseif (b <= 2.6e+120) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.75e-124], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.6e+120], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.75 \cdot 10^{-124}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{+120}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -2.75000000000000008e-124Initial program 19.6%
div-sub19.3%
sub-neg19.3%
neg-mul-119.3%
*-commutative19.3%
associate-/l*18.3%
distribute-neg-frac18.3%
neg-mul-118.3%
*-commutative18.3%
associate-/l*19.3%
distribute-rgt-out19.6%
associate-/r*19.6%
metadata-eval19.6%
sub-neg19.6%
+-commutative19.6%
Simplified19.7%
Taylor expanded in b around -inf 77.3%
mul-1-neg77.3%
distribute-neg-frac277.3%
Simplified77.3%
if -2.75000000000000008e-124 < b < 2.5999999999999999e120Initial program 82.2%
if 2.5999999999999999e120 < b Initial program 47.7%
div-sub47.7%
sub-neg47.7%
neg-mul-147.7%
*-commutative47.7%
associate-/l*47.6%
distribute-neg-frac47.6%
neg-mul-147.6%
*-commutative47.6%
associate-/l*47.6%
distribute-rgt-out47.6%
associate-/r*47.6%
metadata-eval47.6%
sub-neg47.6%
+-commutative47.6%
Simplified47.7%
Taylor expanded in a around 0 97.7%
associate-*r/97.7%
mul-1-neg97.7%
Simplified97.7%
Final simplification82.4%
(FPCore (a b c)
:precision binary64
(if (<= b -2.75e-124)
(/ c (- b))
(if (<= b 6.4e-105)
(/ (+ 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 <= -2.75e-124) {
tmp = c / -b;
} else if (b <= 6.4e-105) {
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 <= (-2.75d-124)) then
tmp = c / -b
else if (b <= 6.4d-105) 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 <= -2.75e-124) {
tmp = c / -b;
} else if (b <= 6.4e-105) {
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 <= -2.75e-124: tmp = c / -b elif b <= 6.4e-105: 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 <= -2.75e-124) tmp = Float64(c / Float64(-b)); elseif (b <= 6.4e-105) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / Float64(a * -2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.75e-124) tmp = c / -b; elseif (b <= 6.4e-105) 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, -2.75e-124], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 6.4e-105], 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 -2.75 \cdot 10^{-124}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 6.4 \cdot 10^{-105}:\\
\;\;\;\;\frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.75000000000000008e-124Initial program 19.6%
div-sub19.3%
sub-neg19.3%
neg-mul-119.3%
*-commutative19.3%
associate-/l*18.3%
distribute-neg-frac18.3%
neg-mul-118.3%
*-commutative18.3%
associate-/l*19.3%
distribute-rgt-out19.6%
associate-/r*19.6%
metadata-eval19.6%
sub-neg19.6%
+-commutative19.6%
Simplified19.7%
Taylor expanded in b around -inf 77.3%
mul-1-neg77.3%
distribute-neg-frac277.3%
Simplified77.3%
if -2.75000000000000008e-124 < b < 6.39999999999999962e-105Initial program 71.0%
*-commutative71.0%
*-commutative71.0%
sqr-neg71.0%
*-commutative71.0%
sqr-neg71.0%
*-commutative71.0%
associate-*r*71.0%
Simplified71.0%
Taylor expanded in b around 0 69.5%
associate-*r*69.5%
*-commutative69.5%
Simplified69.5%
frac-2neg69.5%
distribute-frac-neg269.5%
Applied egg-rr69.5%
distribute-neg-frac269.5%
associate-*r*69.5%
*-commutative69.5%
associate-*r*69.5%
*-commutative69.5%
distribute-rgt-neg-in69.5%
metadata-eval69.5%
Simplified69.5%
if 6.39999999999999962e-105 < b Initial program 73.3%
div-sub73.3%
sub-neg73.3%
neg-mul-173.3%
*-commutative73.3%
associate-/l*73.2%
distribute-neg-frac73.2%
neg-mul-173.2%
*-commutative73.2%
associate-/l*73.0%
distribute-rgt-out73.0%
associate-/r*73.0%
metadata-eval73.0%
sub-neg73.0%
+-commutative73.0%
Simplified73.1%
Taylor expanded in c around 0 91.0%
+-commutative91.0%
mul-1-neg91.0%
unsub-neg91.0%
Simplified91.0%
Final simplification80.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.7e-124)
(/ c (- b))
(if (<= b 2.55e-110)
(* (+ b (sqrt (* c (* a -4.0)))) (/ -0.5 a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.7e-124) {
tmp = c / -b;
} else if (b <= 2.55e-110) {
tmp = (b + sqrt((c * (a * -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 <= (-2.7d-124)) then
tmp = c / -b
else if (b <= 2.55d-110) then
tmp = (b + sqrt((c * (a * (-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 <= -2.7e-124) {
tmp = c / -b;
} else if (b <= 2.55e-110) {
tmp = (b + Math.sqrt((c * (a * -4.0)))) * (-0.5 / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.7e-124: tmp = c / -b elif b <= 2.55e-110: tmp = (b + math.sqrt((c * (a * -4.0)))) * (-0.5 / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.7e-124) tmp = Float64(c / Float64(-b)); elseif (b <= 2.55e-110) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -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 <= -2.7e-124) tmp = c / -b; elseif (b <= 2.55e-110) tmp = (b + sqrt((c * (a * -4.0)))) * (-0.5 / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.7e-124], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.55e-110], N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.7 \cdot 10^{-124}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.55 \cdot 10^{-110}:\\
\;\;\;\;\left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.70000000000000018e-124Initial program 19.6%
div-sub19.3%
sub-neg19.3%
neg-mul-119.3%
*-commutative19.3%
associate-/l*18.3%
distribute-neg-frac18.3%
neg-mul-118.3%
*-commutative18.3%
associate-/l*19.3%
distribute-rgt-out19.6%
associate-/r*19.6%
metadata-eval19.6%
sub-neg19.6%
+-commutative19.6%
Simplified19.7%
Taylor expanded in b around -inf 77.3%
mul-1-neg77.3%
distribute-neg-frac277.3%
Simplified77.3%
if -2.70000000000000018e-124 < b < 2.5500000000000001e-110Initial program 71.0%
*-commutative71.0%
*-commutative71.0%
sqr-neg71.0%
*-commutative71.0%
sqr-neg71.0%
*-commutative71.0%
associate-*r*71.0%
Simplified71.0%
Taylor expanded in b around 0 69.5%
associate-*r*69.5%
*-commutative69.5%
Simplified69.5%
*-un-lft-identity69.5%
frac-2neg69.5%
div-inv69.4%
Applied egg-rr69.4%
*-lft-identity69.4%
*-commutative69.4%
associate-*r*69.4%
*-commutative69.4%
associate-*r*69.4%
*-commutative69.4%
Simplified69.4%
if 2.5500000000000001e-110 < b Initial program 73.3%
div-sub73.3%
sub-neg73.3%
neg-mul-173.3%
*-commutative73.3%
associate-/l*73.2%
distribute-neg-frac73.2%
neg-mul-173.2%
*-commutative73.2%
associate-/l*73.0%
distribute-rgt-out73.0%
associate-/r*73.0%
metadata-eval73.0%
sub-neg73.0%
+-commutative73.0%
Simplified73.1%
Taylor expanded in c around 0 91.0%
+-commutative91.0%
mul-1-neg91.0%
unsub-neg91.0%
Simplified91.0%
Final simplification80.2%
(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(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 <= -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.9%
div-sub29.6%
sub-neg29.6%
neg-mul-129.6%
*-commutative29.6%
associate-/l*28.8%
distribute-neg-frac28.8%
neg-mul-128.8%
*-commutative28.8%
associate-/l*29.6%
distribute-rgt-out29.8%
associate-/r*29.9%
metadata-eval29.9%
sub-neg29.9%
+-commutative29.9%
Simplified29.9%
Taylor expanded in b around -inf 63.0%
mul-1-neg63.0%
distribute-neg-frac263.0%
Simplified63.0%
if -1.999999999999994e-310 < b Initial program 72.5%
div-sub72.5%
sub-neg72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.4%
distribute-neg-frac72.4%
neg-mul-172.4%
*-commutative72.4%
associate-/l*72.3%
distribute-rgt-out72.3%
associate-/r*72.3%
metadata-eval72.3%
sub-neg72.3%
+-commutative72.3%
Simplified72.3%
Taylor expanded in c around 0 73.9%
+-commutative73.9%
mul-1-neg73.9%
unsub-neg73.9%
Simplified73.9%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
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 <= (-2d-310)) 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 <= -2e-310) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) 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 <= -2e-310) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 29.9%
div-sub29.6%
sub-neg29.6%
neg-mul-129.6%
*-commutative29.6%
associate-/l*28.8%
distribute-neg-frac28.8%
neg-mul-128.8%
*-commutative28.8%
associate-/l*29.6%
distribute-rgt-out29.8%
associate-/r*29.9%
metadata-eval29.9%
sub-neg29.9%
+-commutative29.9%
Simplified29.9%
Taylor expanded in b around -inf 63.0%
mul-1-neg63.0%
distribute-neg-frac263.0%
Simplified63.0%
if -1.999999999999994e-310 < b Initial program 72.5%
div-sub72.5%
sub-neg72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.4%
distribute-neg-frac72.4%
neg-mul-172.4%
*-commutative72.4%
associate-/l*72.3%
distribute-rgt-out72.3%
associate-/r*72.3%
metadata-eval72.3%
sub-neg72.3%
+-commutative72.3%
Simplified72.3%
Taylor expanded in a around 0 73.5%
associate-*r/73.5%
mul-1-neg73.5%
Simplified73.5%
Final simplification67.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(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 48.7%
div-sub48.5%
sub-neg48.5%
neg-mul-148.5%
*-commutative48.5%
associate-/l*48.0%
distribute-neg-frac48.0%
neg-mul-148.0%
*-commutative48.0%
associate-/l*48.4%
distribute-rgt-out48.6%
associate-/r*48.6%
metadata-eval48.6%
sub-neg48.6%
+-commutative48.6%
Simplified48.6%
Taylor expanded in b around -inf 36.3%
mul-1-neg36.3%
distribute-neg-frac236.3%
Simplified36.3%
(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 48.7%
*-commutative48.7%
*-commutative48.7%
sqr-neg48.7%
*-commutative48.7%
sqr-neg48.7%
*-commutative48.7%
associate-*r*48.7%
Simplified48.7%
Taylor expanded in c around 0 32.9%
distribute-lft-out--32.9%
associate-/l*33.8%
Simplified33.8%
Taylor expanded in a around inf 9.3%
(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 2024099
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(if (< b 0.0) (/ c (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0))) (/ (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (- a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))