
(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 11 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
(let* ((t_0 (* (* 4.0 a) c)) (t_1 (- (pow b 2.0) t_0)))
(if (<= (/ (- (sqrt (- (* b b) t_0)) b) (* a 2.0)) -86.0)
(/ (/ (- t_1 (pow (- b) 2.0)) (+ b (sqrt t_1))) (* a 2.0))
(-
(*
a
(*
(* c c)
(+
(* c (* a (- (* -5.0 (* a (/ c (pow b 7.0)))) (/ 2.0 (pow b 5.0)))))
(/ -1.0 (pow b 3.0)))))
(/ c b)))))
double code(double a, double b, double c) {
double t_0 = (4.0 * a) * c;
double t_1 = pow(b, 2.0) - t_0;
double tmp;
if (((sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -86.0) {
tmp = ((t_1 - pow(-b, 2.0)) / (b + sqrt(t_1))) / (a * 2.0);
} else {
tmp = (a * ((c * c) * ((c * (a * ((-5.0 * (a * (c / pow(b, 7.0)))) - (2.0 / pow(b, 5.0))))) + (-1.0 / pow(b, 3.0))))) - (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) :: t_1
real(8) :: tmp
t_0 = (4.0d0 * a) * c
t_1 = (b ** 2.0d0) - t_0
if (((sqrt(((b * b) - t_0)) - b) / (a * 2.0d0)) <= (-86.0d0)) then
tmp = ((t_1 - (-b ** 2.0d0)) / (b + sqrt(t_1))) / (a * 2.0d0)
else
tmp = (a * ((c * c) * ((c * (a * (((-5.0d0) * (a * (c / (b ** 7.0d0)))) - (2.0d0 / (b ** 5.0d0))))) + ((-1.0d0) / (b ** 3.0d0))))) - (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (4.0 * a) * c;
double t_1 = Math.pow(b, 2.0) - t_0;
double tmp;
if (((Math.sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -86.0) {
tmp = ((t_1 - Math.pow(-b, 2.0)) / (b + Math.sqrt(t_1))) / (a * 2.0);
} else {
tmp = (a * ((c * c) * ((c * (a * ((-5.0 * (a * (c / Math.pow(b, 7.0)))) - (2.0 / Math.pow(b, 5.0))))) + (-1.0 / Math.pow(b, 3.0))))) - (c / b);
}
return tmp;
}
def code(a, b, c): t_0 = (4.0 * a) * c t_1 = math.pow(b, 2.0) - t_0 tmp = 0 if ((math.sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -86.0: tmp = ((t_1 - math.pow(-b, 2.0)) / (b + math.sqrt(t_1))) / (a * 2.0) else: tmp = (a * ((c * c) * ((c * (a * ((-5.0 * (a * (c / math.pow(b, 7.0)))) - (2.0 / math.pow(b, 5.0))))) + (-1.0 / math.pow(b, 3.0))))) - (c / b) return tmp
function code(a, b, c) t_0 = Float64(Float64(4.0 * a) * c) t_1 = Float64((b ^ 2.0) - t_0) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(a * 2.0)) <= -86.0) tmp = Float64(Float64(Float64(t_1 - (Float64(-b) ^ 2.0)) / Float64(b + sqrt(t_1))) / Float64(a * 2.0)); else tmp = Float64(Float64(a * Float64(Float64(c * c) * Float64(Float64(c * Float64(a * Float64(Float64(-5.0 * Float64(a * Float64(c / (b ^ 7.0)))) - Float64(2.0 / (b ^ 5.0))))) + Float64(-1.0 / (b ^ 3.0))))) - Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (4.0 * a) * c; t_1 = (b ^ 2.0) - t_0; tmp = 0.0; if (((sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -86.0) tmp = ((t_1 - (-b ^ 2.0)) / (b + sqrt(t_1))) / (a * 2.0); else tmp = (a * ((c * c) * ((c * (a * ((-5.0 * (a * (c / (b ^ 7.0)))) - (2.0 / (b ^ 5.0))))) + (-1.0 / (b ^ 3.0))))) - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[b, 2.0], $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -86.0], N[(N[(N[(t$95$1 - N[Power[(-b), 2.0], $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(a * N[(N[(c * c), $MachinePrecision] * N[(N[(c * N[(a * N[(N[(-5.0 * N[(a * N[(c / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(2.0 / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(4 \cdot a\right) \cdot c\\
t_1 := {b}^{2} - t\_0\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - t\_0} - b}{a \cdot 2} \leq -86:\\
\;\;\;\;\frac{\frac{t\_1 - {\left(-b\right)}^{2}}{b + \sqrt{t\_1}}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(\left(c \cdot c\right) \cdot \left(c \cdot \left(a \cdot \left(-5 \cdot \left(a \cdot \frac{c}{{b}^{7}}\right) - \frac{2}{{b}^{5}}\right)\right) + \frac{-1}{{b}^{3}}\right)\right) - \frac{c}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -86Initial program 92.9%
*-commutative92.9%
Simplified92.9%
add-cbrt-cube92.0%
pow1/389.2%
pow389.2%
pow289.2%
pow-pow89.3%
metadata-eval89.3%
Applied egg-rr89.3%
unpow1/392.3%
Simplified92.3%
flip-+92.4%
pow292.4%
add-sqr-sqrt92.1%
pow1/389.4%
pow-pow94.4%
metadata-eval94.4%
*-commutative94.4%
pow1/394.2%
pow-pow94.4%
metadata-eval94.4%
*-commutative94.4%
Applied egg-rr94.4%
if -86 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in a around 0 93.2%
+-commutative93.2%
mul-1-neg93.2%
unsub-neg93.2%
Simplified93.2%
Taylor expanded in c around 0 93.2%
Taylor expanded in a around 0 93.2%
associate-/l*93.2%
associate-*r/93.2%
metadata-eval93.2%
Simplified93.2%
unpow293.2%
Applied egg-rr93.2%
Final simplification93.3%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)) -86.0)
(- (* 0.5 (/ (sqrt (+ (pow b 2.0) (* a (* c -4.0)))) a)) (* 0.5 (/ b a)))
(-
(*
a
(*
(* c c)
(+
(* c (* a (- (* -5.0 (* a (/ c (pow b 7.0)))) (/ 2.0 (pow b 5.0)))))
(/ -1.0 (pow b 3.0)))))
(/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -86.0) {
tmp = (0.5 * (sqrt((pow(b, 2.0) + (a * (c * -4.0)))) / a)) - (0.5 * (b / a));
} else {
tmp = (a * ((c * c) * ((c * (a * ((-5.0 * (a * (c / pow(b, 7.0)))) - (2.0 / pow(b, 5.0))))) + (-1.0 / pow(b, 3.0))))) - (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) - ((4.0d0 * a) * c))) - b) / (a * 2.0d0)) <= (-86.0d0)) then
tmp = (0.5d0 * (sqrt(((b ** 2.0d0) + (a * (c * (-4.0d0))))) / a)) - (0.5d0 * (b / a))
else
tmp = (a * ((c * c) * ((c * (a * (((-5.0d0) * (a * (c / (b ** 7.0d0)))) - (2.0d0 / (b ** 5.0d0))))) + ((-1.0d0) / (b ** 3.0d0))))) - (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) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -86.0) {
tmp = (0.5 * (Math.sqrt((Math.pow(b, 2.0) + (a * (c * -4.0)))) / a)) - (0.5 * (b / a));
} else {
tmp = (a * ((c * c) * ((c * (a * ((-5.0 * (a * (c / Math.pow(b, 7.0)))) - (2.0 / Math.pow(b, 5.0))))) + (-1.0 / Math.pow(b, 3.0))))) - (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if ((math.sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -86.0: tmp = (0.5 * (math.sqrt((math.pow(b, 2.0) + (a * (c * -4.0)))) / a)) - (0.5 * (b / a)) else: tmp = (a * ((c * c) * ((c * (a * ((-5.0 * (a * (c / math.pow(b, 7.0)))) - (2.0 / math.pow(b, 5.0))))) + (-1.0 / math.pow(b, 3.0))))) - (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)) <= -86.0) tmp = Float64(Float64(0.5 * Float64(sqrt(Float64((b ^ 2.0) + Float64(a * Float64(c * -4.0)))) / a)) - Float64(0.5 * Float64(b / a))); else tmp = Float64(Float64(a * Float64(Float64(c * c) * Float64(Float64(c * Float64(a * Float64(Float64(-5.0 * Float64(a * Float64(c / (b ^ 7.0)))) - Float64(2.0 / (b ^ 5.0))))) + Float64(-1.0 / (b ^ 3.0))))) - Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (((sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -86.0) tmp = (0.5 * (sqrt(((b ^ 2.0) + (a * (c * -4.0)))) / a)) - (0.5 * (b / a)); else tmp = (a * ((c * c) * ((c * (a * ((-5.0 * (a * (c / (b ^ 7.0)))) - (2.0 / (b ^ 5.0))))) + (-1.0 / (b ^ 3.0))))) - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -86.0], N[(N[(0.5 * N[(N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] - N[(0.5 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a * N[(N[(c * c), $MachinePrecision] * N[(N[(c * N[(a * N[(N[(-5.0 * N[(a * N[(c / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(2.0 / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2} \leq -86:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{{b}^{2} + a \cdot \left(c \cdot -4\right)}}{a} - 0.5 \cdot \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left(\left(c \cdot c\right) \cdot \left(c \cdot \left(a \cdot \left(-5 \cdot \left(a \cdot \frac{c}{{b}^{7}}\right) - \frac{2}{{b}^{5}}\right)\right) + \frac{-1}{{b}^{3}}\right)\right) - \frac{c}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -86Initial program 92.9%
+-commutative92.9%
sqr-neg92.9%
unsub-neg92.9%
sqr-neg92.9%
sub-neg92.9%
+-commutative92.9%
*-commutative92.9%
associate-*r*92.9%
distribute-rgt-neg-in92.9%
fma-define92.9%
*-commutative92.9%
distribute-rgt-neg-in92.9%
metadata-eval92.9%
Simplified92.9%
div-sub93.4%
*-un-lft-identity93.4%
*-commutative93.4%
times-frac93.4%
metadata-eval93.4%
pow293.4%
*-un-lft-identity93.4%
*-commutative93.4%
times-frac93.4%
metadata-eval93.4%
Applied egg-rr93.4%
fma-undefine93.4%
Applied egg-rr93.4%
if -86 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in a around 0 93.2%
+-commutative93.2%
mul-1-neg93.2%
unsub-neg93.2%
Simplified93.2%
Taylor expanded in c around 0 93.2%
Taylor expanded in a around 0 93.2%
associate-/l*93.2%
associate-*r/93.2%
metadata-eval93.2%
Simplified93.2%
unpow293.2%
Applied egg-rr93.2%
Final simplification93.2%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)) -1.15)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(-
(*
a
(* (pow c 2.0) (+ (/ (* c (* a -2.0)) (pow b 5.0)) (/ -1.0 (pow b 3.0)))))
(/ c b))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -1.15) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (a * (pow(c, 2.0) * (((c * (a * -2.0)) / pow(b, 5.0)) + (-1.0 / pow(b, 3.0))))) - (c / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)) <= -1.15) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(a * Float64((c ^ 2.0) * Float64(Float64(Float64(c * Float64(a * -2.0)) / (b ^ 5.0)) + Float64(-1.0 / (b ^ 3.0))))) - Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -1.15], 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[(a * N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(N[(c * N[(a * -2.0), $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2} \leq -1.15:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot \left({c}^{2} \cdot \left(\frac{c \cdot \left(a \cdot -2\right)}{{b}^{5}} + \frac{-1}{{b}^{3}}\right)\right) - \frac{c}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -1.1499999999999999Initial program 84.6%
*-commutative84.6%
+-commutative84.6%
sqr-neg84.6%
unsub-neg84.6%
sqr-neg84.6%
fma-neg84.8%
distribute-lft-neg-in84.8%
*-commutative84.8%
*-commutative84.8%
distribute-rgt-neg-in84.8%
metadata-eval84.8%
Simplified84.8%
if -1.1499999999999999 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.4%
*-commutative46.4%
Simplified46.4%
Taylor expanded in a around 0 94.4%
+-commutative94.4%
mul-1-neg94.4%
unsub-neg94.4%
Simplified94.4%
Taylor expanded in c around 0 92.8%
associate-*r/92.8%
associate-*r*92.8%
Simplified92.8%
Final simplification91.6%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)) -1.15)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(/
(-
(* a (- (/ (* -2.0 (* a (pow c 3.0))) (pow b 4.0)) (pow (/ c b) 2.0)))
c)
b)))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -1.15) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = ((a * (((-2.0 * (a * pow(c, 3.0))) / pow(b, 4.0)) - pow((c / b), 2.0))) - c) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)) <= -1.15) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(a * Float64(Float64(Float64(-2.0 * Float64(a * (c ^ 3.0))) / (b ^ 4.0)) - (Float64(c / b) ^ 2.0))) - c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -1.15], 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[(N[(a * N[(N[(N[(-2.0 * N[(a * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] - N[Power[N[(c / b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - c), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2} \leq -1.15:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot \left(\frac{-2 \cdot \left(a \cdot {c}^{3}\right)}{{b}^{4}} - {\left(\frac{c}{b}\right)}^{2}\right) - c}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -1.1499999999999999Initial program 84.6%
*-commutative84.6%
+-commutative84.6%
sqr-neg84.6%
unsub-neg84.6%
sqr-neg84.6%
fma-neg84.8%
distribute-lft-neg-in84.8%
*-commutative84.8%
*-commutative84.8%
distribute-rgt-neg-in84.8%
metadata-eval84.8%
Simplified84.8%
if -1.1499999999999999 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.4%
*-commutative46.4%
Simplified46.4%
Taylor expanded in b around inf 92.8%
associate-+r+92.8%
mul-1-neg92.8%
unsub-neg92.8%
mul-1-neg92.8%
unsub-neg92.8%
associate-/l*92.8%
Simplified92.8%
Taylor expanded in c around 0 92.7%
Taylor expanded in a around 0 92.8%
+-commutative92.8%
neg-mul-192.8%
unsub-neg92.8%
associate-*r/92.8%
unpow292.8%
unpow292.8%
times-frac92.8%
unpow292.8%
Simplified92.8%
Final simplification91.6%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)) -1.15) (/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0)) (/ -1.0 (/ (- b (* a (/ c b))) c))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -1.15) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = -1.0 / ((b - (a * (c / b))) / c);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)) <= -1.15) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(-1.0 / Float64(Float64(b - Float64(a * Float64(c / b))) / c)); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -1.15], 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[(-1.0 / N[(N[(b - N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2} \leq -1.15:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{b - a \cdot \frac{c}{b}}{c}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -1.1499999999999999Initial program 84.6%
*-commutative84.6%
+-commutative84.6%
sqr-neg84.6%
unsub-neg84.6%
sqr-neg84.6%
fma-neg84.8%
distribute-lft-neg-in84.8%
*-commutative84.8%
*-commutative84.8%
distribute-rgt-neg-in84.8%
metadata-eval84.8%
Simplified84.8%
if -1.1499999999999999 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.4%
*-commutative46.4%
Simplified46.4%
Taylor expanded in b around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
mul-1-neg88.8%
Simplified88.8%
clear-num88.6%
inv-pow88.6%
associate-/l*88.6%
Applied egg-rr88.6%
unpow-188.6%
sub-neg88.6%
distribute-neg-in88.6%
+-commutative88.6%
remove-double-neg88.6%
sub-neg88.6%
fma-neg88.6%
unpow288.6%
unpow288.6%
times-frac88.6%
unpow288.6%
remove-double-neg88.6%
Simplified88.6%
Taylor expanded in c around 0 89.0%
+-commutative89.0%
mul-1-neg89.0%
unsub-neg89.0%
associate-/l*89.0%
Simplified89.0%
Final simplification88.4%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)) -1.15) (/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0)) (/ -1.0 (/ (- b (* a (/ c b))) c))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0)) <= -1.15) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else {
tmp = -1.0 / ((b - (a * (c / b))) / c);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)) <= -1.15) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); else tmp = Float64(-1.0 / Float64(Float64(b - Float64(a * Float64(c / b))) / c)); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -1.15], 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[(-1.0 / N[(N[(b - N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2} \leq -1.15:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{b - a \cdot \frac{c}{b}}{c}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -1.1499999999999999Initial program 84.6%
+-commutative84.6%
sqr-neg84.6%
unsub-neg84.6%
sqr-neg84.6%
sub-neg84.6%
+-commutative84.6%
*-commutative84.6%
associate-*r*84.6%
distribute-rgt-neg-in84.6%
fma-define84.7%
*-commutative84.7%
distribute-rgt-neg-in84.7%
metadata-eval84.7%
Simplified84.7%
if -1.1499999999999999 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.4%
*-commutative46.4%
Simplified46.4%
Taylor expanded in b around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
mul-1-neg88.8%
Simplified88.8%
clear-num88.6%
inv-pow88.6%
associate-/l*88.6%
Applied egg-rr88.6%
unpow-188.6%
sub-neg88.6%
distribute-neg-in88.6%
+-commutative88.6%
remove-double-neg88.6%
sub-neg88.6%
fma-neg88.6%
unpow288.6%
unpow288.6%
times-frac88.6%
unpow288.6%
remove-double-neg88.6%
Simplified88.6%
Taylor expanded in c around 0 89.0%
+-commutative89.0%
mul-1-neg89.0%
unsub-neg89.0%
associate-/l*89.0%
Simplified89.0%
Final simplification88.4%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* (* 4.0 a) c))) b) (* a 2.0)))) (if (<= t_0 -1.15) t_0 (/ -1.0 (/ (- b (* a (/ c b))) c)))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -1.15) {
tmp = t_0;
} else {
tmp = -1.0 / ((b - (a * (c / b))) / c);
}
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) - ((4.0d0 * a) * c))) - b) / (a * 2.0d0)
if (t_0 <= (-1.15d0)) then
tmp = t_0
else
tmp = (-1.0d0) / ((b - (a * (c / b))) / c)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -1.15) {
tmp = t_0;
} else {
tmp = -1.0 / ((b - (a * (c / b))) / c);
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0) tmp = 0 if t_0 <= -1.15: tmp = t_0 else: tmp = -1.0 / ((b - (a * (c / b))) / c) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -1.15) tmp = t_0; else tmp = Float64(-1.0 / Float64(Float64(b - Float64(a * Float64(c / b))) / c)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - ((4.0 * a) * c))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -1.15) tmp = t_0; else tmp = -1.0 / ((b - (a * (c / b))) / c); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1.15], t$95$0, N[(-1.0 / N[(N[(b - N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -1.15:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{b - a \cdot \frac{c}{b}}{c}}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -1.1499999999999999Initial program 84.6%
if -1.1499999999999999 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 46.4%
*-commutative46.4%
Simplified46.4%
Taylor expanded in b around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
mul-1-neg88.8%
Simplified88.8%
clear-num88.6%
inv-pow88.6%
associate-/l*88.6%
Applied egg-rr88.6%
unpow-188.6%
sub-neg88.6%
distribute-neg-in88.6%
+-commutative88.6%
remove-double-neg88.6%
sub-neg88.6%
fma-neg88.6%
unpow288.6%
unpow288.6%
times-frac88.6%
unpow288.6%
remove-double-neg88.6%
Simplified88.6%
Taylor expanded in c around 0 89.0%
+-commutative89.0%
mul-1-neg89.0%
unsub-neg89.0%
associate-/l*89.0%
Simplified89.0%
Final simplification88.4%
(FPCore (a b c) :precision binary64 (/ -1.0 (/ (- b (* a (/ c b))) c)))
double code(double a, double b, double c) {
return -1.0 / ((b - (a * (c / b))) / c);
}
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) / ((b - (a * (c / b))) / c)
end function
public static double code(double a, double b, double c) {
return -1.0 / ((b - (a * (c / b))) / c);
}
def code(a, b, c): return -1.0 / ((b - (a * (c / b))) / c)
function code(a, b, c) return Float64(-1.0 / Float64(Float64(b - Float64(a * Float64(c / b))) / c)) end
function tmp = code(a, b, c) tmp = -1.0 / ((b - (a * (c / b))) / c); end
code[a_, b_, c_] := N[(-1.0 / N[(N[(b - N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\frac{b - a \cdot \frac{c}{b}}{c}}
\end{array}
Initial program 51.9%
*-commutative51.9%
Simplified51.9%
Taylor expanded in b around inf 83.9%
mul-1-neg83.9%
unsub-neg83.9%
mul-1-neg83.9%
Simplified83.9%
clear-num83.6%
inv-pow83.6%
associate-/l*83.6%
Applied egg-rr83.6%
unpow-183.6%
sub-neg83.6%
distribute-neg-in83.6%
+-commutative83.6%
remove-double-neg83.6%
sub-neg83.6%
fma-neg83.6%
unpow283.6%
unpow283.6%
times-frac83.6%
unpow283.6%
remove-double-neg83.6%
Simplified83.6%
Taylor expanded in c around 0 84.2%
+-commutative84.2%
mul-1-neg84.2%
unsub-neg84.2%
associate-/l*84.2%
Simplified84.2%
Final simplification84.2%
(FPCore (a b c) :precision binary64 (/ -1.0 (- (/ b c) (/ a b))))
double code(double a, double b, double c) {
return -1.0 / ((b / c) - (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) / ((b / c) - (a / b))
end function
public static double code(double a, double b, double c) {
return -1.0 / ((b / c) - (a / b));
}
def code(a, b, c): return -1.0 / ((b / c) - (a / b))
function code(a, b, c) return Float64(-1.0 / Float64(Float64(b / c) - Float64(a / b))) end
function tmp = code(a, b, c) tmp = -1.0 / ((b / c) - (a / b)); end
code[a_, b_, c_] := N[(-1.0 / N[(N[(b / c), $MachinePrecision] - N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\frac{b}{c} - \frac{a}{b}}
\end{array}
Initial program 51.9%
*-commutative51.9%
Simplified51.9%
Taylor expanded in b around inf 83.9%
mul-1-neg83.9%
unsub-neg83.9%
mul-1-neg83.9%
Simplified83.9%
clear-num83.6%
inv-pow83.6%
associate-/l*83.6%
Applied egg-rr83.6%
unpow-183.6%
sub-neg83.6%
distribute-neg-in83.6%
+-commutative83.6%
remove-double-neg83.6%
sub-neg83.6%
fma-neg83.6%
unpow283.6%
unpow283.6%
times-frac83.6%
unpow283.6%
remove-double-neg83.6%
Simplified83.6%
Taylor expanded in a around 0 84.2%
+-commutative84.2%
mul-1-neg84.2%
unsub-neg84.2%
Simplified84.2%
Final simplification84.2%
(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 51.9%
*-commutative51.9%
Simplified51.9%
Taylor expanded in b around inf 67.4%
associate-*r/67.4%
mul-1-neg67.4%
Simplified67.4%
Final simplification67.4%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.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.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 51.9%
*-commutative51.9%
Simplified51.9%
Taylor expanded in b around inf 83.9%
mul-1-neg83.9%
unsub-neg83.9%
mul-1-neg83.9%
Simplified83.9%
expm1-log1p-u75.2%
expm1-undefine53.9%
associate-/l*53.9%
Applied egg-rr53.9%
sub-neg53.9%
Simplified62.5%
Taylor expanded in c around 0 3.2%
metadata-eval3.2%
Applied egg-rr3.2%
herbie shell --seed 2024116
(FPCore (a b c)
:name "Quadratic roots, 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) (* (* 4.0 a) c)))) (* 2.0 a)))