
(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 (+ (+ (* (hypot a b) (pow (hypot a b) 3.0)) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return ((hypot(a, b) * pow(hypot(a, b), 3.0)) + (4.0 * (b * b))) + -1.0;
}
public static double code(double a, double b) {
return ((Math.hypot(a, b) * Math.pow(Math.hypot(a, b), 3.0)) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return ((math.hypot(a, b) * math.pow(math.hypot(a, b), 3.0)) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64(Float64(hypot(a, b) * (hypot(a, b) ^ 3.0)) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((hypot(a, b) * (hypot(a, b) ^ 3.0)) + (4.0 * (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[(N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision] * N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\mathsf{hypot}\left(a, b\right) \cdot {\left(\mathsf{hypot}\left(a, b\right)\right)}^{3} + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Initial program 99.9%
add-sqr-sqrt99.9%
sqrt-unprod93.4%
pow-prod-up93.4%
add-sqr-sqrt93.4%
pow293.4%
hypot-define93.4%
metadata-eval93.4%
Applied egg-rr93.4%
sqrt-pow199.9%
metadata-eval99.9%
pow299.9%
unpow299.9%
associate-*r*99.9%
unpow299.9%
pow399.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (+ (+ (* 4.0 (* b b)) (pow (+ (* b b) (* a a)) 2.0)) -1.0))
double code(double a, double b) {
return ((4.0 * (b * b)) + pow(((b * b) + (a * a)), 2.0)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((4.0d0 * (b * b)) + (((b * b) + (a * a)) ** 2.0d0)) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((4.0 * (b * b)) + Math.pow(((b * b) + (a * a)), 2.0)) + -1.0;
}
def code(a, b): return ((4.0 * (b * b)) + math.pow(((b * b) + (a * a)), 2.0)) + -1.0
function code(a, b) return Float64(Float64(Float64(4.0 * Float64(b * b)) + (Float64(Float64(b * b) + Float64(a * a)) ^ 2.0)) + -1.0) end
function tmp = code(a, b) tmp = ((4.0 * (b * b)) + (((b * b) + (a * a)) ^ 2.0)) + -1.0; end
code[a_, b_] := N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(b * b), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(4 \cdot \left(b \cdot b\right) + {\left(b \cdot b + a \cdot a\right)}^{2}\right) + -1
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (let* ((t_0 (* 4.0 (* b b)))) (if (<= a 0.43) (+ (+ 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 = 4.0 * (b * b);
double tmp;
if (a <= 0.43) {
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 = 4.0d0 * (b * b)
if (a <= 0.43d0) 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 = 4.0 * (b * b);
double tmp;
if (a <= 0.43) {
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 = 4.0 * (b * b) tmp = 0 if a <= 0.43: 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(4.0 * Float64(b * b)) tmp = 0.0 if (a <= 0.43) 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 = 4.0 * (b * b); tmp = 0.0; if (a <= 0.43) 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[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, 0.43], 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 := 4 \cdot \left(b \cdot b\right)\\
\mathbf{if}\;a \leq 0.43:\\
\;\;\;\;\left(t\_0 + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 0.429999999999999993Initial program 99.9%
Taylor expanded in a around 0 74.1%
if 0.429999999999999993 < a Initial program 99.8%
Taylor expanded in a around inf 96.9%
Final simplification79.4%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1e+283) (+ (pow a 4.0) -1.0) (+ (* 4.0 (* b b)) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+283) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = (4.0 * (b * b)) + -1.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+283) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = (4.0d0 * (b * b)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+283) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = (4.0 * (b * b)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1e+283: tmp = math.pow(a, 4.0) + -1.0 else: tmp = (4.0 * (b * b)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1e+283) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(Float64(4.0 * Float64(b * b)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1e+283) tmp = (a ^ 4.0) + -1.0; else tmp = (4.0 * (b * b)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1e+283], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 10^{+283}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 9.99999999999999955e282Initial program 99.8%
Taylor expanded in a around inf 84.8%
Taylor expanded in b around 0 83.9%
if 9.99999999999999955e282 < (*.f64 b b) Initial program 100.0%
Taylor expanded in a around inf 96.8%
Taylor expanded in a around 0 96.8%
pow296.8%
Applied egg-rr96.8%
Final simplification86.7%
(FPCore (a b) :precision binary64 (+ (+ (* 4.0 (* b b)) (pow a 4.0)) -1.0))
double code(double a, double b) {
return ((4.0 * (b * b)) + pow(a, 4.0)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((4.0d0 * (b * b)) + (a ** 4.0d0)) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((4.0 * (b * b)) + Math.pow(a, 4.0)) + -1.0;
}
def code(a, b): return ((4.0 * (b * b)) + math.pow(a, 4.0)) + -1.0
function code(a, b) return Float64(Float64(Float64(4.0 * Float64(b * b)) + (a ^ 4.0)) + -1.0) end
function tmp = code(a, b) tmp = ((4.0 * (b * b)) + (a ^ 4.0)) + -1.0; end
code[a_, b_] := N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(4 \cdot \left(b \cdot b\right) + {a}^{4}\right) + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around inf 87.4%
Final simplification87.4%
(FPCore (a b) :precision binary64 (if (<= (* b b) 8.6e-9) -1.0 (* 4.0 (* b b))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 8.6e-9) {
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) <= 8.6d-9) 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) <= 8.6e-9) {
tmp = -1.0;
} else {
tmp = 4.0 * (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 8.6e-9: tmp = -1.0 else: tmp = 4.0 * (b * b) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 8.6e-9) 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) <= 8.6e-9) tmp = -1.0; else tmp = 4.0 * (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 8.6e-9], -1.0, N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 8.6 \cdot 10^{-9}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 8.59999999999999925e-9Initial program 99.9%
Taylor expanded in a around 0 47.5%
Taylor expanded in b around 0 47.5%
if 8.59999999999999925e-9 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around inf 72.7%
Taylor expanded in b around inf 49.0%
pow249.0%
Applied egg-rr49.0%
(FPCore (a b) :precision binary64 (+ (* 4.0 (* b b)) -1.0))
double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (4.0d0 * (b * b)) + (-1.0d0)
end function
public static double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
def code(a, b): return (4.0 * (b * b)) + -1.0
function code(a, b) return Float64(Float64(4.0 * Float64(b * b)) + -1.0) end
function tmp = code(a, b) tmp = (4.0 * (b * b)) + -1.0; end
code[a_, b_] := N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(b \cdot b\right) + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around inf 87.4%
Taylor expanded in a around 0 48.2%
pow248.2%
Applied egg-rr48.2%
Final simplification48.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%
Taylor expanded in a around 0 65.5%
Taylor expanded in b around 0 25.9%
herbie shell --seed 2024161
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))