
(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 8 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 (+ (fma 2.0 (* a (* b (* a b))) (+ (pow b 4.0) (pow a 4.0))) (fma b (* b 4.0) -1.0)))
double code(double a, double b) {
return fma(2.0, (a * (b * (a * b))), (pow(b, 4.0) + pow(a, 4.0))) + fma(b, (b * 4.0), -1.0);
}
function code(a, b) return Float64(fma(2.0, Float64(a * Float64(b * Float64(a * b))), Float64((b ^ 4.0) + (a ^ 4.0))) + fma(b, Float64(b * 4.0), -1.0)) end
code[a_, b_] := N[(N[(2.0 * N[(a * N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[b, 4.0], $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2, a \cdot \left(b \cdot \left(a \cdot b\right)\right), {b}^{4} + {a}^{4}\right) + \mathsf{fma}\left(b, b \cdot 4, -1\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 85.5%
fma-def85.5%
unpow285.5%
unpow285.5%
swap-sqr100.0%
unpow2100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
unpow2100.0%
associate-*r*100.0%
*-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (+ (fma b (* b 4.0) -1.0) (pow (hypot a b) 4.0)))
double code(double a, double b) {
return fma(b, (b * 4.0), -1.0) + pow(hypot(a, b), 4.0);
}
function code(a, b) return Float64(fma(b, Float64(b * 4.0), -1.0) + (hypot(a, b) ^ 4.0)) end
code[a_, b_] := N[(N[(b * N[(b * 4.0), $MachinePrecision] + -1.0), $MachinePrecision] + N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b, b \cdot 4, -1\right) + {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4}
\end{array}
Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
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.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1e+28) (+ (+ (pow a 4.0) (* 4.0 (* b b))) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+28) {
tmp = (pow(a, 4.0) + (4.0 * (b * b))) + -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 * b) <= 1d+28) then
tmp = ((a ** 4.0d0) + (4.0d0 * (b * b))) + (-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 * b) <= 1e+28) {
tmp = (Math.pow(a, 4.0) + (4.0 * (b * b))) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1e+28: tmp = (math.pow(a, 4.0) + (4.0 * (b * b))) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1e+28) tmp = Float64(Float64((a ^ 4.0) + Float64(4.0 * Float64(b * b))) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1e+28) tmp = ((a ^ 4.0) + (4.0 * (b * b))) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1e+28], N[(N[(N[Power[a, 4.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 10^{+28}:\\
\;\;\;\;\left({a}^{4} + 4 \cdot \left(b \cdot b\right)\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 9.99999999999999958e27Initial program 99.9%
Taylor expanded in a around 0 99.9%
+-commutative99.9%
unpow299.9%
fma-udef99.9%
Simplified99.9%
Taylor expanded in b around 0 98.7%
if 9.99999999999999958e27 < (*.f64 b b) Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 91.5%
Taylor expanded in b around inf 91.5%
Final simplification95.2%
(FPCore (a b) :precision binary64 (if (<= a 1.78e-264) (pow b 4.0) (if (<= a 1.1e-206) -1.0 (if (<= a 15.5) (pow b 4.0) (pow a 4.0)))))
double code(double a, double b) {
double tmp;
if (a <= 1.78e-264) {
tmp = pow(b, 4.0);
} else if (a <= 1.1e-206) {
tmp = -1.0;
} else if (a <= 15.5) {
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 (a <= 1.78d-264) then
tmp = b ** 4.0d0
else if (a <= 1.1d-206) then
tmp = -1.0d0
else if (a <= 15.5d0) 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 (a <= 1.78e-264) {
tmp = Math.pow(b, 4.0);
} else if (a <= 1.1e-206) {
tmp = -1.0;
} else if (a <= 15.5) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.78e-264: tmp = math.pow(b, 4.0) elif a <= 1.1e-206: tmp = -1.0 elif a <= 15.5: tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 1.78e-264) tmp = b ^ 4.0; elseif (a <= 1.1e-206) tmp = -1.0; elseif (a <= 15.5) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.78e-264) tmp = b ^ 4.0; elseif (a <= 1.1e-206) tmp = -1.0; elseif (a <= 15.5) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.78e-264], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 1.1e-206], -1.0, If[LessEqual[a, 15.5], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.78 \cdot 10^{-264}:\\
\;\;\;\;{b}^{4}\\
\mathbf{elif}\;a \leq 1.1 \cdot 10^{-206}:\\
\;\;\;\;-1\\
\mathbf{elif}\;a \leq 15.5:\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 1.78e-264 or 1.0999999999999999e-206 < a < 15.5Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 78.0%
Taylor expanded in b around inf 52.4%
if 1.78e-264 < a < 1.0999999999999999e-206Initial program 99.7%
associate--l+99.7%
sqr-pow99.7%
sqr-pow99.7%
unpow299.7%
unpow199.7%
sqr-pow99.7%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 66.9%
if 15.5 < a Initial program 99.8%
Taylor expanded in a around 0 99.8%
+-commutative99.8%
unpow299.8%
fma-udef99.8%
Simplified99.8%
Taylor expanded in b around 0 96.4%
Taylor expanded in a around inf 93.0%
Final simplification64.8%
(FPCore (a b) :precision binary64 (if (<= b 98000000000000.0) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 98000000000000.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 <= 98000000000000.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 <= 98000000000000.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 <= 98000000000000.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 <= 98000000000000.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 <= 98000000000000.0) tmp = (a ^ 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 98000000000000.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 98000000000000:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 9.8e13Initial program 99.9%
Taylor expanded in a around 0 99.9%
+-commutative99.9%
unpow299.9%
fma-udef99.9%
Simplified99.9%
Taylor expanded in b around 0 88.5%
Taylor expanded in b around 0 76.0%
if 9.8e13 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 91.5%
Taylor expanded in b around inf 91.5%
Final simplification79.3%
(FPCore (a b) :precision binary64 (if (<= a 1.7e-9) -1.0 (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.7e-9) {
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.7d-9) 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.7e-9) {
tmp = -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.7e-9: tmp = -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 1.7e-9) tmp = -1.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.7e-9) tmp = -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.7e-9], -1.0, N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.7 \cdot 10^{-9}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 1.6999999999999999e-9Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 78.4%
Taylor expanded in b around 0 28.2%
if 1.6999999999999999e-9 < a Initial program 99.8%
Taylor expanded in a around 0 99.8%
+-commutative99.8%
unpow299.8%
fma-udef99.8%
Simplified99.8%
Taylor expanded in b around 0 95.3%
Taylor expanded in a around inf 89.6%
Final simplification47.2%
(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-*r*99.9%
Simplified100.0%
Taylor expanded in a around 0 65.3%
Taylor expanded in b around 0 19.7%
Final simplification19.7%
herbie shell --seed 2024011
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))