
(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 (+ (+ (* (hypot a b) (pow (hypot a b) 3.0)) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return ((hypot(a, b) * pow(hypot(a, b), 3.0)) + (4.0 * (b * b))) + -1.0;
}
public static double code(double a, double b) {
return ((Math.hypot(a, b) * Math.pow(Math.hypot(a, b), 3.0)) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return ((math.hypot(a, b) * math.pow(math.hypot(a, b), 3.0)) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64(Float64(hypot(a, b) * (hypot(a, b) ^ 3.0)) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((hypot(a, b) * (hypot(a, b) ^ 3.0)) + (4.0 * (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[(N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision] * N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\mathsf{hypot}\left(a, b\right) \cdot {\left(\mathsf{hypot}\left(a, b\right)\right)}^{3} + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Initial program 99.9%
add-cbrt-cube91.9%
pow391.9%
pow-pow91.9%
add-sqr-sqrt91.9%
pow291.9%
hypot-define91.9%
metadata-eval91.9%
Applied egg-rr91.9%
hypot-undefine91.9%
unpow291.9%
unpow291.9%
+-commutative91.9%
unpow291.9%
unpow291.9%
hypot-define91.9%
Simplified91.9%
pow1/391.4%
pow-pow99.9%
metadata-eval99.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
add-sqr-sqrt99.9%
+-commutative99.9%
add-sqr-sqrt99.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
hypot-undefine99.9%
pow-prod-down99.9%
unpow299.9%
associate-*r*99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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 5.0) (+ (+ 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 <= 5.0) {
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 <= 5.0d0) 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 <= 5.0) {
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 <= 5.0: 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 <= 5.0) 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 <= 5.0) 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, 5.0], 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 5:\\
\;\;\;\;\left(t\_0 + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 5Initial program 99.9%
Taylor expanded in a around 0 78.7%
if 5 < a Initial program 99.9%
Taylor expanded in a around inf 96.7%
Final simplification82.6%
(FPCore (a b) :precision binary64 (if (<= a 5.0) (+ (pow b 4.0) -1.0) (+ (+ (* 4.0 (* b b)) (pow a 4.0)) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 5.0) {
tmp = pow(b, 4.0) + -1.0;
} else {
tmp = ((4.0 * (b * b)) + 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 <= 5.0d0) then
tmp = (b ** 4.0d0) + (-1.0d0)
else
tmp = ((4.0d0 * (b * b)) + (a ** 4.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 5.0) {
tmp = Math.pow(b, 4.0) + -1.0;
} else {
tmp = ((4.0 * (b * b)) + Math.pow(a, 4.0)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 5.0: tmp = math.pow(b, 4.0) + -1.0 else: tmp = ((4.0 * (b * b)) + math.pow(a, 4.0)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 5.0) tmp = Float64((b ^ 4.0) + -1.0); else tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + (a ^ 4.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 5.0) tmp = (b ^ 4.0) + -1.0; else tmp = ((4.0 * (b * b)) + (a ^ 4.0)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 5.0], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 5:\\
\;\;\;\;{b}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 5Initial program 99.9%
add-sqr-sqrt99.9%
pow299.9%
unpow299.9%
add-sqr-sqrt99.9%
hypot-define99.9%
add-sqr-sqrt99.9%
pow299.9%
hypot-define99.9%
*-commutative99.9%
sqrt-prod99.9%
sqrt-prod67.4%
add-sqr-sqrt99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in b around inf 78.3%
if 5 < a Initial program 99.9%
Taylor expanded in a around inf 96.7%
Final simplification82.4%
(FPCore (a b) :precision binary64 (if (<= b 4800000000000.0) (+ (pow a 4.0) -1.0) (+ (pow b 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (b <= 4800000000000.0) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = pow(b, 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 (b <= 4800000000000.0d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = (b ** 4.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 4800000000000.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = Math.pow(b, 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4800000000000.0: tmp = math.pow(a, 4.0) + -1.0 else: tmp = math.pow(b, 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (b <= 4800000000000.0) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64((b ^ 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 4800000000000.0) tmp = (a ^ 4.0) + -1.0; else tmp = (b ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4800000000000.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4800000000000:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + -1\\
\end{array}
\end{array}
if b < 4.8e12Initial program 99.9%
add-sqr-sqrt99.9%
pow299.9%
unpow299.9%
add-sqr-sqrt99.9%
hypot-define99.9%
add-sqr-sqrt99.9%
pow299.9%
hypot-define99.9%
*-commutative99.9%
sqrt-prod99.9%
sqrt-prod61.0%
add-sqr-sqrt99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in a around inf 82.6%
if 4.8e12 < b Initial program 99.9%
add-sqr-sqrt99.9%
pow299.9%
unpow299.9%
add-sqr-sqrt99.9%
hypot-define99.9%
add-sqr-sqrt99.9%
pow299.9%
hypot-define99.9%
*-commutative99.9%
sqrt-prod99.9%
sqrt-prod99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in b around inf 95.8%
Final simplification86.0%
(FPCore (a b) :precision binary64 (+ (pow a 4.0) -1.0))
double code(double a, double b) {
return pow(a, 4.0) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (a ** 4.0d0) + (-1.0d0)
end function
public static double code(double a, double b) {
return Math.pow(a, 4.0) + -1.0;
}
def code(a, b): return math.pow(a, 4.0) + -1.0
function code(a, b) return Float64((a ^ 4.0) + -1.0) end
function tmp = code(a, b) tmp = (a ^ 4.0) + -1.0; end
code[a_, b_] := N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
{a}^{4} + -1
\end{array}
Initial program 99.9%
add-sqr-sqrt99.9%
pow299.9%
unpow299.9%
add-sqr-sqrt99.9%
hypot-define99.9%
add-sqr-sqrt99.9%
pow299.9%
hypot-define99.9%
*-commutative99.9%
sqrt-prod99.9%
sqrt-prod71.0%
add-sqr-sqrt99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in a around inf 71.4%
Final simplification71.4%
herbie shell --seed 2024108
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))