
(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 10 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%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.9%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (+ (pow (fma a a (* b b)) 2.0) (+ (* 4.0 (* b b)) -1.0)))
double code(double a, double b) {
return pow(fma(a, a, (b * b)), 2.0) + ((4.0 * (b * b)) + -1.0);
}
function code(a, b) return Float64((fma(a, a, Float64(b * b)) ^ 2.0) + Float64(Float64(4.0 * Float64(b * b)) + -1.0)) end
code[a_, b_] := N[(N[Power[N[(a * a + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(4 \cdot \left(b \cdot b\right) + -1\right)
\end{array}
Initial program 99.8%
associate--l+99.8%
fma-def99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e-6) (+ (pow a 4.0) -1.0) (+ (pow b 4.0) (* (* b b) (+ 4.0 (* 2.0 (* a a)))))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e-6) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = pow(b, 4.0) + ((b * b) * (4.0 + (2.0 * (a * a))));
}
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-6) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = (b ** 4.0d0) + ((b * b) * (4.0d0 + (2.0d0 * (a * a))))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 2e-6) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = Math.pow(b, 4.0) + ((b * b) * (4.0 + (2.0 * (a * a))));
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2e-6: tmp = math.pow(a, 4.0) + -1.0 else: tmp = math.pow(b, 4.0) + ((b * b) * (4.0 + (2.0 * (a * a)))) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2e-6) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64((b ^ 4.0) + Float64(Float64(b * b) * Float64(4.0 + Float64(2.0 * Float64(a * a))))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2e-6) tmp = (a ^ 4.0) + -1.0; else tmp = (b ^ 4.0) + ((b * b) * (4.0 + (2.0 * (a * a)))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e-6], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[b, 4.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(2.0 * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2 \cdot 10^{-6}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + \left(b \cdot b\right) \cdot \left(4 + 2 \cdot \left(a \cdot a\right)\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 1.99999999999999991e-6Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
if 1.99999999999999991e-6 < (*.f64 b b) Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around inf 96.8%
*-commutative96.8%
unpow296.8%
unpow296.8%
Simplified96.8%
Final simplification98.2%
(FPCore (a b) :precision binary64 (+ (+ (pow (+ (* b b) (* a a)) 2.0) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return (pow(((b * b) + (a * a)), 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 = ((((b * b) + (a * a)) ** 2.0d0) + (4.0d0 * (b * b))) + (-1.0d0)
end function
public static double code(double a, double b) {
return (Math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return (math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64((Float64(Float64(b * b) + Float64(a * a)) ^ 2.0) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((((b * b) + (a * a)) ^ 2.0) + (4.0 * (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[Power[N[(N[(b * b), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(b \cdot b + a \cdot a\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 (<= a 1.2e+29) (+ (+ (* 4.0 (* b b)) -1.0) (* (* b b) (* b b))) (+ (pow a 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.2e+29) {
tmp = ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b));
} 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 <= 1.2d+29) then
tmp = ((4.0d0 * (b * b)) + (-1.0d0)) + ((b * b) * (b * b))
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 <= 1.2e+29) {
tmp = ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b));
} else {
tmp = Math.pow(a, 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.2e+29: tmp = ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b)) else: tmp = math.pow(a, 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 1.2e+29) tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + -1.0) + Float64(Float64(b * b) * Float64(b * b))); else tmp = Float64((a ^ 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.2e+29) tmp = ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b)); else tmp = (a ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.2e+29], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.2 \cdot 10^{+29}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + -1\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} + -1\\
\end{array}
\end{array}
if a < 1.2e29Initial program 99.8%
associate--l+99.8%
fma-def99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 81.5%
unpow281.5%
Simplified81.5%
unpow281.5%
Applied egg-rr81.5%
if 1.2e29 < a Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in b around 0 93.5%
Final simplification84.2%
(FPCore (a b) :precision binary64 (if (<= a 7.5e+26) (+ (+ (* 4.0 (* b b)) -1.0) (* (* b b) (* b b))) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 7.5e+26) {
tmp = ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b));
} 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 <= 7.5d+26) then
tmp = ((4.0d0 * (b * b)) + (-1.0d0)) + ((b * b) * (b * b))
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 7.5e+26) {
tmp = ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b));
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 7.5e+26: tmp = ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b)) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 7.5e+26) tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + -1.0) + Float64(Float64(b * b) * Float64(b * b))); else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 7.5e+26) tmp = ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b)); else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 7.5e+26], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.5 \cdot 10^{+26}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + -1\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 7.49999999999999941e26Initial program 99.8%
associate--l+99.8%
fma-def99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 81.5%
unpow281.5%
Simplified81.5%
unpow281.5%
Applied egg-rr81.5%
if 7.49999999999999941e26 < a Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in a around inf 93.5%
Final simplification84.2%
(FPCore (a b) :precision binary64 (+ (+ (* 4.0 (* b b)) -1.0) (* (* b b) (* b b))))
double code(double a, double b) {
return ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((4.0d0 * (b * b)) + (-1.0d0)) + ((b * b) * (b * b))
end function
public static double code(double a, double b) {
return ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b));
}
def code(a, b): return ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b))
function code(a, b) return Float64(Float64(Float64(4.0 * Float64(b * b)) + -1.0) + Float64(Float64(b * b) * Float64(b * b))) end
function tmp = code(a, b) tmp = ((4.0 * (b * b)) + -1.0) + ((b * b) * (b * b)); end
code[a_, b_] := N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(4 \cdot \left(b \cdot b\right) + -1\right) + \left(b \cdot b\right) \cdot \left(b \cdot b\right)
\end{array}
Initial program 99.8%
associate--l+99.8%
fma-def99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 73.3%
unpow273.3%
Simplified73.3%
unpow273.3%
Applied egg-rr73.3%
Final simplification73.3%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1e-18) -1.0 (* 4.0 (* b b))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1e-18) {
tmp = -1.0;
} else {
tmp = 4.0 * (b * b);
}
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-18) then
tmp = -1.0d0
else
tmp = 4.0d0 * (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 1e-18) {
tmp = -1.0;
} else {
tmp = 4.0 * (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1e-18: tmp = -1.0 else: tmp = 4.0 * (b * b) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1e-18) tmp = -1.0; else tmp = Float64(4.0 * Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1e-18) tmp = -1.0; else tmp = 4.0 * (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1e-18], -1.0, N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 10^{-18}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 1.0000000000000001e-18Initial program 99.9%
associate--l+99.9%
fma-def99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 46.6%
unpow246.6%
Simplified46.6%
unpow246.6%
Applied egg-rr46.6%
Taylor expanded in b around 0 46.6%
if 1.0000000000000001e-18 < (*.f64 b b) Initial program 99.8%
associate--l+99.8%
fma-def99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 92.2%
unpow292.2%
Simplified92.2%
Taylor expanded in b around inf 92.4%
unpow292.4%
metadata-eval92.4%
pow-plus92.3%
unpow392.3%
associate-*r*92.2%
distribute-rgt-out92.2%
+-commutative92.2%
fma-udef92.2%
associate-*l*92.3%
Simplified92.3%
Taylor expanded in b around 0 53.2%
unpow253.2%
Simplified53.2%
Final simplification50.5%
(FPCore (a b) :precision binary64 (+ -1.0 (* (* b b) (* b b))))
double code(double a, double b) {
return -1.0 + ((b * b) * (b * b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + ((b * b) * (b * b))
end function
public static double code(double a, double b) {
return -1.0 + ((b * b) * (b * b));
}
def code(a, b): return -1.0 + ((b * b) * (b * b))
function code(a, b) return Float64(-1.0 + Float64(Float64(b * b) * Float64(b * b))) end
function tmp = code(a, b) tmp = -1.0 + ((b * b) * (b * b)); end
code[a_, b_] := N[(-1.0 + N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left(b \cdot b\right) \cdot \left(b \cdot b\right)
\end{array}
Initial program 99.8%
associate--l+99.8%
fma-def99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 73.3%
unpow273.3%
Simplified73.3%
unpow273.3%
Applied egg-rr73.3%
Taylor expanded in b around 0 72.9%
Final simplification72.9%
(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-def99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in a around 0 73.3%
unpow273.3%
Simplified73.3%
unpow273.3%
Applied egg-rr73.3%
Taylor expanded in b around 0 19.7%
Final simplification19.7%
herbie shell --seed 2023229
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))