
(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 (- 2.0))))
(if (<= b -2.1e-40)
(/ c (- b))
(if (<= b 2.4e-53)
(/ (+ b (sqrt (- (* b b) (* (* c 4.0) a)))) t_0)
(/
(+ b (fabs (* b (sqrt (fma -4.0 (* a (* c (pow b -2.0))) 1.0)))))
t_0)))))
double code(double a, double b, double c) {
double t_0 = a * -2.0;
double tmp;
if (b <= -2.1e-40) {
tmp = c / -b;
} else if (b <= 2.4e-53) {
tmp = (b + sqrt(((b * b) - ((c * 4.0) * a)))) / t_0;
} else {
tmp = (b + fabs((b * sqrt(fma(-4.0, (a * (c * pow(b, -2.0))), 1.0))))) / t_0;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(a * Float64(-2.0)) tmp = 0.0 if (b <= -2.1e-40) tmp = Float64(c / Float64(-b)); elseif (b <= 2.4e-53) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / t_0); else tmp = Float64(Float64(b + abs(Float64(b * sqrt(fma(-4.0, Float64(a * Float64(c * (b ^ -2.0))), 1.0))))) / t_0); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * (-2.0)), $MachinePrecision]}, If[LessEqual[b, -2.1e-40], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.4e-53], N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * 4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(b + N[Abs[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]), $MachinePrecision] / t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(-2\right)\\
\mathbf{if}\;b \leq -2.1 \cdot 10^{-40}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-53}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + \left|b \cdot \sqrt{\mathsf{fma}\left(-4, a \cdot \left(c \cdot {b}^{-2}\right), 1\right)}\right|}{t\_0}\\
\end{array}
\end{array}
if b < -2.10000000000000018e-40Initial program 13.7%
div-sub13.1%
sub-neg13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*11.8%
distribute-neg-frac11.8%
neg-mul-111.8%
*-commutative11.8%
associate-/l*13.1%
distribute-rgt-out13.6%
associate-/r*13.6%
metadata-eval13.6%
sub-neg13.6%
+-commutative13.6%
Simplified13.6%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
distribute-neg-frac287.5%
Simplified87.5%
if -2.10000000000000018e-40 < b < 2.40000000000000007e-53Initial program 74.3%
*-commutative74.3%
*-commutative74.3%
sqr-neg74.3%
*-commutative74.3%
sqr-neg74.3%
*-commutative74.3%
associate-*r*74.4%
Simplified74.4%
if 2.40000000000000007e-53 < b Initial 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 inf 71.0%
associate-/l*71.1%
Simplified71.1%
add-sqr-sqrt71.1%
rem-sqrt-square71.1%
sqrt-prod72.2%
sqrt-pow195.9%
metadata-eval95.9%
pow195.9%
+-commutative95.9%
fma-define95.9%
div-inv95.9%
pow-flip95.9%
metadata-eval95.9%
Applied egg-rr95.9%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -2.4e-38)
(/ c (- b))
(if (<= b 2e+87)
(/ (+ 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.4e-38) {
tmp = c / -b;
} else if (b <= 2e+87) {
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.4d-38)) then
tmp = c / -b
else if (b <= 2d+87) 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.4e-38) {
tmp = c / -b;
} else if (b <= 2e+87) {
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.4e-38: tmp = c / -b elif b <= 2e+87: 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.4e-38) tmp = Float64(c / Float64(-b)); elseif (b <= 2e+87) tmp = Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(c * 4.0) * a)))) / Float64(a * Float64(-2.0))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.4e-38) tmp = c / -b; elseif (b <= 2e+87) 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.4e-38], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2e+87], 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.4 \cdot 10^{-38}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+87}:\\
\;\;\;\;\frac{b + \sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a}}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.40000000000000022e-38Initial program 13.7%
div-sub13.1%
sub-neg13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*11.8%
distribute-neg-frac11.8%
neg-mul-111.8%
*-commutative11.8%
associate-/l*13.1%
distribute-rgt-out13.6%
associate-/r*13.6%
metadata-eval13.6%
sub-neg13.6%
+-commutative13.6%
Simplified13.6%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
distribute-neg-frac287.5%
Simplified87.5%
if -2.40000000000000022e-38 < b < 1.9999999999999999e87Initial program 79.0%
*-commutative79.0%
*-commutative79.0%
sqr-neg79.0%
*-commutative79.0%
sqr-neg79.0%
*-commutative79.0%
associate-*r*79.1%
Simplified79.1%
if 1.9999999999999999e87 < b Initial program 59.5%
div-sub59.5%
sub-neg59.5%
neg-mul-159.5%
*-commutative59.5%
associate-/l*59.5%
distribute-neg-frac59.5%
neg-mul-159.5%
*-commutative59.5%
associate-/l*59.5%
distribute-rgt-out59.5%
associate-/r*59.5%
metadata-eval59.5%
sub-neg59.5%
+-commutative59.5%
Simplified59.6%
Taylor expanded in c around 0 98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
Simplified98.4%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -4.4e-40)
(/ c (- b))
(if (<= b 1.15e+87)
(/ (- (- 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 <= -4.4e-40) {
tmp = c / -b;
} else if (b <= 1.15e+87) {
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 <= (-4.4d-40)) then
tmp = c / -b
else if (b <= 1.15d+87) 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 <= -4.4e-40) {
tmp = c / -b;
} else if (b <= 1.15e+87) {
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 <= -4.4e-40: tmp = c / -b elif b <= 1.15e+87: 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 <= -4.4e-40) tmp = Float64(c / Float64(-b)); elseif (b <= 1.15e+87) 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 <= -4.4e-40) tmp = c / -b; elseif (b <= 1.15e+87) 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, -4.4e-40], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.15e+87], 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 -4.4 \cdot 10^{-40}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{+87}:\\
\;\;\;\;\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 < -4.40000000000000018e-40Initial program 13.7%
div-sub13.1%
sub-neg13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*11.8%
distribute-neg-frac11.8%
neg-mul-111.8%
*-commutative11.8%
associate-/l*13.1%
distribute-rgt-out13.6%
associate-/r*13.6%
metadata-eval13.6%
sub-neg13.6%
+-commutative13.6%
Simplified13.6%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
distribute-neg-frac287.5%
Simplified87.5%
if -4.40000000000000018e-40 < b < 1.1500000000000001e87Initial program 79.0%
if 1.1500000000000001e87 < b Initial program 59.5%
div-sub59.5%
sub-neg59.5%
neg-mul-159.5%
*-commutative59.5%
associate-/l*59.5%
distribute-neg-frac59.5%
neg-mul-159.5%
*-commutative59.5%
associate-/l*59.5%
distribute-rgt-out59.5%
associate-/r*59.5%
metadata-eval59.5%
sub-neg59.5%
+-commutative59.5%
Simplified59.6%
Taylor expanded in c around 0 98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
Simplified98.4%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -3.6e-37)
(/ c (- b))
(if (<= b 1.9e-52)
(/ (- (- 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 <= -3.6e-37) {
tmp = c / -b;
} else if (b <= 1.9e-52) {
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 <= (-3.6d-37)) then
tmp = c / -b
else if (b <= 1.9d-52) 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 <= -3.6e-37) {
tmp = c / -b;
} else if (b <= 1.9e-52) {
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 <= -3.6e-37: tmp = c / -b elif b <= 1.9e-52: 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 <= -3.6e-37) tmp = Float64(c / Float64(-b)); elseif (b <= 1.9e-52) tmp = Float64(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 <= -3.6e-37) tmp = c / -b; elseif (b <= 1.9e-52) 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, -3.6e-37], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.9e-52], 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 -3.6 \cdot 10^{-37}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-52}:\\
\;\;\;\;\frac{\left(-b\right) - \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 < -3.60000000000000007e-37Initial program 13.7%
div-sub13.1%
sub-neg13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*11.8%
distribute-neg-frac11.8%
neg-mul-111.8%
*-commutative11.8%
associate-/l*13.1%
distribute-rgt-out13.6%
associate-/r*13.6%
metadata-eval13.6%
sub-neg13.6%
+-commutative13.6%
Simplified13.6%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
distribute-neg-frac287.5%
Simplified87.5%
if -3.60000000000000007e-37 < b < 1.9000000000000002e-52Initial program 74.6%
*-commutative74.6%
*-commutative74.6%
sqr-neg74.6%
*-commutative74.6%
sqr-neg74.6%
*-commutative74.6%
associate-*r*74.7%
Simplified74.7%
Taylor expanded in b around 0 71.0%
associate-*r*71.0%
*-commutative71.0%
Simplified71.0%
if 1.9000000000000002e-52 < b Initial program 70.8%
div-sub70.8%
sub-neg70.8%
neg-mul-170.8%
*-commutative70.8%
associate-/l*70.8%
distribute-neg-frac70.8%
neg-mul-170.8%
*-commutative70.8%
associate-/l*70.6%
distribute-rgt-out70.6%
associate-/r*70.6%
metadata-eval70.6%
sub-neg70.6%
+-commutative70.6%
Simplified70.7%
Taylor expanded in c around 0 87.2%
+-commutative87.2%
mul-1-neg87.2%
unsub-neg87.2%
Simplified87.2%
Final simplification82.1%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
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 <= (-1d-309)) 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 <= -1e-309) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) 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 <= -1e-309) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[(c / (-b)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 35.5%
div-sub35.1%
sub-neg35.1%
neg-mul-135.1%
*-commutative35.1%
associate-/l*34.3%
distribute-neg-frac34.3%
neg-mul-134.3%
*-commutative34.3%
associate-/l*35.0%
distribute-rgt-out35.4%
associate-/r*35.4%
metadata-eval35.4%
sub-neg35.4%
+-commutative35.4%
Simplified35.4%
Taylor expanded in b around -inf 63.9%
mul-1-neg63.9%
distribute-neg-frac263.9%
Simplified63.9%
if -1.000000000000002e-309 < b Initial program 71.6%
div-sub71.6%
sub-neg71.6%
neg-mul-171.6%
*-commutative71.6%
associate-/l*71.6%
distribute-neg-frac71.6%
neg-mul-171.6%
*-commutative71.6%
associate-/l*71.4%
distribute-rgt-out71.4%
associate-/r*71.4%
metadata-eval71.4%
sub-neg71.4%
+-commutative71.4%
Simplified71.5%
Taylor expanded in c around 0 66.4%
+-commutative66.4%
mul-1-neg66.4%
unsub-neg66.4%
Simplified66.4%
(FPCore (a b c) :precision binary64 (if (<= b -3.2e-308) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-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 <= (-3.2d-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 <= -3.2e-308) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.2e-308: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.2e-308) 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 <= -3.2e-308) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.2e-308], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.2 \cdot 10^{-308}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -3.2000000000000001e-308Initial program 34.9%
div-sub34.6%
sub-neg34.6%
neg-mul-134.6%
*-commutative34.6%
associate-/l*33.7%
distribute-neg-frac33.7%
neg-mul-133.7%
*-commutative33.7%
associate-/l*34.5%
distribute-rgt-out34.8%
associate-/r*34.8%
metadata-eval34.8%
sub-neg34.8%
+-commutative34.8%
Simplified34.9%
Taylor expanded in b around -inf 64.4%
mul-1-neg64.4%
distribute-neg-frac264.4%
Simplified64.4%
if -3.2000000000000001e-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.6%
distribute-rgt-out71.6%
associate-/r*71.6%
metadata-eval71.6%
sub-neg71.6%
+-commutative71.6%
Simplified71.7%
Taylor expanded in a around 0 65.6%
associate-*r/65.6%
mul-1-neg65.6%
Simplified65.6%
Final simplification65.0%
(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 54.4%
div-sub54.2%
sub-neg54.2%
neg-mul-154.2%
*-commutative54.2%
associate-/l*53.8%
distribute-neg-frac53.8%
neg-mul-153.8%
*-commutative53.8%
associate-/l*54.1%
distribute-rgt-out54.2%
associate-/r*54.2%
metadata-eval54.2%
sub-neg54.2%
+-commutative54.2%
Simplified54.3%
Taylor expanded in b around -inf 31.6%
mul-1-neg31.6%
distribute-neg-frac231.6%
Simplified31.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 / 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 54.4%
div-sub54.2%
sub-neg54.2%
neg-mul-154.2%
*-commutative54.2%
associate-/l*53.8%
distribute-neg-frac53.8%
neg-mul-153.8%
*-commutative53.8%
associate-/l*54.1%
distribute-rgt-out54.2%
associate-/r*54.2%
metadata-eval54.2%
sub-neg54.2%
+-commutative54.2%
Simplified54.3%
Taylor expanded in a around 0 34.4%
Taylor expanded in b around 0 13.3%
(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 54.4%
div-sub54.2%
sub-neg54.2%
neg-mul-154.2%
*-commutative54.2%
associate-/l*53.8%
distribute-neg-frac53.8%
neg-mul-153.8%
*-commutative53.8%
associate-/l*54.1%
distribute-rgt-out54.2%
associate-/r*54.2%
metadata-eval54.2%
sub-neg54.2%
+-commutative54.2%
Simplified54.3%
Applied egg-rr35.6%
Taylor expanded in b around -inf 2.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 2024106
(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)))