
(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 (+ (+ (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 100.0%
Final simplification100.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (* (* b b) 4.0)))
(if (<= (* b b) 2.5e+93)
(+ (+ 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) <= 2.5e+93) {
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) <= 2.5d+93) 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) <= 2.5e+93) {
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) <= 2.5e+93: 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) <= 2.5e+93) 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) <= 2.5e+93) 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], 2.5e+93], 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.5 \cdot 10^{+93}:\\
\;\;\;\;\left(t\_0 + {a}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 + {b}^{4}\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 2.5000000000000001e93Initial program 99.9%
Taylor expanded in a around inf 97.6%
if 2.5000000000000001e93 < (*.f64 b b) Initial program 100.0%
Taylor expanded in a around 0 97.3%
Final simplification97.5%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2.5e+93) (+ (+ (* (* b b) 4.0) (pow a 4.0)) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2.5e+93) {
tmp = (((b * b) * 4.0) + pow(a, 4.0)) + -1.0;
} else {
tmp = pow(b, 4.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) <= 2.5d+93) then
tmp = (((b * b) * 4.0d0) + (a ** 4.0d0)) + (-1.0d0)
else
tmp = b ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 2.5e+93) {
tmp = (((b * b) * 4.0) + Math.pow(a, 4.0)) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2.5e+93: tmp = (((b * b) * 4.0) + math.pow(a, 4.0)) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2.5e+93) tmp = Float64(Float64(Float64(Float64(b * b) * 4.0) + (a ^ 4.0)) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2.5e+93) tmp = (((b * b) * 4.0) + (a ^ 4.0)) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2.5e+93], N[(N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2.5 \cdot 10^{+93}:\\
\;\;\;\;\left(\left(b \cdot b\right) \cdot 4 + {a}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 2.5000000000000001e93Initial program 99.9%
Taylor expanded in a around inf 97.6%
if 2.5000000000000001e93 < (*.f64 b b) Initial program 100.0%
Taylor expanded in a around 0 97.3%
Taylor expanded in b around inf 97.3%
Final simplification97.5%
(FPCore (a b) :precision binary64 (if (<= (* a a) 2e-29) (+ (* (* b b) 4.0) -1.0) (if (<= (* a a) 1e+121) (pow b 4.0) (pow a 4.0))))
double code(double a, double b) {
double tmp;
if ((a * a) <= 2e-29) {
tmp = ((b * b) * 4.0) + -1.0;
} else if ((a * a) <= 1e+121) {
tmp = pow(b, 4.0);
} 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 * a) <= 2d-29) then
tmp = ((b * b) * 4.0d0) + (-1.0d0)
else if ((a * a) <= 1d+121) then
tmp = b ** 4.0d0
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a * a) <= 2e-29) {
tmp = ((b * b) * 4.0) + -1.0;
} else if ((a * a) <= 1e+121) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (a * a) <= 2e-29: tmp = ((b * b) * 4.0) + -1.0 elif (a * a) <= 1e+121: tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(a * a) <= 2e-29) tmp = Float64(Float64(Float64(b * b) * 4.0) + -1.0); elseif (Float64(a * a) <= 1e+121) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a * a) <= 2e-29) tmp = ((b * b) * 4.0) + -1.0; elseif ((a * a) <= 1e+121) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(a * a), $MachinePrecision], 2e-29], N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(a * a), $MachinePrecision], 1e+121], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot a \leq 2 \cdot 10^{-29}:\\
\;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\
\mathbf{elif}\;a \cdot a \leq 10^{+121}:\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if (*.f64 a a) < 1.99999999999999989e-29Initial program 100.0%
Taylor expanded in a around inf 81.8%
Taylor expanded in a around 0 81.8%
unpow281.8%
Applied egg-rr81.8%
if 1.99999999999999989e-29 < (*.f64 a a) < 1.00000000000000004e121Initial program 99.8%
Taylor expanded in a around 0 69.8%
Taylor expanded in b around inf 64.4%
if 1.00000000000000004e121 < (*.f64 a a) Initial program 100.0%
Taylor expanded in a around inf 100.0%
Taylor expanded in a around inf 99.0%
Final simplification86.0%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2.5e+93) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2.5e+93) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = pow(b, 4.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) <= 2.5d+93) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = b ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 2.5e+93) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2.5e+93: tmp = math.pow(a, 4.0) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2.5e+93) tmp = Float64((a ^ 4.0) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2.5e+93) tmp = (a ^ 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2.5e+93], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2.5 \cdot 10^{+93}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 2.5000000000000001e93Initial program 99.9%
Taylor expanded in a around inf 97.6%
Taylor expanded in b around 0 97.1%
if 2.5000000000000001e93 < (*.f64 b b) Initial program 100.0%
Taylor expanded in a around 0 97.3%
Taylor expanded in b around inf 97.3%
Final simplification97.2%
(FPCore (a b) :precision binary64 (if (<= (* a a) 40000000.0) (+ (* (* b b) 4.0) -1.0) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if ((a * a) <= 40000000.0) {
tmp = ((b * b) * 4.0) + -1.0;
} 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 * a) <= 40000000.0d0) then
tmp = ((b * b) * 4.0d0) + (-1.0d0)
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a * a) <= 40000000.0) {
tmp = ((b * b) * 4.0) + -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (a * a) <= 40000000.0: tmp = ((b * b) * 4.0) + -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(a * a) <= 40000000.0) tmp = Float64(Float64(Float64(b * b) * 4.0) + -1.0); else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a * a) <= 40000000.0) tmp = ((b * b) * 4.0) + -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(a * a), $MachinePrecision], 40000000.0], N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot a \leq 40000000:\\
\;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if (*.f64 a a) < 4e7Initial program 100.0%
Taylor expanded in a around inf 81.1%
Taylor expanded in a around 0 81.0%
unpow281.0%
Applied egg-rr81.0%
if 4e7 < (*.f64 a a) Initial program 99.9%
Taylor expanded in a around inf 94.4%
Taylor expanded in a around inf 86.3%
Final simplification83.5%
(FPCore (a b) :precision binary64 (+ (* (* b b) 4.0) -1.0))
double code(double a, double b) {
return ((b * b) * 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) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((b * b) * 4.0) + -1.0;
}
def code(a, b): return ((b * b) * 4.0) + -1.0
function code(a, b) return Float64(Float64(Float64(b * b) * 4.0) + -1.0) end
function tmp = code(a, b) tmp = ((b * b) * 4.0) + -1.0; end
code[a_, b_] := N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(b \cdot b\right) \cdot 4 + -1
\end{array}
Initial program 100.0%
Taylor expanded in a around inf 87.3%
Taylor expanded in a around 0 56.5%
unpow256.5%
Applied egg-rr56.5%
Final simplification56.5%
(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 100.0%
Taylor expanded in a around 0 73.3%
Taylor expanded in b around 0 32.7%
herbie shell --seed 2024191
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))