
(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.8%
associate--l+99.8%
sqr-pow99.8%
sqr-pow99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.9%
Simplified100.0%
Final simplification100.0%
(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.8%
Final simplification99.8%
(FPCore (a b) :precision binary64 (if (<= b 0.48) -1.0 (* a (pow b 3.0))))
double code(double a, double b) {
double tmp;
if (b <= 0.48) {
tmp = -1.0;
} else {
tmp = a * pow(b, 3.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.48d0) then
tmp = -1.0d0
else
tmp = a * (b ** 3.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 0.48) {
tmp = -1.0;
} else {
tmp = a * Math.pow(b, 3.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 0.48: tmp = -1.0 else: tmp = a * math.pow(b, 3.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 0.48) tmp = -1.0; else tmp = Float64(a * (b ^ 3.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 0.48) tmp = -1.0; else tmp = a * (b ^ 3.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 0.48], -1.0, N[(a * N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.48:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;a \cdot {b}^{3}\\
\end{array}
\end{array}
if b < 0.47999999999999998Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in a around 0 36.5%
Taylor expanded in b around 0 36.3%
if 0.47999999999999998 < b Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in a around 0 90.8%
Taylor expanded in a around inf 30.2%
Final simplification34.9%
(FPCore (a b) :precision binary64 (if (<= b 3.4e+68) (+ (pow a 4.0) -1.0) (* a (pow b 3.0))))
double code(double a, double b) {
double tmp;
if (b <= 3.4e+68) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = a * pow(b, 3.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 3.4d+68) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = a * (b ** 3.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 3.4e+68) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = a * Math.pow(b, 3.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.4e+68: tmp = math.pow(a, 4.0) + -1.0 else: tmp = a * math.pow(b, 3.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.4e+68) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(a * (b ^ 3.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 3.4e+68) tmp = (a ^ 4.0) + -1.0; else tmp = a * (b ^ 3.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.4e+68], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(a * N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.4 \cdot 10^{+68}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;a \cdot {b}^{3}\\
\end{array}
\end{array}
if b < 3.40000000000000015e68Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in b around 0 77.0%
if 3.40000000000000015e68 < b Initial program 100.0%
associate--l+100.0%
unpow2100.0%
unpow1100.0%
sqr-pow100.0%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in a around inf 38.4%
Final simplification69.9%
(FPCore (a b) :precision binary64 (if (<= a 2.25e+33) (+ (pow b 4.0) -1.0) (+ (pow a 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 2.25e+33) {
tmp = pow(b, 4.0) + -1.0;
} else {
tmp = 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 <= 2.25d+33) then
tmp = (b ** 4.0d0) + (-1.0d0)
else
tmp = (a ** 4.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 2.25e+33) {
tmp = Math.pow(b, 4.0) + -1.0;
} else {
tmp = Math.pow(a, 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 2.25e+33: tmp = math.pow(b, 4.0) + -1.0 else: tmp = math.pow(a, 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 2.25e+33) tmp = Float64((b ^ 4.0) + -1.0); else tmp = Float64((a ^ 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 2.25e+33) tmp = (b ^ 4.0) + -1.0; else tmp = (a ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 2.25e+33], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.25 \cdot 10^{+33}:\\
\;\;\;\;{b}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} + -1\\
\end{array}
\end{array}
if a < 2.25e33Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in b around 0 95.1%
Taylor expanded in a around inf 88.9%
associate-*r*88.9%
*-commutative88.9%
associate-*l*88.9%
Simplified88.9%
Taylor expanded in a around 0 79.3%
if 2.25e33 < a Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*l*99.9%
fma-def99.9%
Simplified100.0%
Taylor expanded in b around 0 96.4%
Final simplification82.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.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in a around 0 49.5%
Taylor expanded in b around 0 27.8%
Final simplification27.8%
herbie shell --seed 2023339
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))