
(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 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e+112) (+ (+ (* (* 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) <= 2e+112) {
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) <= 2d+112) 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) <= 2e+112) {
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) <= 2e+112: 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) <= 2e+112) 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) <= 2e+112) 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], 2e+112], 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 \cdot 10^{+112}:\\
\;\;\;\;\left(\left(b \cdot b\right) \cdot 4 + {a}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 1.9999999999999999e112Initial program 99.9%
Taylor expanded in a around inf 94.3%
if 1.9999999999999999e112 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 97.1%
Taylor expanded in b around inf 97.1%
Final simplification95.4%
(FPCore (a b) :precision binary64 (let* ((t_0 (* (* b b) 4.0))) (if (<= a 39.0) (+ (+ 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 <= 39.0) {
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 <= 39.0d0) 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 <= 39.0) {
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 <= 39.0: 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 <= 39.0) 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 <= 39.0) 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, 39.0], 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 39:\\
\;\;\;\;\left(t\_0 + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 39Initial program 99.9%
Taylor expanded in a around 0 79.1%
if 39 < a Initial program 99.9%
Taylor expanded in a around inf 98.4%
Final simplification83.5%
(FPCore (a b) :precision binary64 (if (<= a 4.8e-16) (+ (* (* b b) 4.0) -1.0) (if (<= a 1.35e+43) (pow b 4.0) (pow a 4.0))))
double code(double a, double b) {
double tmp;
if (a <= 4.8e-16) {
tmp = ((b * b) * 4.0) + -1.0;
} else if (a <= 1.35e+43) {
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 <= 4.8d-16) then
tmp = ((b * b) * 4.0d0) + (-1.0d0)
else if (a <= 1.35d+43) 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 <= 4.8e-16) {
tmp = ((b * b) * 4.0) + -1.0;
} else if (a <= 1.35e+43) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 4.8e-16: tmp = ((b * b) * 4.0) + -1.0 elif a <= 1.35e+43: tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 4.8e-16) tmp = Float64(Float64(Float64(b * b) * 4.0) + -1.0); elseif (a <= 1.35e+43) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 4.8e-16) tmp = ((b * b) * 4.0) + -1.0; elseif (a <= 1.35e+43) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 4.8e-16], N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[a, 1.35e+43], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4.8 \cdot 10^{-16}:\\
\;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\
\mathbf{elif}\;a \leq 1.35 \cdot 10^{+43}:\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 4.8000000000000001e-16Initial program 99.9%
Taylor expanded in a around inf 84.8%
Taylor expanded in a around 0 61.5%
unpow261.5%
Applied egg-rr61.5%
if 4.8000000000000001e-16 < a < 1.3500000000000001e43Initial program 100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around inf 100.0%
if 1.3500000000000001e43 < a Initial program 99.9%
Taylor expanded in a around inf 100.0%
Taylor expanded in a around inf 94.9%
Final simplification69.6%
(FPCore (a b) :precision binary64 (if (<= a 190.0) (+ (* (* b b) 4.0) -1.0) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 190.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 <= 190.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 <= 190.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 <= 190.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 (a <= 190.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 <= 190.0) tmp = ((b * b) * 4.0) + -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 190.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 \leq 190:\\
\;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 190Initial program 99.9%
Taylor expanded in a around inf 84.1%
Taylor expanded in a around 0 61.1%
unpow261.1%
Applied egg-rr61.1%
if 190 < a Initial program 99.9%
Taylor expanded in a around inf 98.4%
Taylor expanded in a around inf 90.3%
Final simplification67.7%
(FPCore (a b) :precision binary64 (if (<= (* b b) 0.0012) -1.0 (* (* b b) 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 0.0012) {
tmp = -1.0;
} else {
tmp = (b * 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) <= 0.0012d0) then
tmp = -1.0d0
else
tmp = (b * b) * 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 0.0012) {
tmp = -1.0;
} else {
tmp = (b * b) * 4.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 0.0012: tmp = -1.0 else: tmp = (b * b) * 4.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 0.0012) tmp = -1.0; else tmp = Float64(Float64(b * b) * 4.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 0.0012) tmp = -1.0; else tmp = (b * b) * 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 0.0012], -1.0, N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 0.0012:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;\left(b \cdot b\right) \cdot 4\\
\end{array}
\end{array}
if (*.f64 b b) < 0.00119999999999999989Initial program 99.9%
Taylor expanded in a around 0 55.6%
Taylor expanded in b around 0 54.7%
if 0.00119999999999999989 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around inf 74.1%
Taylor expanded in b around inf 47.8%
unpow247.7%
Applied egg-rr47.8%
Final simplification51.4%
(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 99.9%
Taylor expanded in a around inf 87.4%
Taylor expanded in a around 0 51.7%
unpow251.7%
Applied egg-rr51.7%
Final simplification51.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 0 69.3%
Taylor expanded in b around 0 28.6%
herbie shell --seed 2024146
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))