
(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 7 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 (<=
(+
(pow (+ (* a a) (* b b)) 2.0)
(* 4.0 (+ (* (* a a) (+ a 1.0)) (* (* b b) (- 1.0 (* a 3.0))))))
INFINITY)
(+
(pow (hypot a b) 4.0)
(fma 4.0 (fma a (* a (+ a 1.0)) (* (* b b) (+ 1.0 (* a -3.0)))) -1.0))
(* (pow a 3.0) (+ a 4.0))))
double code(double a, double b) {
double tmp;
if ((pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))))) <= ((double) INFINITY)) {
tmp = pow(hypot(a, b), 4.0) + fma(4.0, fma(a, (a * (a + 1.0)), ((b * b) * (1.0 + (a * -3.0)))), -1.0);
} else {
tmp = pow(a, 3.0) * (a + 4.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(a + 1.0)) + Float64(Float64(b * b) * Float64(1.0 - Float64(a * 3.0)))))) <= Inf) tmp = Float64((hypot(a, b) ^ 4.0) + fma(4.0, fma(a, Float64(a * Float64(a + 1.0)), Float64(Float64(b * b) * Float64(1.0 + Float64(a * -3.0)))), -1.0)); else tmp = Float64((a ^ 3.0) * Float64(a + 4.0)); end return tmp end
code[a_, b_] := 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[(a + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(4.0 * N[(a * N[(a * N[(a + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 + N[(a * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[Power[a, 3.0], $MachinePrecision] * N[(a + 4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right) \leq \infty:\\
\;\;\;\;{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(4, \mathsf{fma}\left(a, a \cdot \left(a + 1\right), \left(b \cdot b\right) \cdot \left(1 + a \cdot -3\right)\right), -1\right)\\
\mathbf{else}:\\
\;\;\;\;{a}^{3} \cdot \left(a + 4\right)\\
\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 1 (*.f64 3 a)))))) < +inf.0Initial program 99.9%
associate--l+99.9%
fma-def99.9%
fma-neg99.9%
associate-*l*99.9%
fma-def99.9%
+-commutative99.9%
sub-neg99.9%
*-commutative99.9%
distribute-rgt-neg-in99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
expm1-log1p-u98.3%
expm1-udef98.2%
fma-def98.2%
fma-def98.2%
add-sqr-sqrt98.2%
pow298.2%
fma-def98.2%
hypot-def98.2%
Applied egg-rr98.2%
expm1-def98.3%
expm1-log1p99.9%
unpow299.9%
pow-sqr100.0%
metadata-eval100.0%
Simplified100.0%
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 1 (*.f64 3 a)))))) Initial program 0.0%
associate--l+0.0%
fma-def0.0%
fma-neg0.0%
associate-*l*0.0%
fma-def2.9%
+-commutative2.9%
sub-neg2.9%
*-commutative2.9%
distribute-rgt-neg-in2.9%
metadata-eval2.9%
metadata-eval2.9%
Simplified2.9%
expm1-log1p-u2.9%
expm1-udef2.9%
fma-def2.9%
fma-def2.9%
add-sqr-sqrt2.9%
pow22.9%
fma-def2.9%
hypot-def2.9%
Applied egg-rr2.9%
expm1-def2.9%
expm1-log1p2.9%
unpow22.9%
pow-sqr2.9%
metadata-eval2.9%
Simplified2.9%
Taylor expanded in b around 0 26.5%
fma-def26.5%
distribute-rgt-in26.5%
*-lft-identity26.5%
unpow226.5%
unpow226.5%
cube-mult26.5%
fma-udef26.5%
fma-udef26.5%
+-commutative26.5%
associate--l+26.5%
fma-neg26.5%
metadata-eval26.5%
Simplified26.5%
Taylor expanded in a around inf 26.5%
+-commutative26.5%
metadata-eval26.5%
pow-plus26.5%
*-commutative26.5%
distribute-lft-out90.2%
Simplified90.2%
Final simplification97.4%
(FPCore (a b)
:precision binary64
(let* ((t_0
(+
(pow (+ (* a a) (* b b)) 2.0)
(* 4.0 (+ (* (* a a) (+ a 1.0)) (* (* b b) (- 1.0 (* a 3.0))))))))
(if (<= t_0 INFINITY) (+ t_0 -1.0) (* (pow a 3.0) (+ a 4.0)))))
double code(double a, double b) {
double t_0 = pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))));
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0 + -1.0;
} else {
tmp = pow(a, 3.0) * (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) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))));
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0 + -1.0;
} else {
tmp = Math.pow(a, 3.0) * (a + 4.0);
}
return tmp;
}
def code(a, b): t_0 = math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0))))) tmp = 0 if t_0 <= math.inf: tmp = t_0 + -1.0 else: tmp = math.pow(a, 3.0) * (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(a + 1.0)) + Float64(Float64(b * b) * Float64(1.0 - Float64(a * 3.0)))))) tmp = 0.0 if (t_0 <= Inf) tmp = Float64(t_0 + -1.0); else tmp = Float64((a ^ 3.0) * Float64(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) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0))))); tmp = 0.0; if (t_0 <= Inf) tmp = t_0 + -1.0; else tmp = (a ^ 3.0) * (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[(a + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], N[(t$95$0 + -1.0), $MachinePrecision], N[(N[Power[a, 3.0], $MachinePrecision] * N[(a + 4.0), $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(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right)\\
\mathbf{if}\;t_0 \leq \infty:\\
\;\;\;\;t_0 + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{3} \cdot \left(a + 4\right)\\
\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 1 (*.f64 3 a)))))) < +inf.0Initial program 99.9%
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 1 (*.f64 3 a)))))) Initial program 0.0%
associate--l+0.0%
fma-def0.0%
fma-neg0.0%
associate-*l*0.0%
fma-def2.9%
+-commutative2.9%
sub-neg2.9%
*-commutative2.9%
distribute-rgt-neg-in2.9%
metadata-eval2.9%
metadata-eval2.9%
Simplified2.9%
expm1-log1p-u2.9%
expm1-udef2.9%
fma-def2.9%
fma-def2.9%
add-sqr-sqrt2.9%
pow22.9%
fma-def2.9%
hypot-def2.9%
Applied egg-rr2.9%
expm1-def2.9%
expm1-log1p2.9%
unpow22.9%
pow-sqr2.9%
metadata-eval2.9%
Simplified2.9%
Taylor expanded in b around 0 26.5%
fma-def26.5%
distribute-rgt-in26.5%
*-lft-identity26.5%
unpow226.5%
unpow226.5%
cube-mult26.5%
fma-udef26.5%
fma-udef26.5%
+-commutative26.5%
associate--l+26.5%
fma-neg26.5%
metadata-eval26.5%
Simplified26.5%
Taylor expanded in a around inf 26.5%
+-commutative26.5%
metadata-eval26.5%
pow-plus26.5%
*-commutative26.5%
distribute-lft-out90.2%
Simplified90.2%
Final simplification97.3%
(FPCore (a b) :precision binary64 (if (<= b 580.0) (+ -1.0 (pow a 4.0)) (if (or (<= b 7.2e+40) (not (<= b 2.8e+49))) (pow b 4.0) (pow a 4.0))))
double code(double a, double b) {
double tmp;
if (b <= 580.0) {
tmp = -1.0 + pow(a, 4.0);
} else if ((b <= 7.2e+40) || !(b <= 2.8e+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 <= 580.0d0) then
tmp = (-1.0d0) + (a ** 4.0d0)
else if ((b <= 7.2d+40) .or. (.not. (b <= 2.8d+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 <= 580.0) {
tmp = -1.0 + Math.pow(a, 4.0);
} else if ((b <= 7.2e+40) || !(b <= 2.8e+49)) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 580.0: tmp = -1.0 + math.pow(a, 4.0) elif (b <= 7.2e+40) or not (b <= 2.8e+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 <= 580.0) tmp = Float64(-1.0 + (a ^ 4.0)); elseif ((b <= 7.2e+40) || !(b <= 2.8e+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 <= 580.0) tmp = -1.0 + (a ^ 4.0); elseif ((b <= 7.2e+40) || ~((b <= 2.8e+49))) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 580.0], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 7.2e+40], N[Not[LessEqual[b, 2.8e+49]], $MachinePrecision]], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 580:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{elif}\;b \leq 7.2 \cdot 10^{+40} \lor \neg \left(b \leq 2.8 \cdot 10^{+49}\right):\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if b < 580Initial program 77.1%
sub-neg77.1%
Simplified77.7%
Taylor expanded in a around inf 77.6%
if 580 < b < 7.19999999999999993e40 or 2.7999999999999998e49 < b Initial program 66.1%
associate--l+66.1%
fma-def66.1%
fma-neg66.1%
associate-*l*66.1%
fma-def67.5%
+-commutative67.5%
sub-neg67.5%
*-commutative67.5%
distribute-rgt-neg-in67.5%
metadata-eval67.5%
metadata-eval67.5%
Simplified67.5%
expm1-log1p-u66.5%
expm1-udef66.5%
fma-def66.5%
fma-def66.5%
add-sqr-sqrt66.5%
pow266.5%
fma-def66.5%
hypot-def66.5%
Applied egg-rr66.5%
expm1-def66.5%
expm1-log1p67.5%
unpow267.5%
pow-sqr67.6%
metadata-eval67.6%
Simplified67.6%
Taylor expanded in b around inf 95.3%
if 7.19999999999999993e40 < b < 2.7999999999999998e49Initial program 20.0%
associate--l+20.0%
fma-def20.0%
fma-neg20.0%
associate-*l*20.0%
fma-def20.0%
+-commutative20.0%
sub-neg20.0%
*-commutative20.0%
distribute-rgt-neg-in20.0%
metadata-eval20.0%
metadata-eval20.0%
Simplified20.0%
expm1-log1p-u20.0%
expm1-udef20.0%
fma-def20.0%
fma-def20.0%
add-sqr-sqrt20.0%
pow220.0%
fma-def20.0%
hypot-def20.0%
Applied egg-rr20.0%
expm1-def20.0%
expm1-log1p20.0%
unpow220.0%
pow-sqr20.0%
metadata-eval20.0%
Simplified20.0%
Taylor expanded in a around inf 100.0%
Final simplification83.0%
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ -1.0 (* a (* a 4.0)))))
(if (<= b 3.9e-128)
t_0
(if (<= b 1.15e-120) (pow a 4.0) (if (<= b 475.0) t_0 (pow b 4.0))))))
double code(double a, double b) {
double t_0 = -1.0 + (a * (a * 4.0));
double tmp;
if (b <= 3.9e-128) {
tmp = t_0;
} else if (b <= 1.15e-120) {
tmp = pow(a, 4.0);
} else if (b <= 475.0) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (-1.0d0) + (a * (a * 4.0d0))
if (b <= 3.9d-128) then
tmp = t_0
else if (b <= 1.15d-120) then
tmp = a ** 4.0d0
else if (b <= 475.0d0) then
tmp = t_0
else
tmp = b ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = -1.0 + (a * (a * 4.0));
double tmp;
if (b <= 3.9e-128) {
tmp = t_0;
} else if (b <= 1.15e-120) {
tmp = Math.pow(a, 4.0);
} else if (b <= 475.0) {
tmp = t_0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): t_0 = -1.0 + (a * (a * 4.0)) tmp = 0 if b <= 3.9e-128: tmp = t_0 elif b <= 1.15e-120: tmp = math.pow(a, 4.0) elif b <= 475.0: tmp = t_0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) t_0 = Float64(-1.0 + Float64(a * Float64(a * 4.0))) tmp = 0.0 if (b <= 3.9e-128) tmp = t_0; elseif (b <= 1.15e-120) tmp = a ^ 4.0; elseif (b <= 475.0) tmp = t_0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) t_0 = -1.0 + (a * (a * 4.0)); tmp = 0.0; if (b <= 3.9e-128) tmp = t_0; elseif (b <= 1.15e-120) tmp = a ^ 4.0; elseif (b <= 475.0) tmp = t_0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(-1.0 + N[(a * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 3.9e-128], t$95$0, If[LessEqual[b, 1.15e-120], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[b, 475.0], t$95$0, N[Power[b, 4.0], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + a \cdot \left(a \cdot 4\right)\\
\mathbf{if}\;b \leq 3.9 \cdot 10^{-128}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-120}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;b \leq 475:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 3.89999999999999997e-128 or 1.14999999999999993e-120 < b < 475Initial program 77.4%
associate--l+77.5%
fma-def77.5%
fma-neg77.5%
associate-*l*77.5%
fma-def78.0%
+-commutative78.0%
sub-neg78.0%
*-commutative78.0%
distribute-rgt-neg-in78.0%
metadata-eval78.0%
metadata-eval78.0%
Simplified78.0%
Taylor expanded in b around 0 62.2%
Taylor expanded in a around 0 60.7%
expm1-log1p-u60.7%
expm1-udef60.7%
log1p-udef60.7%
rem-exp-log60.7%
+-commutative60.7%
Applied egg-rr60.7%
associate--l+60.7%
metadata-eval60.7%
+-rgt-identity60.7%
unpow260.7%
associate-*r*60.7%
Applied egg-rr60.7%
if 3.89999999999999997e-128 < b < 1.14999999999999993e-120Initial program 49.2%
associate--l+49.2%
fma-def49.2%
fma-neg49.2%
associate-*l*49.2%
fma-def49.2%
+-commutative49.2%
sub-neg49.2%
*-commutative49.2%
distribute-rgt-neg-in49.2%
metadata-eval49.2%
metadata-eval49.2%
Simplified49.2%
expm1-log1p-u44.5%
expm1-udef44.5%
fma-def44.5%
fma-def44.5%
add-sqr-sqrt44.5%
pow244.5%
fma-def44.5%
hypot-def44.5%
Applied egg-rr44.5%
expm1-def44.5%
expm1-log1p49.2%
unpow249.2%
pow-sqr50.0%
metadata-eval50.0%
Simplified50.0%
Taylor expanded in a around inf 100.0%
if 475 < b Initial program 63.1%
associate--l+63.1%
fma-def63.1%
fma-neg63.1%
associate-*l*63.1%
fma-def64.4%
+-commutative64.4%
sub-neg64.4%
*-commutative64.4%
distribute-rgt-neg-in64.4%
metadata-eval64.4%
metadata-eval64.4%
Simplified64.4%
expm1-log1p-u63.4%
expm1-udef63.4%
fma-def63.4%
fma-def63.4%
add-sqr-sqrt63.4%
pow263.4%
fma-def63.4%
hypot-def63.4%
Applied egg-rr63.4%
expm1-def63.4%
expm1-log1p64.4%
unpow264.4%
pow-sqr64.5%
metadata-eval64.5%
Simplified64.5%
Taylor expanded in b around inf 89.3%
Final simplification69.5%
(FPCore (a b) :precision binary64 (if (or (<= a -0.0065) (not (<= a 3.9e-7))) (pow a 4.0) (+ -1.0 (* a (* a 4.0)))))
double code(double a, double b) {
double tmp;
if ((a <= -0.0065) || !(a <= 3.9e-7)) {
tmp = pow(a, 4.0);
} else {
tmp = -1.0 + (a * (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.0065d0)) .or. (.not. (a <= 3.9d-7))) then
tmp = a ** 4.0d0
else
tmp = (-1.0d0) + (a * (a * 4.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a <= -0.0065) || !(a <= 3.9e-7)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = -1.0 + (a * (a * 4.0));
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -0.0065) or not (a <= 3.9e-7): tmp = math.pow(a, 4.0) else: tmp = -1.0 + (a * (a * 4.0)) return tmp
function code(a, b) tmp = 0.0 if ((a <= -0.0065) || !(a <= 3.9e-7)) tmp = a ^ 4.0; else tmp = Float64(-1.0 + Float64(a * Float64(a * 4.0))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -0.0065) || ~((a <= 3.9e-7))) tmp = a ^ 4.0; else tmp = -1.0 + (a * (a * 4.0)); end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -0.0065], N[Not[LessEqual[a, 3.9e-7]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], N[(-1.0 + N[(a * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.0065 \lor \neg \left(a \leq 3.9 \cdot 10^{-7}\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;-1 + a \cdot \left(a \cdot 4\right)\\
\end{array}
\end{array}
if a < -0.0064999999999999997 or 3.90000000000000025e-7 < a Initial program 48.4%
associate--l+48.4%
fma-def48.4%
fma-neg48.4%
associate-*l*48.4%
fma-def49.9%
+-commutative49.9%
sub-neg49.9%
*-commutative49.9%
distribute-rgt-neg-in49.9%
metadata-eval49.9%
metadata-eval49.9%
Simplified49.9%
expm1-log1p-u48.5%
expm1-udef48.5%
fma-def48.5%
fma-def48.5%
add-sqr-sqrt48.5%
pow248.5%
fma-def48.5%
hypot-def48.5%
Applied egg-rr48.5%
expm1-def48.5%
expm1-log1p49.9%
unpow249.9%
pow-sqr50.0%
metadata-eval50.0%
Simplified50.0%
Taylor expanded in a around inf 83.1%
if -0.0064999999999999997 < a < 3.90000000000000025e-7Initial program 99.9%
associate--l+99.9%
fma-def99.9%
fma-neg99.9%
associate-*l*99.9%
fma-def99.9%
+-commutative99.9%
sub-neg99.9%
*-commutative99.9%
distribute-rgt-neg-in99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in b around 0 48.0%
Taylor expanded in a around 0 48.0%
expm1-log1p-u48.0%
expm1-udef48.0%
log1p-udef48.0%
rem-exp-log48.0%
+-commutative48.0%
Applied egg-rr48.0%
associate--l+48.0%
metadata-eval48.0%
+-rgt-identity48.0%
unpow248.0%
associate-*r*48.0%
Applied egg-rr48.0%
Final simplification66.4%
(FPCore (a b) :precision binary64 (+ -1.0 (* a (* a 4.0))))
double code(double a, double b) {
return -1.0 + (a * (a * 4.0));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + (a * (a * 4.0d0))
end function
public static double code(double a, double b) {
return -1.0 + (a * (a * 4.0));
}
def code(a, b): return -1.0 + (a * (a * 4.0))
function code(a, b) return Float64(-1.0 + Float64(a * Float64(a * 4.0))) end
function tmp = code(a, b) tmp = -1.0 + (a * (a * 4.0)); end
code[a_, b_] := N[(-1.0 + N[(a * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + a \cdot \left(a \cdot 4\right)
\end{array}
Initial program 73.0%
associate--l+73.0%
fma-def73.0%
fma-neg73.0%
associate-*l*73.0%
fma-def73.7%
+-commutative73.7%
sub-neg73.7%
*-commutative73.7%
distribute-rgt-neg-in73.7%
metadata-eval73.7%
metadata-eval73.7%
Simplified73.7%
Taylor expanded in b around 0 49.8%
Taylor expanded in a around 0 50.2%
expm1-log1p-u50.2%
expm1-udef50.2%
log1p-udef50.2%
rem-exp-log50.2%
+-commutative50.2%
Applied egg-rr50.2%
associate--l+50.2%
metadata-eval50.2%
+-rgt-identity50.2%
unpow250.2%
associate-*r*50.2%
Applied egg-rr50.2%
Final simplification50.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 73.0%
sub-neg73.0%
Simplified73.7%
Taylor expanded in a around inf 66.2%
Taylor expanded in a around 0 23.1%
Final simplification23.1%
herbie shell --seed 2024018
(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))