
(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) (* (* 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
(let* ((t_0 (* (* b b) 4.0)))
(if (<= (* b b) 2e+14)
(+ (+ t_0 (pow a 4.0)) -1.0)
(+ (+ t_0 (pow b 4.0)) -1.0))))
double code(double a, double b) {
double t_0 = (b * b) * 4.0;
double tmp;
if ((b * b) <= 2e+14) {
tmp = (t_0 + pow(a, 4.0)) + -1.0;
} else {
tmp = (t_0 + 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) :: t_0
real(8) :: tmp
t_0 = (b * b) * 4.0d0
if ((b * b) <= 2d+14) then
tmp = (t_0 + (a ** 4.0d0)) + (-1.0d0)
else
tmp = (t_0 + (b ** 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 ((b * b) <= 2e+14) {
tmp = (t_0 + Math.pow(a, 4.0)) + -1.0;
} else {
tmp = (t_0 + Math.pow(b, 4.0)) + -1.0;
}
return tmp;
}
def code(a, b): t_0 = (b * b) * 4.0 tmp = 0 if (b * b) <= 2e+14: tmp = (t_0 + math.pow(a, 4.0)) + -1.0 else: tmp = (t_0 + math.pow(b, 4.0)) + -1.0 return tmp
function code(a, b) t_0 = Float64(Float64(b * b) * 4.0) tmp = 0.0 if (Float64(b * b) <= 2e+14) tmp = Float64(Float64(t_0 + (a ^ 4.0)) + -1.0); else tmp = Float64(Float64(t_0 + (b ^ 4.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) t_0 = (b * b) * 4.0; tmp = 0.0; if ((b * b) <= 2e+14) tmp = (t_0 + (a ^ 4.0)) + -1.0; else tmp = (t_0 + (b ^ 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[N[(b * b), $MachinePrecision], 2e+14], N[(N[(t$95$0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(t$95$0 + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(b \cdot b\right) \cdot 4\\
\mathbf{if}\;b \cdot b \leq 2 \cdot 10^{+14}:\\
\;\;\;\;\left(t\_0 + {a}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 + {b}^{4}\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 2e14Initial program 99.9%
Taylor expanded in a around inf 99.7%
if 2e14 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 95.2%
Final simplification97.3%
(FPCore (a b) :precision binary64 (+ (+ (* (* b b) 4.0) (pow a 4.0)) -1.0))
double code(double a, double b) {
return (((b * b) * 4.0) + pow(a, 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) + (a ** 4.0d0)) + (-1.0d0)
end function
public static double code(double a, double b) {
return (((b * b) * 4.0) + Math.pow(a, 4.0)) + -1.0;
}
def code(a, b): return (((b * b) * 4.0) + math.pow(a, 4.0)) + -1.0
function code(a, b) return Float64(Float64(Float64(Float64(b * b) * 4.0) + (a ^ 4.0)) + -1.0) end
function tmp = code(a, b) tmp = (((b * b) * 4.0) + (a ^ 4.0)) + -1.0; end
code[a_, b_] := N[(N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(b \cdot b\right) \cdot 4 + {a}^{4}\right) + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around inf 88.1%
Final simplification88.1%
(FPCore (a b) :precision binary64 (if (<= b 1e+148) (+ (pow a 4.0) -1.0) (* 4.0 (pow b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= 1e+148) {
tmp = pow(a, 4.0) + -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 <= 1d+148) then
tmp = (a ** 4.0d0) + (-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 <= 1e+148) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = 4.0 * Math.pow(b, 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1e+148: tmp = math.pow(a, 4.0) + -1.0 else: tmp = 4.0 * math.pow(b, 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 1e+148) tmp = Float64((a ^ 4.0) + -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 <= 1e+148) tmp = (a ^ 4.0) + -1.0; else tmp = 4.0 * (b ^ 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1e+148], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(4.0 * N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 10^{+148}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot {b}^{2}\\
\end{array}
\end{array}
if b < 1e148Initial program 99.9%
Taylor expanded in a around inf 86.4%
Taylor expanded in a around inf 72.5%
if 1e148 < b Initial program 100.0%
Taylor expanded in a around inf 97.7%
Taylor expanded in a around 0 97.7%
Taylor expanded in b around inf 97.7%
Final simplification76.3%
(FPCore (a b) :precision binary64 (if (<= b 0.056) -1.0 (* 4.0 (pow b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= 0.056) {
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.056d0) 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.056) {
tmp = -1.0;
} else {
tmp = 4.0 * Math.pow(b, 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 0.056: tmp = -1.0 else: tmp = 4.0 * math.pow(b, 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 0.056) 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.056) tmp = -1.0; else tmp = 4.0 * (b ^ 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 0.056], -1.0, N[(4.0 * N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.056:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot {b}^{2}\\
\end{array}
\end{array}
if b < 0.0560000000000000012Initial program 99.9%
Taylor expanded in a around inf 91.8%
Taylor expanded in a around 0 55.2%
Taylor expanded in b around 0 29.1%
if 0.0560000000000000012 < b Initial program 99.8%
Taylor expanded in a around inf 77.5%
Taylor expanded in a around 0 58.7%
Taylor expanded in b around inf 58.7%
(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 inf 88.1%
Taylor expanded in a around 0 56.1%
Taylor expanded in b around 0 21.8%
herbie shell --seed 2024107
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))