
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (+ 1.0 a)) (* (* b b) (- 1.0 (* 3.0 a)))))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 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 * (((a * a) * (1.0d0 + a)) + ((b * b) * (1.0d0 - (3.0d0 * a)))))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 + a)) + Float64(Float64(b * b) * Float64(1.0 - Float64(3.0 * a)))))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 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[(N[(N[(a * a), $MachinePrecision] * N[(1.0 + a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(3.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\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 (+ (* (* a a) (+ 1.0 a)) (* (* b b) (- 1.0 (* 3.0 a)))))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 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 * (((a * a) * (1.0d0 + a)) + ((b * b) * (1.0d0 - (3.0d0 * a)))))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 + a)) + Float64(Float64(b * b) * Float64(1.0 - Float64(3.0 * a)))))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 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[(N[(N[(a * a), $MachinePrecision] * N[(1.0 + a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(3.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1
\end{array}
(FPCore (a b) :precision binary64 (if (<= a -5e+107) (pow a 4.0) (+ (pow (hypot a b) 4.0) (+ (* 4.0 (* (pow a 2.0) (+ a 1.0))) -1.0))))
double code(double a, double b) {
double tmp;
if (a <= -5e+107) {
tmp = pow(a, 4.0);
} else {
tmp = pow(hypot(a, b), 4.0) + ((4.0 * (pow(a, 2.0) * (a + 1.0))) + -1.0);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -5e+107) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(Math.hypot(a, b), 4.0) + ((4.0 * (Math.pow(a, 2.0) * (a + 1.0))) + -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -5e+107: tmp = math.pow(a, 4.0) else: tmp = math.pow(math.hypot(a, b), 4.0) + ((4.0 * (math.pow(a, 2.0) * (a + 1.0))) + -1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -5e+107) tmp = a ^ 4.0; else tmp = Float64((hypot(a, b) ^ 4.0) + Float64(Float64(4.0 * Float64((a ^ 2.0) * Float64(a + 1.0))) + -1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -5e+107) tmp = a ^ 4.0; else tmp = (hypot(a, b) ^ 4.0) + ((4.0 * ((a ^ 2.0) * (a + 1.0))) + -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -5e+107], N[Power[a, 4.0], $MachinePrecision], N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(N[(4.0 * N[(N[Power[a, 2.0], $MachinePrecision] * N[(a + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5 \cdot 10^{+107}:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(4 \cdot \left({a}^{2} \cdot \left(a + 1\right)\right) + -1\right)\\
\end{array}
\end{array}
if a < -5.0000000000000002e107Initial program 0.0%
Simplified0.0%
Taylor expanded in a around inf 100.0%
if -5.0000000000000002e107 < a Initial program 87.7%
associate--l+87.7%
fma-def87.7%
distribute-rgt-in87.7%
sqr-neg87.7%
distribute-rgt-in87.7%
Simplified87.7%
fma-def87.7%
metadata-eval87.7%
sqrt-pow287.8%
hypot-udef87.8%
expm1-log1p-u86.1%
expm1-udef86.1%
Applied egg-rr86.1%
expm1-def86.1%
expm1-log1p87.8%
Simplified87.8%
Taylor expanded in b around 0 99.6%
Final simplification99.7%
(FPCore (a b) :precision binary64 (if (<= a -5e+107) (pow a 4.0) (+ (pow (hypot a b) 4.0) (+ (* 4.0 (pow a 3.0)) -1.0))))
double code(double a, double b) {
double tmp;
if (a <= -5e+107) {
tmp = pow(a, 4.0);
} else {
tmp = pow(hypot(a, b), 4.0) + ((4.0 * pow(a, 3.0)) + -1.0);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -5e+107) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(Math.hypot(a, b), 4.0) + ((4.0 * Math.pow(a, 3.0)) + -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -5e+107: tmp = math.pow(a, 4.0) else: tmp = math.pow(math.hypot(a, b), 4.0) + ((4.0 * math.pow(a, 3.0)) + -1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -5e+107) tmp = a ^ 4.0; else tmp = Float64((hypot(a, b) ^ 4.0) + Float64(Float64(4.0 * (a ^ 3.0)) + -1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -5e+107) tmp = a ^ 4.0; else tmp = (hypot(a, b) ^ 4.0) + ((4.0 * (a ^ 3.0)) + -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -5e+107], N[Power[a, 4.0], $MachinePrecision], N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(N[(4.0 * N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5 \cdot 10^{+107}:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \left(4 \cdot {a}^{3} + -1\right)\\
\end{array}
\end{array}
if a < -5.0000000000000002e107Initial program 0.0%
Simplified0.0%
Taylor expanded in a around inf 100.0%
if -5.0000000000000002e107 < a Initial program 87.7%
associate--l+87.7%
fma-def87.7%
distribute-rgt-in87.7%
sqr-neg87.7%
distribute-rgt-in87.7%
Simplified87.7%
fma-def87.7%
metadata-eval87.7%
sqrt-pow287.8%
hypot-udef87.8%
expm1-log1p-u86.1%
expm1-udef86.1%
Applied egg-rr86.1%
expm1-def86.1%
expm1-log1p87.8%
Simplified87.8%
Taylor expanded in b around 0 99.6%
Taylor expanded in a around inf 99.1%
Final simplification99.2%
(FPCore (a b)
:precision binary64
(let* ((t_0
(+
(pow (+ (* a a) (* b b)) 2.0)
(* 4.0 (+ (* (+ a 1.0) (* a a)) (* (* b b) (- 1.0 (* a 3.0))))))))
(if (<= t_0 INFINITY) (+ t_0 -1.0) (* (pow a 3.0) (+ a 4.0)))))
double code(double a, double b) {
double t_0 = pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a + 1.0) * (a * a)) + ((b * b) * (1.0 - (a * 3.0)))));
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0 + -1.0;
} else {
tmp = pow(a, 3.0) * (a + 4.0);
}
return tmp;
}
public static double code(double a, double b) {
double t_0 = Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a + 1.0) * (a * a)) + ((b * b) * (1.0 - (a * 3.0)))));
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0 + -1.0;
} else {
tmp = Math.pow(a, 3.0) * (a + 4.0);
}
return tmp;
}
def code(a, b): t_0 = math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a + 1.0) * (a * a)) + ((b * b) * (1.0 - (a * 3.0))))) tmp = 0 if t_0 <= math.inf: tmp = t_0 + -1.0 else: tmp = math.pow(a, 3.0) * (a + 4.0) return tmp
function code(a, b) t_0 = Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a + 1.0) * Float64(a * a)) + Float64(Float64(b * b) * Float64(1.0 - Float64(a * 3.0)))))) tmp = 0.0 if (t_0 <= Inf) tmp = Float64(t_0 + -1.0); else tmp = Float64((a ^ 3.0) * Float64(a + 4.0)); end return tmp end
function tmp_2 = code(a, b) t_0 = (((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a + 1.0) * (a * a)) + ((b * b) * (1.0 - (a * 3.0))))); tmp = 0.0; if (t_0 <= Inf) tmp = t_0 + -1.0; else tmp = (a ^ 3.0) * (a + 4.0); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a + 1.0), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], N[(t$95$0 + -1.0), $MachinePrecision], N[(N[Power[a, 3.0], $MachinePrecision] * N[(a + 4.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a + 1\right) \cdot \left(a \cdot a\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right)\\
\mathbf{if}\;t_0 \leq \infty:\\
\;\;\;\;t_0 + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{3} \cdot \left(a + 4\right)\\
\end{array}
\end{array}
if (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (+.f64 1 a)) (*.f64 (*.f64 b b) (-.f64 1 (*.f64 3 a)))))) < +inf.0Initial program 99.8%
if +inf.0 < (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (+.f64 1 a)) (*.f64 (*.f64 b b) (-.f64 1 (*.f64 3 a)))))) Initial program 0.0%
associate--l+0.0%
fma-def0.0%
distribute-rgt-in0.0%
sqr-neg0.0%
distribute-rgt-in0.0%
Simplified8.8%
fma-def8.8%
metadata-eval8.8%
sqrt-pow28.8%
hypot-udef8.8%
expm1-log1p-u8.8%
expm1-udef8.8%
Applied egg-rr8.8%
expm1-def8.8%
expm1-log1p8.8%
Simplified8.8%
Taylor expanded in b around 0 38.2%
Taylor expanded in a around inf 38.2%
Taylor expanded in a around inf 35.4%
metadata-eval35.4%
pow-plus35.4%
*-commutative35.4%
distribute-rgt-out97.2%
Simplified97.2%
Final simplification99.1%
(FPCore (a b) :precision binary64 (if (or (<= a -1.5e+55) (not (<= a 2.8e+20))) (pow a 4.0) (+ (pow b 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if ((a <= -1.5e+55) || !(a <= 2.8e+20)) {
tmp = pow(a, 4.0);
} else {
tmp = pow(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 ((a <= (-1.5d+55)) .or. (.not. (a <= 2.8d+20))) then
tmp = a ** 4.0d0
else
tmp = (b ** 4.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a <= -1.5e+55) || !(a <= 2.8e+20)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -1.5e+55) or not (a <= 2.8e+20): tmp = math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if ((a <= -1.5e+55) || !(a <= 2.8e+20)) tmp = a ^ 4.0; else tmp = Float64((b ^ 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -1.5e+55) || ~((a <= 2.8e+20))) tmp = a ^ 4.0; else tmp = (b ^ 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -1.5e+55], N[Not[LessEqual[a, 2.8e+20]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], N[(N[Power[b, 4.0], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.5 \cdot 10^{+55} \lor \neg \left(a \leq 2.8 \cdot 10^{+20}\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + -1\\
\end{array}
\end{array}
if a < -1.50000000000000008e55 or 2.8e20 < a Initial program 38.2%
Simplified43.0%
Taylor expanded in a around inf 99.1%
if -1.50000000000000008e55 < a < 2.8e20Initial program 98.5%
associate--l+98.5%
fma-def98.5%
distribute-rgt-in98.5%
sqr-neg98.5%
distribute-rgt-in98.5%
Simplified98.5%
fma-def98.5%
metadata-eval98.5%
sqrt-pow298.6%
hypot-udef98.6%
expm1-log1p-u97.0%
expm1-udef97.0%
Applied egg-rr97.0%
expm1-def97.0%
expm1-log1p98.6%
Simplified98.6%
Taylor expanded in b around 0 99.4%
Taylor expanded in a around 0 95.3%
Final simplification96.9%
(FPCore (a b) :precision binary64 (if (or (<= a -2.9e+54) (not (<= a 9.2e+19))) (pow a 4.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((a <= -2.9e+54) || !(a <= 9.2e+19)) {
tmp = 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 ((a <= (-2.9d+54)) .or. (.not. (a <= 9.2d+19))) then
tmp = 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 ((a <= -2.9e+54) || !(a <= 9.2e+19)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -2.9e+54) or not (a <= 9.2e+19): tmp = math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if ((a <= -2.9e+54) || !(a <= 9.2e+19)) tmp = a ^ 4.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -2.9e+54) || ~((a <= 9.2e+19))) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -2.9e+54], N[Not[LessEqual[a, 9.2e+19]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.9 \cdot 10^{+54} \lor \neg \left(a \leq 9.2 \cdot 10^{+19}\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if a < -2.8999999999999999e54 or 9.2e19 < a Initial program 38.2%
Simplified43.0%
Taylor expanded in a around inf 99.1%
if -2.8999999999999999e54 < a < 9.2e19Initial program 98.5%
Simplified98.6%
Taylor expanded in b around inf 57.6%
Final simplification75.0%
(FPCore (a b) :precision binary64 (pow a 4.0))
double code(double a, double b) {
return pow(a, 4.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = a ** 4.0d0
end function
public static double code(double a, double b) {
return Math.pow(a, 4.0);
}
def code(a, b): return math.pow(a, 4.0)
function code(a, b) return a ^ 4.0 end
function tmp = code(a, b) tmp = a ^ 4.0; end
code[a_, b_] := N[Power[a, 4.0], $MachinePrecision]
\begin{array}{l}
\\
{a}^{4}
\end{array}
Initial program 73.3%
Simplified75.4%
Taylor expanded in a around inf 44.1%
Final simplification44.1%
herbie shell --seed 2023309
(FPCore (a b)
:name "Bouland and Aaronson, Equation (25)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (+ 1.0 a)) (* (* b b) (- 1.0 (* 3.0 a)))))) 1.0))