
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* 4.0 a))) (t_1 (sqrt (- (* b b) t_0))))
(if (<= (/ (- t_1 b) (* a 2.0)) -200.0)
(/ (/ (+ (pow (- b) 2.0) (- t_0 (* b b))) (- (- b) t_1)) (* a 2.0))
(-
(fma
-0.25
(* (/ (pow (* a c) 4.0) a) (/ 20.0 (pow b 7.0)))
(- (/ (* -2.0 (* (pow c 3.0) (* a a))) (pow b 5.0)) (/ c b)))
(/ (* c (* a c)) (pow b 3.0))))))
double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double t_1 = sqrt(((b * b) - t_0));
double tmp;
if (((t_1 - b) / (a * 2.0)) <= -200.0) {
tmp = ((pow(-b, 2.0) + (t_0 - (b * b))) / (-b - t_1)) / (a * 2.0);
} else {
tmp = fma(-0.25, ((pow((a * c), 4.0) / a) * (20.0 / pow(b, 7.0))), (((-2.0 * (pow(c, 3.0) * (a * a))) / pow(b, 5.0)) - (c / b))) - ((c * (a * c)) / pow(b, 3.0));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(c * Float64(4.0 * a)) t_1 = sqrt(Float64(Float64(b * b) - t_0)) tmp = 0.0 if (Float64(Float64(t_1 - b) / Float64(a * 2.0)) <= -200.0) tmp = Float64(Float64(Float64((Float64(-b) ^ 2.0) + Float64(t_0 - Float64(b * b))) / Float64(Float64(-b) - t_1)) / Float64(a * 2.0)); else tmp = Float64(fma(-0.25, Float64(Float64((Float64(a * c) ^ 4.0) / a) * Float64(20.0 / (b ^ 7.0))), Float64(Float64(Float64(-2.0 * Float64((c ^ 3.0) * Float64(a * a))) / (b ^ 5.0)) - Float64(c / b))) - Float64(Float64(c * Float64(a * c)) / (b ^ 3.0))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(t$95$1 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -200.0], N[(N[(N[(N[Power[(-b), 2.0], $MachinePrecision] + N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(-0.25 * N[(N[(N[Power[N[(a * c), $MachinePrecision], 4.0], $MachinePrecision] / a), $MachinePrecision] * N[(20.0 / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-2.0 * N[(N[Power[c, 3.0], $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(4 \cdot a\right)\\
t_1 := \sqrt{b \cdot b - t_0}\\
\mathbf{if}\;\frac{t_1 - b}{a \cdot 2} \leq -200:\\
\;\;\;\;\frac{\frac{{\left(-b\right)}^{2} + \left(t_0 - b \cdot b\right)}{\left(-b\right) - t_1}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.25, \frac{{\left(a \cdot c\right)}^{4}}{a} \cdot \frac{20}{{b}^{7}}, \frac{-2 \cdot \left({c}^{3} \cdot \left(a \cdot a\right)\right)}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -200Initial program 88.7%
flip-+87.8%
pow287.8%
add-sqr-sqrt89.5%
*-commutative89.5%
*-commutative89.5%
*-commutative89.5%
*-commutative89.5%
Applied egg-rr89.5%
if -200 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 52.8%
neg-sub052.8%
associate-+l-52.8%
sub0-neg52.8%
neg-mul-152.8%
associate-*l/52.8%
*-commutative52.8%
associate-/r*52.8%
/-rgt-identity52.8%
metadata-eval52.8%
Simplified52.8%
Taylor expanded in b around inf 92.9%
Simplified92.9%
Taylor expanded in b around 0 92.9%
distribute-rgt-out92.9%
times-frac92.9%
metadata-eval92.9%
pow-sqr92.9%
metadata-eval92.9%
pow-sqr92.9%
unswap-sqr92.9%
unpow292.9%
unpow292.9%
swap-sqr92.9%
unpow292.9%
unpow292.9%
unpow292.9%
swap-sqr92.9%
unpow292.9%
pow-sqr92.9%
metadata-eval92.9%
metadata-eval92.9%
Simplified92.9%
Final simplification92.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* 4.0 a))) (t_1 (sqrt (- (* b b) t_0))))
(if (<= (/ (- t_1 b) (* a 2.0)) -200.0)
(/ (/ (+ (pow (- b) 2.0) (- t_0 (* b b))) (- (- b) t_1)) (* a 2.0))
(-
(- (/ (* -2.0 (* (pow c 3.0) (* a a))) (pow b 5.0)) (/ c b))
(/ (* c (* a c)) (pow b 3.0))))))
double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double t_1 = sqrt(((b * b) - t_0));
double tmp;
if (((t_1 - b) / (a * 2.0)) <= -200.0) {
tmp = ((pow(-b, 2.0) + (t_0 - (b * b))) / (-b - t_1)) / (a * 2.0);
} else {
tmp = (((-2.0 * (pow(c, 3.0) * (a * a))) / pow(b, 5.0)) - (c / b)) - ((c * (a * c)) / pow(b, 3.0));
}
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) :: t_1
real(8) :: tmp
t_0 = c * (4.0d0 * a)
t_1 = sqrt(((b * b) - t_0))
if (((t_1 - b) / (a * 2.0d0)) <= (-200.0d0)) then
tmp = (((-b ** 2.0d0) + (t_0 - (b * b))) / (-b - t_1)) / (a * 2.0d0)
else
tmp = ((((-2.0d0) * ((c ** 3.0d0) * (a * a))) / (b ** 5.0d0)) - (c / b)) - ((c * (a * c)) / (b ** 3.0d0))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double t_1 = Math.sqrt(((b * b) - t_0));
double tmp;
if (((t_1 - b) / (a * 2.0)) <= -200.0) {
tmp = ((Math.pow(-b, 2.0) + (t_0 - (b * b))) / (-b - t_1)) / (a * 2.0);
} else {
tmp = (((-2.0 * (Math.pow(c, 3.0) * (a * a))) / Math.pow(b, 5.0)) - (c / b)) - ((c * (a * c)) / Math.pow(b, 3.0));
}
return tmp;
}
def code(a, b, c): t_0 = c * (4.0 * a) t_1 = math.sqrt(((b * b) - t_0)) tmp = 0 if ((t_1 - b) / (a * 2.0)) <= -200.0: tmp = ((math.pow(-b, 2.0) + (t_0 - (b * b))) / (-b - t_1)) / (a * 2.0) else: tmp = (((-2.0 * (math.pow(c, 3.0) * (a * a))) / math.pow(b, 5.0)) - (c / b)) - ((c * (a * c)) / math.pow(b, 3.0)) return tmp
function code(a, b, c) t_0 = Float64(c * Float64(4.0 * a)) t_1 = sqrt(Float64(Float64(b * b) - t_0)) tmp = 0.0 if (Float64(Float64(t_1 - b) / Float64(a * 2.0)) <= -200.0) tmp = Float64(Float64(Float64((Float64(-b) ^ 2.0) + Float64(t_0 - Float64(b * b))) / Float64(Float64(-b) - t_1)) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(Float64(-2.0 * Float64((c ^ 3.0) * Float64(a * a))) / (b ^ 5.0)) - Float64(c / b)) - Float64(Float64(c * Float64(a * c)) / (b ^ 3.0))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = c * (4.0 * a); t_1 = sqrt(((b * b) - t_0)); tmp = 0.0; if (((t_1 - b) / (a * 2.0)) <= -200.0) tmp = (((-b ^ 2.0) + (t_0 - (b * b))) / (-b - t_1)) / (a * 2.0); else tmp = (((-2.0 * ((c ^ 3.0) * (a * a))) / (b ^ 5.0)) - (c / b)) - ((c * (a * c)) / (b ^ 3.0)); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(t$95$1 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -200.0], N[(N[(N[(N[Power[(-b), 2.0], $MachinePrecision] + N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-2.0 * N[(N[Power[c, 3.0], $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision] - N[(N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(4 \cdot a\right)\\
t_1 := \sqrt{b \cdot b - t_0}\\
\mathbf{if}\;\frac{t_1 - b}{a \cdot 2} \leq -200:\\
\;\;\;\;\frac{\frac{{\left(-b\right)}^{2} + \left(t_0 - b \cdot b\right)}{\left(-b\right) - t_1}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{-2 \cdot \left({c}^{3} \cdot \left(a \cdot a\right)\right)}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -200Initial program 88.7%
flip-+87.8%
pow287.8%
add-sqr-sqrt89.5%
*-commutative89.5%
*-commutative89.5%
*-commutative89.5%
*-commutative89.5%
Applied egg-rr89.5%
if -200 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 52.8%
neg-sub052.8%
associate-+l-52.8%
sub0-neg52.8%
neg-mul-152.8%
associate-*l/52.8%
*-commutative52.8%
associate-/r*52.8%
/-rgt-identity52.8%
metadata-eval52.8%
Simplified52.8%
Taylor expanded in b around inf 90.4%
+-commutative90.4%
mul-1-neg90.4%
unsub-neg90.4%
+-commutative90.4%
mul-1-neg90.4%
unsub-neg90.4%
associate-*r/90.4%
unpow290.4%
unpow290.4%
associate-*l*90.4%
Simplified90.4%
Final simplification90.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* 4.0 a))))
(if (<= b 170.0)
(/
(/ (+ (pow (- b) 2.0) (- t_0 (* b b))) (- (- b) (sqrt (- (* b b) t_0))))
(* a 2.0))
(- (/ (- c) b) (/ (* c (* a c)) (pow b 3.0))))))
double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double tmp;
if (b <= 170.0) {
tmp = ((pow(-b, 2.0) + (t_0 - (b * b))) / (-b - sqrt(((b * b) - t_0)))) / (a * 2.0);
} else {
tmp = (-c / b) - ((c * (a * c)) / pow(b, 3.0));
}
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 = c * (4.0d0 * a)
if (b <= 170.0d0) then
tmp = (((-b ** 2.0d0) + (t_0 - (b * b))) / (-b - sqrt(((b * b) - t_0)))) / (a * 2.0d0)
else
tmp = (-c / b) - ((c * (a * c)) / (b ** 3.0d0))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double tmp;
if (b <= 170.0) {
tmp = ((Math.pow(-b, 2.0) + (t_0 - (b * b))) / (-b - Math.sqrt(((b * b) - t_0)))) / (a * 2.0);
} else {
tmp = (-c / b) - ((c * (a * c)) / Math.pow(b, 3.0));
}
return tmp;
}
def code(a, b, c): t_0 = c * (4.0 * a) tmp = 0 if b <= 170.0: tmp = ((math.pow(-b, 2.0) + (t_0 - (b * b))) / (-b - math.sqrt(((b * b) - t_0)))) / (a * 2.0) else: tmp = (-c / b) - ((c * (a * c)) / math.pow(b, 3.0)) return tmp
function code(a, b, c) t_0 = Float64(c * Float64(4.0 * a)) tmp = 0.0 if (b <= 170.0) tmp = Float64(Float64(Float64((Float64(-b) ^ 2.0) + Float64(t_0 - Float64(b * b))) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - t_0)))) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(Float64(c * Float64(a * c)) / (b ^ 3.0))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = c * (4.0 * a); tmp = 0.0; if (b <= 170.0) tmp = (((-b ^ 2.0) + (t_0 - (b * b))) / (-b - sqrt(((b * b) - t_0)))) / (a * 2.0); else tmp = (-c / b) - ((c * (a * c)) / (b ^ 3.0)); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 170.0], N[(N[(N[(N[Power[(-b), 2.0], $MachinePrecision] + N[(t$95$0 - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(4 \cdot a\right)\\
\mathbf{if}\;b \leq 170:\\
\;\;\;\;\frac{\frac{{\left(-b\right)}^{2} + \left(t_0 - b \cdot b\right)}{\left(-b\right) - \sqrt{b \cdot b - t_0}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}\\
\end{array}
\end{array}
if b < 170Initial program 77.4%
flip-+77.6%
pow277.6%
add-sqr-sqrt79.2%
*-commutative79.2%
*-commutative79.2%
*-commutative79.2%
*-commutative79.2%
Applied egg-rr79.2%
if 170 < b Initial program 44.8%
neg-sub044.8%
associate-+l-44.8%
sub0-neg44.8%
neg-mul-144.8%
associate-*l/44.8%
*-commutative44.8%
associate-/r*44.8%
/-rgt-identity44.8%
metadata-eval44.8%
Simplified44.8%
Taylor expanded in b around inf 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
associate-*r/91.1%
neg-mul-191.1%
unpow291.1%
associate-*l*91.1%
Simplified91.1%
Final simplification87.4%
(FPCore (a b c) :precision binary64 (if (<= b 170.0) (* (- b (sqrt (fma a (* c -4.0) (* b b)))) (/ -0.5 a)) (- (/ (- c) b) (/ (* c (* a c)) (pow b 3.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 170.0) {
tmp = (b - sqrt(fma(a, (c * -4.0), (b * b)))) * (-0.5 / a);
} else {
tmp = (-c / b) - ((c * (a * c)) / pow(b, 3.0));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 170.0) tmp = Float64(Float64(b - sqrt(fma(a, Float64(c * -4.0), Float64(b * b)))) * Float64(-0.5 / a)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(Float64(c * Float64(a * c)) / (b ^ 3.0))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 170.0], N[(N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 170:\\
\;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}\\
\end{array}
\end{array}
if b < 170Initial program 77.4%
neg-sub077.4%
associate-+l-77.4%
sub0-neg77.4%
neg-mul-177.4%
associate-*l/77.4%
*-commutative77.4%
associate-/r*77.4%
/-rgt-identity77.4%
metadata-eval77.4%
Simplified77.5%
if 170 < b Initial program 44.8%
neg-sub044.8%
associate-+l-44.8%
sub0-neg44.8%
neg-mul-144.8%
associate-*l/44.8%
*-commutative44.8%
associate-/r*44.8%
/-rgt-identity44.8%
metadata-eval44.8%
Simplified44.8%
Taylor expanded in b around inf 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
associate-*r/91.1%
neg-mul-191.1%
unpow291.1%
associate-*l*91.1%
Simplified91.1%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (if (<= b 170.0) (* (- (sqrt (fma b b (* (* a c) -4.0))) b) (/ 0.5 a)) (- (/ (- c) b) (/ (* c (* a c)) (pow b 3.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 170.0) {
tmp = (sqrt(fma(b, b, ((a * c) * -4.0))) - b) * (0.5 / a);
} else {
tmp = (-c / b) - ((c * (a * c)) / pow(b, 3.0));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 170.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(a * c) * -4.0))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(Float64(c * Float64(a * c)) / (b ^ 3.0))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 170.0], N[(N[(N[Sqrt[N[(b * b + N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 170:\\
\;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}\\
\end{array}
\end{array}
if b < 170Initial program 77.4%
/-rgt-identity77.4%
metadata-eval77.4%
associate-/l*77.4%
associate-*r/77.4%
+-commutative77.4%
unsub-neg77.4%
fma-neg77.5%
associate-*l*77.5%
*-commutative77.5%
distribute-rgt-neg-in77.5%
metadata-eval77.5%
associate-/r*77.5%
metadata-eval77.5%
metadata-eval77.5%
Simplified77.5%
if 170 < b Initial program 44.8%
neg-sub044.8%
associate-+l-44.8%
sub0-neg44.8%
neg-mul-144.8%
associate-*l/44.8%
*-commutative44.8%
associate-/r*44.8%
/-rgt-identity44.8%
metadata-eval44.8%
Simplified44.8%
Taylor expanded in b around inf 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
associate-*r/91.1%
neg-mul-191.1%
unpow291.1%
associate-*l*91.1%
Simplified91.1%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (if (<= b 170.0) (/ (- (sqrt (fma b b (* (* a c) -4.0))) b) (* a 2.0)) (- (/ (- c) b) (/ (* c (* a c)) (pow b 3.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 170.0) {
tmp = (sqrt(fma(b, b, ((a * c) * -4.0))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - ((c * (a * c)) / pow(b, 3.0));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= 170.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(a * c) * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(Float64(c * Float64(a * c)) / (b ^ 3.0))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, 170.0], N[(N[(N[Sqrt[N[(b * b + N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 170:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}\\
\end{array}
\end{array}
if b < 170Initial program 77.4%
*-commutative77.4%
+-commutative77.4%
unsub-neg77.4%
fma-neg77.6%
associate-*l*77.6%
*-commutative77.6%
distribute-rgt-neg-in77.6%
metadata-eval77.6%
Simplified77.6%
if 170 < b Initial program 44.8%
neg-sub044.8%
associate-+l-44.8%
sub0-neg44.8%
neg-mul-144.8%
associate-*l/44.8%
*-commutative44.8%
associate-/r*44.8%
/-rgt-identity44.8%
metadata-eval44.8%
Simplified44.8%
Taylor expanded in b around inf 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
associate-*r/91.1%
neg-mul-191.1%
unpow291.1%
associate-*l*91.1%
Simplified91.1%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (if (<= b 170.0) (* (/ 0.5 a) (- (sqrt (+ (* b b) (* (* a c) -4.0))) b)) (- (/ (- c) b) (/ (* c (* a c)) (pow b 3.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 170.0) {
tmp = (0.5 / a) * (sqrt(((b * b) + ((a * c) * -4.0))) - b);
} else {
tmp = (-c / b) - ((c * (a * c)) / pow(b, 3.0));
}
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 <= 170.0d0) then
tmp = (0.5d0 / a) * (sqrt(((b * b) + ((a * c) * (-4.0d0)))) - b)
else
tmp = (-c / b) - ((c * (a * c)) / (b ** 3.0d0))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 170.0) {
tmp = (0.5 / a) * (Math.sqrt(((b * b) + ((a * c) * -4.0))) - b);
} else {
tmp = (-c / b) - ((c * (a * c)) / Math.pow(b, 3.0));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 170.0: tmp = (0.5 / a) * (math.sqrt(((b * b) + ((a * c) * -4.0))) - b) else: tmp = (-c / b) - ((c * (a * c)) / math.pow(b, 3.0)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 170.0) tmp = Float64(Float64(0.5 / a) * Float64(sqrt(Float64(Float64(b * b) + Float64(Float64(a * c) * -4.0))) - b)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(Float64(c * Float64(a * c)) / (b ^ 3.0))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 170.0) tmp = (0.5 / a) * (sqrt(((b * b) + ((a * c) * -4.0))) - b); else tmp = (-c / b) - ((c * (a * c)) / (b ^ 3.0)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 170.0], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 170:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4} - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}\\
\end{array}
\end{array}
if b < 170Initial program 77.4%
/-rgt-identity77.4%
metadata-eval77.4%
associate-/l*77.4%
associate-*r/77.4%
+-commutative77.4%
unsub-neg77.4%
fma-neg77.5%
associate-*l*77.5%
*-commutative77.5%
distribute-rgt-neg-in77.5%
metadata-eval77.5%
associate-/r*77.5%
metadata-eval77.5%
metadata-eval77.5%
Simplified77.5%
fma-udef77.4%
*-commutative77.4%
Applied egg-rr77.4%
if 170 < b Initial program 44.8%
neg-sub044.8%
associate-+l-44.8%
sub0-neg44.8%
neg-mul-144.8%
associate-*l/44.8%
*-commutative44.8%
associate-/r*44.8%
/-rgt-identity44.8%
metadata-eval44.8%
Simplified44.8%
Taylor expanded in b around inf 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
associate-*r/91.1%
neg-mul-191.1%
unpow291.1%
associate-*l*91.1%
Simplified91.1%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (if (<= b 170.0) (/ (- (sqrt (+ (* b b) (* (* a c) -4.0))) b) (* a 2.0)) (- (/ (- c) b) (/ (* c (* a c)) (pow b 3.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= 170.0) {
tmp = (sqrt(((b * b) + ((a * c) * -4.0))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - ((c * (a * c)) / pow(b, 3.0));
}
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 <= 170.0d0) then
tmp = (sqrt(((b * b) + ((a * c) * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = (-c / b) - ((c * (a * c)) / (b ** 3.0d0))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 170.0) {
tmp = (Math.sqrt(((b * b) + ((a * c) * -4.0))) - b) / (a * 2.0);
} else {
tmp = (-c / b) - ((c * (a * c)) / Math.pow(b, 3.0));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 170.0: tmp = (math.sqrt(((b * b) + ((a * c) * -4.0))) - b) / (a * 2.0) else: tmp = (-c / b) - ((c * (a * c)) / math.pow(b, 3.0)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 170.0) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(Float64(a * c) * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(Float64(c * Float64(a * c)) / (b ^ 3.0))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 170.0) tmp = (sqrt(((b * b) + ((a * c) * -4.0))) - b) / (a * 2.0); else tmp = (-c / b) - ((c * (a * c)) / (b ^ 3.0)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 170.0], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 170:\\
\;\;\;\;\frac{\sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}\\
\end{array}
\end{array}
if b < 170Initial program 77.4%
*-commutative77.4%
+-commutative77.4%
unsub-neg77.4%
fma-neg77.6%
associate-*l*77.6%
*-commutative77.6%
distribute-rgt-neg-in77.6%
metadata-eval77.6%
Simplified77.6%
fma-udef77.4%
*-commutative77.4%
Applied egg-rr77.4%
if 170 < b Initial program 44.8%
neg-sub044.8%
associate-+l-44.8%
sub0-neg44.8%
neg-mul-144.8%
associate-*l/44.8%
*-commutative44.8%
associate-/r*44.8%
/-rgt-identity44.8%
metadata-eval44.8%
Simplified44.8%
Taylor expanded in b around inf 91.1%
+-commutative91.1%
mul-1-neg91.1%
unsub-neg91.1%
associate-*r/91.1%
neg-mul-191.1%
unpow291.1%
associate-*l*91.1%
Simplified91.1%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (- (/ (- c) b) (/ (* c (* a c)) (pow b 3.0))))
double code(double a, double b, double c) {
return (-c / b) - ((c * (a * c)) / pow(b, 3.0));
}
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) - ((c * (a * c)) / (b ** 3.0d0))
end function
public static double code(double a, double b, double c) {
return (-c / b) - ((c * (a * c)) / Math.pow(b, 3.0));
}
def code(a, b, c): return (-c / b) - ((c * (a * c)) / math.pow(b, 3.0))
function code(a, b, c) return Float64(Float64(Float64(-c) / b) - Float64(Float64(c * Float64(a * c)) / (b ^ 3.0))) end
function tmp = code(a, b, c) tmp = (-c / b) - ((c * (a * c)) / (b ^ 3.0)); end
code[a_, b_, c_] := N[(N[((-c) / b), $MachinePrecision] - N[(N[(c * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-c}{b} - \frac{c \cdot \left(a \cdot c\right)}{{b}^{3}}
\end{array}
Initial program 55.0%
neg-sub055.0%
associate-+l-55.0%
sub0-neg55.0%
neg-mul-155.0%
associate-*l/55.0%
*-commutative55.0%
associate-/r*55.0%
/-rgt-identity55.0%
metadata-eval55.0%
Simplified55.0%
Taylor expanded in b around inf 82.4%
+-commutative82.4%
mul-1-neg82.4%
unsub-neg82.4%
associate-*r/82.4%
neg-mul-182.4%
unpow282.4%
associate-*l*82.4%
Simplified82.4%
Final simplification82.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(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 55.0%
neg-sub055.0%
associate-+l-55.0%
sub0-neg55.0%
neg-mul-155.0%
associate-*l/55.0%
*-commutative55.0%
associate-/r*55.0%
/-rgt-identity55.0%
metadata-eval55.0%
Simplified55.0%
Taylor expanded in b around inf 64.8%
associate-*r/64.8%
neg-mul-164.8%
Simplified64.8%
Final simplification64.8%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 55.0%
add-log-exp49.1%
neg-mul-149.1%
fma-def49.1%
*-commutative49.1%
*-commutative49.1%
*-commutative49.1%
Applied egg-rr49.1%
Taylor expanded in c around 0 3.2%
associate-*r/3.2%
distribute-rgt1-in3.2%
metadata-eval3.2%
mul0-lft3.2%
metadata-eval3.2%
Simplified3.2%
Final simplification3.2%
herbie shell --seed 2023256
(FPCore (a b c)
:name "Quadratic roots, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))