
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (log (sqrt (+ (* x.re x.re) (* x.im x.im))))))
(*
(exp (- (* t_0 y.re) (* (atan2 x.im x.re) y.im)))
(cos (+ (* t_0 y.im) (* (atan2 x.im x.re) y.re))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im))));
return exp(((t_0 * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((t_0 * y_46_im) + (atan2(x_46_im, x_46_re) * y_46_re)));
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
real(8) :: t_0
t_0 = log(sqrt(((x_46re * x_46re) + (x_46im * x_46im))))
code = exp(((t_0 * y_46re) - (atan2(x_46im, x_46re) * y_46im))) * cos(((t_0 * y_46im) + (atan2(x_46im, x_46re) * y_46re)))
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = Math.log(Math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im))));
return Math.exp(((t_0 * y_46_re) - (Math.atan2(x_46_im, x_46_re) * y_46_im))) * Math.cos(((t_0 * y_46_im) + (Math.atan2(x_46_im, x_46_re) * y_46_re)));
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): t_0 = math.log(math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) return math.exp(((t_0 * y_46_re) - (math.atan2(x_46_im, x_46_re) * y_46_im))) * math.cos(((t_0 * y_46_im) + (math.atan2(x_46_im, x_46_re) * y_46_re)))
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im)))) return Float64(exp(Float64(Float64(t_0 * y_46_re) - Float64(atan(x_46_im, x_46_re) * y_46_im))) * cos(Float64(Float64(t_0 * y_46_im) + Float64(atan(x_46_im, x_46_re) * y_46_re)))) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))); tmp = exp(((t_0 * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((t_0 * y_46_im) + (atan2(x_46_im, x_46_re) * y_46_re))); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, N[(N[Exp[N[(N[(t$95$0 * y$46$re), $MachinePrecision] - N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(t$95$0 * y$46$im), $MachinePrecision] + N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right)\\
e^{t\_0 \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(t\_0 \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (log (sqrt (+ (* x.re x.re) (* x.im x.im))))))
(*
(exp (- (* t_0 y.re) (* (atan2 x.im x.re) y.im)))
(cos (+ (* t_0 y.im) (* (atan2 x.im x.re) y.re))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im))));
return exp(((t_0 * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((t_0 * y_46_im) + (atan2(x_46_im, x_46_re) * y_46_re)));
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
real(8) :: t_0
t_0 = log(sqrt(((x_46re * x_46re) + (x_46im * x_46im))))
code = exp(((t_0 * y_46re) - (atan2(x_46im, x_46re) * y_46im))) * cos(((t_0 * y_46im) + (atan2(x_46im, x_46re) * y_46re)))
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = Math.log(Math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im))));
return Math.exp(((t_0 * y_46_re) - (Math.atan2(x_46_im, x_46_re) * y_46_im))) * Math.cos(((t_0 * y_46_im) + (Math.atan2(x_46_im, x_46_re) * y_46_re)));
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): t_0 = math.log(math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) return math.exp(((t_0 * y_46_re) - (math.atan2(x_46_im, x_46_re) * y_46_im))) * math.cos(((t_0 * y_46_im) + (math.atan2(x_46_im, x_46_re) * y_46_re)))
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im)))) return Float64(exp(Float64(Float64(t_0 * y_46_re) - Float64(atan(x_46_im, x_46_re) * y_46_im))) * cos(Float64(Float64(t_0 * y_46_im) + Float64(atan(x_46_im, x_46_re) * y_46_re)))) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))); tmp = exp(((t_0 * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((t_0 * y_46_im) + (atan2(x_46_im, x_46_re) * y_46_re))); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, N[(N[Exp[N[(N[(t$95$0 * y$46$re), $MachinePrecision] - N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(t$95$0 * y$46$im), $MachinePrecision] + N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right)\\
e^{t\_0 \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(t\_0 \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\end{array}
\end{array}
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (log (hypot x.re x.im)))
(t_1 (* (atan2 x.im x.re) y.im))
(t_2 (* y.re (atan2 x.im x.re))))
(if (<= y.re 4.8e+16)
(* (- (cos t_2) (* y.im (* t_0 (sin t_2)))) (exp (- (* y.re t_0) t_1)))
(*
(/ (pow (hypot x.re x.im) y.re) (+ 1.0 t_1))
(sqrt (pow (cos (fma t_0 y.im t_2)) 2.0))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = log(hypot(x_46_re, x_46_im));
double t_1 = atan2(x_46_im, x_46_re) * y_46_im;
double t_2 = y_46_re * atan2(x_46_im, x_46_re);
double tmp;
if (y_46_re <= 4.8e+16) {
tmp = (cos(t_2) - (y_46_im * (t_0 * sin(t_2)))) * exp(((y_46_re * t_0) - t_1));
} else {
tmp = (pow(hypot(x_46_re, x_46_im), y_46_re) / (1.0 + t_1)) * sqrt(pow(cos(fma(t_0, y_46_im, t_2)), 2.0));
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = log(hypot(x_46_re, x_46_im)) t_1 = Float64(atan(x_46_im, x_46_re) * y_46_im) t_2 = Float64(y_46_re * atan(x_46_im, x_46_re)) tmp = 0.0 if (y_46_re <= 4.8e+16) tmp = Float64(Float64(cos(t_2) - Float64(y_46_im * Float64(t_0 * sin(t_2)))) * exp(Float64(Float64(y_46_re * t_0) - t_1))); else tmp = Float64(Float64((hypot(x_46_re, x_46_im) ^ y_46_re) / Float64(1.0 + t_1)) * sqrt((cos(fma(t_0, y_46_im, t_2)) ^ 2.0))); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[Log[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]}, Block[{t$95$2 = N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$re, 4.8e+16], N[(N[(N[Cos[t$95$2], $MachinePrecision] - N[(y$46$im * N[(t$95$0 * N[Sin[t$95$2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(y$46$re * t$95$0), $MachinePrecision] - t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision], y$46$re], $MachinePrecision] / N[(1.0 + t$95$1), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Power[N[Cos[N[(t$95$0 * y$46$im + t$95$2), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\mathsf{hypot}\left(x.re, x.im\right)\right)\\
t_1 := \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im\\
t_2 := y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\\
\mathbf{if}\;y.re \leq 4.8 \cdot 10^{+16}:\\
\;\;\;\;\left(\cos t\_2 - y.im \cdot \left(t\_0 \cdot \sin t\_2\right)\right) \cdot e^{y.re \cdot t\_0 - t\_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\left(\mathsf{hypot}\left(x.re, x.im\right)\right)}^{y.re}}{1 + t\_1} \cdot \sqrt{{\cos \left(\mathsf{fma}\left(t\_0, y.im, t\_2\right)\right)}^{2}}\\
\end{array}
\end{array}
if y.re < 4.8e16Initial program 45.7%
Taylor expanded in y.im around 0 48.1%
mul-1-neg48.1%
+-commutative48.1%
unpow248.1%
unpow248.1%
hypot-undefine66.7%
Simplified66.7%
*-un-lft-identity66.7%
hypot-define84.6%
log-prod84.6%
metadata-eval84.6%
Applied egg-rr84.6%
+-lft-identity84.6%
Simplified84.6%
if 4.8e16 < y.re Initial program 44.1%
exp-diff42.6%
exp-to-pow42.6%
hypot-define42.6%
*-commutative42.6%
exp-prod42.6%
fma-define42.6%
hypot-define63.2%
*-commutative63.2%
Simplified63.2%
Taylor expanded in y.im around 0 60.3%
add-sqr-sqrt39.7%
sqrt-unprod82.4%
pow282.4%
Applied egg-rr82.4%
Final simplification84.0%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (* (atan2 x.im x.re) y.im))
(t_1 (log (hypot x.re x.im)))
(t_2 (- (* y.re t_1) t_0))
(t_3 (* y.re (atan2 x.im x.re)))
(t_4 (cos (fma t_1 y.im t_3))))
(if (<= y.im -3.6e-7)
(* t_4 (pow E t_2))
(if (<= y.im 7.8e-145)
(* (/ (pow (hypot x.re x.im) y.re) (+ 1.0 t_0)) (sqrt (pow t_4 2.0)))
(* (exp t_2) (cos (+ t_3 (* t_1 y.im))))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = atan2(x_46_im, x_46_re) * y_46_im;
double t_1 = log(hypot(x_46_re, x_46_im));
double t_2 = (y_46_re * t_1) - t_0;
double t_3 = y_46_re * atan2(x_46_im, x_46_re);
double t_4 = cos(fma(t_1, y_46_im, t_3));
double tmp;
if (y_46_im <= -3.6e-7) {
tmp = t_4 * pow(((double) M_E), t_2);
} else if (y_46_im <= 7.8e-145) {
tmp = (pow(hypot(x_46_re, x_46_im), y_46_re) / (1.0 + t_0)) * sqrt(pow(t_4, 2.0));
} else {
tmp = exp(t_2) * cos((t_3 + (t_1 * y_46_im)));
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(atan(x_46_im, x_46_re) * y_46_im) t_1 = log(hypot(x_46_re, x_46_im)) t_2 = Float64(Float64(y_46_re * t_1) - t_0) t_3 = Float64(y_46_re * atan(x_46_im, x_46_re)) t_4 = cos(fma(t_1, y_46_im, t_3)) tmp = 0.0 if (y_46_im <= -3.6e-7) tmp = Float64(t_4 * (exp(1) ^ t_2)); elseif (y_46_im <= 7.8e-145) tmp = Float64(Float64((hypot(x_46_re, x_46_im) ^ y_46_re) / Float64(1.0 + t_0)) * sqrt((t_4 ^ 2.0))); else tmp = Float64(exp(t_2) * cos(Float64(t_3 + Float64(t_1 * y_46_im)))); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]}, Block[{t$95$1 = N[Log[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(y$46$re * t$95$1), $MachinePrecision] - t$95$0), $MachinePrecision]}, Block[{t$95$3 = N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Cos[N[(t$95$1 * y$46$im + t$95$3), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[y$46$im, -3.6e-7], N[(t$95$4 * N[Power[E, t$95$2], $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$im, 7.8e-145], N[(N[(N[Power[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision], y$46$re], $MachinePrecision] / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Power[t$95$4, 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Exp[t$95$2], $MachinePrecision] * N[Cos[N[(t$95$3 + N[(t$95$1 * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im\\
t_1 := \log \left(\mathsf{hypot}\left(x.re, x.im\right)\right)\\
t_2 := y.re \cdot t\_1 - t\_0\\
t_3 := y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\\
t_4 := \cos \left(\mathsf{fma}\left(t\_1, y.im, t\_3\right)\right)\\
\mathbf{if}\;y.im \leq -3.6 \cdot 10^{-7}:\\
\;\;\;\;t\_4 \cdot {e}^{t\_2}\\
\mathbf{elif}\;y.im \leq 7.8 \cdot 10^{-145}:\\
\;\;\;\;\frac{{\left(\mathsf{hypot}\left(x.re, x.im\right)\right)}^{y.re}}{1 + t\_0} \cdot \sqrt{{t\_4}^{2}}\\
\mathbf{else}:\\
\;\;\;\;e^{t\_2} \cdot \cos \left(t\_3 + t\_1 \cdot y.im\right)\\
\end{array}
\end{array}
if y.im < -3.59999999999999994e-7Initial program 40.9%
fmm-def40.9%
hypot-define40.9%
distribute-rgt-neg-out40.9%
fma-define40.9%
hypot-define72.0%
*-commutative72.0%
Simplified72.0%
distribute-rgt-neg-out72.0%
fmm-undef72.0%
*-commutative72.0%
*-commutative72.0%
Applied egg-rr72.0%
add-cube-cbrt72.0%
pow372.0%
Applied egg-rr72.0%
*-un-lft-identity72.0%
exp-prod72.0%
rem-cube-cbrt72.0%
Applied egg-rr72.0%
exp-1-e72.0%
Simplified72.0%
if -3.59999999999999994e-7 < y.im < 7.80000000000000058e-145Initial program 44.0%
exp-diff44.0%
exp-to-pow44.0%
hypot-define44.0%
*-commutative44.0%
exp-prod44.0%
fma-define44.0%
hypot-define81.0%
*-commutative81.0%
Simplified81.0%
Taylor expanded in y.im around 0 81.0%
add-sqr-sqrt66.0%
sqrt-unprod94.0%
pow294.0%
Applied egg-rr94.0%
if 7.80000000000000058e-145 < y.im Initial program 49.0%
fmm-def49.0%
hypot-define49.0%
distribute-rgt-neg-out49.0%
fma-define49.0%
hypot-define80.5%
*-commutative80.5%
Simplified80.5%
distribute-rgt-neg-out80.5%
fmm-undef80.5%
*-commutative80.5%
*-commutative80.5%
Applied egg-rr80.5%
fma-undefine80.5%
hypot-define49.0%
*-commutative49.0%
+-commutative49.0%
*-commutative49.0%
*-commutative49.0%
hypot-define80.5%
Applied egg-rr80.5%
Final simplification83.9%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (* (atan2 x.im x.re) y.im))
(t_1
(cos (+ (* y.re (atan2 x.im x.re)) (* (log (hypot x.re x.im)) y.im))))
(t_2 (pow (hypot x.re x.im) y.re)))
(if (<= y.re -29500000.0)
(* (/ t_2 (+ 1.0 t_0)) t_1)
(* t_1 (/ t_2 (exp t_0))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = atan2(x_46_im, x_46_re) * y_46_im;
double t_1 = cos(((y_46_re * atan2(x_46_im, x_46_re)) + (log(hypot(x_46_re, x_46_im)) * y_46_im)));
double t_2 = pow(hypot(x_46_re, x_46_im), y_46_re);
double tmp;
if (y_46_re <= -29500000.0) {
tmp = (t_2 / (1.0 + t_0)) * t_1;
} else {
tmp = t_1 * (t_2 / exp(t_0));
}
return tmp;
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = Math.atan2(x_46_im, x_46_re) * y_46_im;
double t_1 = Math.cos(((y_46_re * Math.atan2(x_46_im, x_46_re)) + (Math.log(Math.hypot(x_46_re, x_46_im)) * y_46_im)));
double t_2 = Math.pow(Math.hypot(x_46_re, x_46_im), y_46_re);
double tmp;
if (y_46_re <= -29500000.0) {
tmp = (t_2 / (1.0 + t_0)) * t_1;
} else {
tmp = t_1 * (t_2 / Math.exp(t_0));
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): t_0 = math.atan2(x_46_im, x_46_re) * y_46_im t_1 = math.cos(((y_46_re * math.atan2(x_46_im, x_46_re)) + (math.log(math.hypot(x_46_re, x_46_im)) * y_46_im))) t_2 = math.pow(math.hypot(x_46_re, x_46_im), y_46_re) tmp = 0 if y_46_re <= -29500000.0: tmp = (t_2 / (1.0 + t_0)) * t_1 else: tmp = t_1 * (t_2 / math.exp(t_0)) return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(atan(x_46_im, x_46_re) * y_46_im) t_1 = cos(Float64(Float64(y_46_re * atan(x_46_im, x_46_re)) + Float64(log(hypot(x_46_re, x_46_im)) * y_46_im))) t_2 = hypot(x_46_re, x_46_im) ^ y_46_re tmp = 0.0 if (y_46_re <= -29500000.0) tmp = Float64(Float64(t_2 / Float64(1.0 + t_0)) * t_1); else tmp = Float64(t_1 * Float64(t_2 / exp(t_0))); end return tmp end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = atan2(x_46_im, x_46_re) * y_46_im; t_1 = cos(((y_46_re * atan2(x_46_im, x_46_re)) + (log(hypot(x_46_re, x_46_im)) * y_46_im))); t_2 = hypot(x_46_re, x_46_im) ^ y_46_re; tmp = 0.0; if (y_46_re <= -29500000.0) tmp = (t_2 / (1.0 + t_0)) * t_1; else tmp = t_1 * (t_2 / exp(t_0)); end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision] + N[(N[Log[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision]], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision], y$46$re], $MachinePrecision]}, If[LessEqual[y$46$re, -29500000.0], N[(N[(t$95$2 / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision], N[(t$95$1 * N[(t$95$2 / N[Exp[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im\\
t_1 := \cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re} + \log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.im\right)\\
t_2 := {\left(\mathsf{hypot}\left(x.re, x.im\right)\right)}^{y.re}\\
\mathbf{if}\;y.re \leq -29500000:\\
\;\;\;\;\frac{t\_2}{1 + t\_0} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \frac{t\_2}{e^{t\_0}}\\
\end{array}
\end{array}
if y.re < -2.95e7Initial program 43.1%
exp-diff32.3%
exp-to-pow32.3%
hypot-define32.3%
*-commutative32.3%
exp-prod30.8%
fma-define30.8%
hypot-define69.2%
*-commutative69.2%
Simplified69.2%
Taylor expanded in y.im around 0 84.8%
fma-undefine86.2%
hypot-define43.1%
*-commutative43.1%
+-commutative43.1%
*-commutative43.1%
*-commutative43.1%
hypot-define86.2%
Applied egg-rr84.8%
if -2.95e7 < y.re Initial program 46.0%
exp-diff45.5%
exp-to-pow45.5%
hypot-define45.5%
*-commutative45.5%
exp-prod45.5%
fma-define45.5%
hypot-define73.6%
*-commutative73.6%
Simplified73.6%
fma-undefine76.3%
hypot-define46.0%
*-commutative46.0%
+-commutative46.0%
*-commutative46.0%
*-commutative46.0%
hypot-define76.3%
Applied egg-rr73.6%
Taylor expanded in y.im around inf 74.2%
Final simplification76.9%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (log (hypot x.re x.im))))
(*
(exp (- (* y.re t_0) (* (atan2 x.im x.re) y.im)))
(cos (+ (* y.re (atan2 x.im x.re)) (* t_0 y.im))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = log(hypot(x_46_re, x_46_im));
return exp(((y_46_re * t_0) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((y_46_re * atan2(x_46_im, x_46_re)) + (t_0 * y_46_im)));
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = Math.log(Math.hypot(x_46_re, x_46_im));
return Math.exp(((y_46_re * t_0) - (Math.atan2(x_46_im, x_46_re) * y_46_im))) * Math.cos(((y_46_re * Math.atan2(x_46_im, x_46_re)) + (t_0 * y_46_im)));
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): t_0 = math.log(math.hypot(x_46_re, x_46_im)) return math.exp(((y_46_re * t_0) - (math.atan2(x_46_im, x_46_re) * y_46_im))) * math.cos(((y_46_re * math.atan2(x_46_im, x_46_re)) + (t_0 * y_46_im)))
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = log(hypot(x_46_re, x_46_im)) return Float64(exp(Float64(Float64(y_46_re * t_0) - Float64(atan(x_46_im, x_46_re) * y_46_im))) * cos(Float64(Float64(y_46_re * atan(x_46_im, x_46_re)) + Float64(t_0 * y_46_im)))) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = log(hypot(x_46_re, x_46_im)); tmp = exp(((y_46_re * t_0) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((y_46_re * atan2(x_46_im, x_46_re)) + (t_0 * y_46_im))); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[Log[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision]], $MachinePrecision]}, N[(N[Exp[N[(N[(y$46$re * t$95$0), $MachinePrecision] - N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\mathsf{hypot}\left(x.re, x.im\right)\right)\\
e^{y.re \cdot t\_0 - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re} + t\_0 \cdot y.im\right)
\end{array}
\end{array}
Initial program 45.3%
fmm-def45.3%
hypot-define45.3%
distribute-rgt-neg-out45.3%
fma-define45.3%
hypot-define78.8%
*-commutative78.8%
Simplified78.8%
distribute-rgt-neg-out78.8%
fmm-undef78.8%
*-commutative78.8%
*-commutative78.8%
Applied egg-rr78.8%
fma-undefine78.8%
hypot-define45.3%
*-commutative45.3%
+-commutative45.3%
*-commutative45.3%
*-commutative45.3%
hypot-define78.8%
Applied egg-rr78.8%
Final simplification78.8%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0
(cos (+ (* y.re (atan2 x.im x.re)) (* (log (hypot x.re x.im)) y.im))))
(t_1 (+ 1.0 (* (atan2 x.im x.re) y.im))))
(if (<= y.im -1.95e+72)
(* t_0 (/ (pow (+ x.re (* 0.5 (/ (pow x.im 2.0) x.re))) y.re) t_1))
(* (/ (pow (hypot x.re x.im) y.re) t_1) t_0))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = cos(((y_46_re * atan2(x_46_im, x_46_re)) + (log(hypot(x_46_re, x_46_im)) * y_46_im)));
double t_1 = 1.0 + (atan2(x_46_im, x_46_re) * y_46_im);
double tmp;
if (y_46_im <= -1.95e+72) {
tmp = t_0 * (pow((x_46_re + (0.5 * (pow(x_46_im, 2.0) / x_46_re))), y_46_re) / t_1);
} else {
tmp = (pow(hypot(x_46_re, x_46_im), y_46_re) / t_1) * t_0;
}
return tmp;
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = Math.cos(((y_46_re * Math.atan2(x_46_im, x_46_re)) + (Math.log(Math.hypot(x_46_re, x_46_im)) * y_46_im)));
double t_1 = 1.0 + (Math.atan2(x_46_im, x_46_re) * y_46_im);
double tmp;
if (y_46_im <= -1.95e+72) {
tmp = t_0 * (Math.pow((x_46_re + (0.5 * (Math.pow(x_46_im, 2.0) / x_46_re))), y_46_re) / t_1);
} else {
tmp = (Math.pow(Math.hypot(x_46_re, x_46_im), y_46_re) / t_1) * t_0;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): t_0 = math.cos(((y_46_re * math.atan2(x_46_im, x_46_re)) + (math.log(math.hypot(x_46_re, x_46_im)) * y_46_im))) t_1 = 1.0 + (math.atan2(x_46_im, x_46_re) * y_46_im) tmp = 0 if y_46_im <= -1.95e+72: tmp = t_0 * (math.pow((x_46_re + (0.5 * (math.pow(x_46_im, 2.0) / x_46_re))), y_46_re) / t_1) else: tmp = (math.pow(math.hypot(x_46_re, x_46_im), y_46_re) / t_1) * t_0 return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = cos(Float64(Float64(y_46_re * atan(x_46_im, x_46_re)) + Float64(log(hypot(x_46_re, x_46_im)) * y_46_im))) t_1 = Float64(1.0 + Float64(atan(x_46_im, x_46_re) * y_46_im)) tmp = 0.0 if (y_46_im <= -1.95e+72) tmp = Float64(t_0 * Float64((Float64(x_46_re + Float64(0.5 * Float64((x_46_im ^ 2.0) / x_46_re))) ^ y_46_re) / t_1)); else tmp = Float64(Float64((hypot(x_46_re, x_46_im) ^ y_46_re) / t_1) * t_0); end return tmp end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = cos(((y_46_re * atan2(x_46_im, x_46_re)) + (log(hypot(x_46_re, x_46_im)) * y_46_im))); t_1 = 1.0 + (atan2(x_46_im, x_46_re) * y_46_im); tmp = 0.0; if (y_46_im <= -1.95e+72) tmp = t_0 * (((x_46_re + (0.5 * ((x_46_im ^ 2.0) / x_46_re))) ^ y_46_re) / t_1); else tmp = ((hypot(x_46_re, x_46_im) ^ y_46_re) / t_1) * t_0; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[Cos[N[(N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision] + N[(N[Log[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision]], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$im, -1.95e+72], N[(t$95$0 * N[(N[Power[N[(x$46$re + N[(0.5 * N[(N[Power[x$46$im, 2.0], $MachinePrecision] / x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], y$46$re], $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision], y$46$re], $MachinePrecision] / t$95$1), $MachinePrecision] * t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re} + \log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.im\right)\\
t_1 := 1 + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im\\
\mathbf{if}\;y.im \leq -1.95 \cdot 10^{+72}:\\
\;\;\;\;t\_0 \cdot \frac{{\left(x.re + 0.5 \cdot \frac{{x.im}^{2}}{x.re}\right)}^{y.re}}{t\_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\left(\mathsf{hypot}\left(x.re, x.im\right)\right)}^{y.re}}{t\_1} \cdot t\_0\\
\end{array}
\end{array}
if y.im < -1.94999999999999996e72Initial program 42.9%
exp-diff38.1%
exp-to-pow38.1%
hypot-define38.1%
*-commutative38.1%
exp-prod38.1%
fma-define38.1%
hypot-define60.2%
*-commutative60.2%
Simplified60.2%
Taylor expanded in y.im around 0 22.2%
fma-undefine67.6%
hypot-define42.9%
*-commutative42.9%
+-commutative42.9%
*-commutative42.9%
*-commutative42.9%
hypot-define67.6%
Applied egg-rr22.2%
Taylor expanded in x.im around 0 44.5%
if -1.94999999999999996e72 < y.im Initial program 45.8%
exp-diff43.0%
exp-to-pow43.0%
hypot-define43.0%
*-commutative43.0%
exp-prod42.5%
fma-define42.5%
hypot-define74.9%
*-commutative74.9%
Simplified74.9%
Taylor expanded in y.im around 0 68.0%
fma-undefine81.0%
hypot-define45.8%
*-commutative45.8%
+-commutative45.8%
*-commutative45.8%
*-commutative45.8%
hypot-define81.0%
Applied egg-rr68.0%
Final simplification64.1%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* (/ (pow (hypot x.re x.im) y.re) (+ 1.0 (* (atan2 x.im x.re) y.im))) (cos (+ (* y.re (atan2 x.im x.re)) (* (log (hypot x.re x.im)) y.im)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (pow(hypot(x_46_re, x_46_im), y_46_re) / (1.0 + (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((y_46_re * atan2(x_46_im, x_46_re)) + (log(hypot(x_46_re, x_46_im)) * y_46_im)));
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (Math.pow(Math.hypot(x_46_re, x_46_im), y_46_re) / (1.0 + (Math.atan2(x_46_im, x_46_re) * y_46_im))) * Math.cos(((y_46_re * Math.atan2(x_46_im, x_46_re)) + (Math.log(Math.hypot(x_46_re, x_46_im)) * y_46_im)));
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return (math.pow(math.hypot(x_46_re, x_46_im), y_46_re) / (1.0 + (math.atan2(x_46_im, x_46_re) * y_46_im))) * math.cos(((y_46_re * math.atan2(x_46_im, x_46_re)) + (math.log(math.hypot(x_46_re, x_46_im)) * y_46_im)))
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64((hypot(x_46_re, x_46_im) ^ y_46_re) / Float64(1.0 + Float64(atan(x_46_im, x_46_re) * y_46_im))) * cos(Float64(Float64(y_46_re * atan(x_46_im, x_46_re)) + Float64(log(hypot(x_46_re, x_46_im)) * y_46_im)))) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = ((hypot(x_46_re, x_46_im) ^ y_46_re) / (1.0 + (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((y_46_re * atan2(x_46_im, x_46_re)) + (log(hypot(x_46_re, x_46_im)) * y_46_im))); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[Power[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision], y$46$re], $MachinePrecision] / N[(1.0 + N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision] + N[(N[Log[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision]], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{\left(\mathsf{hypot}\left(x.re, x.im\right)\right)}^{y.re}}{1 + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re} + \log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.im\right)
\end{array}
Initial program 45.3%
exp-diff42.2%
exp-to-pow42.2%
hypot-define42.2%
*-commutative42.2%
exp-prod41.8%
fma-define41.8%
hypot-define72.5%
*-commutative72.5%
Simplified72.5%
Taylor expanded in y.im around 0 60.5%
fma-undefine78.8%
hypot-define45.3%
*-commutative45.3%
+-commutative45.3%
*-commutative45.3%
*-commutative45.3%
hypot-define78.8%
Applied egg-rr60.5%
Final simplification60.5%
herbie shell --seed 2024179
(FPCore (x.re x.im y.re y.im)
:name "powComplex, real part"
:precision binary64
(* (exp (- (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re) (* (atan2 x.im x.re) y.im))) (cos (+ (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.im) (* (atan2 x.im x.re) y.re)))))