
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(+
(* -2.0 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0)))
(-
(-
(*
-0.25
(/
(+ (* 16.0 (* (pow a 4.0) (pow c 4.0))) (* 4.0 (pow (* a c) 4.0)))
(* a (pow b 7.0))))
(/ (* a (pow c 2.0)) (pow b 3.0)))
(/ c b))))
double code(double a, double b, double c) {
return (-2.0 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) + (((-0.25 * (((16.0 * (pow(a, 4.0) * pow(c, 4.0))) + (4.0 * pow((a * c), 4.0))) / (a * pow(b, 7.0)))) - ((a * pow(c, 2.0)) / pow(b, 3.0))) - (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 = ((-2.0d0) * (((a ** 2.0d0) * (c ** 3.0d0)) / (b ** 5.0d0))) + ((((-0.25d0) * (((16.0d0 * ((a ** 4.0d0) * (c ** 4.0d0))) + (4.0d0 * ((a * c) ** 4.0d0))) / (a * (b ** 7.0d0)))) - ((a * (c ** 2.0d0)) / (b ** 3.0d0))) - (c / b))
end function
public static double code(double a, double b, double c) {
return (-2.0 * ((Math.pow(a, 2.0) * Math.pow(c, 3.0)) / Math.pow(b, 5.0))) + (((-0.25 * (((16.0 * (Math.pow(a, 4.0) * Math.pow(c, 4.0))) + (4.0 * Math.pow((a * c), 4.0))) / (a * Math.pow(b, 7.0)))) - ((a * Math.pow(c, 2.0)) / Math.pow(b, 3.0))) - (c / b));
}
def code(a, b, c): return (-2.0 * ((math.pow(a, 2.0) * math.pow(c, 3.0)) / math.pow(b, 5.0))) + (((-0.25 * (((16.0 * (math.pow(a, 4.0) * math.pow(c, 4.0))) + (4.0 * math.pow((a * c), 4.0))) / (a * math.pow(b, 7.0)))) - ((a * math.pow(c, 2.0)) / math.pow(b, 3.0))) - (c / b))
function code(a, b, c) return Float64(Float64(-2.0 * Float64(Float64((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + Float64(Float64(Float64(-0.25 * Float64(Float64(Float64(16.0 * Float64((a ^ 4.0) * (c ^ 4.0))) + Float64(4.0 * (Float64(a * c) ^ 4.0))) / Float64(a * (b ^ 7.0)))) - Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0))) - Float64(c / b))) end
function tmp = code(a, b, c) tmp = (-2.0 * (((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) + (((-0.25 * (((16.0 * ((a ^ 4.0) * (c ^ 4.0))) + (4.0 * ((a * c) ^ 4.0))) / (a * (b ^ 7.0)))) - ((a * (c ^ 2.0)) / (b ^ 3.0))) - (c / b)); end
code[a_, b_, c_] := N[(N[(-2.0 * 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[(N[(-0.25 * N[(N[(N[(16.0 * N[(N[Power[a, 4.0], $MachinePrecision] * N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[Power[N[(a * c), $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} + \left(\left(-0.25 \cdot \frac{16 \cdot \left({a}^{4} \cdot {c}^{4}\right) + 4 \cdot {\left(a \cdot c\right)}^{4}}{a \cdot {b}^{7}} - \frac{a \cdot {c}^{2}}{{b}^{3}}\right) - \frac{c}{b}\right)
\end{array}
Initial program 33.7%
*-commutative33.7%
Simplified33.7%
Taylor expanded in b around inf 94.9%
*-commutative94.9%
unpow-prod-down94.9%
pow-prod-down94.9%
pow-pow94.9%
metadata-eval94.9%
metadata-eval94.9%
Applied egg-rr94.9%
Final simplification94.9%
(FPCore (a b c)
:precision binary64
(/
(+
(* -4.0 (/ (* (pow c 3.0) (pow a 3.0)) (pow b 5.0)))
(+
(* -2.0 (/ (* a c) b))
(+
(* -2.0 (/ (* (pow a 2.0) (pow c 2.0)) (pow b 3.0)))
(* -0.5 (* (pow (* a c) 4.0) (/ 20.0 (pow b 7.0)))))))
(* a 2.0)))
double code(double a, double b, double c) {
return ((-4.0 * ((pow(c, 3.0) * pow(a, 3.0)) / pow(b, 5.0))) + ((-2.0 * ((a * c) / b)) + ((-2.0 * ((pow(a, 2.0) * pow(c, 2.0)) / pow(b, 3.0))) + (-0.5 * (pow((a * c), 4.0) * (20.0 / pow(b, 7.0))))))) / (a * 2.0);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (((-4.0d0) * (((c ** 3.0d0) * (a ** 3.0d0)) / (b ** 5.0d0))) + (((-2.0d0) * ((a * c) / b)) + (((-2.0d0) * (((a ** 2.0d0) * (c ** 2.0d0)) / (b ** 3.0d0))) + ((-0.5d0) * (((a * c) ** 4.0d0) * (20.0d0 / (b ** 7.0d0))))))) / (a * 2.0d0)
end function
public static double code(double a, double b, double c) {
return ((-4.0 * ((Math.pow(c, 3.0) * Math.pow(a, 3.0)) / Math.pow(b, 5.0))) + ((-2.0 * ((a * c) / b)) + ((-2.0 * ((Math.pow(a, 2.0) * Math.pow(c, 2.0)) / Math.pow(b, 3.0))) + (-0.5 * (Math.pow((a * c), 4.0) * (20.0 / Math.pow(b, 7.0))))))) / (a * 2.0);
}
def code(a, b, c): return ((-4.0 * ((math.pow(c, 3.0) * math.pow(a, 3.0)) / math.pow(b, 5.0))) + ((-2.0 * ((a * c) / b)) + ((-2.0 * ((math.pow(a, 2.0) * math.pow(c, 2.0)) / math.pow(b, 3.0))) + (-0.5 * (math.pow((a * c), 4.0) * (20.0 / math.pow(b, 7.0))))))) / (a * 2.0)
function code(a, b, c) return Float64(Float64(Float64(-4.0 * Float64(Float64((c ^ 3.0) * (a ^ 3.0)) / (b ^ 5.0))) + Float64(Float64(-2.0 * Float64(Float64(a * c) / b)) + Float64(Float64(-2.0 * Float64(Float64((a ^ 2.0) * (c ^ 2.0)) / (b ^ 3.0))) + Float64(-0.5 * Float64((Float64(a * c) ^ 4.0) * Float64(20.0 / (b ^ 7.0))))))) / Float64(a * 2.0)) end
function tmp = code(a, b, c) tmp = ((-4.0 * (((c ^ 3.0) * (a ^ 3.0)) / (b ^ 5.0))) + ((-2.0 * ((a * c) / b)) + ((-2.0 * (((a ^ 2.0) * (c ^ 2.0)) / (b ^ 3.0))) + (-0.5 * (((a * c) ^ 4.0) * (20.0 / (b ^ 7.0))))))) / (a * 2.0); end
code[a_, b_, c_] := N[(N[(N[(-4.0 * N[(N[(N[Power[c, 3.0], $MachinePrecision] * N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 * N[(N[(a * c), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 * N[(N[(N[Power[a, 2.0], $MachinePrecision] * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(N[Power[N[(a * c), $MachinePrecision], 4.0], $MachinePrecision] * N[(20.0 / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-4 \cdot \frac{{c}^{3} \cdot {a}^{3}}{{b}^{5}} + \left(-2 \cdot \frac{a \cdot c}{b} + \left(-2 \cdot \frac{{a}^{2} \cdot {c}^{2}}{{b}^{3}} + -0.5 \cdot \left({\left(a \cdot c\right)}^{4} \cdot \frac{20}{{b}^{7}}\right)\right)\right)}{a \cdot 2}
\end{array}
Initial program 33.7%
*-commutative33.7%
Simplified33.7%
Taylor expanded in b around inf 94.5%
Taylor expanded in a around 0 94.5%
distribute-rgt-out94.5%
associate-*r*94.5%
associate-/l*94.5%
metadata-eval94.5%
pow-sqr94.5%
metadata-eval94.5%
pow-sqr94.5%
unswap-sqr94.5%
unpow294.5%
unpow294.5%
swap-sqr94.5%
unpow294.5%
unpow294.5%
unpow294.5%
swap-sqr94.5%
unpow294.5%
pow-sqr94.5%
metadata-eval94.5%
metadata-eval94.5%
Simplified94.5%
Final simplification94.5%
(FPCore (a b c) :precision binary64 (- (* -2.0 (/ (* (pow a 2.0) (pow c 3.0)) (pow b 5.0))) (+ (/ c b) (/ (* a (pow c 2.0)) (pow b 3.0)))))
double code(double a, double b, double c) {
return (-2.0 * ((pow(a, 2.0) * pow(c, 3.0)) / pow(b, 5.0))) - ((c / b) + ((a * pow(c, 2.0)) / 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 = ((-2.0d0) * (((a ** 2.0d0) * (c ** 3.0d0)) / (b ** 5.0d0))) - ((c / b) + ((a * (c ** 2.0d0)) / (b ** 3.0d0)))
end function
public static double code(double a, double b, double c) {
return (-2.0 * ((Math.pow(a, 2.0) * Math.pow(c, 3.0)) / Math.pow(b, 5.0))) - ((c / b) + ((a * Math.pow(c, 2.0)) / Math.pow(b, 3.0)));
}
def code(a, b, c): return (-2.0 * ((math.pow(a, 2.0) * math.pow(c, 3.0)) / math.pow(b, 5.0))) - ((c / b) + ((a * math.pow(c, 2.0)) / math.pow(b, 3.0)))
function code(a, b, c) return Float64(Float64(-2.0 * Float64(Float64((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) - Float64(Float64(c / b) + Float64(Float64(a * (c ^ 2.0)) / (b ^ 3.0)))) end
function tmp = code(a, b, c) tmp = (-2.0 * (((a ^ 2.0) * (c ^ 3.0)) / (b ^ 5.0))) - ((c / b) + ((a * (c ^ 2.0)) / (b ^ 3.0))); end
code[a_, b_, c_] := N[(N[(-2.0 * 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[(c / b), $MachinePrecision] + N[(N[(a * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \frac{{a}^{2} \cdot {c}^{3}}{{b}^{5}} - \left(\frac{c}{b} + \frac{a \cdot {c}^{2}}{{b}^{3}}\right)
\end{array}
Initial program 33.7%
*-commutative33.7%
Simplified33.7%
Taylor expanded in b around inf 93.3%
Final simplification93.3%
(FPCore (a b c) :precision binary64 (/ (+ (* -4.0 (/ (pow (* a c) 3.0) (pow b 5.0))) (+ (* -2.0 (/ (* a c) b)) (* -2.0 (/ (pow (* a c) 2.0) (pow b 3.0))))) (* a 2.0)))
double code(double a, double b, double c) {
return ((-4.0 * (pow((a * c), 3.0) / pow(b, 5.0))) + ((-2.0 * ((a * c) / b)) + (-2.0 * (pow((a * c), 2.0) / pow(b, 3.0))))) / (a * 2.0);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (((-4.0d0) * (((a * c) ** 3.0d0) / (b ** 5.0d0))) + (((-2.0d0) * ((a * c) / b)) + ((-2.0d0) * (((a * c) ** 2.0d0) / (b ** 3.0d0))))) / (a * 2.0d0)
end function
public static double code(double a, double b, double c) {
return ((-4.0 * (Math.pow((a * c), 3.0) / Math.pow(b, 5.0))) + ((-2.0 * ((a * c) / b)) + (-2.0 * (Math.pow((a * c), 2.0) / Math.pow(b, 3.0))))) / (a * 2.0);
}
def code(a, b, c): return ((-4.0 * (math.pow((a * c), 3.0) / math.pow(b, 5.0))) + ((-2.0 * ((a * c) / b)) + (-2.0 * (math.pow((a * c), 2.0) / math.pow(b, 3.0))))) / (a * 2.0)
function code(a, b, c) return Float64(Float64(Float64(-4.0 * Float64((Float64(a * c) ^ 3.0) / (b ^ 5.0))) + Float64(Float64(-2.0 * Float64(Float64(a * c) / b)) + Float64(-2.0 * Float64((Float64(a * c) ^ 2.0) / (b ^ 3.0))))) / Float64(a * 2.0)) end
function tmp = code(a, b, c) tmp = ((-4.0 * (((a * c) ^ 3.0) / (b ^ 5.0))) + ((-2.0 * ((a * c) / b)) + (-2.0 * (((a * c) ^ 2.0) / (b ^ 3.0))))) / (a * 2.0); end
code[a_, b_, c_] := N[(N[(N[(-4.0 * N[(N[Power[N[(a * c), $MachinePrecision], 3.0], $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 * N[(N[(a * c), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[Power[N[(a * c), $MachinePrecision], 2.0], $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-4 \cdot \frac{{\left(a \cdot c\right)}^{3}}{{b}^{5}} + \left(-2 \cdot \frac{a \cdot c}{b} + -2 \cdot \frac{{\left(a \cdot c\right)}^{2}}{{b}^{3}}\right)}{a \cdot 2}
\end{array}
Initial program 33.7%
*-commutative33.7%
Simplified33.7%
Taylor expanded in b around inf 92.9%
associate-/l*92.9%
Applied egg-rr92.9%
associate-*r/92.9%
cube-prod92.9%
Simplified92.9%
pow192.9%
pow-prod-down92.9%
Applied egg-rr92.9%
unpow192.9%
Simplified92.9%
Final simplification92.9%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -0.0015) (/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0)) (- (/ c (- b)) (* 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 * 4.0)))) - b) / (a * 2.0)) <= -0.0015) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else {
tmp = (c / -b) - (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 * 4.0)))) - b) / Float64(a * 2.0)) <= -0.0015) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(c / Float64(-b)) - Float64(a * Float64((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 * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -0.0015], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / (-b)), $MachinePrecision] - N[(a * N[(N[Power[c, 2.0], $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 4\right)} - b}{a \cdot 2} \leq -0.0015:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b} - a \cdot \frac{{c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -0.0015Initial program 75.3%
*-commutative75.3%
Simplified75.3%
if -0.0015 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 23.8%
*-commutative23.8%
Simplified23.8%
Taylor expanded in b around inf 94.7%
distribute-lft-out94.7%
associate-/l*94.8%
associate-/l*94.8%
Simplified94.8%
Taylor expanded in a around 0 95.1%
mul-1-neg95.1%
unsub-neg95.1%
associate-*r/95.1%
mul-1-neg95.1%
associate-/l*95.1%
Simplified95.1%
Final simplification91.3%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)) -0.0015) (/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0)) (- (/ c (- b)) (* 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 * 4.0)))) - b) / (a * 2.0)) <= -0.0015) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (c / -b) - (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 * 4.0)))) - b) / Float64(a * 2.0)) <= -0.0015) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(c / Float64(-b)) - Float64(a * Float64((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 * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -0.0015], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / (-b)), $MachinePrecision] - N[(a * N[(N[Power[c, 2.0], $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 4\right)} - b}{a \cdot 2} \leq -0.0015:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b} - a \cdot \frac{{c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -0.0015Initial program 75.3%
*-commutative75.3%
+-commutative75.3%
sqr-neg75.3%
unsub-neg75.3%
sqr-neg75.3%
fma-neg75.6%
distribute-lft-neg-in75.6%
*-commutative75.6%
*-commutative75.6%
distribute-rgt-neg-in75.6%
metadata-eval75.6%
Simplified75.6%
if -0.0015 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 23.8%
*-commutative23.8%
Simplified23.8%
Taylor expanded in b around inf 94.7%
distribute-lft-out94.7%
associate-/l*94.8%
associate-/l*94.8%
Simplified94.8%
Taylor expanded in a around 0 95.1%
mul-1-neg95.1%
unsub-neg95.1%
associate-*r/95.1%
mul-1-neg95.1%
associate-/l*95.1%
Simplified95.1%
Final simplification91.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))))
(if (<= t_0 -0.0015)
t_0
(- (/ c (- b)) (* a (/ (pow c 2.0) (pow b 3.0)))))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.0015) {
tmp = t_0;
} else {
tmp = (c / -b) - (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) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
if (t_0 <= (-0.0015d0)) then
tmp = t_0
else
tmp = (c / -b) - (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 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.0015) {
tmp = t_0;
} else {
tmp = (c / -b) - (a * (Math.pow(c, 2.0) / Math.pow(b, 3.0)));
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -0.0015: tmp = t_0 else: tmp = (c / -b) - (a * (math.pow(c, 2.0) / math.pow(b, 3.0))) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -0.0015) tmp = t_0; else tmp = Float64(Float64(c / Float64(-b)) - Float64(a * Float64((c ^ 2.0) / (b ^ 3.0)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -0.0015) tmp = t_0; else tmp = (c / -b) - (a * ((c ^ 2.0) / (b ^ 3.0))); 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 * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.0015], t$95$0, N[(N[(c / (-b)), $MachinePrecision] - N[(a * N[(N[Power[c, 2.0], $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -0.0015:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b} - a \cdot \frac{{c}^{2}}{{b}^{3}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -0.0015Initial program 75.3%
if -0.0015 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 23.8%
*-commutative23.8%
Simplified23.8%
Taylor expanded in b around inf 94.7%
distribute-lft-out94.7%
associate-/l*94.8%
associate-/l*94.8%
Simplified94.8%
Taylor expanded in a around 0 95.1%
mul-1-neg95.1%
unsub-neg95.1%
associate-*r/95.1%
mul-1-neg95.1%
associate-/l*95.1%
Simplified95.1%
Final simplification91.3%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))) (if (<= t_0 -0.0015) t_0 (/ c (- b)))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.0015) {
tmp = t_0;
} else {
tmp = 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 * 4.0d0)))) - b) / (a * 2.0d0)
if (t_0 <= (-0.0015d0)) then
tmp = t_0
else
tmp = 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 * 4.0)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.0015) {
tmp = t_0;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -0.0015: tmp = t_0 else: tmp = c / -b return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -0.0015) tmp = t_0; else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -0.0015) tmp = t_0; else tmp = 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 * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.0015], t$95$0, N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -0.0015:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -0.0015Initial program 75.3%
if -0.0015 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) Initial program 23.8%
*-commutative23.8%
Simplified23.8%
Taylor expanded in b around inf 87.1%
mul-1-neg87.1%
distribute-neg-frac287.1%
Simplified87.1%
Final simplification84.8%
(FPCore (a b c) :precision binary64 (/ c (- b)))
double code(double a, double b, double c) {
return c / -b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / -b
end function
public static double code(double a, double b, double c) {
return c / -b;
}
def code(a, b, c): return c / -b
function code(a, b, c) return Float64(c / Float64(-b)) end
function tmp = code(a, b, c) tmp = c / -b; end
code[a_, b_, c_] := N[(c / (-b)), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{-b}
\end{array}
Initial program 33.7%
*-commutative33.7%
Simplified33.7%
Taylor expanded in b around inf 79.5%
mul-1-neg79.5%
distribute-neg-frac279.5%
Simplified79.5%
Final simplification79.5%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 33.7%
*-commutative33.7%
Simplified33.7%
Taylor expanded in b around -inf 10.3%
+-commutative10.3%
mul-1-neg10.3%
unsub-neg10.3%
Simplified10.3%
Taylor expanded in c around inf 1.6%
Final simplification1.6%
herbie shell --seed 2024039
(FPCore (a b c)
:name "Quadratic roots, 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) (* (* 4.0 a) c)))) (* 2.0 a)))