
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 1.0; end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 1.0; end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}
(FPCore (a b) :precision binary64 (+ (pow (hypot a b) 4.0) (fma (* b b) 4.0 -1.0)))
double code(double a, double b) {
return pow(hypot(a, b), 4.0) + fma((b * b), 4.0, -1.0);
}
function code(a, b) return Float64((hypot(a, b) ^ 4.0) + fma(Float64(b * b), 4.0, -1.0)) end
code[a_, b_] := N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * 4.0 + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b \cdot b, 4, -1\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (+ -1.0 (+ (pow (+ (* b b) (* a a)) 2.0) (* 4.0 (* b b)))))
double code(double a, double b) {
return -1.0 + (pow(((b * b) + (a * a)), 2.0) + (4.0 * (b * b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + ((((b * b) + (a * a)) ** 2.0d0) + (4.0d0 * (b * b)))
end function
public static double code(double a, double b) {
return -1.0 + (Math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (b * b)));
}
def code(a, b): return -1.0 + (math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (b * b)))
function code(a, b) return Float64(-1.0 + Float64((Float64(Float64(b * b) + Float64(a * a)) ^ 2.0) + Float64(4.0 * Float64(b * b)))) end
function tmp = code(a, b) tmp = -1.0 + ((((b * b) + (a * a)) ^ 2.0) + (4.0 * (b * b))); end
code[a_, b_] := N[(-1.0 + N[(N[Power[N[(N[(b * b), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left({\left(b \cdot b + a \cdot a\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= b 2.1e+153) (+ -1.0 (pow a 4.0)) (* (+ 1.0 (* b 2.0)) (+ -1.0 (* b 2.0)))))
double code(double a, double b) {
double tmp;
if (b <= 2.1e+153) {
tmp = -1.0 + pow(a, 4.0);
} else {
tmp = (1.0 + (b * 2.0)) * (-1.0 + (b * 2.0));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.1d+153) then
tmp = (-1.0d0) + (a ** 4.0d0)
else
tmp = (1.0d0 + (b * 2.0d0)) * ((-1.0d0) + (b * 2.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.1e+153) {
tmp = -1.0 + Math.pow(a, 4.0);
} else {
tmp = (1.0 + (b * 2.0)) * (-1.0 + (b * 2.0));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.1e+153: tmp = -1.0 + math.pow(a, 4.0) else: tmp = (1.0 + (b * 2.0)) * (-1.0 + (b * 2.0)) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.1e+153) tmp = Float64(-1.0 + (a ^ 4.0)); else tmp = Float64(Float64(1.0 + Float64(b * 2.0)) * Float64(-1.0 + Float64(b * 2.0))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.1e+153) tmp = -1.0 + (a ^ 4.0); else tmp = (1.0 + (b * 2.0)) * (-1.0 + (b * 2.0)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.1e+153], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] * N[(-1.0 + N[(b * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.1 \cdot 10^{+153}:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + b \cdot 2\right) \cdot \left(-1 + b \cdot 2\right)\\
\end{array}
\end{array}
if b < 2.10000000000000017e153Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 99.4%
Taylor expanded in a around inf 71.1%
if 2.10000000000000017e153 < b Initial program 100.0%
associate--l+100.0%
unpow2100.0%
unpow1100.0%
sqr-pow100.0%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 100.0%
add-sqr-sqrt100.0%
difference-of-sqr-1100.0%
*-commutative100.0%
sqrt-prod100.0%
unpow2100.0%
sqrt-prod100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
*-commutative100.0%
sqrt-prod100.0%
unpow2100.0%
sqrt-prod100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification74.9%
(FPCore (a b) :precision binary64 (if (<= a 1.75e+68) (+ -1.0 (pow b 4.0)) (+ -1.0 (pow a 4.0))))
double code(double a, double b) {
double tmp;
if (a <= 1.75e+68) {
tmp = -1.0 + pow(b, 4.0);
} else {
tmp = -1.0 + pow(a, 4.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= 1.75d+68) then
tmp = (-1.0d0) + (b ** 4.0d0)
else
tmp = (-1.0d0) + (a ** 4.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 1.75e+68) {
tmp = -1.0 + Math.pow(b, 4.0);
} else {
tmp = -1.0 + Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.75e+68: tmp = -1.0 + math.pow(b, 4.0) else: tmp = -1.0 + math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 1.75e+68) tmp = Float64(-1.0 + (b ^ 4.0)); else tmp = Float64(-1.0 + (a ^ 4.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.75e+68) tmp = -1.0 + (b ^ 4.0); else tmp = -1.0 + (a ^ 4.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.75e+68], N[(-1.0 + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.75 \cdot 10^{+68}:\\
\;\;\;\;-1 + {b}^{4}\\
\mathbf{else}:\\
\;\;\;\;-1 + {a}^{4}\\
\end{array}
\end{array}
if a < 1.74999999999999989e68Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 84.5%
Taylor expanded in b around 0 83.9%
if 1.74999999999999989e68 < a Initial program 100.0%
associate--l+100.0%
unpow2100.0%
unpow1100.0%
sqr-pow100.0%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around inf 100.0%
Final simplification87.5%
(FPCore (a b) :precision binary64 (* (+ 1.0 (* b 2.0)) (+ -1.0 (* b 2.0))))
double code(double a, double b) {
return (1.0 + (b * 2.0)) * (-1.0 + (b * 2.0));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (1.0d0 + (b * 2.0d0)) * ((-1.0d0) + (b * 2.0d0))
end function
public static double code(double a, double b) {
return (1.0 + (b * 2.0)) * (-1.0 + (b * 2.0));
}
def code(a, b): return (1.0 + (b * 2.0)) * (-1.0 + (b * 2.0))
function code(a, b) return Float64(Float64(1.0 + Float64(b * 2.0)) * Float64(-1.0 + Float64(b * 2.0))) end
function tmp = code(a, b) tmp = (1.0 + (b * 2.0)) * (-1.0 + (b * 2.0)); end
code[a_, b_] := N[(N[(1.0 + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] * N[(-1.0 + N[(b * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + b \cdot 2\right) \cdot \left(-1 + b \cdot 2\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in a around 0 73.9%
Taylor expanded in b around 0 56.0%
add-sqr-sqrt56.0%
difference-of-sqr-156.0%
*-commutative56.0%
sqrt-prod56.0%
unpow256.0%
sqrt-prod24.6%
add-sqr-sqrt38.6%
metadata-eval38.6%
*-commutative38.6%
sqrt-prod38.6%
unpow238.6%
sqrt-prod24.6%
add-sqr-sqrt56.0%
metadata-eval56.0%
Applied egg-rr56.0%
Final simplification56.0%
(FPCore (a b) :precision binary64 -1.0)
double code(double a, double b) {
return -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = -1.0d0
end function
public static double code(double a, double b) {
return -1.0;
}
def code(a, b): return -1.0
function code(a, b) return -1.0 end
function tmp = code(a, b) tmp = -1.0; end
code[a_, b_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in a around 0 73.9%
Taylor expanded in b around 0 25.0%
Final simplification25.0%
herbie shell --seed 2023301
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))