
(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 (+ (* a a) (* b b)) 2.0) (expm1 (log1p (* (pow b 2.0) 4.0)))) -1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + expm1(log1p((pow(b, 2.0) * 4.0)))) + -1.0;
}
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + Math.expm1(Math.log1p((Math.pow(b, 2.0) * 4.0)))) + -1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + math.expm1(math.log1p((math.pow(b, 2.0) * 4.0)))) + -1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + expm1(log1p(Float64((b ^ 2.0) * 4.0)))) + -1.0) end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(Exp[N[Log[1 + N[(N[Power[b, 2.0], $MachinePrecision] * 4.0), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + \mathsf{expm1}\left(\mathsf{log1p}\left({b}^{2} \cdot 4\right)\right)\right) + -1
\end{array}
Initial program 99.9%
expm1-log1p-u99.9%
*-commutative99.9%
pow299.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (+ (+ (pow (+ (* a a) (* b b)) 2.0) (* (* b b) 4.0)) -1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 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 = ((((a * a) + (b * b)) ** 2.0d0) + ((b * b) * 4.0d0)) + (-1.0d0)
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + ((b * b) * 4.0)) + -1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + ((b * b) * 4.0)) + -1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(Float64(b * b) * 4.0)) + -1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + ((b * b) * 4.0)) + -1.0; end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + \left(b \cdot b\right) \cdot 4\right) + -1
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= a 1.1e-18) (+ (pow b 4.0) -1.0) (+ (+ (* (* b b) 4.0) (pow a 4.0)) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.1e-18) {
tmp = pow(b, 4.0) + -1.0;
} else {
tmp = (((b * b) * 4.0) + 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.1d-18) then
tmp = (b ** 4.0d0) + (-1.0d0)
else
tmp = (((b * b) * 4.0d0) + (a ** 4.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 1.1e-18) {
tmp = Math.pow(b, 4.0) + -1.0;
} else {
tmp = (((b * b) * 4.0) + Math.pow(a, 4.0)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.1e-18: tmp = math.pow(b, 4.0) + -1.0 else: tmp = (((b * b) * 4.0) + math.pow(a, 4.0)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 1.1e-18) tmp = Float64((b ^ 4.0) + -1.0); else tmp = Float64(Float64(Float64(Float64(b * b) * 4.0) + (a ^ 4.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.1e-18) tmp = (b ^ 4.0) + -1.0; else tmp = (((b * b) * 4.0) + (a ^ 4.0)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.1e-18], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.1 \cdot 10^{-18}:\\
\;\;\;\;{b}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(b \cdot b\right) \cdot 4 + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 1.0999999999999999e-18Initial program 99.9%
Taylor expanded in a around 0 79.2%
Taylor expanded in b around inf 77.7%
if 1.0999999999999999e-18 < a Initial program 99.8%
Taylor expanded in a around inf 95.9%
Final simplification82.5%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* (* b b) 4.0)))
(if (<= a 1.1e-18)
(+ (+ t_0 (pow b 4.0)) -1.0)
(+ (+ t_0 (pow a 4.0)) -1.0))))
double code(double a, double b) {
double t_0 = (b * b) * 4.0;
double tmp;
if (a <= 1.1e-18) {
tmp = (t_0 + pow(b, 4.0)) + -1.0;
} else {
tmp = (t_0 + 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) :: t_0
real(8) :: tmp
t_0 = (b * b) * 4.0d0
if (a <= 1.1d-18) then
tmp = (t_0 + (b ** 4.0d0)) + (-1.0d0)
else
tmp = (t_0 + (a ** 4.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = (b * b) * 4.0;
double tmp;
if (a <= 1.1e-18) {
tmp = (t_0 + Math.pow(b, 4.0)) + -1.0;
} else {
tmp = (t_0 + Math.pow(a, 4.0)) + -1.0;
}
return tmp;
}
def code(a, b): t_0 = (b * b) * 4.0 tmp = 0 if a <= 1.1e-18: tmp = (t_0 + math.pow(b, 4.0)) + -1.0 else: tmp = (t_0 + math.pow(a, 4.0)) + -1.0 return tmp
function code(a, b) t_0 = Float64(Float64(b * b) * 4.0) tmp = 0.0 if (a <= 1.1e-18) tmp = Float64(Float64(t_0 + (b ^ 4.0)) + -1.0); else tmp = Float64(Float64(t_0 + (a ^ 4.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) t_0 = (b * b) * 4.0; tmp = 0.0; if (a <= 1.1e-18) tmp = (t_0 + (b ^ 4.0)) + -1.0; else tmp = (t_0 + (a ^ 4.0)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision]}, If[LessEqual[a, 1.1e-18], N[(N[(t$95$0 + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(t$95$0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(b \cdot b\right) \cdot 4\\
\mathbf{if}\;a \leq 1.1 \cdot 10^{-18}:\\
\;\;\;\;\left(t\_0 + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 1.0999999999999999e-18Initial program 99.9%
Taylor expanded in a around 0 79.2%
if 1.0999999999999999e-18 < a Initial program 99.8%
Taylor expanded in a around inf 95.9%
Final simplification83.6%
(FPCore (a b) :precision binary64 (+ (pow b 4.0) -1.0))
double code(double a, double b) {
return pow(b, 4.0) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (b ** 4.0d0) + (-1.0d0)
end function
public static double code(double a, double b) {
return Math.pow(b, 4.0) + -1.0;
}
def code(a, b): return math.pow(b, 4.0) + -1.0
function code(a, b) return Float64((b ^ 4.0) + -1.0) end
function tmp = code(a, b) tmp = (b ^ 4.0) + -1.0; end
code[a_, b_] := N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
{b}^{4} + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around 0 68.2%
Taylor expanded in b around inf 67.1%
Final simplification67.1%
(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%
Taylor expanded in a around 0 68.2%
Taylor expanded in b around inf 67.1%
Taylor expanded in b around 0 28.6%
Final simplification28.6%
herbie shell --seed 2024066
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))