
(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) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return (pow(hypot(a, b), 4.0) + (4.0 * (b * b))) + -1.0;
}
public static double code(double a, double b) {
return (Math.pow(Math.hypot(a, b), 4.0) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return (math.pow(math.hypot(a, b), 4.0) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64((hypot(a, b) ^ 4.0) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((hypot(a, b) ^ 4.0) + (4.0 * (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Initial program 99.9%
add-log-exp87.8%
*-un-lft-identity87.8%
log-prod87.8%
metadata-eval87.8%
add-log-exp99.9%
add-sqr-sqrt99.9%
pow299.9%
hypot-define99.9%
Applied egg-rr99.9%
+-lft-identity99.9%
unpow299.9%
pow-sqr100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (* b b) 5e+62) (+ (+ (* 4.0 (* b b)) (pow a 4.0)) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 5e+62) {
tmp = ((4.0 * (b * b)) + 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 * b) <= 5d+62) then
tmp = ((4.0d0 * (b * b)) + (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 * b) <= 5e+62) {
tmp = ((4.0 * (b * b)) + Math.pow(a, 4.0)) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 5e+62: tmp = ((4.0 * (b * b)) + math.pow(a, 4.0)) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 5e+62) tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + (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 * b) <= 5e+62) tmp = ((4.0 * (b * b)) + (a ^ 4.0)) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 5e+62], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 5 \cdot 10^{+62}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + {a}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 5.00000000000000029e62Initial program 99.9%
Taylor expanded in a around inf 96.4%
if 5.00000000000000029e62 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 95.1%
Taylor expanded in b around inf 95.1%
Final simplification95.8%
(FPCore (a b) :precision binary64 (+ (+ (* 4.0 (* b b)) (pow (+ (* b b) (* a a)) 2.0)) -1.0))
double code(double a, double b) {
return ((4.0 * (b * b)) + pow(((b * b) + (a * a)), 2.0)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((4.0d0 * (b * b)) + (((b * b) + (a * a)) ** 2.0d0)) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((4.0 * (b * b)) + Math.pow(((b * b) + (a * a)), 2.0)) + -1.0;
}
def code(a, b): return ((4.0 * (b * b)) + math.pow(((b * b) + (a * a)), 2.0)) + -1.0
function code(a, b) return Float64(Float64(Float64(4.0 * Float64(b * b)) + (Float64(Float64(b * b) + Float64(a * a)) ^ 2.0)) + -1.0) end
function tmp = code(a, b) tmp = ((4.0 * (b * b)) + (((b * b) + (a * a)) ^ 2.0)) + -1.0; end
code[a_, b_] := N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(b * b), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(4 \cdot \left(b \cdot b\right) + {\left(b \cdot b + a \cdot a\right)}^{2}\right) + -1
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* 4.0 (* b b))))
(if (<= a 4.1e+16)
(+ (+ t_0 (pow b 4.0)) -1.0)
(+ (+ t_0 (pow a 4.0)) -1.0))))
double code(double a, double b) {
double t_0 = 4.0 * (b * b);
double tmp;
if (a <= 4.1e+16) {
tmp = (t_0 + pow(b, 4.0)) + -1.0;
} else {
tmp = (t_0 + 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) :: t_0
real(8) :: tmp
t_0 = 4.0d0 * (b * b)
if (a <= 4.1d+16) then
tmp = (t_0 + (b ** 4.0d0)) + (-1.0d0)
else
tmp = (t_0 + (a ** 4.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 4.0 * (b * b);
double tmp;
if (a <= 4.1e+16) {
tmp = (t_0 + Math.pow(b, 4.0)) + -1.0;
} else {
tmp = (t_0 + Math.pow(a, 4.0)) + -1.0;
}
return tmp;
}
def code(a, b): t_0 = 4.0 * (b * b) tmp = 0 if a <= 4.1e+16: tmp = (t_0 + math.pow(b, 4.0)) + -1.0 else: tmp = (t_0 + math.pow(a, 4.0)) + -1.0 return tmp
function code(a, b) t_0 = Float64(4.0 * Float64(b * b)) tmp = 0.0 if (a <= 4.1e+16) tmp = Float64(Float64(t_0 + (b ^ 4.0)) + -1.0); else tmp = Float64(Float64(t_0 + (a ^ 4.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) t_0 = 4.0 * (b * b); tmp = 0.0; if (a <= 4.1e+16) tmp = (t_0 + (b ^ 4.0)) + -1.0; else tmp = (t_0 + (a ^ 4.0)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, 4.1e+16], N[(N[(t$95$0 + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(t$95$0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \left(b \cdot b\right)\\
\mathbf{if}\;a \leq 4.1 \cdot 10^{+16}:\\
\;\;\;\;\left(t\_0 + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 4.1e16Initial program 99.9%
Taylor expanded in a around 0 84.9%
if 4.1e16 < a Initial program 99.9%
Taylor expanded in a around inf 97.5%
Final simplification88.9%
(FPCore (a b) :precision binary64 (if (<= a 4.6e+20) (+ (* 4.0 (* b b)) -1.0) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 4.6e+20) {
tmp = (4.0 * (b * b)) + -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 <= 4.6d+20) then
tmp = (4.0d0 * (b * b)) + (-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 <= 4.6e+20) {
tmp = (4.0 * (b * b)) + -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 4.6e+20: tmp = (4.0 * (b * b)) + -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 4.6e+20) tmp = Float64(Float64(4.0 * Float64(b * b)) + -1.0); else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 4.6e+20) tmp = (4.0 * (b * b)) + -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 4.6e+20], N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.6 \cdot 10^{+20}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 4.6e20Initial program 99.9%
Taylor expanded in a around inf 83.6%
Taylor expanded in a around 0 64.5%
pow264.5%
Applied egg-rr64.5%
if 4.6e20 < a Initial program 99.9%
Taylor expanded in a around inf 97.4%
Taylor expanded in a around inf 92.6%
Final simplification73.1%
(FPCore (a b) :precision binary64 (+ (* 4.0 (* b b)) -1.0))
double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (4.0d0 * (b * b)) + (-1.0d0)
end function
public static double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
def code(a, b): return (4.0 * (b * b)) + -1.0
function code(a, b) return Float64(Float64(4.0 * Float64(b * b)) + -1.0) end
function tmp = code(a, b) tmp = (4.0 * (b * b)) + -1.0; end
code[a_, b_] := N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(b \cdot b\right) + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around inf 87.8%
Taylor expanded in a around 0 52.1%
pow252.1%
Applied egg-rr52.1%
Final simplification52.1%
(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 a around 0 70.3%
Taylor expanded in b around 0 22.9%
herbie shell --seed 2024136
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))