
(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 (/ (/ (* 4.0 (* c a)) (+ b (sqrt (fma b b (* (* c a) -4.0))))) (* a (- 2.0))))
double code(double a, double b, double c) {
return ((4.0 * (c * a)) / (b + sqrt(fma(b, b, ((c * a) * -4.0))))) / (a * -2.0);
}
function code(a, b, c) return Float64(Float64(Float64(4.0 * Float64(c * a)) / Float64(b + sqrt(fma(b, b, Float64(Float64(c * a) * -4.0))))) / Float64(a * Float64(-2.0))) end
code[a_, b_, c_] := N[(N[(N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * (-2.0)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{4 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}}}{a \cdot \left(-2\right)}
\end{array}
Initial program 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
flip-+55.4%
Applied egg-rr57.8%
associate--r-99.4%
unpow299.4%
unpow299.4%
difference-of-squares99.4%
+-commutative99.4%
neg-mul-199.4%
distribute-rgt1-in99.4%
metadata-eval99.4%
mul0-lft99.4%
associate-*r*99.4%
unpow299.4%
fma-neg99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in b around 0 99.3%
*-commutative99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -2.6) (/ 1.0 (* 2.0 (/ a (- (sqrt (fma b b (* (* c a) -4.0))) b)))) (/ 1.0 (- (* a (+ (/ (* c a) (pow b 3.0)) (/ 1.0 b))) (/ b c)))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -2.6) {
tmp = 1.0 / (2.0 * (a / (sqrt(fma(b, b, ((c * a) * -4.0))) - b)));
} else {
tmp = 1.0 / ((a * (((c * a) / pow(b, 3.0)) + (1.0 / b))) - (b / c));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -2.6) tmp = Float64(1.0 / Float64(2.0 * Float64(a / Float64(sqrt(fma(b, b, Float64(Float64(c * a) * -4.0))) - b)))); else tmp = Float64(1.0 / Float64(Float64(a * Float64(Float64(Float64(c * a) / (b ^ 3.0)) + Float64(1.0 / b))) - Float64(b / c))); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -2.6], N[(1.0 / N[(2.0 * N[(a / N[(N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(a * N[(N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -2.6:\\
\;\;\;\;\frac{1}{2 \cdot \frac{a}{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a \cdot \left(\frac{c \cdot a}{{b}^{3}} + \frac{1}{b}\right) - \frac{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)) < -2.60000000000000009Initial program 86.3%
*-commutative86.3%
Simplified86.3%
neg-sub086.3%
flip3--85.3%
metadata-eval85.3%
metadata-eval85.3%
pow285.3%
Applied egg-rr85.3%
sub0-neg85.3%
+-lft-identity85.3%
mul0-lft85.3%
+-rgt-identity85.3%
Simplified85.3%
clear-num85.3%
inv-pow85.3%
distribute-frac-neg85.3%
pow-div86.4%
metadata-eval86.4%
pow186.4%
pow286.4%
associate-*l*86.4%
Applied egg-rr86.4%
unpow-186.4%
*-commutative86.4%
*-lft-identity86.4%
times-frac86.4%
metadata-eval86.4%
+-commutative86.4%
unsub-neg86.4%
unpow286.4%
fma-neg86.6%
*-commutative86.6%
distribute-rgt-neg-in86.6%
metadata-eval86.6%
Simplified86.6%
if -2.60000000000000009 < (/.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 52.4%
*-commutative52.4%
Simplified52.4%
neg-sub052.4%
flip3--51.7%
metadata-eval51.7%
metadata-eval51.7%
pow251.7%
Applied egg-rr51.7%
sub0-neg51.7%
+-lft-identity51.7%
mul0-lft51.7%
+-rgt-identity51.7%
Simplified51.7%
clear-num51.7%
inv-pow51.7%
distribute-frac-neg51.7%
pow-div52.4%
metadata-eval52.4%
pow152.4%
pow252.4%
associate-*l*52.4%
Applied egg-rr52.4%
unpow-152.4%
*-commutative52.4%
*-lft-identity52.4%
times-frac52.4%
metadata-eval52.4%
+-commutative52.4%
unsub-neg52.4%
unpow252.4%
fma-neg52.4%
*-commutative52.4%
distribute-rgt-neg-in52.4%
metadata-eval52.4%
Simplified52.4%
Taylor expanded in a around 0 91.6%
Taylor expanded in c around 0 91.6%
Final simplification91.1%
(FPCore (a b c) :precision binary64 (if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -2.6) (/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0)) (/ 1.0 (- (* a (+ (/ (* c a) (pow b 3.0)) (/ 1.0 b))) (/ b c)))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -2.6) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = 1.0 / ((a * (((c * a) / pow(b, 3.0)) + (1.0 / b))) - (b / c));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -2.6) 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(a * Float64(Float64(Float64(c * a) / (b ^ 3.0)) + Float64(1.0 / b))) - Float64(b / c))); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -2.6], 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[(a * N[(N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -2.6:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a \cdot \left(\frac{c \cdot a}{{b}^{3}} + \frac{1}{b}\right) - \frac{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)) < -2.60000000000000009Initial program 86.3%
*-commutative86.3%
+-commutative86.3%
sqr-neg86.3%
unsub-neg86.3%
sqr-neg86.3%
fma-neg86.5%
distribute-lft-neg-in86.5%
*-commutative86.5%
*-commutative86.5%
distribute-rgt-neg-in86.5%
metadata-eval86.5%
Simplified86.5%
if -2.60000000000000009 < (/.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 52.4%
*-commutative52.4%
Simplified52.4%
neg-sub052.4%
flip3--51.7%
metadata-eval51.7%
metadata-eval51.7%
pow251.7%
Applied egg-rr51.7%
sub0-neg51.7%
+-lft-identity51.7%
mul0-lft51.7%
+-rgt-identity51.7%
Simplified51.7%
clear-num51.7%
inv-pow51.7%
distribute-frac-neg51.7%
pow-div52.4%
metadata-eval52.4%
pow152.4%
pow252.4%
associate-*l*52.4%
Applied egg-rr52.4%
unpow-152.4%
*-commutative52.4%
*-lft-identity52.4%
times-frac52.4%
metadata-eval52.4%
+-commutative52.4%
unsub-neg52.4%
unpow252.4%
fma-neg52.4%
*-commutative52.4%
distribute-rgt-neg-in52.4%
metadata-eval52.4%
Simplified52.4%
Taylor expanded in a around 0 91.6%
Taylor expanded in c around 0 91.6%
Final simplification91.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0))))
(if (<= t_0 -2.6)
t_0
(/ 1.0 (- (* a (+ (/ (* c a) (pow b 3.0)) (/ 1.0 b))) (/ b c))))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -2.6) {
tmp = t_0;
} else {
tmp = 1.0 / ((a * (((c * a) / pow(b, 3.0)) + (1.0 / b))) - (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) - (c * (4.0d0 * a)))) - b) / (a * 2.0d0)
if (t_0 <= (-2.6d0)) then
tmp = t_0
else
tmp = 1.0d0 / ((a * (((c * a) / (b ** 3.0d0)) + (1.0d0 / b))) - (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) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -2.6) {
tmp = t_0;
} else {
tmp = 1.0 / ((a * (((c * a) / Math.pow(b, 3.0)) + (1.0 / b))) - (b / c));
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -2.6: tmp = t_0 else: tmp = 1.0 / ((a * (((c * a) / math.pow(b, 3.0)) + (1.0 / b))) - (b / c)) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -2.6) tmp = t_0; else tmp = Float64(1.0 / Float64(Float64(a * Float64(Float64(Float64(c * a) / (b ^ 3.0)) + Float64(1.0 / b))) - Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -2.6) tmp = t_0; else tmp = 1.0 / ((a * (((c * a) / (b ^ 3.0)) + (1.0 / b))) - (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[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2.6], t$95$0, N[(1.0 / N[(N[(a * N[(N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -2.6:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{a \cdot \left(\frac{c \cdot a}{{b}^{3}} + \frac{1}{b}\right) - \frac{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)) < -2.60000000000000009Initial program 86.3%
if -2.60000000000000009 < (/.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 52.4%
*-commutative52.4%
Simplified52.4%
neg-sub052.4%
flip3--51.7%
metadata-eval51.7%
metadata-eval51.7%
pow251.7%
Applied egg-rr51.7%
sub0-neg51.7%
+-lft-identity51.7%
mul0-lft51.7%
+-rgt-identity51.7%
Simplified51.7%
clear-num51.7%
inv-pow51.7%
distribute-frac-neg51.7%
pow-div52.4%
metadata-eval52.4%
pow152.4%
pow252.4%
associate-*l*52.4%
Applied egg-rr52.4%
unpow-152.4%
*-commutative52.4%
*-lft-identity52.4%
times-frac52.4%
metadata-eval52.4%
+-commutative52.4%
unsub-neg52.4%
unpow252.4%
fma-neg52.4%
*-commutative52.4%
distribute-rgt-neg-in52.4%
metadata-eval52.4%
Simplified52.4%
Taylor expanded in a around 0 91.6%
Taylor expanded in c around 0 91.6%
Final simplification91.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0))))
(if (<= t_0 -0.1)
t_0
(/ (* 2.0 (/ (* c a) a)) (- (- b) (fma -2.0 (/ (* c a) b) b))))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.1) {
tmp = t_0;
} else {
tmp = (2.0 * ((c * a) / a)) / (-b - fma(-2.0, ((c * a) / b), b));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -0.1) tmp = t_0; else tmp = Float64(Float64(2.0 * Float64(Float64(c * a) / a)) / Float64(Float64(-b) - fma(-2.0, Float64(Float64(c * a) / b), b))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.1], t$95$0, N[(N[(2.0 * N[(N[(c * a), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[(-2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -0.1:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \frac{c \cdot a}{a}}{\left(-b\right) - \mathsf{fma}\left(-2, \frac{c \cdot a}{b}, b\right)}\\
\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)) < -0.10000000000000001Initial program 82.6%
if -0.10000000000000001 < (/.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 50.7%
*-commutative50.7%
Simplified50.7%
neg-sub050.7%
flip3--50.1%
metadata-eval50.1%
metadata-eval50.1%
pow250.1%
Applied egg-rr50.1%
sub0-neg50.1%
+-lft-identity50.1%
mul0-lft50.1%
+-rgt-identity50.1%
Simplified50.1%
flip-+50.3%
Applied egg-rr52.7%
associate--r-99.4%
unpow299.4%
unpow299.4%
difference-of-squares99.4%
+-commutative99.4%
neg-mul-199.4%
distribute-rgt1-in99.4%
metadata-eval99.4%
mul0-lft99.4%
associate-*r*99.4%
unpow299.4%
fma-neg99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in a around 0 86.6%
*-commutative86.6%
Simplified86.6%
div-inv86.5%
+-commutative86.5%
associate-*l*86.5%
*-commutative86.5%
associate-*r*86.5%
fma-define86.5%
mul0-lft86.5%
+-commutative86.5%
fma-define86.5%
associate-/l*86.5%
Applied egg-rr86.5%
*-commutative86.5%
times-frac86.6%
associate-*r/86.6%
*-lft-identity86.6%
associate-/r*86.7%
fma-undefine86.7%
+-rgt-identity86.7%
associate-*r*86.7%
*-commutative86.7%
*-commutative86.7%
times-frac86.7%
metadata-eval86.7%
*-commutative86.7%
associate-*r/86.7%
Simplified86.7%
Final simplification86.1%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)))) (if (<= t_0 -0.1) t_0 (/ 1.0 (/ (- (/ (* c a) b) b) c)))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.1) {
tmp = t_0;
} else {
tmp = 1.0 / ((((c * a) / b) - 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) - (c * (4.0d0 * a)))) - b) / (a * 2.0d0)
if (t_0 <= (-0.1d0)) then
tmp = t_0
else
tmp = 1.0d0 / ((((c * a) / b) - 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) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.1) {
tmp = t_0;
} else {
tmp = 1.0 / ((((c * a) / b) - b) / c);
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -0.1: tmp = t_0 else: tmp = 1.0 / ((((c * a) / b) - b) / c) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -0.1) tmp = t_0; else tmp = Float64(1.0 / Float64(Float64(Float64(Float64(c * a) / b) - b) / c)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -0.1) tmp = t_0; else tmp = 1.0 / ((((c * a) / b) - 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[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.1], t$95$0, N[(1.0 / N[(N[(N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision] - b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -0.1:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\frac{c \cdot a}{b} - 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)) < -0.10000000000000001Initial program 82.6%
if -0.10000000000000001 < (/.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 50.7%
*-commutative50.7%
Simplified50.7%
neg-sub050.7%
flip3--50.1%
metadata-eval50.1%
metadata-eval50.1%
pow250.1%
Applied egg-rr50.1%
sub0-neg50.1%
+-lft-identity50.1%
mul0-lft50.1%
+-rgt-identity50.1%
Simplified50.1%
clear-num50.1%
inv-pow50.1%
distribute-frac-neg50.1%
pow-div50.7%
metadata-eval50.7%
pow150.7%
pow250.7%
associate-*l*50.7%
Applied egg-rr50.7%
unpow-150.7%
*-commutative50.7%
*-lft-identity50.7%
times-frac50.7%
metadata-eval50.7%
+-commutative50.7%
unsub-neg50.7%
unpow250.7%
fma-neg50.7%
*-commutative50.7%
distribute-rgt-neg-in50.7%
metadata-eval50.7%
Simplified50.7%
Taylor expanded in c around 0 86.7%
Final simplification86.1%
(FPCore (a b c) :precision binary64 (/ 1.0 (/ (- (/ (* c a) b) b) c)))
double code(double a, double b, double c) {
return 1.0 / ((((c * a) / b) - 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 / ((((c * a) / b) - b) / c)
end function
public static double code(double a, double b, double c) {
return 1.0 / ((((c * a) / b) - b) / c);
}
def code(a, b, c): return 1.0 / ((((c * a) / b) - b) / c)
function code(a, b, c) return Float64(1.0 / Float64(Float64(Float64(Float64(c * a) / b) - b) / c)) end
function tmp = code(a, b, c) tmp = 1.0 / ((((c * a) / b) - b) / c); end
code[a_, b_, c_] := N[(1.0 / N[(N[(N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision] - b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\frac{c \cdot a}{b} - b}{c}}
\end{array}
Initial program 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
clear-num55.2%
inv-pow55.2%
distribute-frac-neg55.2%
pow-div55.8%
metadata-eval55.8%
pow155.8%
pow255.8%
associate-*l*55.8%
Applied egg-rr55.8%
unpow-155.8%
*-commutative55.8%
*-lft-identity55.8%
times-frac55.8%
metadata-eval55.8%
+-commutative55.8%
unsub-neg55.8%
unpow255.8%
fma-neg55.9%
*-commutative55.9%
distribute-rgt-neg-in55.9%
metadata-eval55.9%
Simplified55.9%
Taylor expanded in c around 0 82.4%
Final simplification82.4%
(FPCore (a b c) :precision binary64 (/ 1.0 (- (/ a b) (/ b c))))
double code(double a, double b, double c) {
return 1.0 / ((a / b) - (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 / ((a / b) - (b / c))
end function
public static double code(double a, double b, double c) {
return 1.0 / ((a / b) - (b / c));
}
def code(a, b, c): return 1.0 / ((a / b) - (b / c))
function code(a, b, c) return Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))) end
function tmp = code(a, b, c) tmp = 1.0 / ((a / b) - (b / c)); end
code[a_, b_, c_] := N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{a}{b} - \frac{b}{c}}
\end{array}
Initial program 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
clear-num55.2%
inv-pow55.2%
distribute-frac-neg55.2%
pow-div55.8%
metadata-eval55.8%
pow155.8%
pow255.8%
associate-*l*55.8%
Applied egg-rr55.8%
unpow-155.8%
*-commutative55.8%
*-lft-identity55.8%
times-frac55.8%
metadata-eval55.8%
+-commutative55.8%
unsub-neg55.8%
unpow255.8%
fma-neg55.9%
*-commutative55.9%
distribute-rgt-neg-in55.9%
metadata-eval55.9%
Simplified55.9%
Taylor expanded in a around 0 82.4%
Final simplification82.4%
(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(-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 55.8%
*-commutative55.8%
+-commutative55.8%
sqr-neg55.8%
unsub-neg55.8%
sqr-neg55.8%
fma-neg55.8%
distribute-lft-neg-in55.8%
*-commutative55.8%
*-commutative55.8%
distribute-rgt-neg-in55.8%
metadata-eval55.8%
Simplified55.8%
Taylor expanded in b around inf 64.4%
associate-*r/64.4%
mul-1-neg64.4%
Simplified64.4%
Final simplification64.4%
(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 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
Taylor expanded in a around 0 3.2%
associate-*r/3.2%
distribute-rgt1-in3.2%
metadata-eval3.2%
mul0-lft3.2%
metadata-eval3.2%
Simplified3.2%
herbie shell --seed 2024123
(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)))