
(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(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}
(FPCore (a b) :precision binary64 (+ -1.0 (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b)))))
double code(double a, double b) {
return -1.0 + (pow(((a * a) + (b * b)), 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) + ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (b * b)))
end function
public static double code(double a, double b) {
return -1.0 + (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)));
}
def code(a, b): return -1.0 + (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)))
function code(a, b) return Float64(-1.0 + Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b)))) end
function tmp = code(a, b) tmp = -1.0 + ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))); end
code[a_, b_] := N[(-1.0 + 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]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right)
\end{array}
(FPCore (a b)
:precision binary64
(if (<= b 1.6e-275)
-1.0
(if (<= b 5.5e-127)
(pow a 4.0)
(if (<= b 6e-119)
-1.0
(if (<= b 8.2e-79)
(pow a 4.0)
(if (<= b 2.2e-49)
-1.0
(if (<= b 2500000.0) (pow a 4.0) (pow b 4.0))))))))
double code(double a, double b) {
double tmp;
if (b <= 1.6e-275) {
tmp = -1.0;
} else if (b <= 5.5e-127) {
tmp = pow(a, 4.0);
} else if (b <= 6e-119) {
tmp = -1.0;
} else if (b <= 8.2e-79) {
tmp = pow(a, 4.0);
} else if (b <= 2.2e-49) {
tmp = -1.0;
} else if (b <= 2500000.0) {
tmp = pow(a, 4.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 <= 1.6d-275) then
tmp = -1.0d0
else if (b <= 5.5d-127) then
tmp = a ** 4.0d0
else if (b <= 6d-119) then
tmp = -1.0d0
else if (b <= 8.2d-79) then
tmp = a ** 4.0d0
else if (b <= 2.2d-49) then
tmp = -1.0d0
else if (b <= 2500000.0d0) then
tmp = a ** 4.0d0
else
tmp = b ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.6e-275) {
tmp = -1.0;
} else if (b <= 5.5e-127) {
tmp = Math.pow(a, 4.0);
} else if (b <= 6e-119) {
tmp = -1.0;
} else if (b <= 8.2e-79) {
tmp = Math.pow(a, 4.0);
} else if (b <= 2.2e-49) {
tmp = -1.0;
} else if (b <= 2500000.0) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.6e-275: tmp = -1.0 elif b <= 5.5e-127: tmp = math.pow(a, 4.0) elif b <= 6e-119: tmp = -1.0 elif b <= 8.2e-79: tmp = math.pow(a, 4.0) elif b <= 2.2e-49: tmp = -1.0 elif b <= 2500000.0: tmp = math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.6e-275) tmp = -1.0; elseif (b <= 5.5e-127) tmp = a ^ 4.0; elseif (b <= 6e-119) tmp = -1.0; elseif (b <= 8.2e-79) tmp = a ^ 4.0; elseif (b <= 2.2e-49) tmp = -1.0; elseif (b <= 2500000.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.6e-275) tmp = -1.0; elseif (b <= 5.5e-127) tmp = a ^ 4.0; elseif (b <= 6e-119) tmp = -1.0; elseif (b <= 8.2e-79) tmp = a ^ 4.0; elseif (b <= 2.2e-49) tmp = -1.0; elseif (b <= 2500000.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.6e-275], -1.0, If[LessEqual[b, 5.5e-127], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 6e-119], -1.0, If[LessEqual[b, 8.2e-79], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 2.2e-49], -1.0, If[LessEqual[b, 2500000.0], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.6 \cdot 10^{-275}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{-127}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-119}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 8.2 \cdot 10^{-79}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-49}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 2500000:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
(FPCore (a b) :precision binary64 (if (<= b 1.1) (- (pow a 4.0) 1.0) (+ (* 2.0 (* a (* b (* a b)))) (pow b 4.0))))
double code(double a, double b) {
double tmp;
if (b <= 1.1) {
tmp = pow(a, 4.0) - 1.0;
} else {
tmp = (2.0 * (a * (b * (a * b)))) + 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 <= 1.1d0) then
tmp = (a ** 4.0d0) - 1.0d0
else
tmp = (2.0d0 * (a * (b * (a * b)))) + (b ** 4.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 1.1) {
tmp = Math.pow(a, 4.0) - 1.0;
} else {
tmp = (2.0 * (a * (b * (a * b)))) + Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.1: tmp = math.pow(a, 4.0) - 1.0 else: tmp = (2.0 * (a * (b * (a * b)))) + math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.1) tmp = Float64((a ^ 4.0) - 1.0); else tmp = Float64(Float64(2.0 * Float64(a * Float64(b * Float64(a * b)))) + (b ^ 4.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.1) tmp = (a ^ 4.0) - 1.0; else tmp = (2.0 * (a * (b * (a * b)))) + (b ^ 4.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.1], N[(N[Power[a, 4.0], $MachinePrecision] - 1.0), $MachinePrecision], N[(N[(2.0 * N[(a * N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.1:\\
\;\;\;\;{a}^{4} - 1\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(a \cdot \left(b \cdot \left(a \cdot b\right)\right)\right) + {b}^{4}\\
\end{array}
\end{array}
(FPCore (a b) :precision binary64 (if (<= b 760000.0) (- (pow a 4.0) 1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 760000.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 <= 760000.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 <= 760000.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 <= 760000.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 <= 760000.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 <= 760000.0) tmp = (a ^ 4.0) - 1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 760000.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 760000:\\
\;\;\;\;{a}^{4} - 1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
(FPCore (a b) :precision binary64 (if (<= a 0.44) -1.0 (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 0.44) {
tmp = -1.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 <= 0.44d0) then
tmp = -1.0d0
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 0.44) {
tmp = -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 0.44: tmp = -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 0.44) tmp = -1.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 0.44) tmp = -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 0.44], -1.0, N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 0.44:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
(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}
herbie shell --seed 2023342
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))