
(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 -4.8e+72)
(- (/ c b) (/ b a))
(if (<= b 2.3e-254)
(/ (* (- b (sqrt (- (* b b) (* a (* c 4.0))))) -0.5) a)
(if (<= b 1.75e-72)
(/
0.5
(/
1.0
(*
(/ a (- a))
(/ (* c 4.0) (+ b (hypot (sqrt (* a (* c -4.0))) b))))))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e+72) {
tmp = (c / b) - (b / a);
} else if (b <= 2.3e-254) {
tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else if (b <= 1.75e-72) {
tmp = 0.5 / (1.0 / ((a / -a) * ((c * 4.0) / (b + hypot(sqrt((a * (c * -4.0))), b)))));
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e+72) {
tmp = (c / b) - (b / a);
} else if (b <= 2.3e-254) {
tmp = ((b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else if (b <= 1.75e-72) {
tmp = 0.5 / (1.0 / ((a / -a) * ((c * 4.0) / (b + Math.hypot(Math.sqrt((a * (c * -4.0))), b)))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.8e+72: tmp = (c / b) - (b / a) elif b <= 2.3e-254: tmp = ((b - math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a elif b <= 1.75e-72: tmp = 0.5 / (1.0 / ((a / -a) * ((c * 4.0) / (b + math.hypot(math.sqrt((a * (c * -4.0))), b))))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.8e+72) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.3e-254) tmp = Float64(Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * -0.5) / a); elseif (b <= 1.75e-72) tmp = Float64(0.5 / Float64(1.0 / Float64(Float64(a / Float64(-a)) * Float64(Float64(c * 4.0) / Float64(b + hypot(sqrt(Float64(a * Float64(c * -4.0))), b)))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.8e+72) tmp = (c / b) - (b / a); elseif (b <= 2.3e-254) tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a; elseif (b <= 1.75e-72) tmp = 0.5 / (1.0 / ((a / -a) * ((c * 4.0) / (b + hypot(sqrt((a * (c * -4.0))), b))))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.8e+72], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.3e-254], N[(N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 1.75e-72], N[(0.5 / N[(1.0 / N[(N[(a / (-a)), $MachinePrecision] * N[(N[(c * 4.0), $MachinePrecision] / N[(b + N[Sqrt[N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.8 \cdot 10^{+72}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-254}:\\
\;\;\;\;\frac{\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot -0.5}{a}\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{-72}:\\
\;\;\;\;\frac{0.5}{\frac{1}{\frac{a}{-a} \cdot \frac{c \cdot 4}{b + \mathsf{hypot}\left(\sqrt{a \cdot \left(c \cdot -4\right)}, b\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.8000000000000002e72Initial program 55.6%
neg-sub055.6%
associate-+l-55.6%
sub0-neg55.6%
neg-mul-155.6%
*-commutative55.6%
associate-*r/55.5%
Simplified55.6%
Taylor expanded in b around -inf 96.9%
mul-1-neg96.9%
unsub-neg96.9%
Simplified96.9%
if -4.8000000000000002e72 < b < 2.2999999999999999e-254Initial program 83.6%
neg-sub083.6%
associate-+l-83.6%
sub0-neg83.6%
neg-mul-183.6%
*-commutative83.6%
associate-*r/83.3%
Simplified83.3%
fma-udef83.3%
associate-*r*83.3%
metadata-eval83.3%
distribute-rgt-neg-in83.3%
*-commutative83.3%
+-commutative83.3%
sub-neg83.3%
*-commutative83.3%
associate-*l*83.3%
Applied egg-rr83.3%
associate-*r/83.6%
Applied egg-rr83.6%
if 2.2999999999999999e-254 < b < 1.75e-72Initial program 61.3%
neg-sub061.3%
associate-+l-61.3%
sub0-neg61.3%
neg-mul-161.3%
*-commutative61.3%
associate-*r/61.0%
Simplified61.2%
associate-*r/61.5%
frac-2neg61.5%
Applied egg-rr61.5%
distribute-rgt-neg-in61.5%
metadata-eval61.5%
*-commutative61.5%
associate-/l*61.1%
fma-def61.1%
+-commutative61.1%
fma-def61.1%
Simplified61.1%
flip--60.6%
add-sqr-sqrt60.7%
Applied egg-rr60.7%
metadata-eval60.7%
distribute-rgt-neg-in60.7%
distribute-rgt-neg-in60.7%
fma-def60.7%
associate--r+67.1%
+-inverses67.1%
associate-*r*66.8%
*-commutative66.8%
distribute-rgt-neg-in66.8%
metadata-eval66.8%
associate-*l*67.1%
fma-def67.1%
+-commutative67.1%
associate-*r*67.0%
*-commutative67.0%
fma-def67.0%
Simplified67.0%
clear-num67.1%
inv-pow67.1%
sub0-neg67.1%
associate-*r*67.0%
*-commutative67.0%
associate-*r*67.1%
fma-udef67.1%
*-commutative67.1%
associate-*r*67.3%
add-sqr-sqrt67.3%
hypot-def67.3%
Applied egg-rr67.3%
unpow-167.3%
associate-/l/66.5%
distribute-rgt-neg-in66.5%
times-frac80.3%
distribute-rgt-neg-in80.3%
metadata-eval80.3%
Simplified80.3%
if 1.75e-72 < b Initial program 10.0%
neg-sub010.0%
associate-+l-10.0%
sub0-neg10.0%
neg-mul-110.0%
*-commutative10.0%
associate-*r/9.9%
Simplified9.9%
Taylor expanded in b around inf 87.1%
associate-*r/87.1%
neg-mul-187.1%
Simplified87.1%
Final simplification87.9%
(FPCore (a b c)
:precision binary64
(if (<= b -5.2e+72)
(- (/ c b) (/ b a))
(if (<= b 2.4e-74)
(* (- b (sqrt (- (* b b) (* a (* c 4.0))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e+72) {
tmp = (c / b) - (b / a);
} else if (b <= 2.4e-74) {
tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
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.2d+72)) then
tmp = (c / b) - (b / a)
else if (b <= 2.4d-74) then
tmp = (b - sqrt(((b * b) - (a * (c * 4.0d0))))) * ((-0.5d0) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e+72) {
tmp = (c / b) - (b / a);
} else if (b <= 2.4e-74) {
tmp = (b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e+72: tmp = (c / b) - (b / a) elif b <= 2.4e-74: tmp = (b - math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e+72) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.4e-74) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e+72) tmp = (c / b) - (b / a); elseif (b <= 2.4e-74) tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e+72], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.4e-74], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{+72}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-74}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.19999999999999963e72Initial program 55.6%
neg-sub055.6%
associate-+l-55.6%
sub0-neg55.6%
neg-mul-155.6%
*-commutative55.6%
associate-*r/55.5%
Simplified55.6%
Taylor expanded in b around -inf 96.9%
mul-1-neg96.9%
unsub-neg96.9%
Simplified96.9%
if -5.19999999999999963e72 < b < 2.3999999999999999e-74Initial program 78.2%
neg-sub078.2%
associate-+l-78.2%
sub0-neg78.2%
neg-mul-178.2%
*-commutative78.2%
associate-*r/77.9%
Simplified78.0%
fma-udef78.0%
associate-*r*77.9%
metadata-eval77.9%
distribute-rgt-neg-in77.9%
*-commutative77.9%
+-commutative77.9%
sub-neg77.9%
*-commutative77.9%
associate-*l*78.0%
Applied egg-rr78.0%
if 2.3999999999999999e-74 < b Initial program 10.0%
neg-sub010.0%
associate-+l-10.0%
sub0-neg10.0%
neg-mul-110.0%
*-commutative10.0%
associate-*r/9.9%
Simplified9.9%
Taylor expanded in b around inf 87.1%
associate-*r/87.1%
neg-mul-187.1%
Simplified87.1%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -7.5e+70)
(- (/ c b) (/ b a))
(if (<= b 8e-73)
(/ (* (- b (sqrt (- (* b b) (* a (* c 4.0))))) -0.5) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e+70) {
tmp = (c / b) - (b / a);
} else if (b <= 8e-73) {
tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else {
tmp = -c / b;
}
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.5d+70)) then
tmp = (c / b) - (b / a)
else if (b <= 8d-73) then
tmp = ((b - sqrt(((b * b) - (a * (c * 4.0d0))))) * (-0.5d0)) / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e+70) {
tmp = (c / b) - (b / a);
} else if (b <= 8e-73) {
tmp = ((b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.5e+70: tmp = (c / b) - (b / a) elif b <= 8e-73: tmp = ((b - math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.5e+70) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 8e-73) tmp = Float64(Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * -0.5) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.5e+70) tmp = (c / b) - (b / a); elseif (b <= 8e-73) tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.5e+70], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8e-73], N[(N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.5 \cdot 10^{+70}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-73}:\\
\;\;\;\;\frac{\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot -0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.50000000000000031e70Initial program 55.6%
neg-sub055.6%
associate-+l-55.6%
sub0-neg55.6%
neg-mul-155.6%
*-commutative55.6%
associate-*r/55.5%
Simplified55.6%
Taylor expanded in b around -inf 96.9%
mul-1-neg96.9%
unsub-neg96.9%
Simplified96.9%
if -7.50000000000000031e70 < b < 7.99999999999999998e-73Initial program 78.2%
neg-sub078.2%
associate-+l-78.2%
sub0-neg78.2%
neg-mul-178.2%
*-commutative78.2%
associate-*r/77.9%
Simplified78.0%
fma-udef78.0%
associate-*r*77.9%
metadata-eval77.9%
distribute-rgt-neg-in77.9%
*-commutative77.9%
+-commutative77.9%
sub-neg77.9%
*-commutative77.9%
associate-*l*78.0%
Applied egg-rr78.0%
associate-*r/78.3%
Applied egg-rr78.3%
if 7.99999999999999998e-73 < b Initial program 10.0%
neg-sub010.0%
associate-+l-10.0%
sub0-neg10.0%
neg-mul-110.0%
*-commutative10.0%
associate-*r/9.9%
Simplified9.9%
Taylor expanded in b around inf 87.1%
associate-*r/87.1%
neg-mul-187.1%
Simplified87.1%
Final simplification86.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.8e-54)
(/ (- b) a)
(if (<= b 9.5e-75)
(* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-54) {
tmp = -b / a;
} else if (b <= 9.5e-75) {
tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
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.8d-54)) then
tmp = -b / a
else if (b <= 9.5d-75) then
tmp = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.0d0)))))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-54) {
tmp = -b / a;
} else if (b <= 9.5e-75) {
tmp = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.8e-54: tmp = -b / a elif b <= 9.5e-75: tmp = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.8e-54) tmp = Float64(Float64(-b) / a); elseif (b <= 9.5e-75) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.8e-54) tmp = -b / a; elseif (b <= 9.5e-75) tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.8e-54], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 9.5e-75], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.8 \cdot 10^{-54}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-75}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.79999999999999988e-54Initial program 65.2%
neg-sub065.2%
associate-+l-65.2%
sub0-neg65.2%
neg-mul-165.2%
*-commutative65.2%
associate-*r/65.0%
Simplified65.1%
Taylor expanded in b around -inf 92.0%
associate-*r/92.0%
mul-1-neg92.0%
Simplified92.0%
if -1.79999999999999988e-54 < b < 9.4999999999999991e-75Initial program 73.7%
neg-sub073.7%
associate-+l-73.7%
sub0-neg73.7%
neg-mul-173.7%
*-commutative73.7%
associate-*r/73.5%
Simplified73.6%
Taylor expanded in a around inf 66.6%
*-commutative66.6%
*-commutative66.6%
associate-*r*66.6%
Simplified66.6%
if 9.4999999999999991e-75 < b Initial program 10.0%
neg-sub010.0%
associate-+l-10.0%
sub0-neg10.0%
neg-mul-110.0%
*-commutative10.0%
associate-*r/9.9%
Simplified9.9%
Taylor expanded in b around inf 87.1%
associate-*r/87.1%
neg-mul-187.1%
Simplified87.1%
Final simplification82.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.55e-55)
(/ (- b) a)
(if (<= b 1.25e-74)
(/ (* -0.5 (- b (sqrt (* a (* c -4.0))))) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.55e-55) {
tmp = -b / a;
} else if (b <= 1.25e-74) {
tmp = (-0.5 * (b - sqrt((a * (c * -4.0))))) / a;
} else {
tmp = -c / b;
}
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.55d-55)) then
tmp = -b / a
else if (b <= 1.25d-74) then
tmp = ((-0.5d0) * (b - sqrt((a * (c * (-4.0d0)))))) / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.55e-55) {
tmp = -b / a;
} else if (b <= 1.25e-74) {
tmp = (-0.5 * (b - Math.sqrt((a * (c * -4.0))))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.55e-55: tmp = -b / a elif b <= 1.25e-74: tmp = (-0.5 * (b - math.sqrt((a * (c * -4.0))))) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.55e-55) tmp = Float64(Float64(-b) / a); elseif (b <= 1.25e-74) tmp = Float64(Float64(-0.5 * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.55e-55) tmp = -b / a; elseif (b <= 1.25e-74) tmp = (-0.5 * (b - sqrt((a * (c * -4.0))))) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.55e-55], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.25e-74], N[(N[(-0.5 * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.55 \cdot 10^{-55}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-74}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.54999999999999998e-55Initial program 65.2%
neg-sub065.2%
associate-+l-65.2%
sub0-neg65.2%
neg-mul-165.2%
*-commutative65.2%
associate-*r/65.0%
Simplified65.1%
Taylor expanded in b around -inf 92.0%
associate-*r/92.0%
mul-1-neg92.0%
Simplified92.0%
if -1.54999999999999998e-55 < b < 1.25e-74Initial program 73.7%
neg-sub073.7%
associate-+l-73.7%
sub0-neg73.7%
neg-mul-173.7%
*-commutative73.7%
associate-*r/73.5%
Simplified73.6%
Taylor expanded in a around inf 66.6%
*-commutative66.6%
*-commutative66.6%
associate-*r*66.6%
Simplified66.6%
associate-*r/66.8%
Applied egg-rr66.8%
if 1.25e-74 < b Initial program 10.0%
neg-sub010.0%
associate-+l-10.0%
sub0-neg10.0%
neg-mul-110.0%
*-commutative10.0%
associate-*r/9.9%
Simplified9.9%
Taylor expanded in b around inf 87.1%
associate-*r/87.1%
neg-mul-187.1%
Simplified87.1%
Final simplification82.7%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
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 <= (-5d-310)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 69.8%
neg-sub069.8%
associate-+l-69.8%
sub0-neg69.8%
neg-mul-169.8%
*-commutative69.8%
associate-*r/69.6%
Simplified69.7%
Taylor expanded in b around -inf 69.6%
mul-1-neg69.6%
unsub-neg69.6%
Simplified69.6%
if -4.999999999999985e-310 < b Initial program 23.2%
neg-sub023.2%
associate-+l-23.2%
sub0-neg23.2%
neg-mul-123.2%
*-commutative23.2%
associate-*r/23.2%
Simplified23.2%
Taylor expanded in b around inf 71.6%
associate-*r/71.6%
neg-mul-171.6%
Simplified71.6%
Final simplification70.6%
(FPCore (a b c) :precision binary64 (if (<= b 2e+42) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2e+42) {
tmp = -b / a;
} else {
tmp = c / b;
}
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+42) then
tmp = -b / a
else
tmp = c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2e+42) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2e+42: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2e+42) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2e+42) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2e+42], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{+42}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.00000000000000009e42Initial program 62.0%
neg-sub062.0%
associate-+l-62.0%
sub0-neg62.0%
neg-mul-162.0%
*-commutative62.0%
associate-*r/61.8%
Simplified61.9%
Taylor expanded in b around -inf 49.0%
associate-*r/49.0%
mul-1-neg49.0%
Simplified49.0%
if 2.00000000000000009e42 < b Initial program 7.1%
neg-sub07.1%
associate-+l-7.1%
sub0-neg7.1%
neg-mul-17.1%
*-commutative7.1%
associate-*r/7.1%
Simplified7.1%
associate-*r/7.1%
frac-2neg7.1%
Applied egg-rr7.1%
distribute-rgt-neg-in7.1%
metadata-eval7.1%
*-commutative7.1%
associate-/l*7.1%
fma-def7.1%
+-commutative7.1%
fma-def7.1%
Simplified7.1%
Taylor expanded in b around -inf 2.5%
fma-def2.5%
associate-*l/2.5%
mul-1-neg2.5%
fma-neg2.5%
*-commutative2.5%
associate-/r/2.5%
associate-/r/2.5%
associate-/l/2.5%
*-commutative2.5%
Simplified2.5%
Taylor expanded in a around inf 30.2%
Final simplification43.7%
(FPCore (a b c) :precision binary64 (if (<= b 2.3e-254) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.3e-254) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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.3d-254) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.3e-254) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.3e-254: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.3e-254) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.3e-254) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.3e-254], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.3 \cdot 10^{-254}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 2.2999999999999999e-254Initial program 70.7%
neg-sub070.7%
associate-+l-70.7%
sub0-neg70.7%
neg-mul-170.7%
*-commutative70.7%
associate-*r/70.4%
Simplified70.5%
Taylor expanded in b around -inf 65.8%
associate-*r/65.8%
mul-1-neg65.8%
Simplified65.8%
if 2.2999999999999999e-254 < b Initial program 19.6%
neg-sub019.6%
associate-+l-19.6%
sub0-neg19.6%
neg-mul-119.6%
*-commutative19.6%
associate-*r/19.6%
Simplified19.6%
Taylor expanded in b around inf 75.5%
associate-*r/75.5%
neg-mul-175.5%
Simplified75.5%
Final simplification70.4%
(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 46.3%
neg-sub046.3%
associate-+l-46.3%
sub0-neg46.3%
neg-mul-146.3%
*-commutative46.3%
associate-*r/46.2%
Simplified46.2%
associate-*r/46.4%
frac-2neg46.4%
Applied egg-rr46.4%
distribute-rgt-neg-in46.4%
metadata-eval46.4%
*-commutative46.4%
associate-/l*46.3%
fma-def46.2%
+-commutative46.2%
fma-def46.2%
Simplified46.2%
Taylor expanded in b around -inf 34.0%
fma-def34.0%
associate-*l/35.6%
mul-1-neg35.6%
fma-neg35.6%
*-commutative35.6%
associate-/r/35.6%
associate-/r/35.6%
associate-/l/35.6%
*-commutative35.6%
Simplified35.6%
Taylor expanded in a around inf 10.8%
Final simplification10.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- b) t_0) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * 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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-b - t_0) / (2.0d0 * a)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b < 0.0) tmp = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-b - t_0) / (2.0 * a))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023215
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))