
(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%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (+ -1.0 (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b)))))
double code(double a, double b) {
return -1.0 + (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (b * b)))
end function
public static double code(double a, double b) {
return -1.0 + (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)));
}
def code(a, b): return -1.0 + (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)))
function code(a, b) return Float64(-1.0 + Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b)))) end
function tmp = code(a, b) tmp = -1.0 + ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))); end
code[a_, b_] := N[(-1.0 + 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]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e+28) (+ -1.0 (+ (* 4.0 (* b b)) (pow a 4.0))) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e+28) {
tmp = -1.0 + ((4.0 * (b * b)) + pow(a, 4.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+28) then
tmp = (-1.0d0) + ((4.0d0 * (b * b)) + (a ** 4.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+28) {
tmp = -1.0 + ((4.0 * (b * b)) + Math.pow(a, 4.0));
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2e+28: tmp = -1.0 + ((4.0 * (b * b)) + math.pow(a, 4.0)) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2e+28) tmp = Float64(-1.0 + Float64(Float64(4.0 * Float64(b * b)) + (a ^ 4.0))); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2e+28) tmp = -1.0 + ((4.0 * (b * b)) + (a ^ 4.0)); else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e+28], N[(-1.0 + N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2 \cdot 10^{+28}:\\
\;\;\;\;-1 + \left(4 \cdot \left(b \cdot b\right) + {a}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 1.99999999999999992e28Initial program 99.9%
Taylor expanded in a around inf 99.3%
if 1.99999999999999992e28 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 92.9%
Taylor expanded in b around inf 92.9%
Final simplification96.3%
(FPCore (a b) :precision binary64 (fma (* b b) (+ 4.0 (* b b)) -1.0))
double code(double a, double b) {
return fma((b * b), (4.0 + (b * b)), -1.0);
}
function code(a, b) return fma(Float64(b * b), Float64(4.0 + Float64(b * b)), -1.0) end
code[a_, b_] := N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b \cdot b, 4 + b \cdot b, -1\right)
\end{array}
Initial program 99.9%
Taylor expanded in a around 0 66.6%
+-commutative66.6%
sqr-pow66.5%
metadata-eval66.5%
pow266.5%
metadata-eval66.5%
pow266.5%
distribute-rgt-out66.5%
fma-neg66.5%
metadata-eval66.5%
Applied egg-rr66.5%
Final simplification66.5%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e-7) (+ -1.0 (* 4.0 (* b b))) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e-7) {
tmp = -1.0 + (4.0 * (b * b));
} 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-7) then
tmp = (-1.0d0) + (4.0d0 * (b * b))
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-7) {
tmp = -1.0 + (4.0 * (b * b));
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2e-7: tmp = -1.0 + (4.0 * (b * b)) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2e-7) tmp = Float64(-1.0 + Float64(4.0 * Float64(b * b))); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2e-7) tmp = -1.0 + (4.0 * (b * b)); else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e-7], N[(-1.0 + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2 \cdot 10^{-7}:\\
\;\;\;\;-1 + 4 \cdot \left(b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 1.9999999999999999e-7Initial program 99.9%
Taylor expanded in a around 0 46.2%
Taylor expanded in b around 0 46.1%
fma-neg46.1%
unpow246.1%
metadata-eval46.1%
Simplified46.1%
fma-udef46.1%
*-commutative46.1%
Applied egg-rr46.1%
if 1.9999999999999999e-7 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 87.9%
Taylor expanded in b around inf 87.9%
Final simplification66.5%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1.2e-5) -1.0 (* 4.0 (* b b))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1.2e-5) {
tmp = -1.0;
} else {
tmp = 4.0 * (b * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b * b) <= 1.2d-5) then
tmp = -1.0d0
else
tmp = 4.0d0 * (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 1.2e-5) {
tmp = -1.0;
} else {
tmp = 4.0 * (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1.2e-5: tmp = -1.0 else: tmp = 4.0 * (b * b) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1.2e-5) tmp = -1.0; else tmp = Float64(4.0 * Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1.2e-5) tmp = -1.0; else tmp = 4.0 * (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1.2e-5], -1.0, N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 1.2 \cdot 10^{-5}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 1.2e-5Initial program 99.9%
Taylor expanded in a around 0 46.2%
Taylor expanded in b around 0 45.5%
if 1.2e-5 < (*.f64 b b) Initial program 99.9%
Taylor expanded in a around 0 87.9%
Taylor expanded in b around inf 87.9%
unpow287.9%
metadata-eval87.9%
pow-plus87.9%
unpow387.9%
associate-*r*87.8%
distribute-rgt-in87.8%
+-commutative87.8%
fma-udef87.8%
Simplified87.8%
Taylor expanded in b around 0 55.0%
unpow255.0%
Simplified55.0%
Final simplification50.1%
(FPCore (a b) :precision binary64 (+ -1.0 (* 4.0 (* b b))))
double code(double a, double b) {
return -1.0 + (4.0 * (b * b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + (4.0d0 * (b * b))
end function
public static double code(double a, double b) {
return -1.0 + (4.0 * (b * b));
}
def code(a, b): return -1.0 + (4.0 * (b * b))
function code(a, b) return Float64(-1.0 + Float64(4.0 * Float64(b * b))) end
function tmp = code(a, b) tmp = -1.0 + (4.0 * (b * b)); end
code[a_, b_] := N[(-1.0 + N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + 4 \cdot \left(b \cdot b\right)
\end{array}
Initial program 99.9%
Taylor expanded in a around 0 66.6%
Taylor expanded in b around 0 50.4%
fma-neg50.4%
unpow250.4%
metadata-eval50.4%
Simplified50.4%
fma-udef50.4%
*-commutative50.4%
Applied egg-rr50.4%
Final simplification50.4%
(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 66.6%
Taylor expanded in b around 0 23.7%
Final simplification23.7%
herbie shell --seed 2023187
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))