
(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 7 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 (hypot b a) 4.0) (+ (* 4.0 (* b b)) -1.0)))
double code(double a, double b) {
return pow(hypot(b, a), 4.0) + ((4.0 * (b * b)) + -1.0);
}
public static double code(double a, double b) {
return Math.pow(Math.hypot(b, a), 4.0) + ((4.0 * (b * b)) + -1.0);
}
def code(a, b): return math.pow(math.hypot(b, a), 4.0) + ((4.0 * (b * b)) + -1.0)
function code(a, b) return Float64((hypot(b, a) ^ 4.0) + Float64(Float64(4.0 * Float64(b * b)) + -1.0)) end
function tmp = code(a, b) tmp = (hypot(b, a) ^ 4.0) + ((4.0 * (b * b)) + -1.0); end
code[a_, b_] := N[(N[Power[N[Sqrt[b ^ 2 + a ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(b, a\right)\right)}^{4} + \left(4 \cdot \left(b \cdot b\right) + -1\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
fma-define99.9%
unpow299.9%
+-commutative99.9%
distribute-lft-in87.4%
fma-define87.4%
add-sqr-sqrt87.4%
pow287.4%
fma-define87.4%
hypot-define87.4%
pow287.4%
fma-define87.4%
add-sqr-sqrt87.4%
pow287.4%
fma-define87.4%
hypot-define87.4%
pow287.4%
Applied egg-rr87.4%
distribute-lft-out99.9%
rem-square-sqrt99.9%
+-commutative99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
+-commutative99.9%
unpow299.9%
unpow299.9%
hypot-undefine99.9%
unpow299.9%
pow-sqr100.0%
hypot-undefine100.0%
unpow2100.0%
unpow2100.0%
+-commutative100.0%
unpow2100.0%
unpow2100.0%
hypot-define100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (+ (+ (pow (+ (* b b) (* a a)) 2.0) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return (pow(((b * b) + (a * a)), 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 = ((((b * b) + (a * a)) ** 2.0d0) + (4.0d0 * (b * b))) + (-1.0d0)
end function
public static double code(double a, double b) {
return (Math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return (math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64((Float64(Float64(b * b) + Float64(a * a)) ^ 2.0) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((((b * b) + (a * a)) ^ 2.0) + (4.0 * (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[Power[N[(N[(b * b), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(b \cdot b + a \cdot a\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= a 1.15e+40) (+ (+ (* 4.0 (* b b)) -1.0) (pow b 4.0)) (+ (pow a 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.15e+40) {
tmp = ((4.0 * (b * b)) + -1.0) + pow(b, 4.0);
} else {
tmp = 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.15d+40) then
tmp = ((4.0d0 * (b * b)) + (-1.0d0)) + (b ** 4.0d0)
else
tmp = (a ** 4.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 1.15e+40) {
tmp = ((4.0 * (b * b)) + -1.0) + Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.15e+40: tmp = ((4.0 * (b * b)) + -1.0) + math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 1.15e+40) tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + -1.0) + (b ^ 4.0)); else tmp = Float64((a ^ 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.15e+40) tmp = ((4.0 * (b * b)) + -1.0) + (b ^ 4.0); else tmp = (a ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.15e+40], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.15 \cdot 10^{+40}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + -1\right) + {b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} + -1\\
\end{array}
\end{array}
if a < 1.14999999999999997e40Initial program 99.9%
associate--l+99.9%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 83.0%
if 1.14999999999999997e40 < a Initial program 99.9%
associate--l+99.9%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in b around 0 96.6%
Final simplification85.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e+97) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e+97) {
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) <= 2d+97) 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) <= 2e+97) {
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) <= 2e+97: 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) <= 2e+97) 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) <= 2e+97) 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], 2e+97], 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 \cdot 10^{+97}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 2.0000000000000001e97Initial program 99.9%
associate--l+99.9%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in b around 0 90.6%
if 2.0000000000000001e97 < (*.f64 b b) Initial program 99.9%
associate--l+99.9%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 96.5%
Taylor expanded in b around inf 96.5%
Final simplification93.0%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e-6) (+ (* 4.0 (* b b)) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e-6) {
tmp = (4.0 * (b * b)) + -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-6) then
tmp = (4.0d0 * (b * b)) + (-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-6) {
tmp = (4.0 * (b * b)) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2e-6: tmp = (4.0 * (b * b)) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2e-6) tmp = Float64(Float64(4.0 * Float64(b * b)) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2e-6) tmp = (4.0 * (b * b)) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e-6], N[(N[(4.0 * N[(b * b), $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^{-6}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 1.99999999999999991e-6Initial program 99.9%
associate--l+99.9%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 60.6%
Taylor expanded in b around 0 60.4%
unpow260.4%
Applied egg-rr60.4%
if 1.99999999999999991e-6 < (*.f64 b b) Initial program 99.8%
associate--l+99.8%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 85.2%
Taylor expanded in b around inf 84.6%
Final simplification73.2%
(FPCore (a b) :precision binary64 (+ (* 4.0 (* b b)) -1.0))
double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (4.0d0 * (b * b)) + (-1.0d0)
end function
public static double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
def code(a, b): return (4.0 * (b * b)) + -1.0
function code(a, b) return Float64(Float64(4.0 * Float64(b * b)) + -1.0) end
function tmp = code(a, b) tmp = (4.0 * (b * b)) + -1.0; end
code[a_, b_] := N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(b \cdot b\right) + -1
\end{array}
Initial program 99.9%
associate--l+99.9%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 73.6%
Taylor expanded in b around 0 55.2%
unpow255.2%
Applied egg-rr55.2%
Final simplification55.2%
(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%
associate--l+99.9%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in a around 0 73.6%
Taylor expanded in b around 0 28.7%
herbie shell --seed 2024151
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))