
(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 6 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 (+ (fma b (* b 4.0) (pow (hypot a b) 4.0)) -1.0))
double code(double a, double b) {
return fma(b, (b * 4.0), pow(hypot(a, b), 4.0)) + -1.0;
}
function code(a, b) return Float64(fma(b, Float64(b * 4.0), (hypot(a, b) ^ 4.0)) + -1.0) end
code[a_, b_] := N[(N[(b * N[(b * 4.0), $MachinePrecision] + N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b, b \cdot 4, {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4}\right) + -1
\end{array}
Initial program 99.9%
associate--l+99.9%
sqr-neg99.9%
sqr-neg99.9%
associate--l+99.9%
sub-neg99.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 6.6e-5) -1.0 (* b (* b (+ 4.0 (pow b 2.0))))))
double code(double a, double b) {
double tmp;
if (b <= 6.6e-5) {
tmp = -1.0;
} else {
tmp = b * (b * (4.0 + pow(b, 2.0)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 6.6d-5) then
tmp = -1.0d0
else
tmp = b * (b * (4.0d0 + (b ** 2.0d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 6.6e-5) {
tmp = -1.0;
} else {
tmp = b * (b * (4.0 + Math.pow(b, 2.0)));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6.6e-5: tmp = -1.0 else: tmp = b * (b * (4.0 + math.pow(b, 2.0))) return tmp
function code(a, b) tmp = 0.0 if (b <= 6.6e-5) tmp = -1.0; else tmp = Float64(b * Float64(b * Float64(4.0 + (b ^ 2.0)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 6.6e-5) tmp = -1.0; else tmp = b * (b * (4.0 + (b ^ 2.0))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6.6e-5], -1.0, N[(b * N[(b * N[(4.0 + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.6 \cdot 10^{-5}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(b \cdot \left(4 + {b}^{2}\right)\right)\\
\end{array}
\end{array}
if b < 6.6000000000000005e-5Initial program 99.9%
associate--l+99.9%
sqr-neg99.9%
sqr-neg99.9%
associate--l+99.9%
sub-neg99.9%
Simplified100.0%
Taylor expanded in a around 0 61.8%
Taylor expanded in b around 0 26.8%
if 6.6000000000000005e-5 < b Initial program 99.9%
associate--l+99.9%
sqr-neg99.9%
sqr-neg99.9%
associate--l+99.9%
sub-neg99.9%
Simplified100.0%
Taylor expanded in a around 0 90.0%
Taylor expanded in b around inf 90.1%
+-commutative90.1%
*-commutative90.1%
unpow290.1%
associate-*r*90.1%
metadata-eval90.1%
pow-prod-up90.1%
unpow290.1%
associate-*r*90.1%
unpow290.1%
*-commutative90.1%
distribute-lft-out90.1%
pow390.1%
*-commutative90.1%
Applied egg-rr90.1%
unpow390.1%
distribute-rgt-out90.1%
+-commutative90.1%
unpow290.1%
Applied egg-rr90.1%
Final simplification43.6%
(FPCore (a b) :precision binary64 (if (<= b 6.6e-5) -1.0 (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 6.6e-5) {
tmp = -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 <= 6.6d-5) then
tmp = -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 <= 6.6e-5) {
tmp = -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6.6e-5: tmp = -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 6.6e-5) tmp = -1.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 6.6e-5) tmp = -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6.6e-5], -1.0, N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.6 \cdot 10^{-5}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 6.6000000000000005e-5Initial program 99.9%
associate--l+99.9%
sqr-neg99.9%
sqr-neg99.9%
associate--l+99.9%
sub-neg99.9%
Simplified100.0%
Taylor expanded in a around 0 61.8%
Taylor expanded in b around 0 26.8%
if 6.6000000000000005e-5 < b Initial program 99.9%
associate--l+99.9%
sqr-neg99.9%
sqr-neg99.9%
associate--l+99.9%
sub-neg99.9%
Simplified100.0%
Taylor expanded in a around 0 90.0%
Taylor expanded in b around inf 90.1%
Taylor expanded in b around inf 89.7%
Final simplification43.5%
(FPCore (a b) :precision binary64 (if (<= b 6.6e-5) -1.0 (* b (* b 4.0))))
double code(double a, double b) {
double tmp;
if (b <= 6.6e-5) {
tmp = -1.0;
} else {
tmp = b * (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 <= 6.6d-5) then
tmp = -1.0d0
else
tmp = b * (b * 4.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 6.6e-5) {
tmp = -1.0;
} else {
tmp = b * (b * 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 6.6e-5: tmp = -1.0 else: tmp = b * (b * 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 6.6e-5) tmp = -1.0; else tmp = Float64(b * Float64(b * 4.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 6.6e-5) tmp = -1.0; else tmp = b * (b * 4.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 6.6e-5], -1.0, N[(b * N[(b * 4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.6 \cdot 10^{-5}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(b \cdot 4\right)\\
\end{array}
\end{array}
if b < 6.6000000000000005e-5Initial program 99.9%
associate--l+99.9%
sqr-neg99.9%
sqr-neg99.9%
associate--l+99.9%
sub-neg99.9%
Simplified100.0%
Taylor expanded in a around 0 61.8%
Taylor expanded in b around 0 26.8%
if 6.6000000000000005e-5 < b Initial program 99.9%
associate--l+99.9%
sqr-neg99.9%
sqr-neg99.9%
associate--l+99.9%
sub-neg99.9%
Simplified100.0%
Taylor expanded in a around 0 90.0%
Taylor expanded in b around inf 90.1%
+-commutative90.1%
*-commutative90.1%
unpow290.1%
associate-*r*90.1%
metadata-eval90.1%
pow-prod-up90.1%
unpow290.1%
associate-*r*90.1%
unpow290.1%
*-commutative90.1%
distribute-lft-out90.1%
pow390.1%
*-commutative90.1%
Applied egg-rr90.1%
Taylor expanded in b around 0 51.8%
Final simplification33.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%
associate--l+99.9%
sqr-neg99.9%
sqr-neg99.9%
associate--l+99.9%
sub-neg99.9%
Simplified100.0%
Taylor expanded in a around 0 69.3%
Taylor expanded in b around 0 19.8%
Final simplification19.8%
herbie shell --seed 2023326
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))