
(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 7 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.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.9%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (+ (+ (pow (+ (* b b) (* a a)) 2.0) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return (pow(((b * b) + (a * a)), 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 = ((((b * b) + (a * a)) ** 2.0d0) + (4.0d0 * (b * b))) + (-1.0d0)
end function
public static double code(double a, double b) {
return (Math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return (math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64((Float64(Float64(b * b) + Float64(a * a)) ^ 2.0) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((((b * b) + (a * a)) ^ 2.0) + (4.0 * (b * b))) + -1.0; end
code[a_, b_] := N[(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] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(b \cdot b + a \cdot a\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 2150000.0) (+ (pow b 4.0) -1.0) (+ (pow a 4.0) (* 2.0 (* a (* b (* a b)))))))
double code(double a, double b) {
double tmp;
if (a <= 2150000.0) {
tmp = pow(b, 4.0) + -1.0;
} else {
tmp = pow(a, 4.0) + (2.0 * (a * (b * (a * b))));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= 2150000.0d0) then
tmp = (b ** 4.0d0) + (-1.0d0)
else
tmp = (a ** 4.0d0) + (2.0d0 * (a * (b * (a * b))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 2150000.0) {
tmp = Math.pow(b, 4.0) + -1.0;
} else {
tmp = Math.pow(a, 4.0) + (2.0 * (a * (b * (a * b))));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 2150000.0: tmp = math.pow(b, 4.0) + -1.0 else: tmp = math.pow(a, 4.0) + (2.0 * (a * (b * (a * b)))) return tmp
function code(a, b) tmp = 0.0 if (a <= 2150000.0) tmp = Float64((b ^ 4.0) + -1.0); else tmp = Float64((a ^ 4.0) + Float64(2.0 * Float64(a * Float64(b * Float64(a * b))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 2150000.0) tmp = (b ^ 4.0) + -1.0; else tmp = (a ^ 4.0) + (2.0 * (a * (b * (a * b)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 2150000.0], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] + N[(2.0 * N[(a * N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2150000:\\
\;\;\;\;{b}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} + 2 \cdot \left(a \cdot \left(b \cdot \left(a \cdot b\right)\right)\right)\\
\end{array}
\end{array}
if a < 2.15e6Initial program 99.9%
add-exp-log98.6%
+-commutative98.6%
fma-def98.6%
pow298.6%
metadata-eval98.6%
sqrt-pow298.6%
hypot-udef98.6%
Applied egg-rr98.6%
Taylor expanded in b around inf 82.2%
if 2.15e6 < a Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.8%
Simplified100.0%
Taylor expanded in a around inf 94.4%
fma-def94.4%
unpow294.4%
unpow294.4%
swap-sqr98.7%
unpow298.7%
*-commutative98.7%
Simplified98.7%
fma-udef98.7%
+-commutative98.7%
Applied egg-rr98.7%
unpow298.7%
associate-*r*98.7%
Applied egg-rr98.7%
Final simplification86.7%
(FPCore (a b) :precision binary64 (if (<= b 710000000.0) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 710000000.0) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = pow(b, 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 <= 710000000.0d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = b ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 710000000.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 710000000.0: tmp = math.pow(a, 4.0) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 710000000.0) tmp = Float64((a ^ 4.0) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 710000000.0) tmp = (a ^ 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 710000000.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 710000000:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 7.1e8Initial program 99.9%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 73.6%
if 7.1e8 < b Initial 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 inf 88.3%
Final simplification76.8%
(FPCore (a b) :precision binary64 (if (<= a 1.55e-18) (+ (pow b 4.0) -1.0) (+ (pow a 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.55e-18) {
tmp = pow(b, 4.0) + -1.0;
} else {
tmp = pow(a, 4.0) + -1.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.55d-18) then
tmp = (b ** 4.0d0) + (-1.0d0)
else
tmp = (a ** 4.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 1.55e-18) {
tmp = Math.pow(b, 4.0) + -1.0;
} else {
tmp = Math.pow(a, 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.55e-18: tmp = math.pow(b, 4.0) + -1.0 else: tmp = math.pow(a, 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 1.55e-18) tmp = Float64((b ^ 4.0) + -1.0); else tmp = Float64((a ^ 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.55e-18) tmp = (b ^ 4.0) + -1.0; else tmp = (a ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.55e-18], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.55 \cdot 10^{-18}:\\
\;\;\;\;{b}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} + -1\\
\end{array}
\end{array}
if a < 1.55000000000000003e-18Initial program 99.9%
add-exp-log98.6%
+-commutative98.6%
fma-def98.6%
pow298.6%
metadata-eval98.6%
sqrt-pow298.6%
hypot-udef98.6%
Applied egg-rr98.6%
Taylor expanded in b around inf 82.1%
if 1.55000000000000003e-18 < a Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.8%
Simplified100.0%
Taylor expanded in b around 0 88.9%
Final simplification84.0%
(FPCore (a b) :precision binary64 (if (<= a 550000.0) (pow b 4.0) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 550000.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 <= 550000.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 <= 550000.0) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 550000.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 <= 550000.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 <= 550000.0) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 550000.0], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 550000:\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 5.5e5Initial 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 inf 50.8%
if 5.5e5 < a Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.8%
Simplified100.0%
Taylor expanded in a around inf 88.8%
Final simplification61.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.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around inf 44.8%
Final simplification44.8%
herbie shell --seed 2023300
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))