
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 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 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 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[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 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 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 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[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}
(FPCore (a b) :precision binary64 (+ (pow (hypot a b) 4.0) (fma b (* b 4.0) -1.0)))
double code(double a, double b) {
return pow(hypot(a, b), 4.0) + fma(b, (b * 4.0), -1.0);
}
function code(a, b) return Float64((hypot(a, b) ^ 4.0) + fma(b, Float64(b * 4.0), -1.0)) end
code[a_, b_] := N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b, b \cdot 4, -1\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Final simplification100.0%
(FPCore (a b)
:precision binary64
(if (<= b 8.4e-252)
(pow a 4.0)
(if (<= b 1.7e-179)
-1.0
(if (<= b 2.5e-17) (pow a 4.0) (if (<= b 0.49) -1.0 (pow b 4.0))))))
double code(double a, double b) {
double tmp;
if (b <= 8.4e-252) {
tmp = pow(a, 4.0);
} else if (b <= 1.7e-179) {
tmp = -1.0;
} else if (b <= 2.5e-17) {
tmp = pow(a, 4.0);
} else if (b <= 0.49) {
tmp = -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 <= 8.4d-252) then
tmp = a ** 4.0d0
else if (b <= 1.7d-179) then
tmp = -1.0d0
else if (b <= 2.5d-17) then
tmp = a ** 4.0d0
else if (b <= 0.49d0) then
tmp = -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 <= 8.4e-252) {
tmp = Math.pow(a, 4.0);
} else if (b <= 1.7e-179) {
tmp = -1.0;
} else if (b <= 2.5e-17) {
tmp = Math.pow(a, 4.0);
} else if (b <= 0.49) {
tmp = -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 8.4e-252: tmp = math.pow(a, 4.0) elif b <= 1.7e-179: tmp = -1.0 elif b <= 2.5e-17: tmp = math.pow(a, 4.0) elif b <= 0.49: tmp = -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 8.4e-252) tmp = a ^ 4.0; elseif (b <= 1.7e-179) tmp = -1.0; elseif (b <= 2.5e-17) tmp = a ^ 4.0; elseif (b <= 0.49) tmp = -1.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 8.4e-252) tmp = a ^ 4.0; elseif (b <= 1.7e-179) tmp = -1.0; elseif (b <= 2.5e-17) tmp = a ^ 4.0; elseif (b <= 0.49) tmp = -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 8.4e-252], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 1.7e-179], -1.0, If[LessEqual[b, 2.5e-17], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 0.49], -1.0, N[Power[b, 4.0], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.4 \cdot 10^{-252}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-179}:\\
\;\;\;\;-1\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-17}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 0.49:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 8.4000000000000001e-252 or 1.6999999999999999e-179 < b < 2.4999999999999999e-17Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around inf 50.3%
if 8.4000000000000001e-252 < b < 1.6999999999999999e-179 or 2.4999999999999999e-17 < b < 0.48999999999999999Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified99.9%
Taylor expanded in b around 0 95.1%
Taylor expanded in a around 0 73.6%
if 0.48999999999999999 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around inf 88.2%
Final simplification63.8%
(FPCore (a b)
:precision binary64
(if (<= b 0.052)
(+ (pow a 4.0) -1.0)
(if (<= b 3.6e+40)
(+ (+ (* 4.0 (* b b)) (pow b 4.0)) -1.0)
(if (<= b 2.9e+49) (pow a 4.0) (pow b 4.0)))))
double code(double a, double b) {
double tmp;
if (b <= 0.052) {
tmp = pow(a, 4.0) + -1.0;
} else if (b <= 3.6e+40) {
tmp = ((4.0 * (b * b)) + pow(b, 4.0)) + -1.0;
} else if (b <= 2.9e+49) {
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 <= 0.052d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else if (b <= 3.6d+40) then
tmp = ((4.0d0 * (b * b)) + (b ** 4.0d0)) + (-1.0d0)
else if (b <= 2.9d+49) 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 <= 0.052) {
tmp = Math.pow(a, 4.0) + -1.0;
} else if (b <= 3.6e+40) {
tmp = ((4.0 * (b * b)) + Math.pow(b, 4.0)) + -1.0;
} else if (b <= 2.9e+49) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 0.052: tmp = math.pow(a, 4.0) + -1.0 elif b <= 3.6e+40: tmp = ((4.0 * (b * b)) + math.pow(b, 4.0)) + -1.0 elif b <= 2.9e+49: tmp = math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 0.052) tmp = Float64((a ^ 4.0) + -1.0); elseif (b <= 3.6e+40) tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + (b ^ 4.0)) + -1.0); elseif (b <= 2.9e+49) tmp = a ^ 4.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 0.052) tmp = (a ^ 4.0) + -1.0; elseif (b <= 3.6e+40) tmp = ((4.0 * (b * b)) + (b ^ 4.0)) + -1.0; elseif (b <= 2.9e+49) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 0.052], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[b, 3.6e+40], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[b, 2.9e+49], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.052:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{elif}\;b \leq 3.6 \cdot 10^{+40}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + {b}^{4}\right) + -1\\
\mathbf{elif}\;b \leq 2.9 \cdot 10^{+49}:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 0.0519999999999999976Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around 0 79.0%
if 0.0519999999999999976 < b < 3.59999999999999996e40Initial program 99.2%
add-cbrt-cube83.2%
pow383.2%
metadata-eval83.2%
sqrt-pow283.6%
hypot-udef83.6%
pow-pow83.8%
metadata-eval83.8%
Applied egg-rr83.8%
Taylor expanded in a around 0 67.7%
if 3.59999999999999996e40 < b < 2.9e49Initial program 100.0%
associate--l+100.0%
sqr-pow100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if 2.9e49 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around inf 97.3%
Final simplification83.9%
(FPCore (a b) :precision binary64 (if (<= b 610.0) (+ (pow a 4.0) -1.0) (if (or (<= b 6.6e+40) (not (<= b 3.4e+49))) (pow b 4.0) (pow a 4.0))))
double code(double a, double b) {
double tmp;
if (b <= 610.0) {
tmp = pow(a, 4.0) + -1.0;
} else if ((b <= 6.6e+40) || !(b <= 3.4e+49)) {
tmp = pow(b, 4.0);
} else {
tmp = pow(a, 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 <= 610.0d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else if ((b <= 6.6d+40) .or. (.not. (b <= 3.4d+49))) then
tmp = b ** 4.0d0
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 610.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else if ((b <= 6.6e+40) || !(b <= 3.4e+49)) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 610.0: tmp = math.pow(a, 4.0) + -1.0 elif (b <= 6.6e+40) or not (b <= 3.4e+49): tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 610.0) tmp = Float64((a ^ 4.0) + -1.0); elseif ((b <= 6.6e+40) || !(b <= 3.4e+49)) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 610.0) tmp = (a ^ 4.0) + -1.0; elseif ((b <= 6.6e+40) || ~((b <= 3.4e+49))) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 610.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], If[Or[LessEqual[b, 6.6e+40], N[Not[LessEqual[b, 3.4e+49]], $MachinePrecision]], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 610:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{elif}\;b \leq 6.6 \cdot 10^{+40} \lor \neg \left(b \leq 3.4 \cdot 10^{+49}\right):\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if b < 610Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around 0 78.7%
if 610 < b < 6.5999999999999997e40 or 3.4000000000000001e49 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around inf 95.3%
if 6.5999999999999997e40 < b < 3.4000000000000001e49Initial program 100.0%
associate--l+100.0%
sqr-pow100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
Final simplification83.7%
(FPCore (a b) :precision binary64 (+ (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) + -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 * (b * b))) + (-1.0d0)
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) + -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[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= a 0.0027) -1.0 (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 0.0027) {
tmp = -1.0;
} else {
tmp = pow(a, 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 <= 0.0027d0) then
tmp = -1.0d0
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 0.0027) {
tmp = -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 0.0027: tmp = -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 0.0027) tmp = -1.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 0.0027) tmp = -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 0.0027], -1.0, N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 0.0027:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 0.0027000000000000001Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around 0 62.4%
Taylor expanded in a around 0 30.5%
if 0.0027000000000000001 < a Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around inf 80.4%
Final simplification42.6%
(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 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in b around 0 67.0%
Taylor expanded in a around 0 23.3%
Final simplification23.3%
herbie shell --seed 2024018
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))