
(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 (+ (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 4.2e-191)
-1.0
(if (<= b 5e-43)
(pow a 4.0)
(if (<= b 5e-25) -1.0 (if (<= b 700.0) (pow a 4.0) (pow b 4.0))))))
double code(double a, double b) {
double tmp;
if (b <= 4.2e-191) {
tmp = -1.0;
} else if (b <= 5e-43) {
tmp = pow(a, 4.0);
} else if (b <= 5e-25) {
tmp = -1.0;
} else if (b <= 700.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 <= 4.2d-191) then
tmp = -1.0d0
else if (b <= 5d-43) then
tmp = a ** 4.0d0
else if (b <= 5d-25) then
tmp = -1.0d0
else if (b <= 700.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 <= 4.2e-191) {
tmp = -1.0;
} else if (b <= 5e-43) {
tmp = Math.pow(a, 4.0);
} else if (b <= 5e-25) {
tmp = -1.0;
} else if (b <= 700.0) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4.2e-191: tmp = -1.0 elif b <= 5e-43: tmp = math.pow(a, 4.0) elif b <= 5e-25: tmp = -1.0 elif b <= 700.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 <= 4.2e-191) tmp = -1.0; elseif (b <= 5e-43) tmp = a ^ 4.0; elseif (b <= 5e-25) tmp = -1.0; elseif (b <= 700.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 <= 4.2e-191) tmp = -1.0; elseif (b <= 5e-43) tmp = a ^ 4.0; elseif (b <= 5e-25) tmp = -1.0; elseif (b <= 700.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4.2e-191], -1.0, If[LessEqual[b, 5e-43], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 5e-25], -1.0, If[LessEqual[b, 700.0], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.2 \cdot 10^{-191}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-43}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-25}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 700:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 4.19999999999999971e-191 or 5.00000000000000019e-43 < b < 4.99999999999999962e-25Initial 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.6%
if 4.19999999999999971e-191 < b < 5.00000000000000019e-43 or 4.99999999999999962e-25 < b < 700Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around inf 64.4%
if 700 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around inf 88.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 700.0) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 700.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 <= 700.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 <= 700.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 <= 700.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 <= 700.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 <= 700.0) tmp = (a ^ 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 700.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 700:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 700Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around 0 79.0%
if 700 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around inf 88.0%
Final simplification81.3%
(FPCore (a b) :precision binary64 (if (<= a 0.0003) -1.0 (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 0.0003) {
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.0003d0) 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.0003) {
tmp = -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 0.0003: tmp = -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 0.0003) tmp = -1.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 0.0003) tmp = -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 0.0003], -1.0, N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 0.0003:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 2.99999999999999974e-4Initial 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%
Simplified100.0%
Taylor expanded in a around 0 59.7%
Taylor expanded in b around 0 36.3%
if 2.99999999999999974e-4 < a Initial program 99.8%
associate--l+99.8%
sqr-pow99.8%
Simplified100.0%
Taylor expanded in a around inf 83.8%
Final simplification47.0%
(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 52.4%
Taylor expanded in b around 0 28.2%
Final simplification28.2%
herbie shell --seed 2024019
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))