
(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 10 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 (* (* b b) (+ a 3.0))))
(if (<=
(+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (- 1.0 a)) t_0)))
INFINITY)
(+ (pow (fma a a (* b b)) 2.0) (fma 4.0 (fma a (* a (- 1.0 a)) t_0) -1.0))
(* (pow a 4.0) (- 1.0 (/ 4.0 a))))))
double code(double a, double b) {
double t_0 = (b * b) * (a + 3.0);
double tmp;
if ((pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + t_0))) <= ((double) INFINITY)) {
tmp = pow(fma(a, a, (b * b)), 2.0) + fma(4.0, fma(a, (a * (1.0 - a)), t_0), -1.0);
} else {
tmp = pow(a, 4.0) * (1.0 - (4.0 / a));
}
return tmp;
}
function code(a, b) t_0 = Float64(Float64(b * b) * Float64(a + 3.0)) tmp = 0.0 if (Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 - a)) + t_0))) <= Inf) tmp = Float64((fma(a, a, Float64(b * b)) ^ 2.0) + fma(4.0, fma(a, Float64(a * Float64(1.0 - a)), t_0), -1.0)); else tmp = Float64((a ^ 4.0) * Float64(1.0 - Float64(4.0 / a))); end return tmp end
code[a_, b_] := Block[{t$95$0 = N[(N[(b * b), $MachinePrecision] * N[(a + 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[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] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[Power[N[(a * a + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(a * N[(a * N[(1.0 - a), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] * N[(1.0 - N[(4.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(b \cdot b\right) \cdot \left(a + 3\right)\\
\mathbf{if}\;{\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + t\_0\right) \leq \infty:\\
\;\;\;\;{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \mathsf{fma}\left(4, \mathsf{fma}\left(a, a \cdot \left(1 - a\right), t\_0\right), -1\right)\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} \cdot \left(1 - \frac{4}{a}\right)\\
\end{array}
\end{array}
if (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) #s(literal 2 binary64)) (*.f64 #s(literal 4 binary64) (+.f64 (*.f64 (*.f64 a a) (-.f64 #s(literal 1 binary64) a)) (*.f64 (*.f64 b b) (+.f64 #s(literal 3 binary64) a))))) < +inf.0Initial program 99.9%
associate--l+99.9%
fma-define99.9%
fma-neg99.9%
associate-*l*99.9%
fma-define99.9%
+-commutative99.9%
metadata-eval99.9%
Simplified99.9%
if +inf.0 < (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) #s(literal 2 binary64)) (*.f64 #s(literal 4 binary64) (+.f64 (*.f64 (*.f64 a a) (-.f64 #s(literal 1 binary64) a)) (*.f64 (*.f64 b b) (+.f64 #s(literal 3 binary64) a))))) Initial program 0.0%
associate--l+0.0%
fma-define0.0%
sqr-neg0.0%
fma-define0.0%
distribute-rgt-in0.0%
sqr-neg0.0%
distribute-rgt-in0.0%
fma-define0.0%
sqr-neg0.0%
Simplified5.8%
Taylor expanded in a around inf 94.6%
associate-*r/94.6%
metadata-eval94.6%
Simplified94.6%
Final simplification98.5%
(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) (- 1.0 (/ 4.0 a))))))
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) * (1.0 - (4.0 / a));
}
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) * (1.0 - (4.0 / a));
}
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) * (1.0 - (4.0 / a)) 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 = Float64((a ^ 4.0) * Float64(1.0 - Float64(4.0 / a))); 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) * (1.0 - (4.0 / a)); 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[(N[Power[a, 4.0], $MachinePrecision] * N[(1.0 - N[(4.0 / a), $MachinePrecision]), $MachinePrecision]), $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} \cdot \left(1 - \frac{4}{a}\right)\\
\end{array}
\end{array}
if (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) #s(literal 2 binary64)) (*.f64 #s(literal 4 binary64) (+.f64 (*.f64 (*.f64 a a) (-.f64 #s(literal 1 binary64) a)) (*.f64 (*.f64 b b) (+.f64 #s(literal 3 binary64) a))))) < +inf.0Initial program 99.9%
if +inf.0 < (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) #s(literal 2 binary64)) (*.f64 #s(literal 4 binary64) (+.f64 (*.f64 (*.f64 a a) (-.f64 #s(literal 1 binary64) a)) (*.f64 (*.f64 b b) (+.f64 #s(literal 3 binary64) a))))) Initial program 0.0%
associate--l+0.0%
fma-define0.0%
sqr-neg0.0%
fma-define0.0%
distribute-rgt-in0.0%
sqr-neg0.0%
distribute-rgt-in0.0%
fma-define0.0%
sqr-neg0.0%
Simplified5.8%
Taylor expanded in a around inf 94.6%
associate-*r/94.6%
metadata-eval94.6%
Simplified94.6%
Final simplification98.5%
(FPCore (a b)
:precision binary64
(if (<= (* b b) 1e+120)
(+
(+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* a a) (* (* b b) (+ a 3.0)))))
-1.0)
(pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+120) {
tmp = (pow(((a * a) + (b * b)), 2.0) + (4.0 * ((a * a) + ((b * b) * (a + 3.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) <= 1d+120) then
tmp = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * ((a * a) + ((b * b) * (a + 3.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) <= 1e+120) {
tmp = (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * ((a * a) + ((b * b) * (a + 3.0))))) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1e+120: tmp = (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * ((a * a) + ((b * b) * (a + 3.0))))) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1e+120) tmp = Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(a * a) + Float64(Float64(b * b) * Float64(a + 3.0))))) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1e+120) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * ((a * a) + ((b * b) * (a + 3.0))))) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1e+120], N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(a * a), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(a + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 10^{+120}:\\
\;\;\;\;\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(a \cdot a + \left(b \cdot b\right) \cdot \left(a + 3\right)\right)\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 9.9999999999999998e119Initial program 81.4%
Taylor expanded in a around 0 96.7%
if 9.9999999999999998e119 < (*.f64 b b) Initial program 59.6%
associate--l+59.6%
fma-define59.6%
sqr-neg59.6%
fma-define59.6%
distribute-rgt-in59.6%
sqr-neg59.6%
distribute-rgt-in59.6%
fma-define59.6%
sqr-neg59.6%
Simplified63.6%
Taylor expanded in a around 0 98.1%
Taylor expanded in b around inf 98.1%
Final simplification97.3%
(FPCore (a b)
:precision binary64
(if (<= a -2900000.0)
(* (pow a 3.0) (- a 4.0))
(if (<= a 18000000.0)
(+ (+ (pow b 4.0) (* (* b b) 12.0)) -1.0)
(* (pow a 4.0) (+ (+ 2.0 (/ -4.0 a)) -1.0)))))
double code(double a, double b) {
double tmp;
if (a <= -2900000.0) {
tmp = pow(a, 3.0) * (a - 4.0);
} else if (a <= 18000000.0) {
tmp = (pow(b, 4.0) + ((b * b) * 12.0)) + -1.0;
} else {
tmp = pow(a, 4.0) * ((2.0 + (-4.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 <= (-2900000.0d0)) then
tmp = (a ** 3.0d0) * (a - 4.0d0)
else if (a <= 18000000.0d0) then
tmp = ((b ** 4.0d0) + ((b * b) * 12.0d0)) + (-1.0d0)
else
tmp = (a ** 4.0d0) * ((2.0d0 + ((-4.0d0) / a)) + (-1.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -2900000.0) {
tmp = Math.pow(a, 3.0) * (a - 4.0);
} else if (a <= 18000000.0) {
tmp = (Math.pow(b, 4.0) + ((b * b) * 12.0)) + -1.0;
} else {
tmp = Math.pow(a, 4.0) * ((2.0 + (-4.0 / a)) + -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -2900000.0: tmp = math.pow(a, 3.0) * (a - 4.0) elif a <= 18000000.0: tmp = (math.pow(b, 4.0) + ((b * b) * 12.0)) + -1.0 else: tmp = math.pow(a, 4.0) * ((2.0 + (-4.0 / a)) + -1.0) return tmp
function code(a, b) tmp = 0.0 if (a <= -2900000.0) tmp = Float64((a ^ 3.0) * Float64(a - 4.0)); elseif (a <= 18000000.0) tmp = Float64(Float64((b ^ 4.0) + Float64(Float64(b * b) * 12.0)) + -1.0); else tmp = Float64((a ^ 4.0) * Float64(Float64(2.0 + Float64(-4.0 / a)) + -1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -2900000.0) tmp = (a ^ 3.0) * (a - 4.0); elseif (a <= 18000000.0) tmp = ((b ^ 4.0) + ((b * b) * 12.0)) + -1.0; else tmp = (a ^ 4.0) * ((2.0 + (-4.0 / a)) + -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -2900000.0], N[(N[Power[a, 3.0], $MachinePrecision] * N[(a - 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 18000000.0], N[(N[(N[Power[b, 4.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * 12.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[a, 4.0], $MachinePrecision] * N[(N[(2.0 + N[(-4.0 / a), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2900000:\\
\;\;\;\;{a}^{3} \cdot \left(a - 4\right)\\
\mathbf{elif}\;a \leq 18000000:\\
\;\;\;\;\left({b}^{4} + \left(b \cdot b\right) \cdot 12\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4} \cdot \left(\left(2 + \frac{-4}{a}\right) + -1\right)\\
\end{array}
\end{array}
if a < -2.9e6Initial program 54.8%
associate--l+54.8%
fma-define54.8%
sqr-neg54.8%
fma-define54.8%
distribute-rgt-in54.8%
sqr-neg54.8%
distribute-rgt-in54.8%
fma-define54.8%
sqr-neg54.8%
Simplified54.8%
Taylor expanded in a around inf 89.4%
associate-*r/89.4%
metadata-eval89.4%
Simplified89.4%
Taylor expanded in a around 0 89.4%
if -2.9e6 < a < 1.8e7Initial program 99.9%
associate--l+99.9%
fma-define99.9%
sqr-neg99.9%
fma-define99.9%
distribute-rgt-in99.9%
sqr-neg99.9%
distribute-rgt-in99.9%
fma-define99.9%
sqr-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 97.9%
pow297.9%
Applied egg-rr97.9%
if 1.8e7 < a Initial program 33.8%
associate--l+33.8%
fma-define33.8%
sqr-neg33.8%
fma-define33.8%
distribute-rgt-in33.8%
sqr-neg33.8%
distribute-rgt-in33.8%
fma-define33.8%
sqr-neg33.8%
Simplified40.2%
Taylor expanded in a around inf 89.4%
associate-*r/89.4%
metadata-eval89.4%
Simplified89.4%
expm1-log1p-u89.4%
Applied egg-rr89.4%
expm1-undefine89.4%
sub-neg89.4%
log1p-undefine89.4%
rem-exp-log89.4%
sub-neg89.4%
metadata-eval89.4%
associate-*r/89.4%
associate-+r+89.4%
metadata-eval89.4%
associate-*r/89.4%
metadata-eval89.4%
distribute-neg-frac89.4%
metadata-eval89.4%
metadata-eval89.4%
Simplified89.4%
Final simplification93.8%
(FPCore (a b) :precision binary64 (if (<= (* b b) 5e+124) (fma (* a a) (+ 4.0 (* a (+ a -4.0))) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 5e+124) {
tmp = fma((a * a), (4.0 + (a * (a + -4.0))), -1.0);
} else {
tmp = pow(b, 4.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 5e+124) tmp = fma(Float64(a * a), Float64(4.0 + Float64(a * Float64(a + -4.0))), -1.0); else tmp = b ^ 4.0; end return tmp end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 5e+124], N[(N[(a * a), $MachinePrecision] * N[(4.0 + N[(a * N[(a + -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 5 \cdot 10^{+124}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot a, 4 + a \cdot \left(a + -4\right), -1\right)\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 4.9999999999999996e124Initial program 80.4%
associate--l+80.4%
fma-define80.4%
sqr-neg80.4%
fma-define80.4%
distribute-rgt-in80.4%
sqr-neg80.4%
distribute-rgt-in80.4%
fma-define80.4%
sqr-neg80.4%
Simplified80.4%
Taylor expanded in b around 0 76.0%
Taylor expanded in a around 0 92.9%
fma-neg92.9%
sub-neg92.9%
metadata-eval92.9%
metadata-eval92.9%
Simplified92.9%
pow292.9%
Applied egg-rr92.9%
if 4.9999999999999996e124 < (*.f64 b b) Initial program 60.8%
associate--l+60.8%
fma-define60.8%
sqr-neg60.8%
fma-define60.8%
distribute-rgt-in60.8%
sqr-neg60.8%
distribute-rgt-in60.8%
fma-define60.8%
sqr-neg60.8%
Simplified64.9%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around inf 100.0%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e-12) (+ (* (* a a) 4.0) -1.0) (if (<= (* b b) 5e+124) (pow a 4.0) (pow b 4.0))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e-12) {
tmp = ((a * a) * 4.0) + -1.0;
} else if ((b * b) <= 5e+124) {
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 * b) <= 2d-12) then
tmp = ((a * a) * 4.0d0) + (-1.0d0)
else if ((b * b) <= 5d+124) 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 * b) <= 2e-12) {
tmp = ((a * a) * 4.0) + -1.0;
} else if ((b * b) <= 5e+124) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2e-12: tmp = ((a * a) * 4.0) + -1.0 elif (b * b) <= 5e+124: tmp = 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) <= 2e-12) tmp = Float64(Float64(Float64(a * a) * 4.0) + -1.0); elseif (Float64(b * b) <= 5e+124) tmp = a ^ 4.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2e-12) tmp = ((a * a) * 4.0) + -1.0; elseif ((b * b) <= 5e+124) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e-12], N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(b * b), $MachinePrecision], 5e+124], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2 \cdot 10^{-12}:\\
\;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\
\mathbf{elif}\;b \cdot b \leq 5 \cdot 10^{+124}:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 1.99999999999999996e-12Initial program 86.2%
associate--l+86.2%
fma-define86.2%
sqr-neg86.2%
fma-define86.2%
distribute-rgt-in86.2%
sqr-neg86.2%
distribute-rgt-in86.2%
fma-define86.2%
sqr-neg86.2%
Simplified86.2%
Taylor expanded in b around 0 86.0%
Taylor expanded in a around 0 79.3%
*-commutative79.3%
Simplified79.3%
pow299.7%
Applied egg-rr79.3%
if 1.99999999999999996e-12 < (*.f64 b b) < 4.9999999999999996e124Initial program 53.5%
associate--l+53.5%
fma-define53.5%
sqr-neg53.5%
fma-define53.5%
distribute-rgt-in53.5%
sqr-neg53.5%
distribute-rgt-in53.5%
fma-define53.5%
sqr-neg53.5%
Simplified53.5%
Taylor expanded in a around inf 61.5%
associate-*r/61.5%
metadata-eval61.5%
Simplified61.5%
Taylor expanded in a around inf 61.8%
if 4.9999999999999996e124 < (*.f64 b b) Initial program 60.8%
associate--l+60.8%
fma-define60.8%
sqr-neg60.8%
fma-define60.8%
distribute-rgt-in60.8%
sqr-neg60.8%
distribute-rgt-in60.8%
fma-define60.8%
sqr-neg60.8%
Simplified64.9%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around inf 100.0%
Final simplification85.2%
(FPCore (a b) :precision binary64 (if (or (<= a -22000.0) (not (<= a 430.0))) (pow a 4.0) (+ (* (* b b) 12.0) -1.0)))
double code(double a, double b) {
double tmp;
if ((a <= -22000.0) || !(a <= 430.0)) {
tmp = pow(a, 4.0);
} else {
tmp = ((b * b) * 12.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 <= (-22000.0d0)) .or. (.not. (a <= 430.0d0))) then
tmp = a ** 4.0d0
else
tmp = ((b * b) * 12.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a <= -22000.0) || !(a <= 430.0)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = ((b * b) * 12.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -22000.0) or not (a <= 430.0): tmp = math.pow(a, 4.0) else: tmp = ((b * b) * 12.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if ((a <= -22000.0) || !(a <= 430.0)) tmp = a ^ 4.0; else tmp = Float64(Float64(Float64(b * b) * 12.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -22000.0) || ~((a <= 430.0))) tmp = a ^ 4.0; else tmp = ((b * b) * 12.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -22000.0], N[Not[LessEqual[a, 430.0]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], N[(N[(N[(b * b), $MachinePrecision] * 12.0), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -22000 \lor \neg \left(a \leq 430\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;\left(b \cdot b\right) \cdot 12 + -1\\
\end{array}
\end{array}
if a < -22000 or 430 < a Initial program 45.2%
associate--l+45.2%
fma-define45.2%
sqr-neg45.2%
fma-define45.2%
distribute-rgt-in45.2%
sqr-neg45.2%
distribute-rgt-in45.2%
fma-define45.2%
sqr-neg45.2%
Simplified48.3%
Taylor expanded in a around inf 88.3%
associate-*r/88.3%
metadata-eval88.3%
Simplified88.3%
Taylor expanded in a around inf 87.6%
if -22000 < a < 430Initial program 99.9%
associate--l+99.9%
fma-define99.9%
sqr-neg99.9%
fma-define99.9%
distribute-rgt-in99.9%
sqr-neg99.9%
distribute-rgt-in99.9%
fma-define99.9%
sqr-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 98.6%
Taylor expanded in b around 0 77.9%
pow298.6%
Applied egg-rr77.9%
Final simplification82.7%
(FPCore (a b) :precision binary64 (if (<= (* b b) 5.4e+270) (+ (* (* a a) 4.0) -1.0) (+ (* (* b b) 12.0) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 5.4e+270) {
tmp = ((a * a) * 4.0) + -1.0;
} else {
tmp = ((b * b) * 12.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 ((b * b) <= 5.4d+270) then
tmp = ((a * a) * 4.0d0) + (-1.0d0)
else
tmp = ((b * b) * 12.0d0) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 5.4e+270) {
tmp = ((a * a) * 4.0) + -1.0;
} else {
tmp = ((b * b) * 12.0) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 5.4e+270: tmp = ((a * a) * 4.0) + -1.0 else: tmp = ((b * b) * 12.0) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 5.4e+270) tmp = Float64(Float64(Float64(a * a) * 4.0) + -1.0); else tmp = Float64(Float64(Float64(b * b) * 12.0) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 5.4e+270) tmp = ((a * a) * 4.0) + -1.0; else tmp = ((b * b) * 12.0) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 5.4e+270], N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(b * b), $MachinePrecision] * 12.0), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 5.4 \cdot 10^{+270}:\\
\;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\
\mathbf{else}:\\
\;\;\;\;\left(b \cdot b\right) \cdot 12 + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 5.3999999999999998e270Initial program 79.0%
associate--l+79.0%
fma-define79.0%
sqr-neg79.0%
fma-define79.0%
distribute-rgt-in79.0%
sqr-neg79.0%
distribute-rgt-in79.0%
fma-define79.0%
sqr-neg79.0%
Simplified79.5%
Taylor expanded in b around 0 66.6%
Taylor expanded in a around 0 64.5%
*-commutative64.5%
Simplified64.5%
pow283.4%
Applied egg-rr64.5%
if 5.3999999999999998e270 < (*.f64 b b) Initial program 55.4%
associate--l+55.4%
fma-define55.4%
sqr-neg55.4%
fma-define55.4%
distribute-rgt-in55.4%
sqr-neg55.4%
distribute-rgt-in55.4%
fma-define55.4%
sqr-neg55.4%
Simplified60.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 91.7%
pow2100.0%
Applied egg-rr91.7%
Final simplification71.4%
(FPCore (a b) :precision binary64 (+ (* (* b b) 12.0) -1.0))
double code(double a, double b) {
return ((b * b) * 12.0) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((b * b) * 12.0d0) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((b * b) * 12.0) + -1.0;
}
def code(a, b): return ((b * b) * 12.0) + -1.0
function code(a, b) return Float64(Float64(Float64(b * b) * 12.0) + -1.0) end
function tmp = code(a, b) tmp = ((b * b) * 12.0) + -1.0; end
code[a_, b_] := N[(N[(N[(b * b), $MachinePrecision] * 12.0), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(b \cdot b\right) \cdot 12 + -1
\end{array}
Initial program 73.0%
associate--l+73.0%
fma-define73.0%
sqr-neg73.0%
fma-define73.0%
distribute-rgt-in73.0%
sqr-neg73.0%
distribute-rgt-in73.0%
fma-define73.0%
sqr-neg73.0%
Simplified74.5%
Taylor expanded in a around 0 71.3%
Taylor expanded in b around 0 53.4%
pow271.3%
Applied egg-rr53.4%
Final simplification53.4%
(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 73.0%
associate--l+73.0%
fma-define73.0%
sqr-neg73.0%
fma-define73.0%
distribute-rgt-in73.0%
sqr-neg73.0%
distribute-rgt-in73.0%
fma-define73.0%
sqr-neg73.0%
Simplified74.5%
Taylor expanded in a around 0 71.3%
Taylor expanded in b around 0 29.0%
herbie shell --seed 2024143
(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))