
(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 b a) 4.0) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return (pow(hypot(b, a), 4.0) + (4.0 * (b * b))) + -1.0;
}
public static double code(double a, double b) {
return (Math.pow(Math.hypot(b, a), 4.0) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return (math.pow(math.hypot(b, a), 4.0) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64((hypot(b, a) ^ 4.0) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((hypot(b, a) ^ 4.0) + (4.0 * (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[Power[N[Sqrt[b ^ 2 + a ^ 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(b, a\right)\right)}^{4} + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Initial program 99.9%
unpow299.9%
distribute-lft-in86.2%
add-sqr-sqrt86.2%
pow286.2%
hypot-define86.2%
pow286.2%
add-sqr-sqrt86.2%
pow286.2%
hypot-define86.2%
pow286.2%
Applied egg-rr86.2%
distribute-lft-out99.9%
rem-square-sqrt99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
pow-sqr100.0%
metadata-eval100.0%
hypot-undefine100.0%
unpow2100.0%
unpow2100.0%
+-commutative100.0%
unpow2100.0%
unpow2100.0%
hypot-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= b 1.5e+14) (+ (pow a 4.0) -1.0) (if (or (<= b 1.5e+45) (not (<= b 8.8e+55))) (pow b 4.0) (pow a 4.0))))
double code(double a, double b) {
double tmp;
if (b <= 1.5e+14) {
tmp = pow(a, 4.0) + -1.0;
} else if ((b <= 1.5e+45) || !(b <= 8.8e+55)) {
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 <= 1.5d+14) then
tmp = (a ** 4.0d0) + (-1.0d0)
else if ((b <= 1.5d+45) .or. (.not. (b <= 8.8d+55))) 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 <= 1.5e+14) {
tmp = Math.pow(a, 4.0) + -1.0;
} else if ((b <= 1.5e+45) || !(b <= 8.8e+55)) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.5e+14: tmp = math.pow(a, 4.0) + -1.0 elif (b <= 1.5e+45) or not (b <= 8.8e+55): tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.5e+14) tmp = Float64((a ^ 4.0) + -1.0); elseif ((b <= 1.5e+45) || !(b <= 8.8e+55)) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.5e+14) tmp = (a ^ 4.0) + -1.0; elseif ((b <= 1.5e+45) || ~((b <= 8.8e+55))) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.5e+14], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], If[Or[LessEqual[b, 1.5e+45], N[Not[LessEqual[b, 8.8e+55]], $MachinePrecision]], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.5 \cdot 10^{+14}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{+45} \lor \neg \left(b \leq 8.8 \cdot 10^{+55}\right):\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if b < 1.5e14Initial program 99.9%
Taylor expanded in b around 0 79.2%
if 1.5e14 < b < 1.50000000000000005e45 or 8.80000000000000042e55 < b Initial program 99.8%
unpow299.8%
distribute-lft-in86.9%
add-sqr-sqrt86.9%
pow286.9%
hypot-define86.9%
pow286.9%
add-sqr-sqrt86.9%
pow286.9%
hypot-define86.9%
pow286.9%
Applied egg-rr86.9%
distribute-lft-out99.9%
rem-square-sqrt99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
pow-sqr100.0%
metadata-eval100.0%
hypot-undefine99.9%
unpow299.9%
unpow299.9%
+-commutative99.9%
unpow299.9%
unpow299.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in b around inf 99.9%
if 1.50000000000000005e45 < b < 8.80000000000000042e55Initial program 100.0%
unpow2100.0%
distribute-lft-in100.0%
add-sqr-sqrt100.0%
pow2100.0%
hypot-define100.0%
pow2100.0%
add-sqr-sqrt100.0%
pow2100.0%
hypot-define100.0%
pow2100.0%
Applied egg-rr100.0%
distribute-lft-out100.0%
rem-square-sqrt100.0%
unpow2100.0%
unpow2100.0%
hypot-undefine100.0%
unpow2100.0%
unpow2100.0%
hypot-undefine100.0%
unpow2100.0%
pow-sqr100.0%
metadata-eval100.0%
hypot-undefine100.0%
unpow2100.0%
unpow2100.0%
+-commutative100.0%
unpow2100.0%
unpow2100.0%
hypot-define100.0%
Simplified100.0%
Taylor expanded in a around inf 68.8%
Final simplification83.4%
(FPCore (a b) :precision binary64 (if (<= b 5e-109) (pow a 4.0) (if (<= b 3.7e-20) -1.0 (if (<= b 1.3e+14) (pow a 4.0) (pow b 4.0)))))
double code(double a, double b) {
double tmp;
if (b <= 5e-109) {
tmp = pow(a, 4.0);
} else if (b <= 3.7e-20) {
tmp = -1.0;
} else if (b <= 1.3e+14) {
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 <= 5d-109) then
tmp = a ** 4.0d0
else if (b <= 3.7d-20) then
tmp = -1.0d0
else if (b <= 1.3d+14) 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 <= 5e-109) {
tmp = Math.pow(a, 4.0);
} else if (b <= 3.7e-20) {
tmp = -1.0;
} else if (b <= 1.3e+14) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 5e-109: tmp = math.pow(a, 4.0) elif b <= 3.7e-20: tmp = -1.0 elif b <= 1.3e+14: tmp = math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 5e-109) tmp = a ^ 4.0; elseif (b <= 3.7e-20) tmp = -1.0; elseif (b <= 1.3e+14) tmp = a ^ 4.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 5e-109) tmp = a ^ 4.0; elseif (b <= 3.7e-20) tmp = -1.0; elseif (b <= 1.3e+14) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 5e-109], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 3.7e-20], -1.0, If[LessEqual[b, 1.3e+14], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5 \cdot 10^{-109}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 3.7 \cdot 10^{-20}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 1.3 \cdot 10^{+14}:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 5.0000000000000002e-109 or 3.7000000000000001e-20 < b < 1.3e14Initial program 99.9%
unpow299.9%
distribute-lft-in84.9%
add-sqr-sqrt84.9%
pow284.9%
hypot-define84.9%
pow284.9%
add-sqr-sqrt84.9%
pow284.9%
hypot-define84.9%
pow284.9%
Applied egg-rr84.9%
distribute-lft-out99.9%
rem-square-sqrt99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
pow-sqr100.0%
metadata-eval100.0%
hypot-undefine100.0%
unpow2100.0%
unpow2100.0%
+-commutative100.0%
unpow2100.0%
unpow2100.0%
hypot-define100.0%
Simplified100.0%
Taylor expanded in a around inf 55.6%
if 5.0000000000000002e-109 < b < 3.7000000000000001e-20Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 75.2%
if 1.3e14 < b Initial program 99.8%
unpow299.8%
distribute-lft-in87.6%
add-sqr-sqrt87.6%
pow287.6%
hypot-define87.6%
pow287.6%
add-sqr-sqrt87.6%
pow287.6%
hypot-define87.6%
pow287.6%
Applied egg-rr87.6%
distribute-lft-out99.9%
rem-square-sqrt99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
pow-sqr100.0%
metadata-eval100.0%
hypot-undefine99.9%
unpow299.9%
unpow299.9%
+-commutative99.9%
unpow299.9%
unpow299.9%
hypot-define100.0%
Simplified100.0%
Taylor expanded in b around inf 96.6%
Final simplification65.6%
(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 4.2e+43) (+ (+ (* 4.0 (* b b)) (pow b 4.0)) -1.0) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 4.2e+43) {
tmp = ((4.0 * (b * b)) + pow(b, 4.0)) + -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.2d+43) then
tmp = ((4.0d0 * (b * b)) + (b ** 4.0d0)) + (-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.2e+43) {
tmp = ((4.0 * (b * b)) + Math.pow(b, 4.0)) + -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 4.2e+43: tmp = ((4.0 * (b * b)) + math.pow(b, 4.0)) + -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 4.2e+43) tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + (b ^ 4.0)) + -1.0); else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 4.2e+43) tmp = ((4.0 * (b * b)) + (b ^ 4.0)) + -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 4.2e+43], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.2 \cdot 10^{+43}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 4.20000000000000003e43Initial program 99.9%
Taylor expanded in a around 0 74.5%
if 4.20000000000000003e43 < a Initial program 99.9%
unpow299.9%
distribute-lft-in79.6%
add-sqr-sqrt79.6%
pow279.6%
hypot-define79.6%
pow279.6%
add-sqr-sqrt79.6%
pow279.6%
hypot-define79.6%
pow279.6%
Applied egg-rr79.6%
distribute-lft-out99.9%
rem-square-sqrt99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
pow-sqr100.0%
metadata-eval100.0%
hypot-undefine100.0%
unpow2100.0%
unpow2100.0%
+-commutative100.0%
unpow2100.0%
unpow2100.0%
hypot-define100.0%
Simplified100.0%
Taylor expanded in a around inf 95.3%
Final simplification79.3%
(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 58.3%
Taylor expanded in a around 0 28.3%
if 1 < a Initial program 99.9%
unpow299.9%
distribute-lft-in82.5%
add-sqr-sqrt82.5%
pow282.5%
hypot-define82.5%
pow282.5%
add-sqr-sqrt82.5%
pow282.5%
hypot-define82.5%
pow282.5%
Applied egg-rr82.5%
distribute-lft-out99.9%
rem-square-sqrt99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
pow-sqr100.0%
metadata-eval100.0%
hypot-undefine100.0%
unpow2100.0%
unpow2100.0%
+-commutative100.0%
unpow2100.0%
unpow2100.0%
hypot-define100.0%
Simplified100.0%
Taylor expanded in a around inf 87.7%
Final simplification44.3%
(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 66.2%
Taylor expanded in a around 0 20.9%
Final simplification20.9%
herbie shell --seed 2024082
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))