
(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 5 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
(let* ((t_0
(+
(pow (+ (* a a) (* b b)) 2.0)
(* 4.0 (+ (* (* a a) (+ a 1.0)) (* (* b b) (- 1.0 (* a 3.0))))))))
(if (<= t_0 INFINITY) (+ t_0 -1.0) (pow a 4.0))))
double code(double a, double b) {
double t_0 = pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))));
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0 + -1.0;
} else {
tmp = pow(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 * a) * (a + 1.0)) + ((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, 4.0);
}
return tmp;
}
def code(a, b): t_0 = math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0))))) tmp = 0 if t_0 <= math.inf: tmp = t_0 + -1.0 else: tmp = math.pow(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 * a) * Float64(a + 1.0)) + 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 = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) t_0 = (((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0))))); tmp = 0.0; if (t_0 <= Inf) tmp = t_0 + -1.0; else tmp = 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 * a), $MachinePrecision] * N[(a + 1.0), $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[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\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}^{4}\\
\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%
Simplified7.4%
Taylor expanded in a around inf 98.6%
Final simplification99.5%
(FPCore (a b)
:precision binary64
(if (<= b 1.7e-286)
(pow a 4.0)
(if (<= b 4.3e-249)
-1.0
(if (<= b 2.05e-213)
(pow a 4.0)
(if (<= b 1.15e-135)
-1.0
(if (<= b 6300000000.0) (pow a 4.0) (pow b 4.0)))))))
double code(double a, double b) {
double tmp;
if (b <= 1.7e-286) {
tmp = pow(a, 4.0);
} else if (b <= 4.3e-249) {
tmp = -1.0;
} else if (b <= 2.05e-213) {
tmp = pow(a, 4.0);
} else if (b <= 1.15e-135) {
tmp = -1.0;
} else if (b <= 6300000000.0) {
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 (b <= 1.7d-286) then
tmp = a ** 4.0d0
else if (b <= 4.3d-249) then
tmp = -1.0d0
else if (b <= 2.05d-213) then
tmp = a ** 4.0d0
else if (b <= 1.15d-135) then
tmp = -1.0d0
else if (b <= 6300000000.0d0) 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 (b <= 1.7e-286) {
tmp = Math.pow(a, 4.0);
} else if (b <= 4.3e-249) {
tmp = -1.0;
} else if (b <= 2.05e-213) {
tmp = Math.pow(a, 4.0);
} else if (b <= 1.15e-135) {
tmp = -1.0;
} else if (b <= 6300000000.0) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.7e-286: tmp = math.pow(a, 4.0) elif b <= 4.3e-249: tmp = -1.0 elif b <= 2.05e-213: tmp = math.pow(a, 4.0) elif b <= 1.15e-135: tmp = -1.0 elif b <= 6300000000.0: tmp = math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.7e-286) tmp = a ^ 4.0; elseif (b <= 4.3e-249) tmp = -1.0; elseif (b <= 2.05e-213) tmp = a ^ 4.0; elseif (b <= 1.15e-135) tmp = -1.0; elseif (b <= 6300000000.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.7e-286) tmp = a ^ 4.0; elseif (b <= 4.3e-249) tmp = -1.0; elseif (b <= 2.05e-213) tmp = a ^ 4.0; elseif (b <= 1.15e-135) tmp = -1.0; elseif (b <= 6300000000.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.7e-286], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 4.3e-249], -1.0, If[LessEqual[b, 2.05e-213], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 1.15e-135], -1.0, If[LessEqual[b, 6300000000.0], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.7 \cdot 10^{-286}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 4.3 \cdot 10^{-249}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 2.05 \cdot 10^{-213}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-135}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 6300000000:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 1.7000000000000001e-286 or 4.3000000000000002e-249 < b < 2.04999999999999987e-213 or 1.15e-135 < b < 6.3e9Initial program 74.7%
associate--l+74.7%
fma-def74.7%
distribute-rgt-in74.7%
sqr-neg74.7%
distribute-rgt-in74.7%
Simplified75.3%
Taylor expanded in a around inf 54.7%
if 1.7000000000000001e-286 < b < 4.3000000000000002e-249 or 2.04999999999999987e-213 < b < 1.15e-135Initial program 83.3%
associate--l+83.3%
fma-def83.3%
distribute-rgt-in83.3%
sqr-neg83.3%
distribute-rgt-in83.3%
Simplified83.3%
Taylor expanded in b around 0 83.3%
Taylor expanded in a around 0 74.2%
if 6.3e9 < b Initial program 65.4%
associate--l+65.4%
fma-def65.4%
distribute-rgt-in65.4%
sqr-neg65.4%
distribute-rgt-in65.4%
Simplified72.0%
Taylor expanded in b around inf 93.7%
Final simplification65.9%
(FPCore (a b) :precision binary64 (if (<= b 1800000000.0) (fma (* a 4.0) a -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 1800000000.0) {
tmp = fma((a * 4.0), a, -1.0);
} else {
tmp = pow(b, 4.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 1800000000.0) tmp = fma(Float64(a * 4.0), a, -1.0); else tmp = b ^ 4.0; end return tmp end
code[a_, b_] := If[LessEqual[b, 1800000000.0], N[(N[(a * 4.0), $MachinePrecision] * a + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1800000000:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 4, a, -1\right)\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 1.8e9Initial program 75.8%
associate--l+75.8%
fma-def75.8%
distribute-rgt-in75.8%
sqr-neg75.8%
distribute-rgt-in75.8%
Simplified76.3%
Taylor expanded in b around 0 64.7%
Taylor expanded in a around 0 63.1%
unpow263.1%
associate-*r*63.1%
fma-neg63.1%
metadata-eval63.1%
Applied egg-rr63.1%
if 1.8e9 < b Initial program 65.4%
associate--l+65.4%
fma-def65.4%
distribute-rgt-in65.4%
sqr-neg65.4%
distribute-rgt-in65.4%
Simplified72.0%
Taylor expanded in b around inf 93.7%
Final simplification70.4%
(FPCore (a b) :precision binary64 (if (or (<= a -2.4) (not (<= a 0.41))) (pow a 4.0) -1.0))
double code(double a, double b) {
double tmp;
if ((a <= -2.4) || !(a <= 0.41)) {
tmp = pow(a, 4.0);
} else {
tmp = -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 <= (-2.4d0)) .or. (.not. (a <= 0.41d0))) then
tmp = a ** 4.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a <= -2.4) || !(a <= 0.41)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -2.4) or not (a <= 0.41): tmp = math.pow(a, 4.0) else: tmp = -1.0 return tmp
function code(a, b) tmp = 0.0 if ((a <= -2.4) || !(a <= 0.41)) tmp = a ^ 4.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -2.4) || ~((a <= 0.41))) tmp = a ^ 4.0; else tmp = -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -2.4], N[Not[LessEqual[a, 0.41]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.4 \lor \neg \left(a \leq 0.41\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if a < -2.39999999999999991 or 0.409999999999999976 < a Initial program 50.3%
associate--l+50.3%
fma-def50.3%
distribute-rgt-in50.3%
sqr-neg50.3%
distribute-rgt-in50.3%
Simplified53.9%
Taylor expanded in a around inf 88.6%
if -2.39999999999999991 < a < 0.409999999999999976Initial program 99.8%
associate--l+99.8%
fma-def99.8%
distribute-rgt-in99.8%
sqr-neg99.8%
distribute-rgt-in99.8%
Simplified99.8%
Taylor expanded in b around 0 50.5%
Taylor expanded in a around 0 48.9%
Final simplification70.1%
(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 73.3%
associate--l+73.3%
fma-def73.3%
distribute-rgt-in73.3%
sqr-neg73.3%
distribute-rgt-in73.3%
Simplified75.2%
Taylor expanded in b around 0 54.6%
Taylor expanded in a around 0 23.1%
Final simplification23.1%
herbie shell --seed 2023314
(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))