
(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 -1.16e+71)
(pow a 4.0)
(+
(+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* b b) (* a (* a a)))))
-1.0)))
double code(double a, double b) {
double tmp;
if (a <= -1.16e+71) {
tmp = pow(a, 4.0);
} else {
tmp = (pow(((a * a) + (b * b)), 2.0) + (4.0 * ((b * b) + (a * (a * 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 <= (-1.16d+71)) then
tmp = a ** 4.0d0
else
tmp = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * ((b * b) + (a * (a * a))))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -1.16e+71) {
tmp = Math.pow(a, 4.0);
} else {
tmp = (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * ((b * b) + (a * (a * a))))) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.16e+71: tmp = math.pow(a, 4.0) else: tmp = (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * ((b * b) + (a * (a * a))))) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (a <= -1.16e+71) tmp = a ^ 4.0; else tmp = Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(b * b) + Float64(a * Float64(a * a))))) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.16e+71) tmp = a ^ 4.0; else tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * ((b * b) + (a * (a * a))))) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.16e+71], N[Power[a, 4.0], $MachinePrecision], N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(b * b), $MachinePrecision] + N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.16 \cdot 10^{+71}:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b + a \cdot \left(a \cdot a\right)\right)\right) + -1\\
\end{array}
\end{array}
if a < -1.1599999999999999e71Initial program 17.9%
associate--l+17.9%
+-commutative17.9%
+-commutative17.9%
sub-neg17.9%
associate-+l+17.9%
+-commutative17.9%
fma-define17.9%
Simplified17.9%
Taylor expanded in a around inf 100.0%
associate-*r/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if -1.1599999999999999e71 < a Initial program 83.9%
add-sqr-sqrt52.4%
sqrt-unprod69.8%
swap-sqr69.8%
metadata-eval69.8%
metadata-eval69.8%
swap-sqr69.8%
sqrt-unprod28.1%
add-sqr-sqrt96.5%
*-commutative96.5%
cancel-sign-sub-inv96.5%
Applied egg-rr96.5%
Taylor expanded in a around inf 95.9%
distribute-lft-neg-out95.9%
unsub-neg95.9%
Applied egg-rr95.9%
Taylor expanded in a around 0 99.3%
Final simplification99.4%
(FPCore (a b) :precision binary64 (if (or (<= a -2.1e+60) (not (<= a 4.5e+33))) (pow a 4.0) (+ (+ (* 4.0 (* b b)) (pow b 4.0)) -1.0)))
double code(double a, double b) {
double tmp;
if ((a <= -2.1e+60) || !(a <= 4.5e+33)) {
tmp = pow(a, 4.0);
} else {
tmp = ((4.0 * (b * b)) + 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 <= (-2.1d+60)) .or. (.not. (a <= 4.5d+33))) then
tmp = a ** 4.0d0
else
tmp = ((4.0d0 * (b * b)) + (b ** 4.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a <= -2.1e+60) || !(a <= 4.5e+33)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = ((4.0 * (b * b)) + Math.pow(b, 4.0)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -2.1e+60) or not (a <= 4.5e+33): tmp = math.pow(a, 4.0) else: tmp = ((4.0 * (b * b)) + math.pow(b, 4.0)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if ((a <= -2.1e+60) || !(a <= 4.5e+33)) tmp = a ^ 4.0; else tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + (b ^ 4.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -2.1e+60) || ~((a <= 4.5e+33))) tmp = a ^ 4.0; else tmp = ((4.0 * (b * b)) + (b ^ 4.0)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -2.1e+60], N[Not[LessEqual[a, 4.5e+33]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.1 \cdot 10^{+60} \lor \neg \left(a \leq 4.5 \cdot 10^{+33}\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + {b}^{4}\right) + -1\\
\end{array}
\end{array}
if a < -2.1000000000000001e60 or 4.5e33 < a Initial program 43.0%
associate--l+43.0%
+-commutative43.0%
+-commutative43.0%
sub-neg43.0%
associate-+l+43.0%
+-commutative43.0%
fma-define43.0%
Simplified50.3%
Taylor expanded in a around inf 96.2%
associate-*r/96.2%
metadata-eval96.2%
Simplified96.2%
Taylor expanded in a around inf 96.2%
if -2.1000000000000001e60 < a < 4.5e33Initial program 96.9%
associate--l+96.9%
+-commutative96.9%
+-commutative96.9%
sub-neg96.9%
associate-+l+96.9%
+-commutative96.9%
fma-define96.9%
Simplified96.9%
Taylor expanded in a around 0 97.8%
pow297.8%
Applied egg-rr97.8%
Final simplification97.0%
(FPCore (a b) :precision binary64 (if (or (<= a -2.4e+59) (not (<= a 9e+29))) (pow a 4.0) (+ (* 4.0 (* b b)) -1.0)))
double code(double a, double b) {
double tmp;
if ((a <= -2.4e+59) || !(a <= 9e+29)) {
tmp = pow(a, 4.0);
} else {
tmp = (4.0 * (b * b)) + -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.4d+59)) .or. (.not. (a <= 9d+29))) then
tmp = a ** 4.0d0
else
tmp = (4.0d0 * (b * b)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a <= -2.4e+59) || !(a <= 9e+29)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = (4.0 * (b * b)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -2.4e+59) or not (a <= 9e+29): tmp = math.pow(a, 4.0) else: tmp = (4.0 * (b * b)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if ((a <= -2.4e+59) || !(a <= 9e+29)) tmp = a ^ 4.0; else tmp = Float64(Float64(4.0 * Float64(b * b)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -2.4e+59) || ~((a <= 9e+29))) tmp = a ^ 4.0; else tmp = (4.0 * (b * b)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -2.4e+59], N[Not[LessEqual[a, 9e+29]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.4 \cdot 10^{+59} \lor \neg \left(a \leq 9 \cdot 10^{+29}\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right) + -1\\
\end{array}
\end{array}
if a < -2.4000000000000002e59 or 9.0000000000000005e29 < a Initial program 43.5%
associate--l+43.5%
+-commutative43.5%
+-commutative43.5%
sub-neg43.5%
associate-+l+43.5%
+-commutative43.5%
fma-define43.5%
Simplified50.7%
Taylor expanded in a around inf 95.5%
associate-*r/95.5%
metadata-eval95.5%
Simplified95.5%
Taylor expanded in a around inf 95.5%
if -2.4000000000000002e59 < a < 9.0000000000000005e29Initial program 96.9%
associate--l+96.9%
+-commutative96.9%
+-commutative96.9%
sub-neg96.9%
associate-+l+96.9%
+-commutative96.9%
fma-define96.9%
Simplified96.9%
Taylor expanded in a around 0 97.7%
Taylor expanded in b around 0 75.8%
pow297.7%
Applied egg-rr75.8%
Final simplification85.3%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2000000000000.0) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2000000000000.0) {
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 * b) <= 2000000000000.0d0) 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 * b) <= 2000000000000.0) {
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 * b) <= 2000000000000.0: 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 (Float64(b * b) <= 2000000000000.0) 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 * b) <= 2000000000000.0) tmp = (a ^ 4.0) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2000000000000.0], 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 \cdot b \leq 2000000000000:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 2e12Initial program 83.2%
add-sqr-sqrt53.1%
sqrt-unprod68.5%
swap-sqr68.5%
metadata-eval68.5%
metadata-eval68.5%
swap-sqr68.5%
sqrt-unprod30.0%
add-sqr-sqrt83.2%
*-commutative83.2%
cancel-sign-sub-inv83.2%
Applied egg-rr83.2%
Taylor expanded in a around inf 82.2%
distribute-lft-neg-out82.2%
unsub-neg82.2%
Applied egg-rr82.2%
Taylor expanded in a around inf 96.0%
if 2e12 < (*.f64 b b) Initial program 55.7%
associate--l+55.7%
+-commutative55.7%
+-commutative55.7%
sub-neg55.7%
associate-+l+55.7%
+-commutative55.7%
fma-define55.7%
Simplified63.6%
Taylor expanded in a around 0 90.9%
Taylor expanded in b around inf 90.9%
Final simplification93.7%
(FPCore (a b) :precision binary64 (+ (* 4.0 (* b b)) -1.0))
double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (4.0d0 * (b * b)) + (-1.0d0)
end function
public static double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
def code(a, b): return (4.0 * (b * b)) + -1.0
function code(a, b) return Float64(Float64(4.0 * Float64(b * b)) + -1.0) end
function tmp = code(a, b) tmp = (4.0 * (b * b)) + -1.0; end
code[a_, b_] := N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(b \cdot b\right) + -1
\end{array}
Initial program 71.0%
associate--l+71.0%
+-commutative71.0%
+-commutative71.0%
sub-neg71.0%
associate-+l+71.0%
+-commutative71.0%
fma-define71.0%
Simplified74.5%
Taylor expanded in a around 0 67.7%
Taylor expanded in b around 0 50.5%
pow267.7%
Applied egg-rr50.5%
Final simplification50.5%
(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 71.0%
associate--l+71.0%
+-commutative71.0%
+-commutative71.0%
sub-neg71.0%
associate-+l+71.0%
+-commutative71.0%
fma-define71.0%
Simplified74.5%
Taylor expanded in a around 0 67.7%
Taylor expanded in b around 0 26.3%
herbie shell --seed 2024145
(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))