
(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 10 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 (/ (* c 2.0) (- (- b) (sqrt (fma -4.0 (* c a) (pow b 2.0))))))
double code(double a, double b, double c) {
return (c * 2.0) / (-b - sqrt(fma(-4.0, (c * a), pow(b, 2.0))));
}
function code(a, b, c) return Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(fma(-4.0, Float64(c * a), (b ^ 2.0))))) end
code[a_, b_, c_] := N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot 2}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, c \cdot a, {b}^{2}\right)}}
\end{array}
Initial program 57.0%
*-commutative57.0%
Simplified57.0%
add-cbrt-cube56.4%
pow1/354.0%
pow354.0%
pow254.0%
pow-pow54.0%
metadata-eval54.0%
Applied egg-rr54.0%
unpow1/356.6%
Simplified56.6%
flip-+56.3%
pow256.3%
add-sqr-sqrt56.7%
pow1/354.0%
pow-pow58.3%
metadata-eval58.3%
associate-*l*58.3%
pow1/358.1%
pow-pow58.3%
metadata-eval58.3%
associate-*l*58.3%
Applied egg-rr58.3%
*-un-lft-identity58.3%
associate-/l/58.3%
neg-mul-158.3%
unpow-prod-down58.3%
metadata-eval58.3%
*-un-lft-identity58.3%
cancel-sign-sub-inv58.3%
unpow258.3%
fma-define57.8%
metadata-eval57.8%
*-commutative57.8%
*-commutative57.8%
Applied egg-rr57.8%
associate-*r/57.8%
times-frac57.8%
*-commutative57.8%
associate-*l/57.8%
Simplified99.3%
Taylor expanded in c around 0 99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* a 4.0))))
(if (<= (/ (- (sqrt (- (* b b) t_0)) b) (* 2.0 a)) -0.021)
(* (- (sqrt (fma b b (* -4.0 (* c a)))) b) (/ 1.0 (* 2.0 a)))
(/ (* (/ 0.5 a) t_0) (* 2.0 (- (* a (/ c b)) b))))))
double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double tmp;
if (((sqrt(((b * b) - t_0)) - b) / (2.0 * a)) <= -0.021) {
tmp = (sqrt(fma(b, b, (-4.0 * (c * a)))) - b) * (1.0 / (2.0 * a));
} else {
tmp = ((0.5 / a) * t_0) / (2.0 * ((a * (c / b)) - b));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(c * Float64(a * 4.0)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(2.0 * a)) <= -0.021) tmp = Float64(Float64(sqrt(fma(b, b, Float64(-4.0 * Float64(c * a)))) - b) * Float64(1.0 / Float64(2.0 * a))); else tmp = Float64(Float64(Float64(0.5 / a) * t_0) / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], -0.021], N[(N[(N[Sqrt[N[(b * b + N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 / a), $MachinePrecision] * t$95$0), $MachinePrecision] / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 4\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - t\_0} - b}{2 \cdot a} \leq -0.021:\\
\;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)} - b\right) \cdot \frac{1}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{a} \cdot t\_0}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -0.0210000000000000013Initial program 81.1%
*-commutative81.1%
Simplified81.1%
add-cbrt-cube80.7%
pow1/376.2%
pow376.2%
pow276.2%
pow-pow76.2%
metadata-eval76.2%
Applied egg-rr76.2%
unpow1/380.6%
Simplified80.6%
div-inv80.5%
neg-mul-180.5%
fma-define80.5%
pow1/376.2%
pow-pow81.1%
metadata-eval81.1%
associate-*l*81.1%
Applied egg-rr81.1%
fma-undefine81.1%
cancel-sign-sub-inv81.1%
unpow281.1%
metadata-eval81.1%
*-commutative81.1%
fma-define81.3%
Applied egg-rr81.3%
if -0.0210000000000000013 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.3%
*-commutative46.3%
Simplified46.3%
add-cbrt-cube45.6%
pow1/344.1%
pow344.1%
pow244.1%
pow-pow44.1%
metadata-eval44.1%
Applied egg-rr44.1%
unpow1/345.8%
Simplified45.8%
flip-+45.6%
pow245.6%
add-sqr-sqrt46.2%
pow1/344.0%
pow-pow47.5%
metadata-eval47.5%
associate-*l*47.5%
pow1/347.5%
pow-pow47.5%
metadata-eval47.5%
associate-*l*47.5%
Applied egg-rr47.5%
*-un-lft-identity47.5%
associate-/l/47.5%
neg-mul-147.5%
unpow-prod-down47.5%
metadata-eval47.5%
*-un-lft-identity47.5%
cancel-sign-sub-inv47.5%
unpow247.5%
fma-define47.0%
metadata-eval47.0%
*-commutative47.0%
*-commutative47.0%
Applied egg-rr47.0%
associate-*r/47.0%
times-frac47.0%
*-commutative47.0%
associate-*l/47.0%
Simplified99.3%
Taylor expanded in c around 0 88.5%
distribute-lft-out--88.5%
associate-/l*88.5%
Simplified88.5%
Final simplification86.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* a 4.0))))
(if (<= (/ (- (sqrt (- (* b b) t_0)) b) (* 2.0 a)) -0.021)
(/ (- (sqrt (fma b b (* c (* -4.0 a)))) b) (* 2.0 a))
(/ (* (/ 0.5 a) t_0) (* 2.0 (- (* a (/ c b)) b))))))
double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double tmp;
if (((sqrt(((b * b) - t_0)) - b) / (2.0 * a)) <= -0.021) {
tmp = (sqrt(fma(b, b, (c * (-4.0 * a)))) - b) / (2.0 * a);
} else {
tmp = ((0.5 / a) * t_0) / (2.0 * ((a * (c / b)) - b));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(c * Float64(a * 4.0)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(2.0 * a)) <= -0.021) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(-4.0 * a)))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(Float64(0.5 / a) * t_0) / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], -0.021], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 / a), $MachinePrecision] * t$95$0), $MachinePrecision] / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 4\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - t\_0} - b}{2 \cdot a} \leq -0.021:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{a} \cdot t\_0}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -0.0210000000000000013Initial program 81.1%
*-commutative81.1%
Simplified81.3%
if -0.0210000000000000013 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.3%
*-commutative46.3%
Simplified46.3%
add-cbrt-cube45.6%
pow1/344.1%
pow344.1%
pow244.1%
pow-pow44.1%
metadata-eval44.1%
Applied egg-rr44.1%
unpow1/345.8%
Simplified45.8%
flip-+45.6%
pow245.6%
add-sqr-sqrt46.2%
pow1/344.0%
pow-pow47.5%
metadata-eval47.5%
associate-*l*47.5%
pow1/347.5%
pow-pow47.5%
metadata-eval47.5%
associate-*l*47.5%
Applied egg-rr47.5%
*-un-lft-identity47.5%
associate-/l/47.5%
neg-mul-147.5%
unpow-prod-down47.5%
metadata-eval47.5%
*-un-lft-identity47.5%
cancel-sign-sub-inv47.5%
unpow247.5%
fma-define47.0%
metadata-eval47.0%
*-commutative47.0%
*-commutative47.0%
Applied egg-rr47.0%
associate-*r/47.0%
times-frac47.0%
*-commutative47.0%
associate-*l/47.0%
Simplified99.3%
Taylor expanded in c around 0 88.5%
distribute-lft-out--88.5%
associate-/l*88.5%
Simplified88.5%
Final simplification86.2%
(FPCore (a b c) :precision binary64 (let* ((t_0 (* c (* a 4.0))) (t_1 (/ (- (sqrt (- (* b b) t_0)) b) (* 2.0 a)))) (if (<= t_1 -0.021) t_1 (/ (* (/ 0.5 a) t_0) (* 2.0 (- (* a (/ c b)) b))))))
double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double t_1 = (sqrt(((b * b) - t_0)) - b) / (2.0 * a);
double tmp;
if (t_1 <= -0.021) {
tmp = t_1;
} else {
tmp = ((0.5 / a) * t_0) / (2.0 * ((a * (c / b)) - 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = c * (a * 4.0d0)
t_1 = (sqrt(((b * b) - t_0)) - b) / (2.0d0 * a)
if (t_1 <= (-0.021d0)) then
tmp = t_1
else
tmp = ((0.5d0 / a) * t_0) / (2.0d0 * ((a * (c / b)) - b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double t_1 = (Math.sqrt(((b * b) - t_0)) - b) / (2.0 * a);
double tmp;
if (t_1 <= -0.021) {
tmp = t_1;
} else {
tmp = ((0.5 / a) * t_0) / (2.0 * ((a * (c / b)) - b));
}
return tmp;
}
def code(a, b, c): t_0 = c * (a * 4.0) t_1 = (math.sqrt(((b * b) - t_0)) - b) / (2.0 * a) tmp = 0 if t_1 <= -0.021: tmp = t_1 else: tmp = ((0.5 / a) * t_0) / (2.0 * ((a * (c / b)) - b)) return tmp
function code(a, b, c) t_0 = Float64(c * Float64(a * 4.0)) t_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(2.0 * a)) tmp = 0.0 if (t_1 <= -0.021) tmp = t_1; else tmp = Float64(Float64(Float64(0.5 / a) * t_0) / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = c * (a * 4.0); t_1 = (sqrt(((b * b) - t_0)) - b) / (2.0 * a); tmp = 0.0; if (t_1 <= -0.021) tmp = t_1; else tmp = ((0.5 / a) * t_0) / (2.0 * ((a * (c / b)) - b)); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.021], t$95$1, N[(N[(N[(0.5 / a), $MachinePrecision] * t$95$0), $MachinePrecision] / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 4\right)\\
t_1 := \frac{\sqrt{b \cdot b - t\_0} - b}{2 \cdot a}\\
\mathbf{if}\;t\_1 \leq -0.021:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{a} \cdot t\_0}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -0.0210000000000000013Initial program 81.1%
if -0.0210000000000000013 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.3%
*-commutative46.3%
Simplified46.3%
add-cbrt-cube45.6%
pow1/344.1%
pow344.1%
pow244.1%
pow-pow44.1%
metadata-eval44.1%
Applied egg-rr44.1%
unpow1/345.8%
Simplified45.8%
flip-+45.6%
pow245.6%
add-sqr-sqrt46.2%
pow1/344.0%
pow-pow47.5%
metadata-eval47.5%
associate-*l*47.5%
pow1/347.5%
pow-pow47.5%
metadata-eval47.5%
associate-*l*47.5%
Applied egg-rr47.5%
*-un-lft-identity47.5%
associate-/l/47.5%
neg-mul-147.5%
unpow-prod-down47.5%
metadata-eval47.5%
*-un-lft-identity47.5%
cancel-sign-sub-inv47.5%
unpow247.5%
fma-define47.0%
metadata-eval47.0%
*-commutative47.0%
*-commutative47.0%
Applied egg-rr47.0%
associate-*r/47.0%
times-frac47.0%
*-commutative47.0%
associate-*l/47.0%
Simplified99.3%
Taylor expanded in c around 0 88.5%
distribute-lft-out--88.5%
associate-/l*88.5%
Simplified88.5%
Final simplification86.2%
(FPCore (a b c) :precision binary64 (/ (* (/ 0.5 a) (* c (* a 4.0))) (- (- b) (sqrt (* a (+ (* c -4.0) (/ (pow b 2.0) a)))))))
double code(double a, double b, double c) {
return ((0.5 / a) * (c * (a * 4.0))) / (-b - sqrt((a * ((c * -4.0) + (pow(b, 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 = ((0.5d0 / a) * (c * (a * 4.0d0))) / (-b - sqrt((a * ((c * (-4.0d0)) + ((b ** 2.0d0) / a)))))
end function
public static double code(double a, double b, double c) {
return ((0.5 / a) * (c * (a * 4.0))) / (-b - Math.sqrt((a * ((c * -4.0) + (Math.pow(b, 2.0) / a)))));
}
def code(a, b, c): return ((0.5 / a) * (c * (a * 4.0))) / (-b - math.sqrt((a * ((c * -4.0) + (math.pow(b, 2.0) / a)))))
function code(a, b, c) return Float64(Float64(Float64(0.5 / a) * Float64(c * Float64(a * 4.0))) / Float64(Float64(-b) - sqrt(Float64(a * Float64(Float64(c * -4.0) + Float64((b ^ 2.0) / a)))))) end
function tmp = code(a, b, c) tmp = ((0.5 / a) * (c * (a * 4.0))) / (-b - sqrt((a * ((c * -4.0) + ((b ^ 2.0) / a))))); end
code[a_, b_, c_] := N[(N[(N[(0.5 / a), $MachinePrecision] * N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(a * N[(N[(c * -4.0), $MachinePrecision] + N[(N[Power[b, 2.0], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{0.5}{a} \cdot \left(c \cdot \left(a \cdot 4\right)\right)}{\left(-b\right) - \sqrt{a \cdot \left(c \cdot -4 + \frac{{b}^{2}}{a}\right)}}
\end{array}
Initial program 57.0%
*-commutative57.0%
Simplified57.0%
add-cbrt-cube56.4%
pow1/354.0%
pow354.0%
pow254.0%
pow-pow54.0%
metadata-eval54.0%
Applied egg-rr54.0%
unpow1/356.6%
Simplified56.6%
flip-+56.3%
pow256.3%
add-sqr-sqrt56.7%
pow1/354.0%
pow-pow58.3%
metadata-eval58.3%
associate-*l*58.3%
pow1/358.1%
pow-pow58.3%
metadata-eval58.3%
associate-*l*58.3%
Applied egg-rr58.3%
*-un-lft-identity58.3%
associate-/l/58.3%
neg-mul-158.3%
unpow-prod-down58.3%
metadata-eval58.3%
*-un-lft-identity58.3%
cancel-sign-sub-inv58.3%
unpow258.3%
fma-define57.8%
metadata-eval57.8%
*-commutative57.8%
*-commutative57.8%
Applied egg-rr57.8%
associate-*r/57.8%
times-frac57.8%
*-commutative57.8%
associate-*l/57.8%
Simplified99.3%
Taylor expanded in a around inf 99.3%
Final simplification99.3%
(FPCore (a b c) :precision binary64 (/ (* (/ 0.5 a) (* c (* a 4.0))) (- (- b) (sqrt (fma -4.0 (* c a) (* b b))))))
double code(double a, double b, double c) {
return ((0.5 / a) * (c * (a * 4.0))) / (-b - sqrt(fma(-4.0, (c * a), (b * b))));
}
function code(a, b, c) return Float64(Float64(Float64(0.5 / a) * Float64(c * Float64(a * 4.0))) / Float64(Float64(-b) - sqrt(fma(-4.0, Float64(c * a), Float64(b * b))))) end
code[a_, b_, c_] := N[(N[(N[(0.5 / a), $MachinePrecision] * N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{0.5}{a} \cdot \left(c \cdot \left(a \cdot 4\right)\right)}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)}}
\end{array}
Initial program 57.0%
*-commutative57.0%
Simplified57.0%
add-cbrt-cube56.4%
pow1/354.0%
pow354.0%
pow254.0%
pow-pow54.0%
metadata-eval54.0%
Applied egg-rr54.0%
unpow1/356.6%
Simplified56.6%
flip-+56.3%
pow256.3%
add-sqr-sqrt56.7%
pow1/354.0%
pow-pow58.3%
metadata-eval58.3%
associate-*l*58.3%
pow1/358.1%
pow-pow58.3%
metadata-eval58.3%
associate-*l*58.3%
Applied egg-rr58.3%
*-un-lft-identity58.3%
associate-/l/58.3%
neg-mul-158.3%
unpow-prod-down58.3%
metadata-eval58.3%
*-un-lft-identity58.3%
cancel-sign-sub-inv58.3%
unpow258.3%
fma-define57.8%
metadata-eval57.8%
*-commutative57.8%
*-commutative57.8%
Applied egg-rr57.8%
associate-*r/57.8%
times-frac57.8%
*-commutative57.8%
associate-*l/57.8%
Simplified99.3%
unpow299.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (a b c) :precision binary64 (/ (* (/ 0.5 a) (* c (* a 4.0))) (* 2.0 (- (* a (/ c b)) b))))
double code(double a, double b, double c) {
return ((0.5 / a) * (c * (a * 4.0))) / (2.0 * ((a * (c / b)) - b));
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((0.5d0 / a) * (c * (a * 4.0d0))) / (2.0d0 * ((a * (c / b)) - b))
end function
public static double code(double a, double b, double c) {
return ((0.5 / a) * (c * (a * 4.0))) / (2.0 * ((a * (c / b)) - b));
}
def code(a, b, c): return ((0.5 / a) * (c * (a * 4.0))) / (2.0 * ((a * (c / b)) - b))
function code(a, b, c) return Float64(Float64(Float64(0.5 / a) * Float64(c * Float64(a * 4.0))) / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))) end
function tmp = code(a, b, c) tmp = ((0.5 / a) * (c * (a * 4.0))) / (2.0 * ((a * (c / b)) - b)); end
code[a_, b_, c_] := N[(N[(N[(0.5 / a), $MachinePrecision] * N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{0.5}{a} \cdot \left(c \cdot \left(a \cdot 4\right)\right)}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}
\end{array}
Initial program 57.0%
*-commutative57.0%
Simplified57.0%
add-cbrt-cube56.4%
pow1/354.0%
pow354.0%
pow254.0%
pow-pow54.0%
metadata-eval54.0%
Applied egg-rr54.0%
unpow1/356.6%
Simplified56.6%
flip-+56.3%
pow256.3%
add-sqr-sqrt56.7%
pow1/354.0%
pow-pow58.3%
metadata-eval58.3%
associate-*l*58.3%
pow1/358.1%
pow-pow58.3%
metadata-eval58.3%
associate-*l*58.3%
Applied egg-rr58.3%
*-un-lft-identity58.3%
associate-/l/58.3%
neg-mul-158.3%
unpow-prod-down58.3%
metadata-eval58.3%
*-un-lft-identity58.3%
cancel-sign-sub-inv58.3%
unpow258.3%
fma-define57.8%
metadata-eval57.8%
*-commutative57.8%
*-commutative57.8%
Applied egg-rr57.8%
associate-*r/57.8%
times-frac57.8%
*-commutative57.8%
associate-*l/57.8%
Simplified99.3%
Taylor expanded in c around 0 80.3%
distribute-lft-out--80.3%
associate-/l*80.3%
Simplified80.3%
Final simplification80.3%
(FPCore (a b c) :precision binary64 (/ (- (* (* (/ c b) (/ c b)) (- a)) c) b))
double code(double a, double b, double c) {
return ((((c / b) * (c / b)) * -a) - 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) * (c / b)) * -a) - c) / b
end function
public static double code(double a, double b, double c) {
return ((((c / b) * (c / b)) * -a) - c) / b;
}
def code(a, b, c): return ((((c / b) * (c / b)) * -a) - c) / b
function code(a, b, c) return Float64(Float64(Float64(Float64(Float64(c / b) * Float64(c / b)) * Float64(-a)) - c) / b) end
function tmp = code(a, b, c) tmp = ((((c / b) * (c / b)) * -a) - c) / b; end
code[a_, b_, c_] := N[(N[(N[(N[(N[(c / b), $MachinePrecision] * N[(c / b), $MachinePrecision]), $MachinePrecision] * (-a)), $MachinePrecision] - c), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\frac{c}{b} \cdot \frac{c}{b}\right) \cdot \left(-a\right) - c}{b}
\end{array}
Initial program 57.0%
*-commutative57.0%
Simplified57.0%
Taylor expanded in a around 0 79.6%
distribute-lft-out79.6%
associate-/l*79.6%
Simplified79.6%
Taylor expanded in b around inf 79.7%
neg-mul-179.7%
+-commutative79.7%
unsub-neg79.7%
mul-1-neg79.7%
associate-/l*79.7%
distribute-rgt-neg-in79.7%
unpow279.7%
unpow279.7%
times-frac79.7%
unpow279.7%
Simplified79.7%
unpow279.7%
Applied egg-rr79.7%
Final simplification79.7%
(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 57.0%
*-commutative57.0%
Simplified57.0%
Taylor expanded in b around inf 63.1%
associate-*r/63.1%
mul-1-neg63.1%
Simplified63.1%
Final simplification63.1%
(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 57.0%
*-commutative57.0%
Simplified57.0%
add-cbrt-cube56.4%
pow1/354.0%
pow354.0%
pow254.0%
pow-pow54.0%
metadata-eval54.0%
Applied egg-rr54.0%
unpow1/356.6%
Simplified56.6%
div-inv56.5%
neg-mul-156.5%
fma-define56.5%
pow1/354.0%
pow-pow57.0%
metadata-eval57.0%
associate-*l*57.0%
Applied egg-rr57.0%
Taylor expanded in a around 0 3.2%
associate-*r/3.2%
distribute-rgt1-in3.2%
metadata-eval3.2%
mul0-lft3.2%
metadata-eval3.2%
Simplified3.2%
herbie shell --seed 2024157
(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)))