
(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 4 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.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 3 a))))) Initial program 0.0%
associate--l+0.0%
fma-def0.0%
distribute-rgt-in0.0%
sqr-neg0.0%
distribute-rgt-in0.0%
fma-def5.1%
sqr-neg5.1%
+-commutative5.1%
Simplified5.1%
Taylor expanded in a around inf 98.4%
Final simplification99.5%
(FPCore (a b) :precision binary64 (if (or (<= a -0.0003) (not (<= a 5.5e-5))) (pow a 4.0) (+ (* 4.0 (* (* a a) (- 1.0 a))) -1.0)))
double code(double a, double b) {
double tmp;
if ((a <= -0.0003) || !(a <= 5.5e-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 <= (-0.0003d0)) .or. (.not. (a <= 5.5d-5))) 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 <= -0.0003) || !(a <= 5.5e-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 <= -0.0003) or not (a <= 5.5e-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 <= -0.0003) || !(a <= 5.5e-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 <= -0.0003) || ~((a <= 5.5e-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, -0.0003], N[Not[LessEqual[a, 5.5e-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 -0.0003 \lor \neg \left(a \leq 5.5 \cdot 10^{-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 < -2.99999999999999974e-4 or 5.5000000000000002e-5 < a Initial program 53.0%
associate--l+53.0%
fma-def53.0%
distribute-rgt-in53.0%
sqr-neg53.0%
distribute-rgt-in53.0%
fma-def55.4%
sqr-neg55.4%
+-commutative55.4%
Simplified55.4%
Taylor expanded in a around inf 87.2%
if -2.99999999999999974e-4 < a < 5.5000000000000002e-5Initial program 99.9%
associate--l+99.9%
fma-def99.9%
distribute-rgt-in99.9%
sqr-neg99.9%
distribute-rgt-in99.9%
fma-def99.9%
sqr-neg99.9%
+-commutative99.9%
Simplified99.9%
fma-def99.9%
add-cube-cbrt99.8%
associate-*l*99.8%
unpow299.8%
cbrt-prod99.9%
fma-def99.9%
fma-def99.9%
pow299.9%
add-sqr-sqrt99.9%
pow299.9%
fma-def99.9%
hypot-def99.9%
Applied egg-rr96.3%
*-commutative96.3%
metadata-eval96.3%
pow-sqr96.3%
unpow296.3%
unpow296.3%
pow-sqr96.3%
metadata-eval96.3%
pow-sqr96.3%
metadata-eval96.3%
pow-sqr96.3%
metadata-eval96.3%
Simplified96.3%
Taylor expanded in a around 0 96.2%
unpow1/396.3%
Simplified96.3%
Taylor expanded in b around 0 54.8%
pow254.8%
Applied egg-rr54.8%
Final simplification70.8%
(FPCore (a b) :precision binary64 (if (<= b 0.012) (+ (* 4.0 (* (* a a) (- 1.0 a))) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 0.012) {
tmp = (4.0 * ((a * a) * (1.0 - a))) + -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 <= 0.012d0) then
tmp = (4.0d0 * ((a * a) * (1.0d0 - a))) + (-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 <= 0.012) {
tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 0.012: tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 0.012) tmp = Float64(Float64(4.0 * Float64(Float64(a * a) * Float64(1.0 - a))) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 0.012) tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 0.012], N[(N[(4.0 * N[(N[(a * a), $MachinePrecision] * N[(1.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.012:\\
\;\;\;\;4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right)\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 0.012Initial program 83.7%
associate--l+83.7%
fma-def83.7%
distribute-rgt-in83.7%
sqr-neg83.7%
distribute-rgt-in83.7%
fma-def85.3%
sqr-neg85.3%
+-commutative85.3%
Simplified85.3%
fma-def85.3%
add-cube-cbrt85.2%
associate-*l*85.2%
unpow285.2%
cbrt-prod85.2%
fma-def85.2%
fma-def85.2%
pow285.2%
add-sqr-sqrt85.2%
pow285.2%
fma-def85.2%
hypot-def85.2%
Applied egg-rr79.5%
*-commutative79.5%
metadata-eval79.5%
pow-sqr79.5%
unpow279.5%
unpow279.5%
pow-sqr79.5%
metadata-eval79.5%
pow-sqr79.5%
metadata-eval79.5%
pow-sqr79.5%
metadata-eval79.5%
Simplified79.5%
Taylor expanded in a around 0 70.1%
unpow1/370.2%
Simplified70.2%
Taylor expanded in b around 0 55.3%
pow255.3%
Applied egg-rr55.3%
if 0.012 < b Initial program 56.2%
associate--l+56.2%
fma-def56.2%
distribute-rgt-in56.2%
sqr-neg56.2%
distribute-rgt-in56.2%
fma-def56.2%
sqr-neg56.2%
+-commutative56.2%
Simplified56.2%
Taylor expanded in b around inf 86.7%
Final simplification63.1%
(FPCore (a b) :precision binary64 (+ (* 4.0 (* (* a a) (- 1.0 a))) -1.0))
double code(double a, double b) {
return (4.0 * ((a * a) * (1.0 - a))) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (4.0d0 * ((a * a) * (1.0d0 - a))) + (-1.0d0)
end function
public static double code(double a, double b) {
return (4.0 * ((a * a) * (1.0 - a))) + -1.0;
}
def code(a, b): return (4.0 * ((a * a) * (1.0 - a))) + -1.0
function code(a, b) return Float64(Float64(4.0 * Float64(Float64(a * a) * Float64(1.0 - a))) + -1.0) end
function tmp = code(a, b) tmp = (4.0 * ((a * a) * (1.0 - a))) + -1.0; end
code[a_, b_] := N[(N[(4.0 * N[(N[(a * a), $MachinePrecision] * N[(1.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right)\right) + -1
\end{array}
Initial program 76.8%
associate--l+76.8%
fma-def76.8%
distribute-rgt-in76.8%
sqr-neg76.8%
distribute-rgt-in76.8%
fma-def78.0%
sqr-neg78.0%
+-commutative78.0%
Simplified78.0%
fma-def78.0%
add-cube-cbrt77.8%
associate-*l*77.8%
unpow277.8%
cbrt-prod77.9%
fma-def77.9%
fma-def77.9%
pow277.9%
add-sqr-sqrt77.9%
pow277.9%
fma-def77.9%
hypot-def77.9%
Applied egg-rr71.9%
*-commutative71.9%
metadata-eval71.9%
pow-sqr71.9%
unpow271.9%
unpow271.9%
pow-sqr71.9%
metadata-eval71.9%
pow-sqr71.9%
metadata-eval71.9%
pow-sqr71.9%
metadata-eval71.9%
Simplified71.9%
Taylor expanded in a around 0 64.6%
unpow1/364.7%
Simplified64.7%
Taylor expanded in b around 0 46.4%
pow246.4%
Applied egg-rr46.4%
Final simplification46.4%
herbie shell --seed 2024019
(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))