
(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 (+ (+ (* (hypot a b) (* (hypot a b) (pow (hypot a b) 2.0))) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return ((hypot(a, b) * (hypot(a, b) * pow(hypot(a, b), 2.0))) + (4.0 * (b * b))) + -1.0;
}
public static double code(double a, double b) {
return ((Math.hypot(a, b) * (Math.hypot(a, b) * Math.pow(Math.hypot(a, b), 2.0))) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return ((math.hypot(a, b) * (math.hypot(a, b) * math.pow(math.hypot(a, b), 2.0))) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64(Float64(hypot(a, b) * Float64(hypot(a, b) * (hypot(a, b) ^ 2.0))) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((hypot(a, b) * (hypot(a, b) * (hypot(a, b) ^ 2.0))) + (4.0 * (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[(N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision] * N[(N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision] * N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $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) \cdot {\left(\mathsf{hypot}\left(a, b\right)\right)}^{2}\right) + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Initial program 99.9%
unpow299.9%
add-sqr-sqrt99.9%
associate-*l*99.9%
hypot-define99.9%
hypot-define99.9%
add-sqr-sqrt99.9%
pow299.9%
hypot-define99.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 (if (<= a 26000000000000.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 <= 26000000000000.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 <= 26000000000000.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 <= 26000000000000.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 <= 26000000000000.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 <= 26000000000000.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 <= 26000000000000.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, 26000000000000.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 26000000000000:\\
\;\;\;\;{b}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 2.6e13Initial program 99.9%
Taylor expanded in a around 0 80.4%
Taylor expanded in b around inf 62.7%
associate-*r/62.7%
metadata-eval62.7%
Simplified62.7%
Taylor expanded in b around inf 79.5%
if 2.6e13 < a Initial program 99.9%
Taylor expanded in a around inf 98.2%
Final simplification83.3%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* 4.0 (* b b))))
(if (<= a 26500000000000.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 <= 26500000000000.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 <= 26500000000000.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 <= 26500000000000.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 <= 26500000000000.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 <= 26500000000000.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 <= 26500000000000.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, 26500000000000.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 26500000000000:\\
\;\;\;\;\left(t\_0 + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 2.65e13Initial program 99.9%
Taylor expanded in a around 0 80.4%
if 2.65e13 < a Initial program 99.9%
Taylor expanded in a around inf 98.2%
Final simplification84.0%
(FPCore (a b) :precision binary64 (if (<= b 0.0132) -1.0 (* 4.0 (pow b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= 0.0132) {
tmp = -1.0;
} else {
tmp = 4.0 * pow(b, 2.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.0132d0) then
tmp = -1.0d0
else
tmp = 4.0d0 * (b ** 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 0.0132) {
tmp = -1.0;
} else {
tmp = 4.0 * Math.pow(b, 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 0.0132: tmp = -1.0 else: tmp = 4.0 * math.pow(b, 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 0.0132) tmp = -1.0; else tmp = Float64(4.0 * (b ^ 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 0.0132) tmp = -1.0; else tmp = 4.0 * (b ^ 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 0.0132], -1.0, N[(4.0 * N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.0132:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot {b}^{2}\\
\end{array}
\end{array}
if b < 0.0132Initial program 99.9%
Taylor expanded in a around inf 89.2%
Taylor expanded in a around 0 50.9%
Taylor expanded in b around 0 33.4%
if 0.0132 < b Initial program 99.9%
Taylor expanded in a around inf 66.2%
Taylor expanded in b around inf 49.0%
Final simplification37.4%
(FPCore (a b) :precision binary64 (if (<= b 6.6e+153) (+ (pow a 4.0) -1.0) (* 4.0 (pow b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= 6.6e+153) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = 4.0 * pow(b, 2.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 6.6d+153) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = 4.0d0 * (b ** 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 6.6e+153) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = 4.0 * Math.pow(b, 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6.6e+153: tmp = math.pow(a, 4.0) + -1.0 else: tmp = 4.0 * math.pow(b, 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 6.6e+153) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(4.0 * (b ^ 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 6.6e+153) tmp = (a ^ 4.0) + -1.0; else tmp = 4.0 * (b ^ 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6.6e+153], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(4.0 * N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.6 \cdot 10^{+153}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot {b}^{2}\\
\end{array}
\end{array}
if b < 6.59999999999999989e153Initial program 99.9%
Taylor expanded in a around inf 81.0%
Taylor expanded in b around 0 71.9%
if 6.59999999999999989e153 < b Initial program 100.0%
Taylor expanded in a around inf 100.0%
Taylor expanded in b around inf 100.0%
Final simplification75.2%
(FPCore (a b) :precision binary64 (if (<= b 2400000000000.0) (+ (pow a 4.0) -1.0) (+ (pow b 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (b <= 2400000000000.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 <= 2400000000000.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 <= 2400000000000.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 <= 2400000000000.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 <= 2400000000000.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 <= 2400000000000.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, 2400000000000.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 2400000000000:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + -1\\
\end{array}
\end{array}
if b < 2.4e12Initial program 99.9%
Taylor expanded in a around inf 88.6%
Taylor expanded in b around 0 78.6%
if 2.4e12 < b Initial program 99.9%
Taylor expanded in a around 0 95.4%
Taylor expanded in b around inf 95.4%
associate-*r/95.4%
metadata-eval95.4%
Simplified95.4%
Taylor expanded in b around inf 95.4%
Final simplification82.6%
(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 inf 83.3%
Taylor expanded in a around 0 50.4%
Taylor expanded in b around 0 25.0%
Final simplification25.0%
herbie shell --seed 2024056
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))