
(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 10 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 (fma (* b 4.0) b (+ -1.0 (pow (hypot a b) 4.0))))
double code(double a, double b) {
return fma((b * 4.0), b, (-1.0 + pow(hypot(a, b), 4.0)));
}
function code(a, b) return fma(Float64(b * 4.0), b, Float64(-1.0 + (hypot(a, b) ^ 4.0))) end
code[a_, b_] := N[(N[(b * 4.0), $MachinePrecision] * b + N[(-1.0 + N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b \cdot 4, b, -1 + {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4}\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
sqr-pow99.9%
fma-def99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
fma-def99.9%
unpow299.9%
+-commutative99.9%
fma-udef99.9%
associate-+l+99.9%
*-commutative99.9%
Applied egg-rr100.0%
Final simplification100.0%
(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%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Final simplification100.0%
(FPCore (a b)
:precision binary64
(if (<= a -1700.0)
(pow a 4.0)
(if (<= a -4.3e-20)
(pow b 4.0)
(if (<= a -1.7e-75)
-1.0
(if (<= a -1.15e-211)
(pow b 4.0)
(if (<= a 2.3e-214)
-1.0
(if (<= a 8.5e-165)
(pow b 4.0)
(if (<= a 4.4e-10)
-1.0
(if (<= a 6e+21) (pow b 4.0) (pow a 4.0))))))))))
double code(double a, double b) {
double tmp;
if (a <= -1700.0) {
tmp = pow(a, 4.0);
} else if (a <= -4.3e-20) {
tmp = pow(b, 4.0);
} else if (a <= -1.7e-75) {
tmp = -1.0;
} else if (a <= -1.15e-211) {
tmp = pow(b, 4.0);
} else if (a <= 2.3e-214) {
tmp = -1.0;
} else if (a <= 8.5e-165) {
tmp = pow(b, 4.0);
} else if (a <= 4.4e-10) {
tmp = -1.0;
} else if (a <= 6e+21) {
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 (a <= (-1700.0d0)) then
tmp = a ** 4.0d0
else if (a <= (-4.3d-20)) then
tmp = b ** 4.0d0
else if (a <= (-1.7d-75)) then
tmp = -1.0d0
else if (a <= (-1.15d-211)) then
tmp = b ** 4.0d0
else if (a <= 2.3d-214) then
tmp = -1.0d0
else if (a <= 8.5d-165) then
tmp = b ** 4.0d0
else if (a <= 4.4d-10) then
tmp = -1.0d0
else if (a <= 6d+21) 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 (a <= -1700.0) {
tmp = Math.pow(a, 4.0);
} else if (a <= -4.3e-20) {
tmp = Math.pow(b, 4.0);
} else if (a <= -1.7e-75) {
tmp = -1.0;
} else if (a <= -1.15e-211) {
tmp = Math.pow(b, 4.0);
} else if (a <= 2.3e-214) {
tmp = -1.0;
} else if (a <= 8.5e-165) {
tmp = Math.pow(b, 4.0);
} else if (a <= 4.4e-10) {
tmp = -1.0;
} else if (a <= 6e+21) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1700.0: tmp = math.pow(a, 4.0) elif a <= -4.3e-20: tmp = math.pow(b, 4.0) elif a <= -1.7e-75: tmp = -1.0 elif a <= -1.15e-211: tmp = math.pow(b, 4.0) elif a <= 2.3e-214: tmp = -1.0 elif a <= 8.5e-165: tmp = math.pow(b, 4.0) elif a <= 4.4e-10: tmp = -1.0 elif a <= 6e+21: tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -1700.0) tmp = a ^ 4.0; elseif (a <= -4.3e-20) tmp = b ^ 4.0; elseif (a <= -1.7e-75) tmp = -1.0; elseif (a <= -1.15e-211) tmp = b ^ 4.0; elseif (a <= 2.3e-214) tmp = -1.0; elseif (a <= 8.5e-165) tmp = b ^ 4.0; elseif (a <= 4.4e-10) tmp = -1.0; elseif (a <= 6e+21) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1700.0) tmp = a ^ 4.0; elseif (a <= -4.3e-20) tmp = b ^ 4.0; elseif (a <= -1.7e-75) tmp = -1.0; elseif (a <= -1.15e-211) tmp = b ^ 4.0; elseif (a <= 2.3e-214) tmp = -1.0; elseif (a <= 8.5e-165) tmp = b ^ 4.0; elseif (a <= 4.4e-10) tmp = -1.0; elseif (a <= 6e+21) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1700.0], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[a, -4.3e-20], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, -1.7e-75], -1.0, If[LessEqual[a, -1.15e-211], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 2.3e-214], -1.0, If[LessEqual[a, 8.5e-165], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 4.4e-10], -1.0, If[LessEqual[a, 6e+21], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1700:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;a \leq -4.3 \cdot 10^{-20}:\\
\;\;\;\;{b}^{4}\\
\mathbf{elif}\;a \leq -1.7 \cdot 10^{-75}:\\
\;\;\;\;-1\\
\mathbf{elif}\;a \leq -1.15 \cdot 10^{-211}:\\
\;\;\;\;{b}^{4}\\
\mathbf{elif}\;a \leq 2.3 \cdot 10^{-214}:\\
\;\;\;\;-1\\
\mathbf{elif}\;a \leq 8.5 \cdot 10^{-165}:\\
\;\;\;\;{b}^{4}\\
\mathbf{elif}\;a \leq 4.4 \cdot 10^{-10}:\\
\;\;\;\;-1\\
\mathbf{elif}\;a \leq 6 \cdot 10^{+21}:\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < -1700 or 6e21 < a Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around inf 95.0%
if -1700 < a < -4.30000000000000011e-20 or -1.70000000000000008e-75 < a < -1.14999999999999994e-211 or 2.30000000000000011e-214 < a < 8.5e-165 or 4.3999999999999998e-10 < a < 6e21Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around inf 74.9%
if -4.30000000000000011e-20 < a < -1.70000000000000008e-75 or -1.14999999999999994e-211 < a < 2.30000000000000011e-214 or 8.5e-165 < a < 4.3999999999999998e-10Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
sqr-pow99.9%
fma-def99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
fma-def99.9%
unpow299.9%
+-commutative99.9%
fma-udef99.9%
associate-+l+99.9%
*-commutative99.9%
Applied egg-rr100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 66.5%
Final simplification82.5%
(FPCore (a b) :precision binary64 (if (<= (* b b) 5e-7) (+ -1.0 (pow a 4.0)) (+ (pow b 4.0) (* (* b b) (+ 4.0 (* (* a a) 2.0))))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 5e-7) {
tmp = -1.0 + pow(a, 4.0);
} else {
tmp = pow(b, 4.0) + ((b * b) * (4.0 + ((a * a) * 2.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) <= 5d-7) then
tmp = (-1.0d0) + (a ** 4.0d0)
else
tmp = (b ** 4.0d0) + ((b * b) * (4.0d0 + ((a * a) * 2.0d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 5e-7) {
tmp = -1.0 + Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0) + ((b * b) * (4.0 + ((a * a) * 2.0)));
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 5e-7: tmp = -1.0 + math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) + ((b * b) * (4.0 + ((a * a) * 2.0))) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 5e-7) tmp = Float64(-1.0 + (a ^ 4.0)); else tmp = Float64((b ^ 4.0) + Float64(Float64(b * b) * Float64(4.0 + Float64(Float64(a * a) * 2.0)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 5e-7) tmp = -1.0 + (a ^ 4.0); else tmp = (b ^ 4.0) + ((b * b) * (4.0 + ((a * a) * 2.0))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 5e-7], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[(N[Power[b, 4.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(N[(a * a), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 5 \cdot 10^{-7}:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + \left(b \cdot b\right) \cdot \left(4 + \left(a \cdot a\right) \cdot 2\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 4.99999999999999977e-7Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 99.0%
if 4.99999999999999977e-7 < (*.f64 b b) Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
Final simplification98.0%
(FPCore (a b) :precision binary64 (+ -1.0 (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b)))))
double code(double a, double b) {
return -1.0 + (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (b * b)))
end function
public static double code(double a, double b) {
return -1.0 + (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)));
}
def code(a, b): return -1.0 + (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)))
function code(a, b) return Float64(-1.0 + Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b)))) end
function tmp = code(a, b) tmp = -1.0 + ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))); end
code[a_, b_] := N[(-1.0 + 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]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e-7) (+ -1.0 (pow a 4.0)) (+ (+ -1.0 (pow b 4.0)) (* b (* b 4.0)))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e-7) {
tmp = -1.0 + pow(a, 4.0);
} else {
tmp = (-1.0 + pow(b, 4.0)) + (b * (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) <= 2d-7) then
tmp = (-1.0d0) + (a ** 4.0d0)
else
tmp = ((-1.0d0) + (b ** 4.0d0)) + (b * (b * 4.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 2e-7) {
tmp = -1.0 + Math.pow(a, 4.0);
} else {
tmp = (-1.0 + Math.pow(b, 4.0)) + (b * (b * 4.0));
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2e-7: tmp = -1.0 + math.pow(a, 4.0) else: tmp = (-1.0 + math.pow(b, 4.0)) + (b * (b * 4.0)) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2e-7) tmp = Float64(-1.0 + (a ^ 4.0)); else tmp = Float64(Float64(-1.0 + (b ^ 4.0)) + Float64(b * Float64(b * 4.0))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2e-7) tmp = -1.0 + (a ^ 4.0); else tmp = (-1.0 + (b ^ 4.0)) + (b * (b * 4.0)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e-7], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2 \cdot 10^{-7}:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{else}:\\
\;\;\;\;\left(-1 + {b}^{4}\right) + b \cdot \left(b \cdot 4\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 1.9999999999999999e-7Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 99.8%
if 1.9999999999999999e-7 < (*.f64 b b) Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
sqr-pow99.9%
fma-def99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
fma-def99.9%
unpow299.9%
+-commutative99.9%
fma-udef99.9%
associate-+l+99.9%
*-commutative99.9%
Applied egg-rr100.0%
Taylor expanded in a around 0 92.5%
fma-udef92.5%
*-commutative92.5%
+-commutative92.5%
sub-neg92.5%
metadata-eval92.5%
Applied egg-rr92.5%
Final simplification96.5%
(FPCore (a b)
:precision binary64
(if (<= a -5.1e-20)
(pow a 4.0)
(if (<= a 1.25e-213)
-1.0
(if (<= a 1.05e-165) (* 4.0 (* b b)) (if (<= a 3e-9) -1.0 (pow a 4.0))))))
double code(double a, double b) {
double tmp;
if (a <= -5.1e-20) {
tmp = pow(a, 4.0);
} else if (a <= 1.25e-213) {
tmp = -1.0;
} else if (a <= 1.05e-165) {
tmp = 4.0 * (b * b);
} else if (a <= 3e-9) {
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 <= (-5.1d-20)) then
tmp = a ** 4.0d0
else if (a <= 1.25d-213) then
tmp = -1.0d0
else if (a <= 1.05d-165) then
tmp = 4.0d0 * (b * b)
else if (a <= 3d-9) 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 <= -5.1e-20) {
tmp = Math.pow(a, 4.0);
} else if (a <= 1.25e-213) {
tmp = -1.0;
} else if (a <= 1.05e-165) {
tmp = 4.0 * (b * b);
} else if (a <= 3e-9) {
tmp = -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -5.1e-20: tmp = math.pow(a, 4.0) elif a <= 1.25e-213: tmp = -1.0 elif a <= 1.05e-165: tmp = 4.0 * (b * b) elif a <= 3e-9: tmp = -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -5.1e-20) tmp = a ^ 4.0; elseif (a <= 1.25e-213) tmp = -1.0; elseif (a <= 1.05e-165) tmp = Float64(4.0 * Float64(b * b)); elseif (a <= 3e-9) tmp = -1.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -5.1e-20) tmp = a ^ 4.0; elseif (a <= 1.25e-213) tmp = -1.0; elseif (a <= 1.05e-165) tmp = 4.0 * (b * b); elseif (a <= 3e-9) tmp = -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -5.1e-20], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[a, 1.25e-213], -1.0, If[LessEqual[a, 1.05e-165], N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 3e-9], -1.0, N[Power[a, 4.0], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5.1 \cdot 10^{-20}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;a \leq 1.25 \cdot 10^{-213}:\\
\;\;\;\;-1\\
\mathbf{elif}\;a \leq 1.05 \cdot 10^{-165}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right)\\
\mathbf{elif}\;a \leq 3 \cdot 10^{-9}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < -5.10000000000000019e-20 or 2.99999999999999998e-9 < a Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around inf 86.2%
if -5.10000000000000019e-20 < a < 1.24999999999999994e-213 or 1.04999999999999997e-165 < a < 2.99999999999999998e-9Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
sqr-pow99.9%
fma-def99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
fma-def99.9%
unpow299.9%
+-commutative99.9%
fma-udef99.9%
associate-+l+99.9%
*-commutative99.9%
Applied egg-rr100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 60.0%
if 1.24999999999999994e-213 < a < 1.04999999999999997e-165Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified99.9%
Taylor expanded in b around inf 77.1%
unpow277.1%
unpow277.1%
Simplified77.1%
Taylor expanded in a around 0 77.1%
unpow277.1%
*-commutative77.1%
associate-*l*77.1%
Simplified77.1%
Taylor expanded in b around 0 53.9%
unpow253.9%
Simplified53.9%
Final simplification74.4%
(FPCore (a b) :precision binary64 (if (<= (* b b) 4e+20) (+ -1.0 (pow a 4.0)) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 4e+20) {
tmp = -1.0 + 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 * b) <= 4d+20) then
tmp = (-1.0d0) + (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 * b) <= 4e+20) {
tmp = -1.0 + Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 4e+20: tmp = -1.0 + math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 4e+20) tmp = Float64(-1.0 + (a ^ 4.0)); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 4e+20) tmp = -1.0 + (a ^ 4.0); else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 4e+20], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 4 \cdot 10^{+20}:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 4e20Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 97.1%
if 4e20 < (*.f64 b b) Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around inf 94.7%
Final simplification96.1%
(FPCore (a b) :precision binary64 (if (<= (* b b) 0.235) -1.0 (* 4.0 (* b b))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 0.235) {
tmp = -1.0;
} else {
tmp = 4.0 * (b * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b * b) <= 0.235d0) then
tmp = -1.0d0
else
tmp = 4.0d0 * (b * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 0.235) {
tmp = -1.0;
} else {
tmp = 4.0 * (b * b);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 0.235: tmp = -1.0 else: tmp = 4.0 * (b * b) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 0.235) tmp = -1.0; else tmp = Float64(4.0 * Float64(b * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 0.235) tmp = -1.0; else tmp = 4.0 * (b * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 0.235], -1.0, N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 0.235:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 0.23499999999999999Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
sqr-pow99.9%
fma-def99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
fma-def99.9%
unpow299.9%
+-commutative99.9%
fma-udef99.9%
associate-+l+99.9%
*-commutative99.9%
Applied egg-rr100.0%
Taylor expanded in a around 0 44.5%
Taylor expanded in b around 0 43.5%
if 0.23499999999999999 < (*.f64 b b) Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around inf 96.7%
unpow296.7%
unpow296.7%
Simplified96.7%
Taylor expanded in a around 0 91.5%
unpow291.5%
*-commutative91.5%
associate-*l*91.5%
Simplified91.5%
Taylor expanded in b around 0 51.9%
unpow251.9%
Simplified51.9%
Final simplification47.2%
(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%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
sqr-pow99.9%
fma-def99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
pow299.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
fma-def99.9%
unpow299.9%
+-commutative99.9%
fma-udef99.9%
associate-+l+99.9%
*-commutative99.9%
Applied egg-rr100.0%
Taylor expanded in a around 0 65.6%
Taylor expanded in b around 0 24.6%
Final simplification24.6%
herbie shell --seed 2023172
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))