
(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 (/ (/ (* c a) a) (- (- b) (sqrt (fma c (* a -3.0) (* b b))))))
double code(double a, double b, double c) {
return ((c * a) / a) / (-b - sqrt(fma(c, (a * -3.0), (b * b))));
}
function code(a, b, c) return Float64(Float64(Float64(c * a) / a) / Float64(Float64(-b) - sqrt(fma(c, Float64(a * -3.0), Float64(b * b))))) end
code[a_, b_, c_] := N[(N[(N[(c * a), $MachinePrecision] / a), $MachinePrecision] / N[((-b) - N[Sqrt[N[(c * N[(a * -3.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{c \cdot a}{a}}{\left(-b\right) - \sqrt{\mathsf{fma}\left(c, a \cdot -3, b \cdot b\right)}}
\end{array}
Initial program 30.6%
sqr-neg30.6%
sqr-neg30.6%
associate-*l*30.6%
Simplified30.6%
associate-*r*30.6%
*-commutative30.6%
*-commutative30.6%
metadata-eval30.6%
div-inv30.6%
clear-num30.6%
un-div-inv30.6%
Applied egg-rr30.6%
associate-/r/30.6%
Simplified30.6%
flip-+30.6%
add-sqr-sqrt31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
Applied egg-rr31.5%
sqr-neg31.5%
associate--r-99.1%
*-commutative99.1%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.3%
Simplified99.3%
div-inv99.3%
+-inverses99.3%
associate-*l*99.0%
associate-*l*99.0%
*-commutative99.0%
*-commutative99.0%
*-commutative99.0%
Applied egg-rr99.0%
+-lft-identity99.0%
associate-*l/99.2%
associate-*r/99.3%
*-rgt-identity99.3%
associate-*r*99.6%
*-commutative99.6%
associate-*r*99.3%
*-commutative99.3%
times-frac99.7%
metadata-eval99.7%
*-commutative99.7%
sub-neg99.7%
+-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -1000.0) (* (- (sqrt (- (* b b) (* a (* c 3.0)))) b) (/ 1.0 (* a 3.0))) (* -0.5 (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1000.0) {
tmp = (sqrt(((b * b) - (a * (c * 3.0)))) - b) * (1.0 / (a * 3.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) :: tmp
if (((sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)) <= (-1000.0d0)) then
tmp = (sqrt(((b * b) - (a * (c * 3.0d0)))) - b) * (1.0d0 / (a * 3.0d0))
else
tmp = (-0.5d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (((Math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1000.0) {
tmp = (Math.sqrt(((b * b) - (a * (c * 3.0)))) - b) * (1.0 / (a * 3.0));
} else {
tmp = -0.5 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if ((math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1000.0: tmp = (math.sqrt(((b * b) - (a * (c * 3.0)))) - b) * (1.0 / (a * 3.0)) else: tmp = -0.5 * (c / 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)) <= -1000.0) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 3.0)))) - b) * Float64(1.0 / Float64(a * 3.0))); else tmp = Float64(-0.5 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1000.0) tmp = (sqrt(((b * b) - (a * (c * 3.0)))) - b) * (1.0 / (a * 3.0)); else tmp = -0.5 * (c / b); end tmp_2 = 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], -1000.0], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(1.0 / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $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 -1000:\\
\;\;\;\;\left(\sqrt{b \cdot b - a \cdot \left(c \cdot 3\right)} - b\right) \cdot \frac{1}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{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)) < -1e3Initial program 79.1%
sqr-neg79.1%
sqr-neg79.1%
associate-*l*79.1%
Simplified79.1%
associate-*r*79.1%
*-commutative79.1%
*-commutative79.1%
metadata-eval79.1%
div-inv79.1%
clear-num79.1%
un-div-inv79.1%
Applied egg-rr79.1%
associate-/r/79.1%
Simplified79.1%
div-inv79.2%
*-commutative79.2%
div-inv79.2%
metadata-eval79.2%
*-commutative79.2%
Applied egg-rr79.2%
if -1e3 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 27.2%
sqr-neg27.2%
sqr-neg27.2%
associate-*l*27.2%
Simplified27.2%
Taylor expanded in b around inf 85.1%
Final simplification84.7%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 3.0)))) b) (* a 3.0)) -1000.0) (/ (- (sqrt (- (* b b) (* 3.0 (* c a)))) b) (* a 3.0)) (* -0.5 (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1000.0) {
tmp = (sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.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) :: tmp
if (((sqrt(((b * b) - (c * (a * 3.0d0)))) - b) / (a * 3.0d0)) <= (-1000.0d0)) then
tmp = (sqrt(((b * b) - (3.0d0 * (c * a)))) - b) / (a * 3.0d0)
else
tmp = (-0.5d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (((Math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1000.0) {
tmp = (Math.sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0);
} else {
tmp = -0.5 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if ((math.sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1000.0: tmp = (math.sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0) else: tmp = -0.5 * (c / 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)) <= -1000.0) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(3.0 * Float64(c * a)))) - b) / Float64(a * 3.0)); else tmp = Float64(-0.5 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (((sqrt(((b * b) - (c * (a * 3.0)))) - b) / (a * 3.0)) <= -1000.0) tmp = (sqrt(((b * b) - (3.0 * (c * a)))) - b) / (a * 3.0); else tmp = -0.5 * (c / b); end tmp_2 = 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], -1000.0], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $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 -1000:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{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)) < -1e3Initial program 79.1%
sqr-neg79.1%
sqr-neg79.1%
associate-*l*79.1%
Simplified79.1%
if -1e3 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 3 a) c)))) (*.f64 3 a)) Initial program 27.2%
sqr-neg27.2%
sqr-neg27.2%
associate-*l*27.2%
Simplified27.2%
Taylor expanded in b around inf 85.1%
Final simplification84.7%
(FPCore (a b c) :precision binary64 (/ (/ (+ (- (* b b) (* b b)) (* 3.0 (* c a))) (- (- b) (sqrt (- (* b b) (* c (* a 3.0)))))) (* a 3.0)))
double code(double a, double b, double c) {
return ((((b * b) - (b * b)) + (3.0 * (c * a))) / (-b - sqrt(((b * b) - (c * (a * 3.0)))))) / (a * 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 = ((((b * b) - (b * b)) + (3.0d0 * (c * a))) / (-b - sqrt(((b * b) - (c * (a * 3.0d0)))))) / (a * 3.0d0)
end function
public static double code(double a, double b, double c) {
return ((((b * b) - (b * b)) + (3.0 * (c * a))) / (-b - Math.sqrt(((b * b) - (c * (a * 3.0)))))) / (a * 3.0);
}
def code(a, b, c): return ((((b * b) - (b * b)) + (3.0 * (c * a))) / (-b - math.sqrt(((b * b) - (c * (a * 3.0)))))) / (a * 3.0)
function code(a, b, c) return Float64(Float64(Float64(Float64(Float64(b * b) - Float64(b * b)) + Float64(3.0 * Float64(c * a))) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) tmp = ((((b * b) - (b * b)) + (3.0 * (c * a))) / (-b - sqrt(((b * b) - (c * (a * 3.0)))))) / (a * 3.0); end
code[a_, b_, c_] := N[(N[(N[(N[(N[(b * b), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(3.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\left(b \cdot b - b \cdot b\right) + 3 \cdot \left(c \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)}}}{a \cdot 3}
\end{array}
Initial program 30.6%
sqr-neg30.6%
sqr-neg30.6%
associate-*l*30.6%
Simplified30.6%
associate-*r*30.6%
*-commutative30.6%
*-commutative30.6%
metadata-eval30.6%
div-inv30.6%
clear-num30.6%
un-div-inv30.6%
Applied egg-rr30.6%
associate-/r/30.6%
Simplified30.6%
flip-+30.6%
add-sqr-sqrt31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
Applied egg-rr31.5%
sqr-neg31.5%
associate--r-99.1%
*-commutative99.1%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.3%
Simplified99.3%
Taylor expanded in a around 0 99.2%
Final simplification99.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* a 3.0))))
(/
(/ (+ (- (* b b) (* b b)) t_0) (- (- b) (sqrt (- (* b b) t_0))))
(* a 3.0))))
double code(double a, double b, double c) {
double t_0 = c * (a * 3.0);
return ((((b * b) - (b * b)) + t_0) / (-b - sqrt(((b * b) - t_0)))) / (a * 3.0);
}
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
t_0 = c * (a * 3.0d0)
code = ((((b * b) - (b * b)) + t_0) / (-b - sqrt(((b * b) - t_0)))) / (a * 3.0d0)
end function
public static double code(double a, double b, double c) {
double t_0 = c * (a * 3.0);
return ((((b * b) - (b * b)) + t_0) / (-b - Math.sqrt(((b * b) - t_0)))) / (a * 3.0);
}
def code(a, b, c): t_0 = c * (a * 3.0) return ((((b * b) - (b * b)) + t_0) / (-b - math.sqrt(((b * b) - t_0)))) / (a * 3.0)
function code(a, b, c) t_0 = Float64(c * Float64(a * 3.0)) return Float64(Float64(Float64(Float64(Float64(b * b) - Float64(b * b)) + t_0) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - t_0)))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) t_0 = c * (a * 3.0); tmp = ((((b * b) - (b * b)) + t_0) / (-b - sqrt(((b * b) - t_0)))) / (a * 3.0); end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(N[(b * b), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 3\right)\\
\frac{\frac{\left(b \cdot b - b \cdot b\right) + t_0}{\left(-b\right) - \sqrt{b \cdot b - t_0}}}{a \cdot 3}
\end{array}
\end{array}
Initial program 30.6%
sqr-neg30.6%
sqr-neg30.6%
associate-*l*30.6%
Simplified30.6%
associate-*r*30.6%
*-commutative30.6%
*-commutative30.6%
metadata-eval30.6%
div-inv30.6%
clear-num30.6%
un-div-inv30.6%
Applied egg-rr30.6%
associate-/r/30.6%
Simplified30.6%
flip-+30.6%
add-sqr-sqrt31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
Applied egg-rr31.5%
sqr-neg31.5%
associate--r-99.1%
*-commutative99.1%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (a b c) :precision binary64 (let* ((t_0 (* a (* c 3.0)))) (/ t_0 (* (* a (- 3.0)) (+ b (sqrt (- (* b b) t_0)))))))
double code(double a, double b, double c) {
double t_0 = a * (c * 3.0);
return t_0 / ((a * -3.0) * (b + sqrt(((b * b) - t_0))));
}
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
t_0 = a * (c * 3.0d0)
code = t_0 / ((a * -3.0d0) * (b + sqrt(((b * b) - t_0))))
end function
public static double code(double a, double b, double c) {
double t_0 = a * (c * 3.0);
return t_0 / ((a * -3.0) * (b + Math.sqrt(((b * b) - t_0))));
}
def code(a, b, c): t_0 = a * (c * 3.0) return t_0 / ((a * -3.0) * (b + math.sqrt(((b * b) - t_0))))
function code(a, b, c) t_0 = Float64(a * Float64(c * 3.0)) return Float64(t_0 / Float64(Float64(a * Float64(-3.0)) * Float64(b + sqrt(Float64(Float64(b * b) - t_0))))) end
function tmp = code(a, b, c) t_0 = a * (c * 3.0); tmp = t_0 / ((a * -3.0) * (b + sqrt(((b * b) - t_0)))); end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 / N[(N[(a * (-3.0)), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(c \cdot 3\right)\\
\frac{t_0}{\left(a \cdot \left(-3\right)\right) \cdot \left(b + \sqrt{b \cdot b - t_0}\right)}
\end{array}
\end{array}
Initial program 30.6%
sqr-neg30.6%
sqr-neg30.6%
associate-*l*30.6%
Simplified30.6%
associate-*r*30.6%
*-commutative30.6%
*-commutative30.6%
metadata-eval30.6%
div-inv30.6%
clear-num30.6%
un-div-inv30.6%
Applied egg-rr30.6%
associate-/r/30.6%
Simplified30.6%
flip-+30.6%
add-sqr-sqrt31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
Applied egg-rr31.5%
sqr-neg31.5%
associate--r-99.1%
*-commutative99.1%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.3%
Simplified99.3%
*-un-lft-identity99.3%
associate-/l/99.3%
+-inverses99.3%
associate-*l*99.1%
*-commutative99.1%
associate-*l*99.1%
*-commutative99.1%
*-commutative99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (a b c) :precision binary64 (let* ((t_0 (* a (* c 3.0)))) (/ (/ t_0 (- (- b) (sqrt (- (* b b) t_0)))) (* a 3.0))))
double code(double a, double b, double c) {
double t_0 = a * (c * 3.0);
return (t_0 / (-b - sqrt(((b * b) - t_0)))) / (a * 3.0);
}
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
t_0 = a * (c * 3.0d0)
code = (t_0 / (-b - sqrt(((b * b) - t_0)))) / (a * 3.0d0)
end function
public static double code(double a, double b, double c) {
double t_0 = a * (c * 3.0);
return (t_0 / (-b - Math.sqrt(((b * b) - t_0)))) / (a * 3.0);
}
def code(a, b, c): t_0 = a * (c * 3.0) return (t_0 / (-b - math.sqrt(((b * b) - t_0)))) / (a * 3.0)
function code(a, b, c) t_0 = Float64(a * Float64(c * 3.0)) return Float64(Float64(t_0 / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - t_0)))) / Float64(a * 3.0)) end
function tmp = code(a, b, c) t_0 = a * (c * 3.0); tmp = (t_0 / (-b - sqrt(((b * b) - t_0)))) / (a * 3.0); end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * 3.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$0 / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $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{t_0}{\left(-b\right) - \sqrt{b \cdot b - t_0}}}{a \cdot 3}
\end{array}
\end{array}
Initial program 30.6%
sqr-neg30.6%
sqr-neg30.6%
associate-*l*30.6%
Simplified30.6%
associate-*r*30.6%
*-commutative30.6%
*-commutative30.6%
metadata-eval30.6%
div-inv30.6%
clear-num30.6%
un-div-inv30.6%
Applied egg-rr30.6%
associate-/r/30.6%
Simplified30.6%
flip-+30.6%
add-sqr-sqrt31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
*-commutative31.5%
div-inv31.5%
metadata-eval31.5%
Applied egg-rr31.5%
sqr-neg31.5%
associate--r-99.1%
*-commutative99.1%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.3%
Simplified99.3%
*-un-lft-identity99.3%
+-inverses99.3%
associate-*l*99.1%
associate-*l*99.1%
*-commutative99.1%
*-commutative99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (a b c) :precision binary64 (if (<= b 5.6e-5) (* (/ 0.3333333333333333 a) (- (sqrt (- (* b b) (* c (* a 3.0)))) b)) (* -0.5 (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.6e-5) {
tmp = (0.3333333333333333 / a) * (sqrt(((b * b) - (c * (a * 3.0)))) - b);
} 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) :: tmp
if (b <= 5.6d-5) then
tmp = (0.3333333333333333d0 / a) * (sqrt(((b * b) - (c * (a * 3.0d0)))) - b)
else
tmp = (-0.5d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 5.6e-5) {
tmp = (0.3333333333333333 / a) * (Math.sqrt(((b * b) - (c * (a * 3.0)))) - b);
} else {
tmp = -0.5 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 5.6e-5: tmp = (0.3333333333333333 / a) * (math.sqrt(((b * b) - (c * (a * 3.0)))) - b) else: tmp = -0.5 * (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 5.6e-5) tmp = Float64(Float64(0.3333333333333333 / a) * Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 3.0)))) - b)); else tmp = Float64(-0.5 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 5.6e-5) tmp = (0.3333333333333333 / a) * (sqrt(((b * b) - (c * (a * 3.0)))) - b); else tmp = -0.5 * (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 5.6e-5], N[(N[(0.3333333333333333 / a), $MachinePrecision] * N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.6 \cdot 10^{-5}:\\
\;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{b \cdot b - c \cdot \left(a \cdot 3\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b}\\
\end{array}
\end{array}
if b < 5.59999999999999992e-5Initial program 74.7%
sqr-neg74.7%
sqr-neg74.7%
associate-*l*74.5%
Simplified74.5%
associate-*r*74.7%
*-commutative74.7%
*-commutative74.7%
metadata-eval74.7%
div-inv74.6%
clear-num74.6%
un-div-inv74.5%
Applied egg-rr74.5%
associate-/r/74.6%
Simplified74.6%
div-inv74.6%
*-commutative74.6%
div-inv74.6%
metadata-eval74.6%
*-commutative74.6%
Applied egg-rr74.6%
*-commutative74.6%
*-commutative74.6%
associate-/r*74.6%
metadata-eval74.6%
rem-log-exp39.2%
rem-log-exp74.6%
*-commutative74.6%
associate-*r*74.7%
Simplified74.7%
if 5.59999999999999992e-5 < b Initial program 26.7%
sqr-neg26.7%
sqr-neg26.7%
associate-*l*26.7%
Simplified26.7%
Taylor expanded in b around inf 85.5%
Final simplification84.6%
(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 30.6%
sqr-neg30.6%
sqr-neg30.6%
associate-*l*30.6%
Simplified30.6%
Taylor expanded in b around inf 82.3%
Final simplification82.3%
herbie shell --seed 2023287
(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)))