
(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 5 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) (* (* 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 (<= (* b b) 1e+38) (+ (+ (* (* b b) 4.0) (pow a 4.0)) -1.0) (+ (pow b 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+38) {
tmp = (((b * b) * 4.0) + pow(a, 4.0)) + -1.0;
} else {
tmp = pow(b, 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 ((b * b) <= 1d+38) then
tmp = (((b * b) * 4.0d0) + (a ** 4.0d0)) + (-1.0d0)
else
tmp = (b ** 4.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+38) {
tmp = (((b * b) * 4.0) + Math.pow(a, 4.0)) + -1.0;
} else {
tmp = Math.pow(b, 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1e+38: tmp = (((b * b) * 4.0) + math.pow(a, 4.0)) + -1.0 else: tmp = math.pow(b, 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1e+38) tmp = Float64(Float64(Float64(Float64(b * b) * 4.0) + (a ^ 4.0)) + -1.0); else tmp = Float64((b ^ 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1e+38) tmp = (((b * b) * 4.0) + (a ^ 4.0)) + -1.0; else tmp = (b ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1e+38], N[(N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 10^{+38}:\\
\;\;\;\;\left(\left(b \cdot b\right) \cdot 4 + {a}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 9.99999999999999977e37Initial program 99.9%
Taylor expanded in a around inf 99.4%
if 9.99999999999999977e37 < (*.f64 b b) Initial program 99.8%
Taylor expanded in a around 0 96.6%
Taylor expanded in b around inf 96.6%
Final simplification98.2%
(FPCore (a b) :precision binary64 (if (<= b 0.000215) -1.0 (* 4.0 (pow b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= 0.000215) {
tmp = -1.0;
} else {
tmp = 4.0 * pow(b, 2.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 0.000215d0) then
tmp = -1.0d0
else
tmp = 4.0d0 * (b ** 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 0.000215) {
tmp = -1.0;
} else {
tmp = 4.0 * Math.pow(b, 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 0.000215: tmp = -1.0 else: tmp = 4.0 * math.pow(b, 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 0.000215) tmp = -1.0; else tmp = Float64(4.0 * (b ^ 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 0.000215) tmp = -1.0; else tmp = 4.0 * (b ^ 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 0.000215], -1.0, N[(4.0 * N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.000215:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot {b}^{2}\\
\end{array}
\end{array}
if b < 2.14999999999999995e-4Initial program 99.9%
Taylor expanded in a around 0 55.9%
Taylor expanded in b around 0 43.1%
Taylor expanded in b around 0 31.3%
if 2.14999999999999995e-4 < b Initial program 99.8%
Taylor expanded in a around 0 91.1%
Taylor expanded in b around 0 55.3%
Taylor expanded in b around inf 55.3%
Final simplification37.4%
(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 64.9%
Taylor expanded in b around inf 64.8%
Final simplification64.8%
(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 64.9%
Taylor expanded in b around 0 46.2%
Taylor expanded in b around 0 23.5%
Final simplification23.5%
herbie shell --seed 2024068
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))