
(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 9 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) 0.02) (+ (pow a 4.0) -1.0) (+ (* b (+ (pow b 3.0) (* b 4.0))) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 0.02) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = (b * (pow(b, 3.0) + (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) <= 0.02d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = (b * ((b ** 3.0d0) + (b * 4.0d0))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 0.02) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = (b * (Math.pow(b, 3.0) + (b * 4.0))) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 0.02: tmp = math.pow(a, 4.0) + -1.0 else: tmp = (b * (math.pow(b, 3.0) + (b * 4.0))) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 0.02) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(Float64(b * Float64((b ^ 3.0) + Float64(b * 4.0))) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 0.02) tmp = (a ^ 4.0) + -1.0; else tmp = (b * ((b ^ 3.0) + (b * 4.0))) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 0.02], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(b * N[(N[Power[b, 3.0], $MachinePrecision] + N[(b * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 0.02:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left({b}^{3} + b \cdot 4\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in a around inf 99.2%
Taylor expanded in a around inf 98.4%
if 0.0200000000000000004 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 94.8%
metadata-eval94.8%
pow-sqr94.7%
pow294.7%
pow294.7%
associate-*r*94.7%
pow394.7%
Applied egg-rr94.7%
associate-*r*94.7%
distribute-rgt-out94.7%
*-commutative94.7%
Applied egg-rr94.7%
Final simplification96.3%
(FPCore (a b) :precision binary64 (if (<= (* b b) 0.02) (+ (pow a 4.0) -1.0) (+ (* b (* b (fma b b 4.0))) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 0.02) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = (b * (b * fma(b, b, 4.0))) + -1.0;
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 0.02) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(Float64(b * Float64(b * fma(b, b, 4.0))) + -1.0); end return tmp end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 0.02], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(b * N[(b * N[(b * b + 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 0.02:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(b \cdot \mathsf{fma}\left(b, b, 4\right)\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in a around inf 99.2%
Taylor expanded in a around inf 98.4%
if 0.0200000000000000004 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 94.8%
metadata-eval94.8%
pow-sqr94.7%
pow294.7%
pow294.7%
associate-*r*94.7%
pow394.7%
Applied egg-rr94.7%
associate-*r*94.7%
distribute-rgt-out94.7%
*-commutative94.7%
Applied egg-rr94.7%
cube-mult94.7%
distribute-lft-out94.7%
fma-define94.7%
Applied egg-rr94.7%
Final simplification96.3%
(FPCore (a b) :precision binary64 (if (<= a 1.3e-7) (+ (* b (+ (pow b 3.0) (* b 4.0))) -1.0) (+ (+ (* (* b b) 4.0) (pow a 4.0)) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.3e-7) {
tmp = (b * (pow(b, 3.0) + (b * 4.0))) + -1.0;
} else {
tmp = (((b * b) * 4.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) :: tmp
if (a <= 1.3d-7) then
tmp = (b * ((b ** 3.0d0) + (b * 4.0d0))) + (-1.0d0)
else
tmp = (((b * b) * 4.0d0) + (a ** 4.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 1.3e-7) {
tmp = (b * (Math.pow(b, 3.0) + (b * 4.0))) + -1.0;
} else {
tmp = (((b * b) * 4.0) + Math.pow(a, 4.0)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.3e-7: tmp = (b * (math.pow(b, 3.0) + (b * 4.0))) + -1.0 else: tmp = (((b * b) * 4.0) + math.pow(a, 4.0)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 1.3e-7) tmp = Float64(Float64(b * Float64((b ^ 3.0) + Float64(b * 4.0))) + -1.0); else tmp = Float64(Float64(Float64(Float64(b * b) * 4.0) + (a ^ 4.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.3e-7) tmp = (b * ((b ^ 3.0) + (b * 4.0))) + -1.0; else tmp = (((b * b) * 4.0) + (a ^ 4.0)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.3e-7], N[(N[(b * N[(N[Power[b, 3.0], $MachinePrecision] + N[(b * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.3 \cdot 10^{-7}:\\
\;\;\;\;b \cdot \left({b}^{3} + b \cdot 4\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(b \cdot b\right) \cdot 4 + {a}^{4}\right) + -1\\
\end{array}
\end{array}
if a < 1.29999999999999999e-7Initial program 99.9%
Taylor expanded in a around 0 85.2%
metadata-eval85.2%
pow-sqr85.2%
pow285.2%
pow285.2%
associate-*r*85.2%
pow385.2%
Applied egg-rr85.2%
associate-*r*85.2%
distribute-rgt-out85.2%
*-commutative85.2%
Applied egg-rr85.2%
if 1.29999999999999999e-7 < a Initial program 100.0%
Taylor expanded in a around inf 92.5%
Final simplification87.0%
(FPCore (a b) :precision binary64 (if (<= (* b b) 5e+17) (+ (pow a 4.0) -1.0) (+ (pow b 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 5e+17) {
tmp = 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) <= 5d+17) then
tmp = (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) <= 5e+17) {
tmp = 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) <= 5e+17: tmp = 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) <= 5e+17) tmp = Float64((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) <= 5e+17) tmp = (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], 5e+17], N[(N[Power[a, 4.0], $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 5 \cdot 10^{+17}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 5e17Initial program 100.0%
Taylor expanded in a around inf 97.0%
Taylor expanded in a around inf 95.9%
if 5e17 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 96.0%
Taylor expanded in b around inf 96.0%
Final simplification95.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e+304) (+ (pow a 4.0) -1.0) (+ (* (* b b) 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e+304) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = ((b * 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) <= 2d+304) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = ((b * b) * 4.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 2e+304) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = ((b * b) * 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2e+304: tmp = math.pow(a, 4.0) + -1.0 else: tmp = ((b * b) * 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2e+304) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(Float64(Float64(b * b) * 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2e+304) tmp = (a ^ 4.0) + -1.0; else tmp = ((b * b) * 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e+304], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2 \cdot 10^{+304}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 1.9999999999999999e304Initial program 99.9%
Taylor expanded in a around inf 77.0%
Taylor expanded in a around inf 75.1%
if 1.9999999999999999e304 < (*.f64 b b) Initial program 100.0%
Taylor expanded in a around inf 100.0%
Taylor expanded in a around 0 100.0%
pow2100.0%
Applied egg-rr100.0%
Final simplification82.0%
(FPCore (a b) :precision binary64 (if (<= a 5.5e+31) (+ (* (* b b) 4.0) -1.0) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 5.5e+31) {
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 <= 5.5d+31) 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 <= 5.5e+31) {
tmp = ((b * b) * 4.0) + -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 5.5e+31: 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 <= 5.5e+31) 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 <= 5.5e+31) tmp = ((b * b) * 4.0) + -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 5.5e+31], 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 5.5 \cdot 10^{+31}:\\
\;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 5.50000000000000002e31Initial program 99.9%
Taylor expanded in a around inf 80.2%
Taylor expanded in a around 0 60.1%
pow260.1%
Applied egg-rr60.1%
if 5.50000000000000002e31 < a Initial program 100.0%
Taylor expanded in a around inf 94.9%
Taylor expanded in a around inf 91.4%
Taylor expanded in a around inf 91.4%
Final simplification66.8%
(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 83.3%
Taylor expanded in a around 0 52.8%
pow252.8%
Applied egg-rr52.8%
Final simplification52.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 77.4%
Taylor expanded in b around 0 23.1%
herbie shell --seed 2024131
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))