
(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 b 4.0) (+ (pow a 4.0) (* 2.0 (* a (* b (* b a)))))) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return ((pow(b, 4.0) + (pow(a, 4.0) + (2.0 * (a * (b * (b * a)))))) + (4.0 * (b * b))) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (((b ** 4.0d0) + ((a ** 4.0d0) + (2.0d0 * (a * (b * (b * a)))))) + (4.0d0 * (b * b))) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((Math.pow(b, 4.0) + (Math.pow(a, 4.0) + (2.0 * (a * (b * (b * a)))))) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return ((math.pow(b, 4.0) + (math.pow(a, 4.0) + (2.0 * (a * (b * (b * a)))))) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64(Float64((b ^ 4.0) + Float64((a ^ 4.0) + Float64(2.0 * Float64(a * Float64(b * Float64(b * a)))))) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = (((b ^ 4.0) + ((a ^ 4.0) + (2.0 * (a * (b * (b * a)))))) + (4.0 * (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[(N[Power[b, 4.0], $MachinePrecision] + N[(N[Power[a, 4.0], $MachinePrecision] + N[(2.0 * N[(a * N[(b * N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\left({b}^{4} + \left({a}^{4} + 2 \cdot \left(a \cdot \left(b \cdot \left(b \cdot a\right)\right)\right)\right)\right) + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around 0 92.9%
+-commutative92.9%
distribute-lft-in88.2%
associate-*r*88.2%
*-commutative88.2%
associate-*r*88.2%
pow-sqr88.3%
metadata-eval88.3%
fma-define88.3%
unpow288.3%
unpow288.3%
swap-sqr100.0%
unpow2100.0%
*-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
Applied egg-rr100.0%
unpow2100.0%
associate-*r*100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (+ (+ (* 4.0 (* b b)) (pow (+ (* b b) (* a a)) 2.0)) -1.0))
double code(double a, double b) {
return ((4.0 * (b * b)) + pow(((b * b) + (a * a)), 2.0)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((4.0d0 * (b * b)) + (((b * b) + (a * a)) ** 2.0d0)) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((4.0 * (b * b)) + Math.pow(((b * b) + (a * a)), 2.0)) + -1.0;
}
def code(a, b): return ((4.0 * (b * b)) + math.pow(((b * b) + (a * a)), 2.0)) + -1.0
function code(a, b) return Float64(Float64(Float64(4.0 * Float64(b * b)) + (Float64(Float64(b * b) + Float64(a * a)) ^ 2.0)) + -1.0) end
function tmp = code(a, b) tmp = ((4.0 * (b * b)) + (((b * b) + (a * a)) ^ 2.0)) + -1.0; end
code[a_, b_] := N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(b * b), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(4 \cdot \left(b \cdot b\right) + {\left(b \cdot b + a \cdot a\right)}^{2}\right) + -1
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (let* ((t_0 (* 4.0 (* b b)))) (if (<= a 3.7) (+ (+ (pow b 4.0) t_0) -1.0) (+ (+ (pow a 4.0) t_0) -1.0))))
double code(double a, double b) {
double t_0 = 4.0 * (b * b);
double tmp;
if (a <= 3.7) {
tmp = (pow(b, 4.0) + t_0) + -1.0;
} else {
tmp = (pow(a, 4.0) + t_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 = 4.0d0 * (b * b)
if (a <= 3.7d0) then
tmp = ((b ** 4.0d0) + t_0) + (-1.0d0)
else
tmp = ((a ** 4.0d0) + t_0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = 4.0 * (b * b);
double tmp;
if (a <= 3.7) {
tmp = (Math.pow(b, 4.0) + t_0) + -1.0;
} else {
tmp = (Math.pow(a, 4.0) + t_0) + -1.0;
}
return tmp;
}
def code(a, b): t_0 = 4.0 * (b * b) tmp = 0 if a <= 3.7: tmp = (math.pow(b, 4.0) + t_0) + -1.0 else: tmp = (math.pow(a, 4.0) + t_0) + -1.0 return tmp
function code(a, b) t_0 = Float64(4.0 * Float64(b * b)) tmp = 0.0 if (a <= 3.7) tmp = Float64(Float64((b ^ 4.0) + t_0) + -1.0); else tmp = Float64(Float64((a ^ 4.0) + t_0) + -1.0); end return tmp end
function tmp_2 = code(a, b) t_0 = 4.0 * (b * b); tmp = 0.0; if (a <= 3.7) tmp = ((b ^ 4.0) + t_0) + -1.0; else tmp = ((a ^ 4.0) + t_0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, 3.7], N[(N[(N[Power[b, 4.0], $MachinePrecision] + t$95$0), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[Power[a, 4.0], $MachinePrecision] + t$95$0), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 4 \cdot \left(b \cdot b\right)\\
\mathbf{if}\;a \leq 3.7:\\
\;\;\;\;\left({b}^{4} + t\_0\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left({a}^{4} + t\_0\right) + -1\\
\end{array}
\end{array}
if a < 3.7000000000000002Initial program 99.9%
Taylor expanded in a around 0 78.8%
if 3.7000000000000002 < a Initial program 99.9%
Taylor expanded in a around inf 98.3%
Final simplification83.1%
(FPCore (a b) :precision binary64 (if (<= a 4.0) (+ (pow b 4.0) -1.0) (+ (+ (pow a 4.0) (* 4.0 (* b b))) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 4.0) {
tmp = pow(b, 4.0) + -1.0;
} else {
tmp = (pow(a, 4.0) + (4.0 * (b * b))) + -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 <= 4.0d0) then
tmp = (b ** 4.0d0) + (-1.0d0)
else
tmp = ((a ** 4.0d0) + (4.0d0 * (b * b))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 4.0) {
tmp = Math.pow(b, 4.0) + -1.0;
} else {
tmp = (Math.pow(a, 4.0) + (4.0 * (b * b))) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 4.0: tmp = math.pow(b, 4.0) + -1.0 else: tmp = (math.pow(a, 4.0) + (4.0 * (b * b))) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 4.0) tmp = Float64((b ^ 4.0) + -1.0); else tmp = Float64(Float64((a ^ 4.0) + Float64(4.0 * Float64(b * b))) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 4.0) tmp = (b ^ 4.0) + -1.0; else tmp = ((a ^ 4.0) + (4.0 * (b * b))) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 4.0], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[Power[a, 4.0], $MachinePrecision] + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4:\\
\;\;\;\;{b}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;\left({a}^{4} + 4 \cdot \left(b \cdot b\right)\right) + -1\\
\end{array}
\end{array}
if a < 4Initial program 99.9%
Taylor expanded in a around 0 91.0%
+-commutative91.0%
distribute-lft-in86.0%
associate-*r*86.0%
*-commutative86.0%
associate-*r*86.0%
pow-sqr86.0%
metadata-eval86.0%
fma-define86.0%
unpow286.0%
unpow286.0%
swap-sqr100.0%
unpow2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 77.7%
if 4 < a Initial program 99.9%
Taylor expanded in a around inf 98.3%
Final simplification82.2%
(FPCore (a b) :precision binary64 (if (<= a 1.08e+21) (+ (pow b 4.0) -1.0) (+ (pow a 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.08e+21) {
tmp = pow(b, 4.0) + -1.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.08d+21) then
tmp = (b ** 4.0d0) + (-1.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.08e+21) {
tmp = Math.pow(b, 4.0) + -1.0;
} else {
tmp = Math.pow(a, 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.08e+21: tmp = math.pow(b, 4.0) + -1.0 else: tmp = math.pow(a, 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 1.08e+21) tmp = Float64((b ^ 4.0) + -1.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.08e+21) tmp = (b ^ 4.0) + -1.0; else tmp = (a ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.08e+21], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.08 \cdot 10^{+21}:\\
\;\;\;\;{b}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} + -1\\
\end{array}
\end{array}
if a < 1.08e21Initial program 99.9%
Taylor expanded in a around 0 91.1%
+-commutative91.1%
distribute-lft-in86.2%
associate-*r*86.2%
*-commutative86.2%
associate-*r*86.2%
pow-sqr86.3%
metadata-eval86.3%
fma-define86.3%
unpow286.3%
unpow286.3%
swap-sqr100.0%
unpow2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around inf 77.2%
if 1.08e21 < a Initial program 99.9%
Taylor expanded in a around 0 99.9%
+-commutative99.9%
distribute-lft-in96.1%
associate-*r*96.1%
*-commutative96.1%
associate-*r*96.1%
pow-sqr96.2%
metadata-eval96.2%
fma-define96.2%
unpow296.2%
unpow296.2%
swap-sqr100.0%
unpow2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 98.2%
Final simplification81.4%
(FPCore (a b) :precision binary64 (+ (pow a 4.0) -1.0))
double code(double a, double b) {
return pow(a, 4.0) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (a ** 4.0d0) + (-1.0d0)
end function
public static double code(double a, double b) {
return Math.pow(a, 4.0) + -1.0;
}
def code(a, b): return math.pow(a, 4.0) + -1.0
function code(a, b) return Float64((a ^ 4.0) + -1.0) end
function tmp = code(a, b) tmp = (a ^ 4.0) + -1.0; end
code[a_, b_] := N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
{a}^{4} + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around 0 92.9%
+-commutative92.9%
distribute-lft-in88.2%
associate-*r*88.2%
*-commutative88.2%
associate-*r*88.2%
pow-sqr88.3%
metadata-eval88.3%
fma-define88.3%
unpow288.3%
unpow288.3%
swap-sqr100.0%
unpow2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 72.7%
Final simplification72.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.9%
herbie shell --seed 2024097
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))