
(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 8 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 (pow (* c a) 4.0))
(t_1 (pow (* c a) 2.0))
(t_2 (* t_1 -3.375))
(t_3 (* a (* c 3.0)))
(t_4 (pow t_3 2.0))
(t_5
(fma -0.5 (* a (* c (* t_4 -1.125))) (* (pow (* c a) 3.0) 3.375))))
(+
(* -0.5 (/ c b))
(*
0.3333333333333333
(+
(+
(/ (- (* (pow c 2.0) (* a -4.5)) (/ t_2 a)) (pow b 3.0))
(/ (- (* (* (pow a 2.0) (pow c 3.0)) 6.75) (/ t_5 a)) (pow b 5.0)))
(/
(fma
-10.125
(* (pow a 3.0) (pow c 4.0))
(-
(* a (* (* (pow c 2.0) t_2) 4.5))
(/
(fma
-0.5
(* t_3 t_5)
(fma
-0.5
(+ (* t_0 5.0625) (* (pow (* a (* c -3.0)) 4.0) 0.015625))
(fma 0.125 (* t_1 (* -3.375 t_4)) (* t_0 -2.53125))))
a)))
(pow b 7.0)))))))
double code(double a, double b, double c) {
double t_0 = pow((c * a), 4.0);
double t_1 = pow((c * a), 2.0);
double t_2 = t_1 * -3.375;
double t_3 = a * (c * 3.0);
double t_4 = pow(t_3, 2.0);
double t_5 = fma(-0.5, (a * (c * (t_4 * -1.125))), (pow((c * a), 3.0) * 3.375));
return (-0.5 * (c / b)) + (0.3333333333333333 * (((((pow(c, 2.0) * (a * -4.5)) - (t_2 / a)) / pow(b, 3.0)) + ((((pow(a, 2.0) * pow(c, 3.0)) * 6.75) - (t_5 / a)) / pow(b, 5.0))) + (fma(-10.125, (pow(a, 3.0) * pow(c, 4.0)), ((a * ((pow(c, 2.0) * t_2) * 4.5)) - (fma(-0.5, (t_3 * t_5), fma(-0.5, ((t_0 * 5.0625) + (pow((a * (c * -3.0)), 4.0) * 0.015625)), fma(0.125, (t_1 * (-3.375 * t_4)), (t_0 * -2.53125)))) / a))) / pow(b, 7.0))));
}
function code(a, b, c) t_0 = Float64(c * a) ^ 4.0 t_1 = Float64(c * a) ^ 2.0 t_2 = Float64(t_1 * -3.375) t_3 = Float64(a * Float64(c * 3.0)) t_4 = t_3 ^ 2.0 t_5 = fma(-0.5, Float64(a * Float64(c * Float64(t_4 * -1.125))), Float64((Float64(c * a) ^ 3.0) * 3.375)) return Float64(Float64(-0.5 * Float64(c / b)) + Float64(0.3333333333333333 * Float64(Float64(Float64(Float64(Float64((c ^ 2.0) * Float64(a * -4.5)) - Float64(t_2 / a)) / (b ^ 3.0)) + Float64(Float64(Float64(Float64((a ^ 2.0) * (c ^ 3.0)) * 6.75) - Float64(t_5 / a)) / (b ^ 5.0))) + Float64(fma(-10.125, Float64((a ^ 3.0) * (c ^ 4.0)), Float64(Float64(a * Float64(Float64((c ^ 2.0) * t_2) * 4.5)) - Float64(fma(-0.5, Float64(t_3 * t_5), fma(-0.5, Float64(Float64(t_0 * 5.0625) + Float64((Float64(a * Float64(c * -3.0)) ^ 4.0) * 0.015625)), fma(0.125, Float64(t_1 * Float64(-3.375 * t_4)), Float64(t_0 * -2.53125)))) / a))) / (b ^ 7.0))))) end
code[a_, b_, c_] := Block[{t$95$0 = N[Power[N[(c * a), $MachinePrecision], 4.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(c * a), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * -3.375), $MachinePrecision]}, Block[{t$95$3 = N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Power[t$95$3, 2.0], $MachinePrecision]}, Block[{t$95$5 = N[(-0.5 * N[(a * N[(c * N[(t$95$4 * -1.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(c * a), $MachinePrecision], 3.0], $MachinePrecision] * 3.375), $MachinePrecision]), $MachinePrecision]}, N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[(N[(N[(N[(N[(N[Power[c, 2.0], $MachinePrecision] * N[(a * -4.5), $MachinePrecision]), $MachinePrecision] - N[(t$95$2 / a), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[Power[a, 2.0], $MachinePrecision] * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] * 6.75), $MachinePrecision] - N[(t$95$5 / a), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-10.125 * N[(N[Power[a, 3.0], $MachinePrecision] * N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[(a * N[(N[(N[Power[c, 2.0], $MachinePrecision] * t$95$2), $MachinePrecision] * 4.5), $MachinePrecision]), $MachinePrecision] - N[(N[(-0.5 * N[(t$95$3 * t$95$5), $MachinePrecision] + N[(-0.5 * N[(N[(t$95$0 * 5.0625), $MachinePrecision] + N[(N[Power[N[(a * N[(c * -3.0), $MachinePrecision]), $MachinePrecision], 4.0], $MachinePrecision] * 0.015625), $MachinePrecision]), $MachinePrecision] + N[(0.125 * N[(t$95$1 * N[(-3.375 * t$95$4), $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * -2.53125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(c \cdot a\right)}^{4}\\
t_1 := {\left(c \cdot a\right)}^{2}\\
t_2 := t_1 \cdot -3.375\\
t_3 := a \cdot \left(c \cdot 3\right)\\
t_4 := {t_3}^{2}\\
t_5 := \mathsf{fma}\left(-0.5, a \cdot \left(c \cdot \left(t_4 \cdot -1.125\right)\right), {\left(c \cdot a\right)}^{3} \cdot 3.375\right)\\
-0.5 \cdot \frac{c}{b} + 0.3333333333333333 \cdot \left(\left(\frac{{c}^{2} \cdot \left(a \cdot -4.5\right) - \frac{t_2}{a}}{{b}^{3}} + \frac{\left({a}^{2} \cdot {c}^{3}\right) \cdot 6.75 - \frac{t_5}{a}}{{b}^{5}}\right) + \frac{\mathsf{fma}\left(-10.125, {a}^{3} \cdot {c}^{4}, a \cdot \left(\left({c}^{2} \cdot t_2\right) \cdot 4.5\right) - \frac{\mathsf{fma}\left(-0.5, t_3 \cdot t_5, \mathsf{fma}\left(-0.5, t_0 \cdot 5.0625 + {\left(a \cdot \left(c \cdot -3\right)\right)}^{4} \cdot 0.015625, \mathsf{fma}\left(0.125, t_1 \cdot \left(-3.375 \cdot t_4\right), t_0 \cdot -2.53125\right)\right)\right)}{a}\right)}{{b}^{7}}\right)
\end{array}
\end{array}
Initial program 35.2%
+-commutative35.2%
sqr-neg35.2%
unsub-neg35.2%
div-sub34.5%
--rgt-identity34.5%
div-sub35.2%
Simplified35.2%
*-un-lft-identity35.2%
*-un-lft-identity35.2%
associate-*r*35.2%
*-commutative35.2%
metadata-eval35.2%
distribute-lft-neg-in35.2%
associate-*l*35.2%
fma-neg35.2%
flip--35.1%
sqrt-div35.0%
Applied egg-rr34.9%
unpow234.9%
swap-sqr34.9%
metadata-eval34.9%
metadata-eval34.9%
swap-sqr34.9%
*-commutative34.9%
associate-*r*34.9%
*-commutative34.9%
associate-*r*34.9%
unpow234.9%
fma-udef34.8%
unpow134.8%
sqr-pow34.8%
hypot-def34.9%
metadata-eval34.9%
unpow1/234.9%
Simplified34.9%
Taylor expanded in b around inf 93.2%
Simplified94.6%
Final simplification94.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (pow (* c a) 4.0)))
(+
(* -0.5625 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0)))
(+
(* -0.5 (/ c b))
(+
(* -0.375 (/ (* (pow c 2.0) a) (pow b 3.0)))
(*
-0.16666666666666666
(*
(fma 5.0625 t_0 (* t_0 1.265625))
(reciprocal (* a (pow b 7.0))))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(c \cdot a\right)}^{4}\\
-0.5625 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-0.5 \cdot \frac{c}{b} + \left(-0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + -0.16666666666666666 \cdot \left(\mathsf{fma}\left(5.0625, t_0, t_0 \cdot 1.265625\right) \cdot \mathsf{reciprocal}\left(\left(a \cdot {b}^{7}\right)\right)\right)\right)\right)
\end{array}
\end{array}
Initial program 35.2%
Taylor expanded in b around inf 94.5%
div-inv94.5%
fma-def94.5%
pow-prod-down94.5%
*-commutative94.5%
unpow-prod-down94.5%
pow-prod-down94.5%
pow-pow94.5%
metadata-eval94.5%
metadata-eval94.5%
reciprocal-define94.6%
Applied egg-rr94.6%
Final simplification94.6%
(FPCore (a b c)
:precision binary64
(+
(* -0.5625 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0)))
(+
(* -0.5 (/ c b))
(+
(* -0.375 (/ (* (pow c 2.0) a) (pow b 3.0)))
(*
-0.16666666666666666
(/ (pow (* c a) 4.0) (/ (* a (pow b 7.0)) 6.328125)))))))
double code(double a, double b, double c) {
return (-0.5625 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) + ((-0.5 * (c / b)) + ((-0.375 * ((pow(c, 2.0) * a) / pow(b, 3.0))) + (-0.16666666666666666 * (pow((c * a), 4.0) / ((a * pow(b, 7.0)) / 6.328125)))));
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((-0.5625d0) * (((a ** 2.0d0) * (c ** 3.0d0)) / (b ** 5.0d0))) + (((-0.5d0) * (c / b)) + (((-0.375d0) * (((c ** 2.0d0) * a) / (b ** 3.0d0))) + ((-0.16666666666666666d0) * (((c * a) ** 4.0d0) / ((a * (b ** 7.0d0)) / 6.328125d0)))))
end function
public static double code(double a, double b, double c) {
return (-0.5625 * ((Math.pow(a, 2.0) * Math.pow(c, 3.0)) / Math.pow(b, 5.0))) + ((-0.5 * (c / b)) + ((-0.375 * ((Math.pow(c, 2.0) * a) / Math.pow(b, 3.0))) + (-0.16666666666666666 * (Math.pow((c * a), 4.0) / ((a * Math.pow(b, 7.0)) / 6.328125)))));
}
def code(a, b, c): return (-0.5625 * ((math.pow(a, 2.0) * math.pow(c, 3.0)) / math.pow(b, 5.0))) + ((-0.5 * (c / b)) + ((-0.375 * ((math.pow(c, 2.0) * a) / math.pow(b, 3.0))) + (-0.16666666666666666 * (math.pow((c * a), 4.0) / ((a * math.pow(b, 7.0)) / 6.328125)))))
function code(a, b, c) return 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((c ^ 2.0) * a) / (b ^ 3.0))) + Float64(-0.16666666666666666 * Float64((Float64(c * a) ^ 4.0) / Float64(Float64(a * (b ^ 7.0)) / 6.328125)))))) end
function tmp = code(a, b, c) tmp = (-0.5625 * (((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + ((-0.5 * (c / b)) + ((-0.375 * (((c ^ 2.0) * a) / (b ^ 3.0))) + (-0.16666666666666666 * (((c * a) ^ 4.0) / ((a * (b ^ 7.0)) / 6.328125))))); end
code[a_, b_, c_] := 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[(N[Power[c, 2.0], $MachinePrecision] * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[(N[Power[N[(c * a), $MachinePrecision], 4.0], $MachinePrecision] / N[(N[(a * N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision] / 6.328125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5625 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-0.5 \cdot \frac{c}{b} + \left(-0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + -0.16666666666666666 \cdot \frac{{\left(c \cdot a\right)}^{4}}{\frac{a \cdot {b}^{7}}{6.328125}}\right)\right)
\end{array}
Initial program 35.2%
Taylor expanded in b around inf 94.5%
Taylor expanded in c around 0 94.5%
associate-*r/94.5%
Simplified94.5%
Final simplification94.5%
(FPCore (a b c) :precision binary64 (+ (* -0.5625 (* (* (pow a 2.0) (pow c 3.0)) (reciprocal (pow b 5.0)))) (+ (* -0.5 (/ c b)) (* -0.375 (/ (* (pow c 2.0) a) (pow b 3.0))))))
\begin{array}{l}
\\
-0.5625 \cdot \left(\left({a}^{2} \cdot {c}^{3}\right) \cdot \mathsf{reciprocal}\left(\left({b}^{5}\right)\right)\right) + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)
\end{array}
Initial program 35.2%
Taylor expanded in b around inf 92.3%
clear-num92.3%
inv-pow92.3%
Applied egg-rr92.3%
unpow-192.3%
associate-/r/92.3%
reciprocal-define92.3%
Simplified92.3%
Final simplification92.3%
(FPCore (a b c) :precision binary64 (+ (* -0.5625 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0))) (+ (* -0.5 (/ c b)) (* -0.375 (/ (* (pow c 2.0) a) (pow b 3.0))))))
double code(double a, double b, double c) {
return (-0.5625 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) + ((-0.5 * (c / b)) + (-0.375 * ((pow(c, 2.0) * a) / 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 = ((-0.5625d0) * (((a ** 2.0d0) * (c ** 3.0d0)) / (b ** 5.0d0))) + (((-0.5d0) * (c / b)) + ((-0.375d0) * (((c ** 2.0d0) * a) / (b ** 3.0d0))))
end function
public static double code(double a, double b, double c) {
return (-0.5625 * ((Math.pow(a, 2.0) * Math.pow(c, 3.0)) / Math.pow(b, 5.0))) + ((-0.5 * (c / b)) + (-0.375 * ((Math.pow(c, 2.0) * a) / Math.pow(b, 3.0))));
}
def code(a, b, c): return (-0.5625 * ((math.pow(a, 2.0) * math.pow(c, 3.0)) / math.pow(b, 5.0))) + ((-0.5 * (c / b)) + (-0.375 * ((math.pow(c, 2.0) * a) / math.pow(b, 3.0))))
function code(a, b, c) return Float64(Float64(-0.5625 * Float64(Float64((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + Float64(Float64(-0.5 * Float64(c / b)) + Float64(-0.375 * Float64(Float64((c ^ 2.0) * a) / (b ^ 3.0))))) end
function tmp = code(a, b, c) tmp = (-0.5625 * (((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + ((-0.5 * (c / b)) + (-0.375 * (((c ^ 2.0) * a) / (b ^ 3.0)))); end
code[a_, b_, c_] := 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[(-0.375 * N[(N[(N[Power[c, 2.0], $MachinePrecision] * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5625 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)
\end{array}
Initial program 35.2%
Taylor expanded in b around inf 92.3%
Final simplification92.3%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)))) (if (<= t_0 -1e-11) t_0 (/ (* -0.5 c) 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 <= -1e-11) {
tmp = t_0;
} else {
tmp = (-0.5 * 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) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)
if (t_0 <= (-1d-11)) then
tmp = t_0
else
tmp = ((-0.5d0) * c) / 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 <= -1e-11) {
tmp = t_0;
} else {
tmp = (-0.5 * c) / 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 <= -1e-11: tmp = t_0 else: tmp = (-0.5 * c) / 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 <= -1e-11) tmp = t_0; else tmp = Float64(Float64(-0.5 * c) / 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 <= -1e-11) tmp = t_0; else tmp = (-0.5 * c) / 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, -1e-11], t$95$0, N[(N[(-0.5 * c), $MachinePrecision] / b), $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 -1 \cdot 10^{-11}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{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)) < -9.99999999999999939e-12Initial program 70.2%
if -9.99999999999999939e-12 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 10.5%
Taylor expanded in b around inf 95.9%
associate-*r/95.9%
Simplified95.9%
Final simplification85.3%
(FPCore (a b c) :precision binary64 (+ (* -0.5 (/ c b)) (* -0.375 (/ (* (pow c 2.0) a) (pow b 3.0)))))
double code(double a, double b, double c) {
return (-0.5 * (c / b)) + (-0.375 * ((pow(c, 2.0) * a) / 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 = ((-0.5d0) * (c / b)) + ((-0.375d0) * (((c ** 2.0d0) * a) / (b ** 3.0d0)))
end function
public static double code(double a, double b, double c) {
return (-0.5 * (c / b)) + (-0.375 * ((Math.pow(c, 2.0) * a) / Math.pow(b, 3.0)));
}
def code(a, b, c): return (-0.5 * (c / b)) + (-0.375 * ((math.pow(c, 2.0) * a) / math.pow(b, 3.0)))
function code(a, b, c) return Float64(Float64(-0.5 * Float64(c / b)) + Float64(-0.375 * Float64(Float64((c ^ 2.0) * a) / (b ^ 3.0)))) end
function tmp = code(a, b, c) tmp = (-0.5 * (c / b)) + (-0.375 * (((c ^ 2.0) * a) / (b ^ 3.0))); end
code[a_, b_, c_] := N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[(N[(N[Power[c, 2.0], $MachinePrecision] * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}
\end{array}
Initial program 35.2%
Taylor expanded in b around inf 88.3%
Final simplification88.3%
(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(Float64(-0.5 * c) / b) end
function tmp = code(a, b, c) tmp = (-0.5 * c) / b; end
code[a_, b_, c_] := N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.5 \cdot c}{b}
\end{array}
Initial program 35.2%
Taylor expanded in b around inf 78.1%
associate-*r/78.1%
Simplified78.1%
Final simplification78.1%
herbie shell --seed 2024024
(FPCore (a b c)
:name "Cubic critical, medium range"
:precision binary64
:pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))