
(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 (+ (* a a) (* b b)) 2.0) (* (* b b) 4.0)) -1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + ((b * b) * 4.0)) + -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) + ((b * b) * 4.0d0)) + (-1.0d0)
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + ((b * b) * 4.0)) + -1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + ((b * b) * 4.0)) + -1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(Float64(b * b) * 4.0)) + -1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + ((b * b) * 4.0)) + -1.0; end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + \left(b \cdot b\right) \cdot 4\right) + -1
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b)
:precision binary64
(if (<= a 1.4e-266)
(pow b 4.0)
(if (<= a 3.8e-204)
-1.0
(if (<= a 5.2e-161)
(pow b 4.0)
(if (<= a 9.8e-85) -1.0 (if (<= a 16000.0) (pow b 4.0) (pow a 4.0)))))))
double code(double a, double b) {
double tmp;
if (a <= 1.4e-266) {
tmp = pow(b, 4.0);
} else if (a <= 3.8e-204) {
tmp = -1.0;
} else if (a <= 5.2e-161) {
tmp = pow(b, 4.0);
} else if (a <= 9.8e-85) {
tmp = -1.0;
} else if (a <= 16000.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 <= 1.4d-266) then
tmp = b ** 4.0d0
else if (a <= 3.8d-204) then
tmp = -1.0d0
else if (a <= 5.2d-161) then
tmp = b ** 4.0d0
else if (a <= 9.8d-85) then
tmp = -1.0d0
else if (a <= 16000.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 <= 1.4e-266) {
tmp = Math.pow(b, 4.0);
} else if (a <= 3.8e-204) {
tmp = -1.0;
} else if (a <= 5.2e-161) {
tmp = Math.pow(b, 4.0);
} else if (a <= 9.8e-85) {
tmp = -1.0;
} else if (a <= 16000.0) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.4e-266: tmp = math.pow(b, 4.0) elif a <= 3.8e-204: tmp = -1.0 elif a <= 5.2e-161: tmp = math.pow(b, 4.0) elif a <= 9.8e-85: tmp = -1.0 elif a <= 16000.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 <= 1.4e-266) tmp = b ^ 4.0; elseif (a <= 3.8e-204) tmp = -1.0; elseif (a <= 5.2e-161) tmp = b ^ 4.0; elseif (a <= 9.8e-85) tmp = -1.0; elseif (a <= 16000.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 <= 1.4e-266) tmp = b ^ 4.0; elseif (a <= 3.8e-204) tmp = -1.0; elseif (a <= 5.2e-161) tmp = b ^ 4.0; elseif (a <= 9.8e-85) tmp = -1.0; elseif (a <= 16000.0) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.4e-266], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 3.8e-204], -1.0, If[LessEqual[a, 5.2e-161], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 9.8e-85], -1.0, If[LessEqual[a, 16000.0], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.4 \cdot 10^{-266}:\\
\;\;\;\;{b}^{4}\\
\mathbf{elif}\;a \leq 3.8 \cdot 10^{-204}:\\
\;\;\;\;-1\\
\mathbf{elif}\;a \leq 5.2 \cdot 10^{-161}:\\
\;\;\;\;{b}^{4}\\
\mathbf{elif}\;a \leq 9.8 \cdot 10^{-85}:\\
\;\;\;\;-1\\
\mathbf{elif}\;a \leq 16000:\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 1.4e-266 or 3.79999999999999983e-204 < a < 5.19999999999999991e-161 or 9.80000000000000029e-85 < a < 16000Initial program 99.9%
expm1-log1p-u99.1%
add-exp-log99.1%
expm1-define99.1%
log1p-expm1-u99.1%
add-sqr-sqrt99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in b around inf 45.1%
if 1.4e-266 < a < 3.79999999999999983e-204 or 5.19999999999999991e-161 < a < 9.80000000000000029e-85Initial program 100.0%
Taylor expanded in b around 0 56.8%
Taylor expanded in a around 0 56.8%
if 16000 < a Initial program 99.8%
expm1-log1p-u98.7%
add-exp-log98.7%
expm1-define98.7%
log1p-expm1-u98.7%
add-sqr-sqrt98.7%
pow298.7%
Applied egg-rr98.7%
Taylor expanded in a around inf 92.5%
Final simplification58.0%
(FPCore (a b) :precision binary64 (if (<= b 8000.0) (+ (pow a 4.0) -1.0) (if (or (<= b 2.05e+34) (not (<= b 4.1e+64))) (pow b 4.0) (pow a 4.0))))
double code(double a, double b) {
double tmp;
if (b <= 8000.0) {
tmp = pow(a, 4.0) + -1.0;
} else if ((b <= 2.05e+34) || !(b <= 4.1e+64)) {
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 <= 8000.0d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else if ((b <= 2.05d+34) .or. (.not. (b <= 4.1d+64))) 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 <= 8000.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else if ((b <= 2.05e+34) || !(b <= 4.1e+64)) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 8000.0: tmp = math.pow(a, 4.0) + -1.0 elif (b <= 2.05e+34) or not (b <= 4.1e+64): tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 8000.0) tmp = Float64((a ^ 4.0) + -1.0); elseif ((b <= 2.05e+34) || !(b <= 4.1e+64)) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 8000.0) tmp = (a ^ 4.0) + -1.0; elseif ((b <= 2.05e+34) || ~((b <= 4.1e+64))) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 8000.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], If[Or[LessEqual[b, 2.05e+34], N[Not[LessEqual[b, 4.1e+64]], $MachinePrecision]], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8000:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{elif}\;b \leq 2.05 \cdot 10^{+34} \lor \neg \left(b \leq 4.1 \cdot 10^{+64}\right):\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if b < 8e3Initial program 99.9%
Taylor expanded in b around 0 81.1%
if 8e3 < b < 2.0499999999999999e34 or 4.09999999999999978e64 < b Initial program 100.0%
expm1-log1p-u99.2%
add-exp-log99.2%
expm1-define99.2%
log1p-expm1-u99.2%
add-sqr-sqrt99.2%
pow299.2%
Applied egg-rr99.2%
Taylor expanded in b around inf 99.3%
if 2.0499999999999999e34 < b < 4.09999999999999978e64Initial program 100.0%
expm1-log1p-u98.5%
add-exp-log98.5%
expm1-define98.5%
log1p-expm1-u98.5%
add-sqr-sqrt98.5%
pow298.5%
Applied egg-rr98.5%
Taylor expanded in a around inf 75.6%
Final simplification84.7%
(FPCore (a b) :precision binary64 (if (<= a 230000.0) (+ (+ (* (* b b) 4.0) (pow b 4.0)) -1.0) (+ (pow a 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 230000.0) {
tmp = (((b * b) * 4.0) + 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 <= 230000.0d0) then
tmp = (((b * b) * 4.0d0) + (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 <= 230000.0) {
tmp = (((b * b) * 4.0) + 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 <= 230000.0: tmp = (((b * b) * 4.0) + 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 <= 230000.0) tmp = Float64(Float64(Float64(Float64(b * b) * 4.0) + (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 <= 230000.0) tmp = (((b * b) * 4.0) + (b ^ 4.0)) + -1.0; else tmp = (a ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 230000.0], N[(N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 230000:\\
\;\;\;\;\left(\left(b \cdot b\right) \cdot 4 + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} + -1\\
\end{array}
\end{array}
if a < 2.3e5Initial program 99.9%
Taylor expanded in a around 0 76.6%
if 2.3e5 < a Initial program 99.8%
Taylor expanded in b around 0 92.5%
Final simplification80.6%
(FPCore (a b) :precision binary64 (if (<= a 1.0) -1.0 (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.0) {
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 <= 1.0d0) 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 <= 1.0) {
tmp = -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.0: tmp = -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 1.0) tmp = -1.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.0) tmp = -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.0], -1.0, N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 1Initial program 99.9%
Taylor expanded in b around 0 65.7%
Taylor expanded in a around 0 33.0%
if 1 < a Initial program 99.8%
expm1-log1p-u98.7%
add-exp-log98.7%
expm1-define98.7%
log1p-expm1-u98.7%
add-sqr-sqrt98.7%
pow298.7%
Applied egg-rr98.7%
Taylor expanded in a around inf 91.1%
Final simplification47.7%
(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%
Taylor expanded in b around 0 72.2%
Taylor expanded in a around 0 24.8%
Final simplification24.8%
herbie shell --seed 2024083
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))