
(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 -1.02e-101)
(/ 1.0 (/ (fabs (- b (* a (/ c b)))) c))
(if (<= b 2.3e-11)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.02e-101) {
tmp = 1.0 / (fabs((b - (a * (c / b)))) / c);
} else if (b <= 2.3e-11) {
tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (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 <= (-1.02d-101)) then
tmp = 1.0d0 / (abs((b - (a * (c / b)))) / c)
else if (b <= 2.3d-11) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (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 <= -1.02e-101) {
tmp = 1.0 / (Math.abs((b - (a * (c / b)))) / c);
} else if (b <= 2.3e-11) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.02e-101: tmp = 1.0 / (math.fabs((b - (a * (c / b)))) / c) elif b <= 2.3e-11: tmp = (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.02e-101) tmp = Float64(1.0 / Float64(abs(Float64(b - Float64(a * Float64(c / b)))) / c)); elseif (b <= 2.3e-11) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / 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 <= -1.02e-101) tmp = 1.0 / (abs((b - (a * (c / b)))) / c); elseif (b <= 2.3e-11) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (a * 2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.02e-101], N[(1.0 / N[(N[Abs[N[(b - N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.3e-11], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $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 -1.02 \cdot 10^{-101}:\\
\;\;\;\;\frac{1}{\frac{\left|b - a \cdot \frac{c}{b}\right|}{c}}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-11}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.02e-101Initial program 22.9%
div-sub20.4%
sub-neg20.4%
neg-mul-120.4%
*-commutative20.4%
associate-/l*20.2%
distribute-neg-frac20.2%
neg-mul-120.2%
*-commutative20.2%
associate-/l*20.5%
distribute-rgt-out22.9%
associate-/r*22.9%
metadata-eval22.9%
sub-neg22.9%
+-commutative22.9%
Simplified22.9%
Applied egg-rr17.6%
Taylor expanded in c around 0 20.4%
mul-1-neg20.4%
unsub-neg20.4%
associate-*r/20.3%
Simplified20.3%
add-sqr-sqrt0.0%
sqrt-unprod56.3%
pow256.3%
Applied egg-rr56.3%
unpow256.3%
rem-sqrt-square81.9%
Simplified81.9%
if -1.02e-101 < b < 2.30000000000000014e-11Initial program 86.4%
if 2.30000000000000014e-11 < b Initial program 59.5%
div-sub59.5%
sub-neg59.5%
neg-mul-159.5%
*-commutative59.5%
associate-/l*59.4%
distribute-neg-frac59.4%
neg-mul-159.4%
*-commutative59.4%
associate-/l*59.3%
distribute-rgt-out59.3%
associate-/r*59.3%
metadata-eval59.3%
sub-neg59.3%
+-commutative59.3%
Simplified59.4%
Taylor expanded in a around 0 94.3%
associate-*r/94.3%
mul-1-neg94.3%
Simplified94.3%
Final simplification87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.25e-101)
(/ 1.0 (/ (fabs (- b (* a (/ c b)))) c))
(if (<= b 3.8e-128)
(/ (+ 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.25e-101) {
tmp = 1.0 / (fabs((b - (a * (c / b)))) / c);
} else if (b <= 3.8e-128) {
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.25d-101)) then
tmp = 1.0d0 / (abs((b - (a * (c / b)))) / c)
else if (b <= 3.8d-128) 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.25e-101) {
tmp = 1.0 / (Math.abs((b - (a * (c / b)))) / c);
} else if (b <= 3.8e-128) {
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.25e-101: tmp = 1.0 / (math.fabs((b - (a * (c / b)))) / c) elif b <= 3.8e-128: 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.25e-101) tmp = Float64(1.0 / Float64(abs(Float64(b - Float64(a * Float64(c / b)))) / c)); elseif (b <= 3.8e-128) 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 <= -1.25e-101) tmp = 1.0 / (abs((b - (a * (c / b)))) / c); elseif (b <= 3.8e-128) 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.25e-101], N[(1.0 / N[(N[Abs[N[(b - N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.8e-128], 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.25 \cdot 10^{-101}:\\
\;\;\;\;\frac{1}{\frac{\left|b - a \cdot \frac{c}{b}\right|}{c}}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-128}:\\
\;\;\;\;\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 < -1.25e-101Initial program 22.9%
div-sub20.4%
sub-neg20.4%
neg-mul-120.4%
*-commutative20.4%
associate-/l*20.2%
distribute-neg-frac20.2%
neg-mul-120.2%
*-commutative20.2%
associate-/l*20.5%
distribute-rgt-out22.9%
associate-/r*22.9%
metadata-eval22.9%
sub-neg22.9%
+-commutative22.9%
Simplified22.9%
Applied egg-rr17.6%
Taylor expanded in c around 0 20.4%
mul-1-neg20.4%
unsub-neg20.4%
associate-*r/20.3%
Simplified20.3%
add-sqr-sqrt0.0%
sqrt-unprod56.3%
pow256.3%
Applied egg-rr56.3%
unpow256.3%
rem-sqrt-square81.9%
Simplified81.9%
if -1.25e-101 < b < 3.8000000000000002e-128Initial program 82.7%
div-sub82.7%
sub-neg82.7%
neg-mul-182.7%
*-commutative82.7%
associate-/l*82.7%
distribute-neg-frac82.7%
neg-mul-182.7%
*-commutative82.7%
associate-/l*82.7%
distribute-rgt-out82.7%
associate-/r*82.7%
metadata-eval82.7%
sub-neg82.7%
+-commutative82.7%
Simplified82.7%
Taylor expanded in a around inf 79.5%
*-commutative79.5%
Simplified79.5%
pow1/279.5%
associate-*l*79.5%
unpow-prod-down45.1%
pow1/245.1%
Applied egg-rr45.1%
unpow1/245.1%
Simplified45.1%
clear-num45.1%
associate-*l/45.1%
*-un-lft-identity45.1%
sqrt-unprod79.6%
*-commutative79.6%
associate-*r*79.6%
div-inv79.6%
metadata-eval79.6%
Applied egg-rr79.6%
if 3.8000000000000002e-128 < b Initial program 67.9%
div-sub67.9%
sub-neg67.9%
neg-mul-167.9%
*-commutative67.9%
associate-/l*67.8%
distribute-neg-frac67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.7%
distribute-rgt-out67.7%
associate-/r*67.7%
metadata-eval67.7%
sub-neg67.7%
+-commutative67.7%
Simplified67.8%
Taylor expanded in c around 0 88.9%
+-commutative88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
Final simplification84.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e-104)
(/ 1.0 (/ (fabs (- b (* a (/ c b)))) c))
(if (<= b 3.8e-128)
(* (/ -0.5 a) (+ b (sqrt (* (* a c) -4.0))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e-104) {
tmp = 1.0 / (fabs((b - (a * (c / b)))) / c);
} else if (b <= 3.8e-128) {
tmp = (-0.5 / a) * (b + sqrt(((a * c) * -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 <= (-1.5d-104)) then
tmp = 1.0d0 / (abs((b - (a * (c / b)))) / c)
else if (b <= 3.8d-128) then
tmp = ((-0.5d0) / a) * (b + sqrt(((a * c) * (-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 <= -1.5e-104) {
tmp = 1.0 / (Math.abs((b - (a * (c / b)))) / c);
} else if (b <= 3.8e-128) {
tmp = (-0.5 / a) * (b + Math.sqrt(((a * c) * -4.0)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.5e-104: tmp = 1.0 / (math.fabs((b - (a * (c / b)))) / c) elif b <= 3.8e-128: tmp = (-0.5 / a) * (b + math.sqrt(((a * c) * -4.0))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.5e-104) tmp = Float64(1.0 / Float64(abs(Float64(b - Float64(a * Float64(c / b)))) / c)); elseif (b <= 3.8e-128) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(a * c) * -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 <= -1.5e-104) tmp = 1.0 / (abs((b - (a * (c / b)))) / c); elseif (b <= 3.8e-128) tmp = (-0.5 / a) * (b + sqrt(((a * c) * -4.0))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.5e-104], N[(1.0 / N[(N[Abs[N[(b - N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.8e-128], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(a * c), $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 -1.5 \cdot 10^{-104}:\\
\;\;\;\;\frac{1}{\frac{\left|b - a \cdot \frac{c}{b}\right|}{c}}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-128}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(a \cdot c\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.5000000000000001e-104Initial program 22.9%
div-sub20.4%
sub-neg20.4%
neg-mul-120.4%
*-commutative20.4%
associate-/l*20.2%
distribute-neg-frac20.2%
neg-mul-120.2%
*-commutative20.2%
associate-/l*20.5%
distribute-rgt-out22.9%
associate-/r*22.9%
metadata-eval22.9%
sub-neg22.9%
+-commutative22.9%
Simplified22.9%
Applied egg-rr17.6%
Taylor expanded in c around 0 20.4%
mul-1-neg20.4%
unsub-neg20.4%
associate-*r/20.3%
Simplified20.3%
add-sqr-sqrt0.0%
sqrt-unprod56.3%
pow256.3%
Applied egg-rr56.3%
unpow256.3%
rem-sqrt-square81.9%
Simplified81.9%
if -1.5000000000000001e-104 < b < 3.8000000000000002e-128Initial program 82.7%
div-sub82.7%
sub-neg82.7%
neg-mul-182.7%
*-commutative82.7%
associate-/l*82.7%
distribute-neg-frac82.7%
neg-mul-182.7%
*-commutative82.7%
associate-/l*82.7%
distribute-rgt-out82.7%
associate-/r*82.7%
metadata-eval82.7%
sub-neg82.7%
+-commutative82.7%
Simplified82.7%
Taylor expanded in a around inf 79.5%
*-commutative79.5%
Simplified79.5%
if 3.8000000000000002e-128 < b Initial program 67.9%
div-sub67.9%
sub-neg67.9%
neg-mul-167.9%
*-commutative67.9%
associate-/l*67.8%
distribute-neg-frac67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.7%
distribute-rgt-out67.7%
associate-/r*67.7%
metadata-eval67.7%
sub-neg67.7%
+-commutative67.7%
Simplified67.8%
Taylor expanded in c around 0 88.9%
+-commutative88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
(FPCore (a b c)
:precision binary64
(if (<= b -2.1e-102)
(- (/ c b))
(if (<= b 3.8e-128)
(* (/ -0.5 a) (+ b (sqrt (* (* a c) -4.0))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-102) {
tmp = -(c / b);
} else if (b <= 3.8e-128) {
tmp = (-0.5 / a) * (b + sqrt(((a * c) * -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 <= (-2.1d-102)) then
tmp = -(c / b)
else if (b <= 3.8d-128) then
tmp = ((-0.5d0) / a) * (b + sqrt(((a * c) * (-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 <= -2.1e-102) {
tmp = -(c / b);
} else if (b <= 3.8e-128) {
tmp = (-0.5 / a) * (b + Math.sqrt(((a * c) * -4.0)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-102: tmp = -(c / b) elif b <= 3.8e-128: tmp = (-0.5 / a) * (b + math.sqrt(((a * c) * -4.0))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-102) tmp = Float64(-Float64(c / b)); elseif (b <= 3.8e-128) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(a * c) * -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 <= -2.1e-102) tmp = -(c / b); elseif (b <= 3.8e-128) tmp = (-0.5 / a) * (b + sqrt(((a * c) * -4.0))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-102], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 3.8e-128], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(a * c), $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 -2.1 \cdot 10^{-102}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-128}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(a \cdot c\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.1e-102Initial program 22.9%
div-sub20.4%
sub-neg20.4%
neg-mul-120.4%
*-commutative20.4%
associate-/l*20.2%
distribute-neg-frac20.2%
neg-mul-120.2%
*-commutative20.2%
associate-/l*20.5%
distribute-rgt-out22.9%
associate-/r*22.9%
metadata-eval22.9%
sub-neg22.9%
+-commutative22.9%
Simplified22.9%
Taylor expanded in b around -inf 81.9%
mul-1-neg81.9%
distribute-neg-frac281.9%
Simplified81.9%
if -2.1e-102 < b < 3.8000000000000002e-128Initial program 82.7%
div-sub82.7%
sub-neg82.7%
neg-mul-182.7%
*-commutative82.7%
associate-/l*82.7%
distribute-neg-frac82.7%
neg-mul-182.7%
*-commutative82.7%
associate-/l*82.7%
distribute-rgt-out82.7%
associate-/r*82.7%
metadata-eval82.7%
sub-neg82.7%
+-commutative82.7%
Simplified82.7%
Taylor expanded in a around inf 79.5%
*-commutative79.5%
Simplified79.5%
if 3.8000000000000002e-128 < b Initial program 67.9%
div-sub67.9%
sub-neg67.9%
neg-mul-167.9%
*-commutative67.9%
associate-/l*67.8%
distribute-neg-frac67.8%
neg-mul-167.8%
*-commutative67.8%
associate-/l*67.7%
distribute-rgt-out67.7%
associate-/r*67.7%
metadata-eval67.7%
sub-neg67.7%
+-commutative67.7%
Simplified67.8%
Taylor expanded in c around 0 88.9%
+-commutative88.9%
mul-1-neg88.9%
unsub-neg88.9%
Simplified88.9%
Final simplification84.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ c b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = -(c / b);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -(c / b) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = -(c / b); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 36.9%
div-sub34.9%
sub-neg34.9%
neg-mul-134.9%
*-commutative34.9%
associate-/l*34.8%
distribute-neg-frac34.8%
neg-mul-134.8%
*-commutative34.8%
associate-/l*34.9%
distribute-rgt-out36.9%
associate-/r*36.9%
metadata-eval36.9%
sub-neg36.9%
+-commutative36.9%
Simplified36.9%
Taylor expanded in b around -inf 66.1%
mul-1-neg66.1%
distribute-neg-frac266.1%
Simplified66.1%
if -9.999999999999969e-311 < b Initial program 69.3%
div-sub69.3%
sub-neg69.3%
neg-mul-169.3%
*-commutative69.3%
associate-/l*69.2%
distribute-neg-frac69.2%
neg-mul-169.2%
*-commutative69.2%
associate-/l*69.1%
distribute-rgt-out69.1%
associate-/r*69.1%
metadata-eval69.1%
sub-neg69.1%
+-commutative69.1%
Simplified69.1%
Taylor expanded in c around 0 73.7%
+-commutative73.7%
mul-1-neg73.7%
unsub-neg73.7%
Simplified73.7%
Final simplification70.2%
(FPCore (a b c) :precision binary64 (if (<= b -6.2e-230) (- (/ c b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.2e-230) {
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 <= (-6.2d-230)) 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 <= -6.2e-230) {
tmp = -(c / b);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.2e-230: tmp = -(c / b) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.2e-230) 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 <= -6.2e-230) tmp = -(c / b); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.2e-230], (-N[(c / b), $MachinePrecision]), N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.2 \cdot 10^{-230}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -6.19999999999999999e-230Initial program 32.6%
div-sub30.5%
sub-neg30.5%
neg-mul-130.5%
*-commutative30.5%
associate-/l*30.3%
distribute-neg-frac30.3%
neg-mul-130.3%
*-commutative30.3%
associate-/l*30.5%
distribute-rgt-out32.6%
associate-/r*32.6%
metadata-eval32.6%
sub-neg32.6%
+-commutative32.6%
Simplified32.6%
Taylor expanded in b around -inf 71.3%
mul-1-neg71.3%
distribute-neg-frac271.3%
Simplified71.3%
if -6.19999999999999999e-230 < b Initial program 70.5%
div-sub70.5%
sub-neg70.5%
neg-mul-170.5%
*-commutative70.5%
associate-/l*70.4%
distribute-neg-frac70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.3%
distribute-rgt-out70.3%
associate-/r*70.3%
metadata-eval70.3%
sub-neg70.3%
+-commutative70.3%
Simplified70.3%
Taylor expanded in a around 0 69.4%
associate-*r/69.4%
mul-1-neg69.4%
Simplified69.4%
Final simplification70.2%
(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 54.3%
div-sub53.4%
sub-neg53.4%
neg-mul-153.4%
*-commutative53.4%
associate-/l*53.3%
distribute-neg-frac53.3%
neg-mul-153.3%
*-commutative53.3%
associate-/l*53.3%
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.8%
mul-1-neg31.8%
distribute-neg-frac231.8%
Simplified31.8%
Final simplification31.8%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 54.3%
div-sub53.4%
sub-neg53.4%
neg-mul-153.4%
*-commutative53.4%
associate-/l*53.3%
distribute-neg-frac53.3%
neg-mul-153.3%
*-commutative53.3%
associate-/l*53.3%
distribute-rgt-out54.2%
associate-/r*54.2%
metadata-eval54.2%
sub-neg54.2%
+-commutative54.2%
Simplified54.3%
Taylor expanded in c around 0 40.8%
+-commutative40.8%
mul-1-neg40.8%
unsub-neg40.8%
Simplified40.8%
Taylor expanded in c around inf 9.2%
(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.3%
div-sub53.4%
sub-neg53.4%
neg-mul-153.4%
*-commutative53.4%
associate-/l*53.3%
distribute-neg-frac53.3%
neg-mul-153.3%
*-commutative53.3%
associate-/l*53.3%
distribute-rgt-out54.2%
associate-/r*54.2%
metadata-eval54.2%
sub-neg54.2%
+-commutative54.2%
Simplified54.3%
Applied egg-rr32.6%
Taylor expanded in b around -inf 2.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 2024114
(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)))