
(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 (+ (fma (* b 4.0) b (pow (hypot a b) 4.0)) -1.0))
double code(double a, double b) {
return fma((b * 4.0), b, pow(hypot(a, b), 4.0)) + -1.0;
}
function code(a, b) return Float64(fma(Float64(b * 4.0), b, (hypot(a, b) ^ 4.0)) + -1.0) end
code[a_, b_] := N[(N[(N[(b * 4.0), $MachinePrecision] * b + N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b \cdot 4, b, {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4}\right) + -1
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-*r*99.9%
*-commutative99.9%
fma-def99.9%
metadata-eval99.9%
sqrt-pow2100.0%
hypot-udef100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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(b, Float64(b * 4.0), -1.0)) end
code[a_, b_] := N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b, b \cdot 4, -1\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= b 24.0) (+ (pow a 4.0) -1.0) (if (or (<= b 3.35e+38) (not (<= b 1.8e+72))) (pow b 4.0) (pow a 4.0))))
double code(double a, double b) {
double tmp;
if (b <= 24.0) {
tmp = pow(a, 4.0) + -1.0;
} else if ((b <= 3.35e+38) || !(b <= 1.8e+72)) {
tmp = pow(b, 4.0);
} else {
tmp = 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 (b <= 24.0d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else if ((b <= 3.35d+38) .or. (.not. (b <= 1.8d+72))) then
tmp = b ** 4.0d0
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 24.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else if ((b <= 3.35e+38) || !(b <= 1.8e+72)) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 24.0: tmp = math.pow(a, 4.0) + -1.0 elif (b <= 3.35e+38) or not (b <= 1.8e+72): tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 24.0) tmp = Float64((a ^ 4.0) + -1.0); elseif ((b <= 3.35e+38) || !(b <= 1.8e+72)) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 24.0) tmp = (a ^ 4.0) + -1.0; elseif ((b <= 3.35e+38) || ~((b <= 1.8e+72))) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 24.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], If[Or[LessEqual[b, 3.35e+38], N[Not[LessEqual[b, 1.8e+72]], $MachinePrecision]], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 24:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{elif}\;b \leq 3.35 \cdot 10^{+38} \lor \neg \left(b \leq 1.8 \cdot 10^{+72}\right):\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if b < 24Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around 0 79.9%
if 24 < b < 3.35000000000000012e38 or 1.80000000000000017e72 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around inf 99.4%
if 3.35000000000000012e38 < b < 1.80000000000000017e72Initial program 99.5%
associate--l+99.5%
sqr-pow99.5%
Simplified100.0%
Taylor expanded in a around inf 68.7%
Final simplification82.6%
(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}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= a 880.0) (pow b 4.0) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 880.0) {
tmp = pow(b, 4.0);
} else {
tmp = 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 <= 880.0d0) then
tmp = b ** 4.0d0
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 880.0) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 880.0: tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 880.0) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 880.0) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 880.0], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 880:\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 880Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around inf 40.7%
if 880 < a Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around inf 93.2%
Final simplification52.2%
(FPCore (a b) :precision binary64 (pow a 4.0))
double code(double a, double b) {
return pow(a, 4.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = a ** 4.0d0
end function
public static double code(double a, double b) {
return Math.pow(a, 4.0);
}
def code(a, b): return math.pow(a, 4.0)
function code(a, b) return a ^ 4.0 end
function tmp = code(a, b) tmp = a ^ 4.0; end
code[a_, b_] := N[Power[a, 4.0], $MachinePrecision]
\begin{array}{l}
\\
{a}^{4}
\end{array}
Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around inf 47.1%
Final simplification47.1%
herbie shell --seed 2024013
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))