
(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 (hypot a b) 4.0) (fma b (* b 4.0) -1.0)))
double code(double a, double b) {
return pow(hypot(a, b), 4.0) + fma(b, (b * 4.0), -1.0);
}
function code(a, b) return Float64((hypot(a, b) ^ 4.0) + fma(b, Float64(b * 4.0), -1.0)) end
code[a_, b_] := N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b, b \cdot 4, -1\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
unpow199.9%
sqr-pow99.9%
unpow3100.0%
pow-plus100.0%
metadata-eval100.0%
unpow1/2100.0%
hypot-def100.0%
metadata-eval100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Final simplification100.0%
(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}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2.0) (+ (pow a 4.0) -1.0) (+ (+ (pow b 4.0) (* b (* b 4.0))) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2.0) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = (pow(b, 4.0) + (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) <= 2.0d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = ((b ** 4.0d0) + (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) <= 2.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = (Math.pow(b, 4.0) + (b * (b * 4.0))) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2.0: tmp = math.pow(a, 4.0) + -1.0 else: tmp = (math.pow(b, 4.0) + (b * (b * 4.0))) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2.0) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(Float64((b ^ 4.0) + Float64(b * Float64(b * 4.0))) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2.0) tmp = (a ^ 4.0) + -1.0; else tmp = ((b ^ 4.0) + (b * (b * 4.0))) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[Power[b, 4.0], $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;\left({b}^{4} + b \cdot \left(b \cdot 4\right)\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 2Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
unpow199.9%
sqr-pow99.9%
unpow3100.0%
pow-plus100.0%
metadata-eval100.0%
unpow1/2100.0%
hypot-def100.0%
metadata-eval100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 99.6%
if 2 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 95.8%
unpow295.8%
*-commutative95.8%
associate-*r*95.8%
fma-def95.8%
Simplified95.8%
metadata-eval95.8%
pow-sqr95.7%
unpow-prod-down95.7%
fma-def95.7%
associate-*r*95.7%
*-commutative95.7%
+-commutative95.7%
unpow-prod-down95.7%
pow-prod-up95.8%
metadata-eval95.8%
*-commutative95.8%
associate-*r*95.8%
Applied egg-rr95.8%
Final simplification97.6%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2.0) (+ (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) <= 2.0) {
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) <= 2.0) 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], 2.0], 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 2:\\
\;\;\;\;{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) < 2Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
unpow199.9%
sqr-pow99.9%
unpow3100.0%
pow-plus100.0%
metadata-eval100.0%
unpow1/2100.0%
hypot-def100.0%
metadata-eval100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 99.6%
if 2 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 95.7%
unpow295.7%
Simplified95.7%
Taylor expanded in b around 0 95.8%
unpow295.8%
metadata-eval95.8%
pow-plus95.7%
unpow395.7%
associate-*r*95.7%
distribute-rgt-in95.7%
associate-*l*95.7%
+-commutative95.7%
fma-udef95.7%
Simplified95.7%
Final simplification97.6%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2.0) (+ (pow a 4.0) -1.0) (+ (* (* b b) (+ 4.0 (* b b))) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2.0) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = ((b * b) * (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 ((b * b) <= 2.0d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = ((b * b) * (4.0d0 + (b * b))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 2.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = ((b * b) * (4.0 + (b * b))) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2.0: tmp = math.pow(a, 4.0) + -1.0 else: tmp = ((b * b) * (4.0 + (b * b))) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2.0) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(Float64(Float64(b * b) * Float64(4.0 + Float64(b * b))) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2.0) tmp = (a ^ 4.0) + -1.0; else tmp = ((b * b) * (4.0 + (b * b))) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 2Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
unpow199.9%
sqr-pow99.9%
unpow3100.0%
pow-plus100.0%
metadata-eval100.0%
unpow1/2100.0%
hypot-def100.0%
metadata-eval100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 99.6%
if 2 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 95.7%
unpow295.7%
Simplified95.7%
+-commutative95.7%
unpow295.7%
distribute-rgt-out95.7%
Applied egg-rr95.7%
Final simplification97.6%
(FPCore (a b) :precision binary64 (+ (* (* b b) (+ 4.0 (* b b))) -1.0))
double code(double a, double b) {
return ((b * b) * (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) * (4.0d0 + (b * b))) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((b * b) * (4.0 + (b * b))) + -1.0;
}
def code(a, b): return ((b * b) * (4.0 + (b * b))) + -1.0
function code(a, b) return Float64(Float64(Float64(b * b) * Float64(4.0 + Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((b * b) * (4.0 + (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right) + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around 0 75.7%
unpow275.7%
Simplified75.7%
+-commutative75.7%
unpow275.7%
distribute-rgt-out75.7%
Applied egg-rr75.7%
Final simplification75.7%
(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(b * Float64(b * 4.0)) + -1.0) end
function tmp = code(a, b) tmp = (b * (b * 4.0)) + -1.0; end
code[a_, b_] := N[(N[(b * N[(b * 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
b \cdot \left(b \cdot 4\right) + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around 0 75.7%
unpow275.7%
Simplified75.7%
Taylor expanded in b around 0 54.2%
unpow254.2%
*-commutative54.2%
associate-*r*54.2%
Simplified54.2%
Final simplification54.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%
Taylor expanded in a around 0 75.7%
unpow275.7%
Simplified75.7%
Taylor expanded in b around 0 75.7%
unpow275.7%
metadata-eval75.7%
pow-plus75.7%
unpow375.7%
associate-*r*75.7%
distribute-rgt-in75.7%
associate-*l*75.7%
+-commutative75.7%
fma-udef75.7%
Simplified75.7%
Taylor expanded in b around inf 75.1%
Taylor expanded in b around 0 26.5%
Final simplification26.5%
herbie shell --seed 2023291
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))