
(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 (+ (pow (fma a a (* b b)) 2.0) (fma b (* b 4.0) -1.0)))
double code(double a, double b) {
return pow(fma(a, a, (b * b)), 2.0) + fma(b, (b * 4.0), -1.0);
}
function code(a, b) return Float64((fma(a, a, Float64(b * b)) ^ 2.0) + fma(b, Float64(b * 4.0), -1.0)) end
code[a_, b_] := N[(N[Power[N[(a * a + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \mathsf{fma}\left(b, b \cdot 4, -1\right)
\end{array}
Initial program 99.8%
associate--l+99.8%
fma-define99.8%
associate-*r*99.8%
*-commutative99.8%
fma-neg99.8%
*-commutative99.8%
metadata-eval99.8%
Simplified99.8%
(FPCore (a b) :precision binary64 (+ (pow (fma a a (* b b)) 2.0) (+ (* (* b b) 4.0) -1.0)))
double code(double a, double b) {
return pow(fma(a, a, (b * b)), 2.0) + (((b * b) * 4.0) + -1.0);
}
function code(a, b) return Float64((fma(a, a, Float64(b * b)) ^ 2.0) + Float64(Float64(Float64(b * b) * 4.0) + -1.0)) end
code[a_, b_] := N[(N[Power[N[(a * a + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(\left(b \cdot b\right) \cdot 4 + -1\right)
\end{array}
Initial program 99.8%
associate--l+99.8%
fma-define99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (a b) :precision binary64 (+ (+ (pow (+ (* b b) (* a a)) 2.0) (* (* b b) 4.0)) -1.0))
double code(double a, double b) {
return (pow(((b * b) + (a * a)), 2.0) + ((b * b) * 4.0)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((((b * b) + (a * a)) ** 2.0d0) + ((b * b) * 4.0d0)) + (-1.0d0)
end function
public static double code(double a, double b) {
return (Math.pow(((b * b) + (a * a)), 2.0) + ((b * b) * 4.0)) + -1.0;
}
def code(a, b): return (math.pow(((b * b) + (a * a)), 2.0) + ((b * b) * 4.0)) + -1.0
function code(a, b) return Float64(Float64((Float64(Float64(b * b) + Float64(a * a)) ^ 2.0) + Float64(Float64(b * b) * 4.0)) + -1.0) end
function tmp = code(a, b) tmp = ((((b * b) + (a * a)) ^ 2.0) + ((b * b) * 4.0)) + -1.0; end
code[a_, b_] := N[(N[(N[Power[N[(N[(b * b), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(b \cdot b + a \cdot a\right)}^{2} + \left(b \cdot b\right) \cdot 4\right) + -1
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e+27) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e+27) {
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 * b) <= 2d+27) 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 * b) <= 2e+27) {
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 * b) <= 2e+27: 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 (Float64(b * b) <= 2e+27) 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 * b) <= 2e+27) tmp = (a ^ 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e+27], 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 \cdot b \leq 2 \cdot 10^{+27}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 2e27Initial program 99.8%
associate--l+99.8%
fma-define99.8%
associate-*r*99.8%
*-commutative99.8%
fma-neg99.8%
*-commutative99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in b around 0 97.9%
if 2e27 < (*.f64 b b) Initial program 99.8%
associate--l+99.8%
fma-define99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 95.0%
Taylor expanded in b around inf 95.0%
Final simplification96.7%
(FPCore (a b) :precision binary64 (if (<= (* b b) 0.4) (+ (* (* b b) 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 0.4) {
tmp = ((b * b) * 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 * b) <= 0.4d0) then
tmp = ((b * b) * 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 * b) <= 0.4) {
tmp = ((b * b) * 4.0) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 0.4: tmp = ((b * b) * 4.0) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 0.4) tmp = Float64(Float64(Float64(b * b) * 4.0) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 0.4) tmp = ((b * b) * 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 0.4], N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 0.4:\\
\;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 0.40000000000000002Initial program 99.8%
associate--l+99.8%
fma-define99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 40.7%
Taylor expanded in b around 0 40.2%
unpow240.2%
Applied egg-rr40.2%
if 0.40000000000000002 < (*.f64 b b) Initial program 99.8%
associate--l+99.8%
fma-define99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 92.8%
Taylor expanded in b around inf 92.3%
Final simplification64.2%
(FPCore (a b) :precision binary64 (+ -1.0 (pow b 4.0)))
double code(double a, double b) {
return -1.0 + pow(b, 4.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + (b ** 4.0d0)
end function
public static double code(double a, double b) {
return -1.0 + Math.pow(b, 4.0);
}
def code(a, b): return -1.0 + math.pow(b, 4.0)
function code(a, b) return Float64(-1.0 + (b ^ 4.0)) end
function tmp = code(a, b) tmp = -1.0 + (b ^ 4.0); end
code[a_, b_] := N[(-1.0 + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + {b}^{4}
\end{array}
Initial program 99.8%
associate--l+99.8%
fma-define99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 64.7%
Taylor expanded in b around 0 64.2%
Final simplification64.2%
(FPCore (a b) :precision binary64 (+ (* (* b b) 4.0) -1.0))
double code(double a, double b) {
return ((b * b) * 4.0) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((b * b) * 4.0d0) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((b * b) * 4.0) + -1.0;
}
def code(a, b): return ((b * b) * 4.0) + -1.0
function code(a, b) return Float64(Float64(Float64(b * b) * 4.0) + -1.0) end
function tmp = code(a, b) tmp = ((b * b) * 4.0) + -1.0; end
code[a_, b_] := N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(b \cdot b\right) \cdot 4 + -1
\end{array}
Initial program 99.8%
associate--l+99.8%
fma-define99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 64.7%
Taylor expanded in b around 0 46.6%
unpow246.6%
Applied egg-rr46.6%
Final simplification46.6%
(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%
fma-define99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 64.7%
Taylor expanded in b around 0 21.9%
herbie shell --seed 2024090
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))