
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.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) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \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) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.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) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma a (* c -3.0) (pow b 2.0))) (t_1 (* c (pow a 2.0))))
(if (<= b 0.009)
(/ (- t_0 (pow b 2.0)) (* (+ b (sqrt t_0)) (* a 3.0)))
(/
1.0
(+
(*
-3.0
(/
(*
(pow a 3.0)
(+
(* -0.75 (* c (+ (* c -0.75) (* c 0.375))))
(+
(*
-0.2222222222222222
(/
(+ (* 1.265625 (pow c 4.0)) (* (pow c 4.0) 5.0625))
(pow c 2.0)))
(* (pow c 2.0) 0.5625))))
(pow b 5.0)))
(+
(* -3.0 (/ (+ (* -0.75 t_1) (* 0.375 t_1)) (pow b 3.0)))
(+ (* -2.0 (/ b c)) (* 1.5 (/ a b)))))))))
double code(double a, double b, double c) {
double t_0 = fma(a, (c * -3.0), pow(b, 2.0));
double t_1 = c * pow(a, 2.0);
double tmp;
if (b <= 0.009) {
tmp = (t_0 - pow(b, 2.0)) / ((b + sqrt(t_0)) * (a * 3.0));
} else {
tmp = 1.0 / ((-3.0 * ((pow(a, 3.0) * ((-0.75 * (c * ((c * -0.75) + (c * 0.375)))) + ((-0.2222222222222222 * (((1.265625 * pow(c, 4.0)) + (pow(c, 4.0) * 5.0625)) / pow(c, 2.0))) + (pow(c, 2.0) * 0.5625)))) / pow(b, 5.0))) + ((-3.0 * (((-0.75 * t_1) + (0.375 * t_1)) / pow(b, 3.0))) + ((-2.0 * (b / c)) + (1.5 * (a / b)))));
}
return tmp;
}
function code(a, b, c) t_0 = fma(a, Float64(c * -3.0), (b ^ 2.0)) t_1 = Float64(c * (a ^ 2.0)) tmp = 0.0 if (b <= 0.009) tmp = Float64(Float64(t_0 - (b ^ 2.0)) / Float64(Float64(b + sqrt(t_0)) * Float64(a * 3.0))); else tmp = Float64(1.0 / Float64(Float64(-3.0 * Float64(Float64((a ^ 3.0) * Float64(Float64(-0.75 * Float64(c * Float64(Float64(c * -0.75) + Float64(c * 0.375)))) + Float64(Float64(-0.2222222222222222 * Float64(Float64(Float64(1.265625 * (c ^ 4.0)) + Float64((c ^ 4.0) * 5.0625)) / (c ^ 2.0))) + Float64((c ^ 2.0) * 0.5625)))) / (b ^ 5.0))) + Float64(Float64(-3.0 * Float64(Float64(Float64(-0.75 * t_1) + Float64(0.375 * t_1)) / (b ^ 3.0))) + Float64(Float64(-2.0 * Float64(b / c)) + Float64(1.5 * Float64(a / b)))))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -3.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.009], N[(N[(t$95$0 - N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(-3.0 * N[(N[(N[Power[a, 3.0], $MachinePrecision] * N[(N[(-0.75 * N[(c * N[(N[(c * -0.75), $MachinePrecision] + N[(c * 0.375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.2222222222222222 * N[(N[(N[(1.265625 * N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[c, 4.0], $MachinePrecision] * 5.0625), $MachinePrecision]), $MachinePrecision] / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[c, 2.0], $MachinePrecision] * 0.5625), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-3.0 * N[(N[(N[(-0.75 * t$95$1), $MachinePrecision] + N[(0.375 * t$95$1), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, c \cdot -3, {b}^{2}\right)\\
t_1 := c \cdot {a}^{2}\\
\mathbf{if}\;b \leq 0.009:\\
\;\;\;\;\frac{t_0 - {b}^{2}}{\left(b + \sqrt{t_0}\right) \cdot \left(a \cdot 3\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-3 \cdot \frac{{a}^{3} \cdot \left(-0.75 \cdot \left(c \cdot \left(c \cdot -0.75 + c \cdot 0.375\right)\right) + \left(-0.2222222222222222 \cdot \frac{1.265625 \cdot {c}^{4} + {c}^{4} \cdot 5.0625}{{c}^{2}} + {c}^{2} \cdot 0.5625\right)\right)}{{b}^{5}} + \left(-3 \cdot \frac{-0.75 \cdot t_1 + 0.375 \cdot t_1}{{b}^{3}} + \left(-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}\right)\right)}\\
\end{array}
\end{array}
if b < 0.00899999999999999932Initial program 91.7%
Simplified91.8%
fma-udef91.6%
*-commutative91.6%
associate-*r*91.7%
*-commutative91.7%
+-commutative91.7%
fma-udef92.0%
add-cbrt-cube89.6%
pow1/386.7%
pow386.7%
sqrt-pow286.6%
fma-udef86.6%
+-commutative86.6%
*-commutative86.6%
associate-*r*86.6%
*-commutative86.6%
fma-udef86.6%
pow286.6%
metadata-eval86.6%
Applied egg-rr86.6%
unpow1/390.0%
Simplified90.0%
add-cbrt-cube89.9%
pow389.9%
pow1/386.6%
pow-pow91.6%
metadata-eval91.6%
pow1/291.6%
*-commutative91.6%
Applied egg-rr91.6%
rem-cbrt-cube91.8%
div-inv91.6%
flip--91.8%
frac-times91.9%
add-sqr-sqrt92.8%
unpow292.8%
Applied egg-rr92.8%
*-rgt-identity92.8%
+-commutative92.8%
Simplified92.8%
if 0.00899999999999999932 < b Initial program 53.7%
Simplified53.8%
fma-udef53.7%
*-commutative53.7%
associate-*r*53.7%
*-commutative53.7%
+-commutative53.7%
fma-udef53.7%
add-cbrt-cube52.6%
pow1/350.7%
pow350.7%
sqrt-pow250.7%
fma-udef50.7%
+-commutative50.7%
*-commutative50.7%
associate-*r*50.7%
*-commutative50.7%
fma-udef50.7%
pow250.7%
metadata-eval50.7%
Applied egg-rr50.7%
unpow1/352.5%
Simplified52.5%
clear-num52.5%
inv-pow52.5%
*-commutative52.5%
pow1/350.7%
pow-pow53.8%
metadata-eval53.8%
pow1/253.8%
Applied egg-rr53.8%
unpow-153.8%
associate-/l*53.8%
Simplified53.8%
Taylor expanded in b around inf 94.2%
Taylor expanded in a around 0 94.2%
Final simplification94.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma a (* c -3.0) (pow b 2.0))))
(if (<= b 0.009)
(/ (- t_0 (pow b 2.0)) (* (+ b (sqrt t_0)) (* a 3.0)))
(+
(* -0.5625 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0)))
(+
(* -0.5 (/ c b))
(+
(* -0.375 (/ (* a (pow c 2.0)) (pow b 3.0)))
(*
-0.16666666666666666
(* (/ (pow (* a c) 4.0) (pow b 7.0)) (/ 6.328125 a)))))))))
double code(double a, double b, double c) {
double t_0 = fma(a, (c * -3.0), pow(b, 2.0));
double tmp;
if (b <= 0.009) {
tmp = (t_0 - pow(b, 2.0)) / ((b + sqrt(t_0)) * (a * 3.0));
} else {
tmp = (-0.5625 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) + ((-0.5 * (c / b)) + ((-0.375 * ((a * pow(c, 2.0)) / pow(b, 3.0))) + (-0.16666666666666666 * ((pow((a * c), 4.0) / pow(b, 7.0)) * (6.328125 / a)))));
}
return tmp;
}
function code(a, b, c) t_0 = fma(a, Float64(c * -3.0), (b ^ 2.0)) tmp = 0.0 if (b <= 0.009) tmp = Float64(Float64(t_0 - (b ^ 2.0)) / Float64(Float64(b + sqrt(t_0)) * Float64(a * 3.0))); else tmp = Float64(Float64(-0.5625 * Float64(Float64((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + Float64(Float64(-0.5 * Float64(c / b)) + Float64(Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0))) + Float64(-0.16666666666666666 * Float64(Float64((Float64(a * c) ^ 4.0) / (b ^ 7.0)) * Float64(6.328125 / a)))))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -3.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 0.009], N[(N[(t$95$0 - N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5625 * N[(N[(N[Power[a, 2.0], $MachinePrecision] * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.375 * N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[(N[(N[Power[N[(a * c), $MachinePrecision], 4.0], $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision] * N[(6.328125 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, c \cdot -3, {b}^{2}\right)\\
\mathbf{if}\;b \leq 0.009:\\
\;\;\;\;\frac{t_0 - {b}^{2}}{\left(b + \sqrt{t_0}\right) \cdot \left(a \cdot 3\right)}\\
\mathbf{else}:\\
\;\;\;\;-0.5625 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-0.5 \cdot \frac{c}{b} + \left(-0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}} + -0.16666666666666666 \cdot \left(\frac{{\left(a \cdot c\right)}^{4}}{{b}^{7}} \cdot \frac{6.328125}{a}\right)\right)\right)\\
\end{array}
\end{array}
if b < 0.00899999999999999932Initial program 91.7%
Simplified91.8%
fma-udef91.6%
*-commutative91.6%
associate-*r*91.7%
*-commutative91.7%
+-commutative91.7%
fma-udef92.0%
add-cbrt-cube89.6%
pow1/386.7%
pow386.7%
sqrt-pow286.6%
fma-udef86.6%
+-commutative86.6%
*-commutative86.6%
associate-*r*86.6%
*-commutative86.6%
fma-udef86.6%
pow286.6%
metadata-eval86.6%
Applied egg-rr86.6%
unpow1/390.0%
Simplified90.0%
add-cbrt-cube89.9%
pow389.9%
pow1/386.6%
pow-pow91.6%
metadata-eval91.6%
pow1/291.6%
*-commutative91.6%
Applied egg-rr91.6%
rem-cbrt-cube91.8%
div-inv91.6%
flip--91.8%
frac-times91.9%
add-sqr-sqrt92.8%
unpow292.8%
Applied egg-rr92.8%
*-rgt-identity92.8%
+-commutative92.8%
Simplified92.8%
if 0.00899999999999999932 < b Initial program 53.7%
Taylor expanded in b around inf 93.9%
Taylor expanded in c around 0 93.9%
distribute-rgt-in93.9%
associate-*r*93.9%
associate-*r*93.9%
distribute-rgt-out93.9%
*-commutative93.9%
times-frac93.9%
Simplified93.9%
Final simplification93.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma a (* c -3.0) (pow b 2.0))) (t_1 (* c (pow a 2.0))))
(if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -0.25)
(/ (- t_0 (pow b 2.0)) (* (+ b (sqrt t_0)) (* a 3.0)))
(/
1.0
(+
(* -3.0 (/ (+ (* -0.75 t_1) (* 0.375 t_1)) (pow b 3.0)))
(+ (* -2.0 (/ b c)) (* 1.5 (/ a b))))))))
double code(double a, double b, double c) {
double t_0 = fma(a, (c * -3.0), pow(b, 2.0));
double t_1 = c * pow(a, 2.0);
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -0.25) {
tmp = (t_0 - pow(b, 2.0)) / ((b + sqrt(t_0)) * (a * 3.0));
} else {
tmp = 1.0 / ((-3.0 * (((-0.75 * t_1) + (0.375 * t_1)) / pow(b, 3.0))) + ((-2.0 * (b / c)) + (1.5 * (a / b))));
}
return tmp;
}
function code(a, b, c) t_0 = fma(a, Float64(c * -3.0), (b ^ 2.0)) t_1 = Float64(c * (a ^ 2.0)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) <= -0.25) tmp = Float64(Float64(t_0 - (b ^ 2.0)) / Float64(Float64(b + sqrt(t_0)) * Float64(a * 3.0))); else tmp = Float64(1.0 / Float64(Float64(-3.0 * Float64(Float64(Float64(-0.75 * t_1) + Float64(0.375 * t_1)) / (b ^ 3.0))) + Float64(Float64(-2.0 * Float64(b / c)) + Float64(1.5 * Float64(a / b))))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -3.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], -0.25], N[(N[(t$95$0 - N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(b + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision] * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(-3.0 * N[(N[(N[(-0.75 * t$95$1), $MachinePrecision] + N[(0.375 * t$95$1), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(a, c \cdot -3, {b}^{2}\right)\\
t_1 := c \cdot {a}^{2}\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -0.25:\\
\;\;\;\;\frac{t_0 - {b}^{2}}{\left(b + \sqrt{t_0}\right) \cdot \left(a \cdot 3\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-3 \cdot \frac{-0.75 \cdot t_1 + 0.375 \cdot t_1}{{b}^{3}} + \left(-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -0.25Initial program 83.1%
Simplified83.2%
fma-udef83.1%
*-commutative83.1%
associate-*r*83.1%
*-commutative83.1%
+-commutative83.1%
fma-udef83.3%
add-cbrt-cube81.9%
pow1/378.8%
pow378.8%
sqrt-pow278.8%
fma-udef78.8%
+-commutative78.8%
*-commutative78.8%
associate-*r*78.8%
*-commutative78.8%
fma-udef78.8%
pow278.8%
metadata-eval78.8%
Applied egg-rr78.8%
unpow1/382.1%
Simplified82.1%
add-cbrt-cube82.0%
pow382.0%
pow1/378.8%
pow-pow83.1%
metadata-eval83.1%
pow1/283.1%
*-commutative83.1%
Applied egg-rr83.1%
rem-cbrt-cube83.2%
div-inv83.1%
flip--83.4%
frac-times83.5%
add-sqr-sqrt84.9%
unpow284.9%
Applied egg-rr84.9%
*-rgt-identity84.9%
+-commutative84.9%
Simplified84.9%
if -0.25 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 50.2%
Simplified50.2%
fma-udef50.2%
*-commutative50.2%
associate-*r*50.2%
*-commutative50.2%
+-commutative50.2%
fma-udef50.1%
add-cbrt-cube49.0%
pow1/347.3%
pow347.2%
sqrt-pow247.2%
fma-udef47.2%
+-commutative47.2%
*-commutative47.2%
associate-*r*47.2%
*-commutative47.2%
fma-udef47.2%
pow247.2%
metadata-eval47.2%
Applied egg-rr47.2%
unpow1/348.8%
Simplified48.8%
clear-num48.8%
inv-pow48.8%
*-commutative48.8%
pow1/347.2%
pow-pow50.2%
metadata-eval50.2%
pow1/250.2%
Applied egg-rr50.2%
unpow-150.2%
associate-/l*50.2%
Simplified50.2%
Taylor expanded in b around inf 93.2%
Final simplification91.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (pow a 2.0))))
(if (<= b 2.1)
(/
1.0
(*
(/ 1.0 (- (sqrt (fma a (* c -3.0) (pow b 2.0))) b))
(/ a 0.3333333333333333)))
(/
1.0
(+
(* -3.0 (/ (+ (* -0.75 t_0) (* 0.375 t_0)) (pow b 3.0)))
(+ (* -2.0 (/ b c)) (* 1.5 (/ a b))))))))
double code(double a, double b, double c) {
double t_0 = c * pow(a, 2.0);
double tmp;
if (b <= 2.1) {
tmp = 1.0 / ((1.0 / (sqrt(fma(a, (c * -3.0), pow(b, 2.0))) - b)) * (a / 0.3333333333333333));
} else {
tmp = 1.0 / ((-3.0 * (((-0.75 * t_0) + (0.375 * t_0)) / pow(b, 3.0))) + ((-2.0 * (b / c)) + (1.5 * (a / b))));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(c * (a ^ 2.0)) tmp = 0.0 if (b <= 2.1) tmp = Float64(1.0 / Float64(Float64(1.0 / Float64(sqrt(fma(a, Float64(c * -3.0), (b ^ 2.0))) - b)) * Float64(a / 0.3333333333333333))); else tmp = Float64(1.0 / Float64(Float64(-3.0 * Float64(Float64(Float64(-0.75 * t_0) + Float64(0.375 * t_0)) / (b ^ 3.0))) + Float64(Float64(-2.0 * Float64(b / c)) + Float64(1.5 * Float64(a / b))))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 2.1], N[(1.0 / N[(N[(1.0 / N[(N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision] * N[(a / 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(-3.0 * N[(N[(N[(-0.75 * t$95$0), $MachinePrecision] + N[(0.375 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot {a}^{2}\\
\mathbf{if}\;b \leq 2.1:\\
\;\;\;\;\frac{1}{\frac{1}{\sqrt{\mathsf{fma}\left(a, c \cdot -3, {b}^{2}\right)} - b} \cdot \frac{a}{0.3333333333333333}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-3 \cdot \frac{-0.75 \cdot t_0 + 0.375 \cdot t_0}{{b}^{3}} + \left(-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < 2.10000000000000009Initial program 82.5%
Simplified82.7%
fma-udef82.5%
*-commutative82.5%
associate-*r*82.5%
*-commutative82.5%
+-commutative82.5%
fma-udef82.7%
add-cbrt-cube80.5%
pow1/379.7%
pow379.4%
sqrt-pow279.3%
fma-udef79.4%
+-commutative79.4%
*-commutative79.4%
associate-*r*79.4%
*-commutative79.4%
fma-udef79.5%
pow279.5%
metadata-eval79.5%
Applied egg-rr79.5%
unpow1/380.8%
Simplified80.8%
clear-num80.8%
inv-pow80.8%
*-commutative80.8%
pow1/379.5%
pow-pow82.6%
metadata-eval82.6%
pow1/282.6%
Applied egg-rr82.6%
unpow-182.6%
associate-/l*82.7%
Simplified82.7%
*-un-lft-identity82.7%
div-inv82.8%
metadata-eval82.8%
times-frac82.8%
Applied egg-rr82.8%
if 2.10000000000000009 < b Initial program 51.5%
Simplified51.5%
fma-udef51.5%
*-commutative51.5%
associate-*r*51.5%
*-commutative51.5%
+-commutative51.5%
fma-udef51.4%
add-cbrt-cube50.4%
pow1/348.3%
pow348.3%
sqrt-pow248.3%
fma-udef48.3%
+-commutative48.3%
*-commutative48.3%
associate-*r*48.3%
*-commutative48.3%
fma-udef48.3%
pow248.3%
metadata-eval48.3%
Applied egg-rr48.3%
unpow1/350.2%
Simplified50.2%
clear-num50.2%
inv-pow50.2%
*-commutative50.2%
pow1/348.3%
pow-pow51.5%
metadata-eval51.5%
pow1/251.5%
Applied egg-rr51.5%
unpow-151.5%
associate-/l*51.5%
Simplified51.5%
Taylor expanded in b around inf 92.9%
Final simplification91.5%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -0.25) (/ (- (sqrt (fma a (* c -3.0) (* b b))) b) (* a 3.0)) (/ 1.0 (+ (* -2.0 (/ b c)) (* 1.5 (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -0.25) {
tmp = (sqrt(fma(a, (c * -3.0), (b * b))) - b) / (a * 3.0);
} else {
tmp = 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / b)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) <= -0.25) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -3.0), Float64(b * b))) - b) / Float64(a * 3.0)); else tmp = Float64(1.0 / Float64(Float64(-2.0 * Float64(b / c)) + Float64(1.5 * Float64(a / b)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], -0.25], N[(N[(N[Sqrt[N[(a * N[(c * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -0.25:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -3, b \cdot b\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -0.25Initial program 83.1%
Simplified83.2%
if -0.25 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 50.2%
Simplified50.2%
fma-udef50.2%
*-commutative50.2%
associate-*r*50.2%
*-commutative50.2%
+-commutative50.2%
fma-udef50.1%
add-cbrt-cube49.0%
pow1/347.3%
pow347.2%
sqrt-pow247.2%
fma-udef47.2%
+-commutative47.2%
*-commutative47.2%
associate-*r*47.2%
*-commutative47.2%
fma-udef47.2%
pow247.2%
metadata-eval47.2%
Applied egg-rr47.2%
unpow1/348.8%
Simplified48.8%
clear-num48.8%
inv-pow48.8%
*-commutative48.8%
pow1/347.2%
pow-pow50.2%
metadata-eval50.2%
pow1/250.2%
Applied egg-rr50.2%
unpow-150.2%
associate-/l*50.2%
Simplified50.2%
Taylor expanded in a around 0 87.7%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -0.25) (/ (- (sqrt (fma b b (* c (* a -3.0)))) b) (* a 3.0)) (/ 1.0 (+ (* -2.0 (/ b c)) (* 1.5 (/ a b))))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -0.25) {
tmp = (sqrt(fma(b, b, (c * (a * -3.0)))) - b) / (a * 3.0);
} else {
tmp = 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / b)));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) <= -0.25) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -3.0)))) - b) / Float64(a * 3.0)); else tmp = Float64(1.0 / Float64(Float64(-2.0 * Float64(b / c)) + Float64(1.5 * Float64(a / b)))); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], -0.25], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3} \leq -0.25:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -0.25Initial program 83.1%
Simplified83.3%
if -0.25 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 50.2%
Simplified50.2%
fma-udef50.2%
*-commutative50.2%
associate-*r*50.2%
*-commutative50.2%
+-commutative50.2%
fma-udef50.1%
add-cbrt-cube49.0%
pow1/347.3%
pow347.2%
sqrt-pow247.2%
fma-udef47.2%
+-commutative47.2%
*-commutative47.2%
associate-*r*47.2%
*-commutative47.2%
fma-udef47.2%
pow247.2%
metadata-eval47.2%
Applied egg-rr47.2%
unpow1/348.8%
Simplified48.8%
clear-num48.8%
inv-pow48.8%
*-commutative48.8%
pow1/347.2%
pow-pow50.2%
metadata-eval50.2%
pow1/250.2%
Applied egg-rr50.2%
unpow-150.2%
associate-/l*50.2%
Simplified50.2%
Taylor expanded in a around 0 87.7%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)))) (if (<= t_0 -0.25) t_0 (/ 1.0 (+ (* -2.0 (/ b c)) (* 1.5 (/ a b)))))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
double tmp;
if (t_0 <= -0.25) {
tmp = t_0;
} else {
tmp = 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / 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) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)
if (t_0 <= (-0.25d0)) then
tmp = t_0
else
tmp = 1.0d0 / (((-2.0d0) * (b / c)) + (1.5d0 * (a / b)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0);
double tmp;
if (t_0 <= -0.25) {
tmp = t_0;
} else {
tmp = 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / b)));
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0) tmp = 0 if t_0 <= -0.25: tmp = t_0 else: tmp = 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / b))) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b) / Float64(a * 3.0)) tmp = 0.0 if (t_0 <= -0.25) tmp = t_0; else tmp = Float64(1.0 / Float64(Float64(-2.0 * Float64(b / c)) + Float64(1.5 * Float64(a / b)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0); tmp = 0.0; if (t_0 <= -0.25) tmp = t_0; else tmp = 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / b))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.25], t$95$0, N[(1.0 / N[(N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b}{a \cdot 3}\\
\mathbf{if}\;t_0 \leq -0.25:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -0.25Initial program 83.1%
if -0.25 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 50.2%
Simplified50.2%
fma-udef50.2%
*-commutative50.2%
associate-*r*50.2%
*-commutative50.2%
+-commutative50.2%
fma-udef50.1%
add-cbrt-cube49.0%
pow1/347.3%
pow347.2%
sqrt-pow247.2%
fma-udef47.2%
+-commutative47.2%
*-commutative47.2%
associate-*r*47.2%
*-commutative47.2%
fma-udef47.2%
pow247.2%
metadata-eval47.2%
Applied egg-rr47.2%
unpow1/348.8%
Simplified48.8%
clear-num48.8%
inv-pow48.8%
*-commutative48.8%
pow1/347.2%
pow-pow50.2%
metadata-eval50.2%
pow1/250.2%
Applied egg-rr50.2%
unpow-150.2%
associate-/l*50.2%
Simplified50.2%
Taylor expanded in a around 0 87.7%
Final simplification86.9%
(FPCore (a b c) :precision binary64 (/ 1.0 (+ (* -2.0 (/ b c)) (* 1.5 (/ a b)))))
double code(double a, double b, double c) {
return 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / b)));
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 1.0d0 / (((-2.0d0) * (b / c)) + (1.5d0 * (a / b)))
end function
public static double code(double a, double b, double c) {
return 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / b)));
}
def code(a, b, c): return 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / b)))
function code(a, b, c) return Float64(1.0 / Float64(Float64(-2.0 * Float64(b / c)) + Float64(1.5 * Float64(a / b)))) end
function tmp = code(a, b, c) tmp = 1.0 / ((-2.0 * (b / c)) + (1.5 * (a / b))); end
code[a_, b_, c_] := N[(1.0 / N[(N[(-2.0 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(1.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{-2 \cdot \frac{b}{c} + 1.5 \cdot \frac{a}{b}}
\end{array}
Initial program 56.0%
Simplified56.0%
fma-udef56.0%
*-commutative56.0%
associate-*r*56.0%
*-commutative56.0%
+-commutative56.0%
fma-udef56.0%
add-cbrt-cube54.7%
pow1/352.8%
pow352.8%
sqrt-pow252.8%
fma-udef52.8%
+-commutative52.8%
*-commutative52.8%
associate-*r*52.8%
*-commutative52.8%
fma-udef52.8%
pow252.8%
metadata-eval52.8%
Applied egg-rr52.8%
unpow1/354.7%
Simplified54.7%
clear-num54.7%
inv-pow54.7%
*-commutative54.7%
pow1/352.8%
pow-pow56.0%
metadata-eval56.0%
pow1/256.0%
Applied egg-rr56.0%
unpow-156.0%
associate-/l*56.0%
Simplified56.0%
Taylor expanded in a around 0 82.5%
Final simplification82.5%
(FPCore (a b c) :precision binary64 (* -0.5 (/ c b)))
double code(double a, double b, double c) {
return -0.5 * (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 = (-0.5d0) * (c / b)
end function
public static double code(double a, double b, double c) {
return -0.5 * (c / b);
}
def code(a, b, c): return -0.5 * (c / b)
function code(a, b, c) return Float64(-0.5 * Float64(c / b)) end
function tmp = code(a, b, c) tmp = -0.5 * (c / b); end
code[a_, b_, c_] := N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \frac{c}{b}
\end{array}
Initial program 56.0%
Taylor expanded in b around inf 64.1%
Final simplification64.1%
herbie shell --seed 2023305
(FPCore (a b c)
:name "Cubic critical, 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) (* (* 3.0 a) c)))) (* 3.0 a)))