
(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 8 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(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%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (+ (pow (fma a a (* b b)) 2.0) (+ (* 4.0 (* b b)) -1.0)))
double code(double a, double b) {
return pow(fma(a, a, (b * b)), 2.0) + ((4.0 * (b * b)) + -1.0);
}
function code(a, b) return Float64((fma(a, a, Float64(b * b)) ^ 2.0) + Float64(Float64(4.0 * Float64(b * b)) + -1.0)) end
code[a_, b_] := N[(N[Power[N[(a * a + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(4 \cdot \left(b \cdot b\right) + -1\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
sqr-neg99.9%
*-commutative99.9%
Simplified99.9%
Final simplification99.9%
(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 9e+29) (+ (+ (* 4.0 (* b b)) -1.0) (pow b 4.0)) (+ (pow a 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 9e+29) {
tmp = ((4.0 * (b * b)) + -1.0) + pow(b, 4.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 <= 9d+29) then
tmp = ((4.0d0 * (b * b)) + (-1.0d0)) + (b ** 4.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 <= 9e+29) {
tmp = ((4.0 * (b * b)) + -1.0) + Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 9e+29: tmp = ((4.0 * (b * b)) + -1.0) + math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 9e+29) tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + -1.0) + (b ^ 4.0)); else tmp = Float64((a ^ 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 9e+29) tmp = ((4.0 * (b * b)) + -1.0) + (b ^ 4.0); else tmp = (a ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 9e+29], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 9 \cdot 10^{+29}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + -1\right) + {b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} + -1\\
\end{array}
\end{array}
if a < 9.0000000000000005e29Initial program 99.9%
associate--l+99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
sqr-neg99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 76.3%
if 9.0000000000000005e29 < a Initial program 99.9%
Taylor expanded in b around 0 90.9%
Final simplification79.8%
(FPCore (a b) :precision binary64 (if (<= a 1.1e+30) (+ (pow b 4.0) -1.0) (+ (pow a 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.1e+30) {
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.1d+30) 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.1e+30) {
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.1e+30: 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.1e+30) 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.1e+30) 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.1e+30], 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.1 \cdot 10^{+30}:\\
\;\;\;\;{b}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} + -1\\
\end{array}
\end{array}
if a < 1.1e30Initial program 99.9%
associate--l+99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
sqr-neg99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 76.3%
Taylor expanded in b around 0 75.1%
if 1.1e30 < a Initial program 99.9%
Taylor expanded in b around 0 90.9%
Final simplification78.9%
(FPCore (a b) :precision binary64 (if (<= b 0.49) -1.0 (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 0.49) {
tmp = -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 <= 0.49d0) then
tmp = -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 <= 0.49) {
tmp = -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 0.49: tmp = -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 0.49) tmp = -1.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 0.49) tmp = -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 0.49], -1.0, N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.49:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 0.48999999999999999Initial program 99.9%
associate--l+99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
sqr-neg99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 57.8%
Taylor expanded in b around 0 28.6%
if 0.48999999999999999 < b Initial program 99.9%
associate--l+99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
sqr-neg99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 90.2%
Taylor expanded in b around inf 89.3%
Final simplification47.1%
(FPCore (a b) :precision binary64 (+ -1.0 (pow b 4.0)))
double code(double a, double b) {
return -1.0 + pow(b, 4.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + (b ** 4.0d0)
end function
public static double code(double a, double b) {
return -1.0 + Math.pow(b, 4.0);
}
def code(a, b): return -1.0 + math.pow(b, 4.0)
function code(a, b) return Float64(-1.0 + (b ^ 4.0)) end
function tmp = code(a, b) tmp = -1.0 + (b ^ 4.0); end
code[a_, b_] := N[(-1.0 + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + {b}^{4}
\end{array}
Initial program 99.9%
associate--l+99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
sqr-neg99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 67.7%
Taylor expanded in b around 0 66.8%
Final simplification66.8%
(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%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
sqr-neg99.9%
sqr-neg99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 67.7%
Taylor expanded in b around 0 20.1%
Final simplification20.1%
herbie shell --seed 2023332
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))