
(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%
Taylor expanded in a around 0 99.9%
+-commutative99.9%
unpow299.9%
fma-undefine99.9%
Simplified99.9%
unpow299.9%
fma-undefine99.9%
pow299.9%
metadata-eval99.9%
distribute-lft-in90.5%
add-sqr-sqrt90.5%
pow290.5%
fma-undefine90.5%
unpow290.5%
hypot-define90.5%
metadata-eval90.5%
add-sqr-sqrt90.5%
pow290.5%
fma-undefine90.5%
unpow290.5%
hypot-define90.5%
Applied egg-rr90.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%
Simplified100.0%
Final simplification100.0%
(FPCore (a b)
:precision binary64
(if (<= b 5.5e-149)
-1.0
(if (<= b 9.5e-76)
(pow a 4.0)
(if (<= b 4.8e-28) -1.0 (if (<= b 14200.0) (pow a 4.0) (pow b 4.0))))))
double code(double a, double b) {
double tmp;
if (b <= 5.5e-149) {
tmp = -1.0;
} else if (b <= 9.5e-76) {
tmp = pow(a, 4.0);
} else if (b <= 4.8e-28) {
tmp = -1.0;
} else if (b <= 14200.0) {
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 <= 5.5d-149) then
tmp = -1.0d0
else if (b <= 9.5d-76) then
tmp = a ** 4.0d0
else if (b <= 4.8d-28) then
tmp = -1.0d0
else if (b <= 14200.0d0) 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 <= 5.5e-149) {
tmp = -1.0;
} else if (b <= 9.5e-76) {
tmp = Math.pow(a, 4.0);
} else if (b <= 4.8e-28) {
tmp = -1.0;
} else if (b <= 14200.0) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 5.5e-149: tmp = -1.0 elif b <= 9.5e-76: tmp = math.pow(a, 4.0) elif b <= 4.8e-28: tmp = -1.0 elif b <= 14200.0: tmp = math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 5.5e-149) tmp = -1.0; elseif (b <= 9.5e-76) tmp = a ^ 4.0; elseif (b <= 4.8e-28) tmp = -1.0; elseif (b <= 14200.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 5.5e-149) tmp = -1.0; elseif (b <= 9.5e-76) tmp = a ^ 4.0; elseif (b <= 4.8e-28) tmp = -1.0; elseif (b <= 14200.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 5.5e-149], -1.0, If[LessEqual[b, 9.5e-76], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 4.8e-28], -1.0, If[LessEqual[b, 14200.0], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.5 \cdot 10^{-149}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-76}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{-28}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 14200:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 5.50000000000000043e-149 or 9.49999999999999984e-76 < b < 4.8000000000000004e-28Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 67.0%
Taylor expanded in b around 0 33.5%
if 5.50000000000000043e-149 < b < 9.49999999999999984e-76 or 4.8000000000000004e-28 < b < 14200Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around inf 100.0%
Taylor expanded in a around inf 77.1%
if 14200 < b Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.8%
Simplified100.0%
Taylor expanded in a around 0 94.8%
Taylor expanded in b around inf 94.8%
Final simplification50.4%
(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 (<= b 12000.0) (+ (pow a 4.0) -1.0) (+ (+ (* 4.0 (* b b)) (pow b 4.0)) -1.0)))
double code(double a, double b) {
double tmp;
if (b <= 12000.0) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = ((4.0 * (b * b)) + 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 <= 12000.0d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = ((4.0d0 * (b * b)) + (b ** 4.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 12000.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = ((4.0 * (b * b)) + Math.pow(b, 4.0)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 12000.0: tmp = math.pow(a, 4.0) + -1.0 else: tmp = ((4.0 * (b * b)) + math.pow(b, 4.0)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (b <= 12000.0) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + (b ^ 4.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 12000.0) tmp = (a ^ 4.0) + -1.0; else tmp = ((4.0 * (b * b)) + (b ^ 4.0)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 12000.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 12000:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + {b}^{4}\right) + -1\\
\end{array}
\end{array}
if b < 12000Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around inf 88.9%
Taylor expanded in b around 0 78.6%
if 12000 < b Initial program 99.8%
Taylor expanded in a around 0 99.8%
+-commutative99.8%
unpow299.8%
fma-undefine99.8%
Simplified99.8%
unpow299.8%
fma-undefine99.8%
pow299.8%
metadata-eval99.8%
distribute-lft-in90.8%
add-sqr-sqrt90.8%
pow290.8%
fma-undefine90.8%
unpow290.8%
hypot-define90.8%
metadata-eval90.8%
add-sqr-sqrt90.8%
pow290.8%
fma-undefine90.8%
unpow290.8%
hypot-define90.8%
Applied egg-rr90.8%
distribute-lft-out99.8%
rem-square-sqrt99.8%
unpow299.8%
unpow299.8%
hypot-undefine99.8%
unpow299.8%
unpow299.8%
hypot-undefine99.8%
unpow299.8%
pow-sqr100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in b around inf 94.8%
Final simplification82.0%
(FPCore (a b) :precision binary64 (if (<= b 14000.0) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 14000.0) {
tmp = 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 <= 14000.0d0) then
tmp = (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 <= 14000.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 14000.0: tmp = math.pow(a, 4.0) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 14000.0) tmp = Float64((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 <= 14000.0) tmp = (a ^ 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 14000.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 14000:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 14000Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around inf 88.9%
Taylor expanded in b around 0 78.6%
if 14000 < b Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.8%
Simplified100.0%
Taylor expanded in a around 0 94.8%
Taylor expanded in b around inf 94.8%
Final simplification82.0%
(FPCore (a b) :precision binary64 (if (<= a 0.085) -1.0 (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 0.085) {
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 <= 0.085d0) 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 <= 0.085) {
tmp = -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 0.085: tmp = -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 0.085) tmp = -1.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 0.085) tmp = -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 0.085], -1.0, N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 0.085:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 0.0850000000000000061Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 76.8%
Taylor expanded in b around 0 34.2%
if 0.0850000000000000061 < a Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around inf 98.6%
Taylor expanded in a around inf 94.3%
Final simplification49.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%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 69.3%
Taylor expanded in b around 0 25.5%
Final simplification25.5%
herbie shell --seed 2024052
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))