
(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 (* a (* c 3.0))))
(/
(/
(* c -3.0)
(+ b (/ (sqrt (- (pow b 4.0) (pow t_0 2.0))) (hypot b (sqrt t_0)))))
3.0)))
double code(double a, double b, double c) {
double t_0 = a * (c * 3.0);
return ((c * -3.0) / (b + (sqrt((pow(b, 4.0) - pow(t_0, 2.0))) / hypot(b, sqrt(t_0))))) / 3.0;
}
public static double code(double a, double b, double c) {
double t_0 = a * (c * 3.0);
return ((c * -3.0) / (b + (Math.sqrt((Math.pow(b, 4.0) - Math.pow(t_0, 2.0))) / Math.hypot(b, Math.sqrt(t_0))))) / 3.0;
}
def code(a, b, c): t_0 = a * (c * 3.0) return ((c * -3.0) / (b + (math.sqrt((math.pow(b, 4.0) - math.pow(t_0, 2.0))) / math.hypot(b, math.sqrt(t_0))))) / 3.0
function code(a, b, c) t_0 = Float64(a * Float64(c * 3.0)) return Float64(Float64(Float64(c * -3.0) / Float64(b + Float64(sqrt(Float64((b ^ 4.0) - (t_0 ^ 2.0))) / hypot(b, sqrt(t_0))))) / 3.0) end
function tmp = code(a, b, c) t_0 = a * (c * 3.0); tmp = ((c * -3.0) / (b + (sqrt(((b ^ 4.0) - (t_0 ^ 2.0))) / hypot(b, sqrt(t_0))))) / 3.0; end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(c * -3.0), $MachinePrecision] / N[(b + N[(N[Sqrt[N[(N[Power[b, 4.0], $MachinePrecision] - N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[b ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(c \cdot 3\right)\\
\frac{\frac{c \cdot -3}{b + \frac{\sqrt{{b}^{4} - {t\_0}^{2}}}{\mathsf{hypot}\left(b, \sqrt{t\_0}\right)}}}{3}
\end{array}
\end{array}
Initial program 30.1%
/-rgt-identity30.1%
metadata-eval30.1%
Simplified30.2%
associate-*r*30.2%
*-commutative30.2%
metadata-eval30.2%
distribute-lft-neg-in30.2%
associate-*l*30.2%
fma-neg30.1%
flip--30.0%
sqrt-div29.9%
pow229.9%
pow229.9%
pow-prod-up30.0%
metadata-eval30.0%
pow230.0%
associate-*l*30.0%
fma-define30.1%
associate-*l*30.1%
Applied egg-rr30.1%
*-commutative30.1%
*-commutative30.1%
associate-*l*30.1%
fma-undefine30.0%
unpow130.0%
sqr-pow30.0%
hypot-define30.1%
metadata-eval30.1%
unpow1/230.1%
*-commutative30.1%
*-commutative30.1%
associate-*l*30.1%
Simplified30.1%
flip--29.9%
Applied egg-rr29.9%
Simplified29.9%
Taylor expanded in b around 0 0.0%
associate-/l*0.0%
unpow20.0%
rem-square-sqrt98.5%
unpow298.5%
rem-square-sqrt99.1%
Simplified99.1%
div-inv99.1%
associate-/l*99.1%
associate-/l*99.1%
metadata-eval99.1%
*-commutative99.1%
Applied egg-rr99.1%
associate-*r/99.1%
*-rgt-identity99.1%
times-frac99.4%
*-inverses99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* a 3.0))) (t_1 (sqrt t_0)))
(if (<= (/ (- (sqrt (- (* b b) t_0)) b) (* a 3.0)) -1.0)
(/ (- (sqrt (* (+ b t_1) (- b t_1))) b) (* a 3.0))
(+ (* -0.5 (/ c b)) (* -0.375 (/ (* a (pow c 2.0)) (pow b 3.0)))))))
double code(double a, double b, double c) {
double t_0 = c * (a * 3.0);
double t_1 = sqrt(t_0);
double tmp;
if (((sqrt(((b * b) - t_0)) - b) / (a * 3.0)) <= -1.0) {
tmp = (sqrt(((b + t_1) * (b - t_1))) - b) / (a * 3.0);
} else {
tmp = (-0.5 * (c / b)) + (-0.375 * ((a * pow(c, 2.0)) / 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 * (a * 3.0d0)
t_1 = sqrt(t_0)
if (((sqrt(((b * b) - t_0)) - b) / (a * 3.0d0)) <= (-1.0d0)) then
tmp = (sqrt(((b + t_1) * (b - t_1))) - b) / (a * 3.0d0)
else
tmp = ((-0.5d0) * (c / b)) + ((-0.375d0) * ((a * (c ** 2.0d0)) / (b ** 3.0d0)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = c * (a * 3.0);
double t_1 = Math.sqrt(t_0);
double tmp;
if (((Math.sqrt(((b * b) - t_0)) - b) / (a * 3.0)) <= -1.0) {
tmp = (Math.sqrt(((b + t_1) * (b - t_1))) - b) / (a * 3.0);
} else {
tmp = (-0.5 * (c / b)) + (-0.375 * ((a * Math.pow(c, 2.0)) / Math.pow(b, 3.0)));
}
return tmp;
}
def code(a, b, c): t_0 = c * (a * 3.0) t_1 = math.sqrt(t_0) tmp = 0 if ((math.sqrt(((b * b) - t_0)) - b) / (a * 3.0)) <= -1.0: tmp = (math.sqrt(((b + t_1) * (b - t_1))) - b) / (a * 3.0) else: tmp = (-0.5 * (c / b)) + (-0.375 * ((a * math.pow(c, 2.0)) / math.pow(b, 3.0))) return tmp
function code(a, b, c) t_0 = Float64(c * Float64(a * 3.0)) t_1 = sqrt(t_0) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(a * 3.0)) <= -1.0) tmp = Float64(Float64(sqrt(Float64(Float64(b + t_1) * Float64(b - t_1))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(-0.5 * Float64(c / b)) + Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = c * (a * 3.0); t_1 = sqrt(t_0); tmp = 0.0; if (((sqrt(((b * b) - t_0)) - b) / (a * 3.0)) <= -1.0) tmp = (sqrt(((b + t_1) * (b - t_1))) - b) / (a * 3.0); else tmp = (-0.5 * (c / b)) + (-0.375 * ((a * (c ^ 2.0)) / (b ^ 3.0))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], -1.0], N[(N[(N[Sqrt[N[(N[(b + t$95$1), $MachinePrecision] * N[(b - t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 3\right)\\
t_1 := \sqrt{t\_0}\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - t\_0} - b}{a \cdot 3} \leq -1:\\
\;\;\;\;\frac{\sqrt{\left(b + t\_1\right) \cdot \left(b - t\_1\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -1Initial program 75.7%
add-sqr-sqrt75.7%
difference-of-squares76.3%
associate-*l*76.3%
associate-*l*76.4%
Applied egg-rr76.4%
associate-*r*76.3%
*-commutative76.3%
associate-*r*76.3%
*-commutative76.3%
Simplified76.3%
if -1 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 21.9%
Taylor expanded in b around inf 95.6%
Final simplification92.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* a (* c 3.0))))
(/
(/
(* a (/ (* c -9.0) 3.0))
(+ b (/ (sqrt (- (pow b 4.0) (* t_0 t_0))) (hypot b (sqrt t_0)))))
(* a 3.0))))
double code(double a, double b, double c) {
double t_0 = a * (c * 3.0);
return ((a * ((c * -9.0) / 3.0)) / (b + (sqrt((pow(b, 4.0) - (t_0 * t_0))) / hypot(b, sqrt(t_0))))) / (a * 3.0);
}
public static double code(double a, double b, double c) {
double t_0 = a * (c * 3.0);
return ((a * ((c * -9.0) / 3.0)) / (b + (Math.sqrt((Math.pow(b, 4.0) - (t_0 * t_0))) / Math.hypot(b, Math.sqrt(t_0))))) / (a * 3.0);
}
def code(a, b, c): t_0 = a * (c * 3.0) return ((a * ((c * -9.0) / 3.0)) / (b + (math.sqrt((math.pow(b, 4.0) - (t_0 * t_0))) / math.hypot(b, math.sqrt(t_0))))) / (a * 3.0)
function code(a, b, c) t_0 = Float64(a * Float64(c * 3.0)) return Float64(Float64(Float64(a * Float64(Float64(c * -9.0) / 3.0)) / Float64(b + Float64(sqrt(Float64((b ^ 4.0) - Float64(t_0 * t_0))) / hypot(b, sqrt(t_0))))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) t_0 = a * (c * 3.0); tmp = ((a * ((c * -9.0) / 3.0)) / (b + (sqrt(((b ^ 4.0) - (t_0 * t_0))) / hypot(b, sqrt(t_0))))) / (a * 3.0); end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(a * N[(N[(c * -9.0), $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision] / N[(b + N[(N[Sqrt[N[(N[Power[b, 4.0], $MachinePrecision] - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[b ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(c \cdot 3\right)\\
\frac{\frac{a \cdot \frac{c \cdot -9}{3}}{b + \frac{\sqrt{{b}^{4} - t\_0 \cdot t\_0}}{\mathsf{hypot}\left(b, \sqrt{t\_0}\right)}}}{a \cdot 3}
\end{array}
\end{array}
Initial program 30.1%
/-rgt-identity30.1%
metadata-eval30.1%
Simplified30.2%
associate-*r*30.2%
*-commutative30.2%
metadata-eval30.2%
distribute-lft-neg-in30.2%
associate-*l*30.2%
fma-neg30.1%
flip--30.0%
sqrt-div29.9%
pow229.9%
pow229.9%
pow-prod-up30.0%
metadata-eval30.0%
pow230.0%
associate-*l*30.0%
fma-define30.1%
associate-*l*30.1%
Applied egg-rr30.1%
*-commutative30.1%
*-commutative30.1%
associate-*l*30.1%
fma-undefine30.0%
unpow130.0%
sqr-pow30.0%
hypot-define30.1%
metadata-eval30.1%
unpow1/230.1%
*-commutative30.1%
*-commutative30.1%
associate-*l*30.1%
Simplified30.1%
flip--29.9%
Applied egg-rr29.9%
Simplified29.9%
Taylor expanded in b around 0 0.0%
associate-/l*0.0%
unpow20.0%
rem-square-sqrt98.5%
unpow298.5%
rem-square-sqrt99.1%
Simplified99.1%
unpow299.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -1.0) (/ (- (sqrt (fma b b (* (* c -3.0) a))) b) (* a 3.0)) (+ (* -0.5 (/ c b)) (* -0.375 (/ (* a (pow c 2.0)) (pow b 3.0))))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1.0) {
tmp = (sqrt(fma(b, b, ((c * -3.0) * a))) - b) / (a * 3.0);
} else {
tmp = (-0.5 * (c / b)) + (-0.375 * ((a * pow(c, 2.0)) / pow(b, 3.0)));
}
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)) <= -1.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(c * -3.0) * a))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(-0.5 * Float64(c / b)) + Float64(-0.375 * Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0)))); 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], -1.0], N[(N[(N[Sqrt[N[(b * b + N[(N[(c * -3.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $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 -1:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot -3\right) \cdot a\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{a \cdot {c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) < -1Initial program 75.7%
/-rgt-identity75.7%
metadata-eval75.7%
Simplified76.3%
if -1 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 21.9%
Taylor expanded in b around inf 95.6%
Final simplification92.6%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -5e-8) (/ (- (sqrt (fma b b (* (* c -3.0) a))) b) (* a 3.0)) (/ (* c -0.5) b)))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -5e-8) {
tmp = (sqrt(fma(b, b, ((c * -3.0) * a))) - b) / (a * 3.0);
} else {
tmp = (c * -0.5) / 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)) <= -5e-8) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(c * -3.0) * a))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(c * -0.5) / 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], -5e-8], N[(N[(N[Sqrt[N[(b * b + N[(N[(c * -3.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b), $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 -5 \cdot 10^{-8}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot -3\right) \cdot a\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{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)) < -4.9999999999999998e-8Initial program 69.8%
/-rgt-identity69.8%
metadata-eval69.8%
Simplified70.0%
if -4.9999999999999998e-8 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 13.4%
Taylor expanded in b around inf 94.0%
*-commutative94.0%
associate-*l/94.0%
Simplified94.0%
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 -5e-8) t_0 (/ (* c -0.5) 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 <= -5e-8) {
tmp = t_0;
} else {
tmp = (c * -0.5) / 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 <= (-5d-8)) then
tmp = t_0
else
tmp = (c * (-0.5d0)) / 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 <= -5e-8) {
tmp = t_0;
} else {
tmp = (c * -0.5) / 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 <= -5e-8: tmp = t_0 else: tmp = (c * -0.5) / 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 <= -5e-8) tmp = t_0; else tmp = Float64(Float64(c * -0.5) / 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 <= -5e-8) tmp = t_0; else tmp = (c * -0.5) / 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, -5e-8], t$95$0, N[(N[(c * -0.5), $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 -5 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{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)) < -4.9999999999999998e-8Initial program 69.8%
if -4.9999999999999998e-8 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 13.4%
Taylor expanded in b around inf 94.0%
*-commutative94.0%
associate-*l/94.0%
Simplified94.0%
Final simplification86.8%
(FPCore (a b c) :precision binary64 (/ (* c -0.5) b))
double code(double a, double b, double c) {
return (c * -0.5) / 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 * (-0.5d0)) / b
end function
public static double code(double a, double b, double c) {
return (c * -0.5) / b;
}
def code(a, b, c): return (c * -0.5) / b
function code(a, b, c) return Float64(Float64(c * -0.5) / b) end
function tmp = code(a, b, c) tmp = (c * -0.5) / b; end
code[a_, b_, c_] := N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c \cdot -0.5}{b}
\end{array}
Initial program 30.1%
Taylor expanded in b around inf 81.9%
*-commutative81.9%
associate-*l/81.9%
Simplified81.9%
Final simplification81.9%
(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 30.1%
add-sqr-sqrt30.1%
difference-of-squares30.2%
associate-*l*30.2%
associate-*l*30.2%
Applied egg-rr30.2%
associate-*r*30.2%
*-commutative30.2%
associate-*r*30.2%
*-commutative30.2%
Simplified30.2%
Taylor expanded in b around inf 3.2%
associate-*r/3.2%
distribute-lft1-in3.2%
metadata-eval3.2%
mul0-lft3.2%
metadata-eval3.2%
Simplified3.2%
Final simplification3.2%
herbie shell --seed 2024040
(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)))