
(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) (fma b (* b 4.0) -1.0)))
double code(double a, double b) {
return pow(hypot(a, b), 4.0) + fma(b, (b * 4.0), -1.0);
}
function code(a, b) return Float64((hypot(a, b) ^ 4.0) + fma(b, Float64(b * 4.0), -1.0)) end
code[a_, b_] := N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b, b \cdot 4, -1\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Final simplification100.0%
(FPCore (a b)
:precision binary64
(if (<= b 1.25e-284)
-1.0
(if (<= b 1.65e-221)
(pow a 4.0)
(if (<= b 1.1e-78)
-1.0
(if (<= b 4.7e-33)
(pow a 4.0)
(if (<= b 1.1e-18)
-1.0
(if (<= b 620.0) (pow a 4.0) (pow b 4.0))))))))
double code(double a, double b) {
double tmp;
if (b <= 1.25e-284) {
tmp = -1.0;
} else if (b <= 1.65e-221) {
tmp = pow(a, 4.0);
} else if (b <= 1.1e-78) {
tmp = -1.0;
} else if (b <= 4.7e-33) {
tmp = pow(a, 4.0);
} else if (b <= 1.1e-18) {
tmp = -1.0;
} else if (b <= 620.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 <= 1.25d-284) then
tmp = -1.0d0
else if (b <= 1.65d-221) then
tmp = a ** 4.0d0
else if (b <= 1.1d-78) then
tmp = -1.0d0
else if (b <= 4.7d-33) then
tmp = a ** 4.0d0
else if (b <= 1.1d-18) then
tmp = -1.0d0
else if (b <= 620.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 <= 1.25e-284) {
tmp = -1.0;
} else if (b <= 1.65e-221) {
tmp = Math.pow(a, 4.0);
} else if (b <= 1.1e-78) {
tmp = -1.0;
} else if (b <= 4.7e-33) {
tmp = Math.pow(a, 4.0);
} else if (b <= 1.1e-18) {
tmp = -1.0;
} else if (b <= 620.0) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.25e-284: tmp = -1.0 elif b <= 1.65e-221: tmp = math.pow(a, 4.0) elif b <= 1.1e-78: tmp = -1.0 elif b <= 4.7e-33: tmp = math.pow(a, 4.0) elif b <= 1.1e-18: tmp = -1.0 elif b <= 620.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 <= 1.25e-284) tmp = -1.0; elseif (b <= 1.65e-221) tmp = a ^ 4.0; elseif (b <= 1.1e-78) tmp = -1.0; elseif (b <= 4.7e-33) tmp = a ^ 4.0; elseif (b <= 1.1e-18) tmp = -1.0; elseif (b <= 620.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 <= 1.25e-284) tmp = -1.0; elseif (b <= 1.65e-221) tmp = a ^ 4.0; elseif (b <= 1.1e-78) tmp = -1.0; elseif (b <= 4.7e-33) tmp = a ^ 4.0; elseif (b <= 1.1e-18) tmp = -1.0; elseif (b <= 620.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.25e-284], -1.0, If[LessEqual[b, 1.65e-221], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 1.1e-78], -1.0, If[LessEqual[b, 4.7e-33], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 1.1e-18], -1.0, If[LessEqual[b, 620.0], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.25 \cdot 10^{-284}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{-221}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{-78}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 4.7 \cdot 10^{-33}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{-18}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 620:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 1.24999999999999993e-284 or 1.64999999999999995e-221 < b < 1.0999999999999999e-78 or 4.7000000000000002e-33 < b < 1.0999999999999999e-18Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in a around 0 37.5%
Taylor expanded in b around 0 37.7%
if 1.24999999999999993e-284 < b < 1.64999999999999995e-221 or 1.0999999999999999e-78 < b < 4.7000000000000002e-33 or 1.0999999999999999e-18 < b < 620Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around inf 64.5%
if 620 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around inf 95.0%
Final simplification54.3%
(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}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= b 1250.0) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 1250.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 <= 1250.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 <= 1250.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 <= 1250.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 <= 1250.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 <= 1250.0) tmp = (a ^ 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1250.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 1250:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 1250Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around 0 81.3%
if 1250 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around inf 95.0%
Final simplification84.7%
(FPCore (a b) :precision binary64 (if (<= b 0.00062) (+ (pow a 4.0) -1.0) (+ (pow b 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (b <= 0.00062) {
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 <= 0.00062d0) 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 <= 0.00062) {
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 <= 0.00062: 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 <= 0.00062) 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 <= 0.00062) tmp = (a ^ 4.0) + -1.0; else tmp = (b ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 0.00062], 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 0.00062:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + -1\\
\end{array}
\end{array}
if b < 6.2e-4Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around 0 81.7%
if 6.2e-4 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around 0 95.8%
add-sqr-sqrt95.7%
pow295.7%
+-commutative95.7%
metadata-eval95.7%
pow-prod-up95.7%
add-sqr-sqrt95.7%
hypot-def95.7%
*-commutative95.7%
sqrt-prod95.7%
unpow295.7%
sqrt-prod95.7%
add-sqr-sqrt95.7%
metadata-eval95.7%
Applied egg-rr95.7%
Taylor expanded in b around inf 93.5%
Final simplification84.7%
(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%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in a around 0 62.0%
Taylor expanded in b around 0 37.5%
if 1 < a Initial program 100.0%
associate--l+100.0%
sqr-pow100.0%
Simplified100.0%
Taylor expanded in a around inf 89.4%
Final simplification50.8%
(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%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in a around 0 53.1%
Taylor expanded in b around 0 28.0%
Final simplification28.0%
herbie shell --seed 2024041
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))