
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ 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) * (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) * (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) * (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) * (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(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) * (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[(3.0 + a), $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(3 + 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) (+ 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) * (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) * (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) * (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) * (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(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) * (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[(3.0 + a), $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(3 + 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) (- 1.0 a)) (* (* b b) (+ 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) * (1.0 - a)) + ((b * b) * (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) * (1.0 - a)) + ((b * b) * (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) * (1.0 - a)) + ((b * b) * (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(1.0 - a)) + Float64(Float64(b * b) * 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) * (1.0 - a)) + ((b * b) * (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[(1.0 - a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(a + 3.0), $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(1 - a\right) + \left(b \cdot b\right) \cdot \left(a + 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 3 a))))) < +inf.0Initial program 99.9%
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 3 a))))) Initial program 0.0%
associate--l+0.0%
sqr-pow0.0%
sqr-pow0.0%
fma-define0.0%
sqr-neg0.0%
Simplified4.5%
Taylor expanded in a around inf 97.1%
Final simplification99.2%
(FPCore (a b) :precision binary64 (if (or (<= a -4.8) (not (<= a 2.5))) (pow a 4.0) (+ (* 4.0 (* (* a a) (- 1.0 a))) -1.0)))
double code(double a, double b) {
double tmp;
if ((a <= -4.8) || !(a <= 2.5)) {
tmp = pow(a, 4.0);
} else {
tmp = (4.0 * ((a * a) * (1.0 - a))) + -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 <= (-4.8d0)) .or. (.not. (a <= 2.5d0))) then
tmp = a ** 4.0d0
else
tmp = (4.0d0 * ((a * a) * (1.0d0 - a))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a <= -4.8) || !(a <= 2.5)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -4.8) or not (a <= 2.5): tmp = math.pow(a, 4.0) else: tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0 return tmp
function code(a, b) tmp = 0.0 if ((a <= -4.8) || !(a <= 2.5)) tmp = a ^ 4.0; else tmp = Float64(Float64(4.0 * Float64(Float64(a * a) * Float64(1.0 - a))) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -4.8) || ~((a <= 2.5))) tmp = a ^ 4.0; else tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -4.8], N[Not[LessEqual[a, 2.5]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], N[(N[(4.0 * N[(N[(a * a), $MachinePrecision] * N[(1.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.8 \lor \neg \left(a \leq 2.5\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right)\right) + -1\\
\end{array}
\end{array}
if a < -4.79999999999999982 or 2.5 < a Initial program 44.0%
associate--l+44.0%
sqr-pow44.0%
sqr-pow44.0%
fma-define44.0%
sqr-neg44.0%
Simplified46.5%
Taylor expanded in a around inf 89.3%
if -4.79999999999999982 < a < 2.5Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
fma-define99.9%
sqr-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 51.7%
pow251.2%
Applied egg-rr51.7%
Taylor expanded in a around 0 51.3%
+-commutative51.3%
metadata-eval51.3%
cancel-sign-sub-inv51.3%
unpow351.3%
unpow251.3%
associate-*l*51.3%
unsub-neg51.3%
*-rgt-identity51.3%
distribute-rgt-neg-out51.3%
distribute-lft-in51.3%
sub-neg51.3%
associate-*r*51.3%
Simplified51.3%
pow251.2%
Applied egg-rr51.3%
Final simplification68.8%
(FPCore (a b) :precision binary64 (if (<= b 1.8e+18) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 1.8e+18) {
tmp = pow(a, 4.0) + -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 <= 1.8d+18) then
tmp = (a ** 4.0d0) + (-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 <= 1.8e+18) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.8e+18: tmp = math.pow(a, 4.0) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.8e+18) tmp = Float64((a ^ 4.0) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.8e+18) tmp = (a ^ 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.8e+18], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.8 \cdot 10^{+18}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 1.8e18Initial program 76.1%
associate--l+76.1%
sqr-pow76.1%
sqr-pow76.1%
fma-define76.1%
sqr-neg76.1%
Simplified76.6%
Taylor expanded in b around 0 64.3%
Taylor expanded in a around inf 79.8%
if 1.8e18 < b Initial program 68.2%
associate--l+68.2%
sqr-pow68.2%
sqr-pow68.2%
fma-define68.2%
sqr-neg68.2%
Simplified71.4%
Taylor expanded in b around inf 95.6%
Final simplification83.7%
(FPCore (a b) :precision binary64 (if (<= b 1.8e+18) (+ (* (* a a) 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 1.8e+18) {
tmp = ((a * a) * 4.0) + -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 <= 1.8d+18) then
tmp = ((a * a) * 4.0d0) + (-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 <= 1.8e+18) {
tmp = ((a * a) * 4.0) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.8e+18: tmp = ((a * a) * 4.0) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.8e+18) tmp = Float64(Float64(Float64(a * a) * 4.0) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.8e+18) tmp = ((a * a) * 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.8e+18], N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.8 \cdot 10^{+18}:\\
\;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 1.8e18Initial program 76.1%
associate--l+76.1%
sqr-pow76.1%
sqr-pow76.1%
fma-define76.1%
sqr-neg76.1%
Simplified76.6%
Taylor expanded in b around 0 64.3%
Taylor expanded in a around 0 62.7%
pow262.7%
Applied egg-rr62.7%
if 1.8e18 < b Initial program 68.2%
associate--l+68.2%
sqr-pow68.2%
sqr-pow68.2%
fma-define68.2%
sqr-neg68.2%
Simplified71.4%
Taylor expanded in b around inf 95.6%
Final simplification70.8%
(FPCore (a b) :precision binary64 (if (<= a 2.5) (+ (* 4.0 (* (* a a) (- 1.0 a))) -1.0) (+ (* (* a a) 4.0) -1.0)))
double code(double a, double b) {
double tmp;
if (a <= 2.5) {
tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0;
} else {
tmp = ((a * a) * 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 <= 2.5d0) then
tmp = (4.0d0 * ((a * a) * (1.0d0 - a))) + (-1.0d0)
else
tmp = ((a * a) * 4.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 2.5) {
tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0;
} else {
tmp = ((a * a) * 4.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 2.5: tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0 else: tmp = ((a * a) * 4.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= 2.5) tmp = Float64(Float64(4.0 * Float64(Float64(a * a) * Float64(1.0 - a))) + -1.0); else tmp = Float64(Float64(Float64(a * a) * 4.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 2.5) tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0; else tmp = ((a * a) * 4.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 2.5], N[(N[(4.0 * N[(N[(a * a), $MachinePrecision] * N[(1.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.5:\\
\;\;\;\;4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right)\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\
\end{array}
\end{array}
if a < 2.5Initial program 88.3%
associate--l+88.3%
sqr-pow88.3%
sqr-pow88.3%
fma-define88.3%
sqr-neg88.3%
Simplified88.3%
Taylor expanded in b around 0 62.4%
pow253.1%
Applied egg-rr62.4%
Taylor expanded in a around 0 55.8%
+-commutative55.8%
metadata-eval55.8%
cancel-sign-sub-inv55.8%
unpow355.8%
unpow255.8%
associate-*l*55.8%
unsub-neg55.8%
*-rgt-identity55.8%
distribute-rgt-neg-out55.8%
distribute-lft-in55.8%
sub-neg55.8%
associate-*r*55.8%
Simplified55.8%
pow253.1%
Applied egg-rr55.8%
if 2.5 < a Initial program 33.3%
associate--l+33.3%
sqr-pow33.3%
sqr-pow33.3%
fma-define33.3%
sqr-neg33.3%
Simplified37.8%
Taylor expanded in b around 0 22.8%
Taylor expanded in a around 0 55.7%
pow255.7%
Applied egg-rr55.7%
Final simplification55.8%
(FPCore (a b) :precision binary64 (+ (* (* a a) 4.0) -1.0))
double code(double a, double b) {
return ((a * a) * 4.0) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((a * a) * 4.0d0) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((a * a) * 4.0) + -1.0;
}
def code(a, b): return ((a * a) * 4.0) + -1.0
function code(a, b) return Float64(Float64(Float64(a * a) * 4.0) + -1.0) end
function tmp = code(a, b) tmp = ((a * a) * 4.0) + -1.0; end
code[a_, b_] := N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(a \cdot a\right) \cdot 4 + -1
\end{array}
Initial program 74.1%
associate--l+74.1%
sqr-pow74.1%
sqr-pow74.1%
fma-define74.1%
sqr-neg74.1%
Simplified75.3%
Taylor expanded in b around 0 52.2%
Taylor expanded in a around 0 53.8%
pow253.8%
Applied egg-rr53.8%
Final simplification53.8%
herbie shell --seed 2024041
(FPCore (a b)
:name "Bouland and Aaronson, Equation (24)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ 3.0 a))))) 1.0))