
(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)))
(sin (+ (* 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))) * sin(((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))) * sin(((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.sin(((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.sin(((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))) * sin(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))) * sin(((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[Sin[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 \sin \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 15 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)))
(sin (+ (* 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))) * sin(((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))) * sin(((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.sin(((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.sin(((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))) * sin(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))) * sin(((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[Sin[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 \sin \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 (* y.im (atan2 x.im x.re)))
(t_1 (* y.re (atan2 x.im x.re)))
(t_2 (sin (fma y.im (log x.re) t_1)))
(t_3
(exp (- (* y.re (log (sqrt (+ (* x.re x.re) (* x.im x.im))))) t_0)))
(t_4 (log (/ -1.0 x.re))))
(if (<= x.re -6.5e+23)
(* (exp (- (fma y.re t_4 t_0))) (sin (fma (- y.im) t_4 t_1)))
(if (<= x.re 5e-282)
(* t_3 (sin t_1))
(if (<= x.re 0.92)
(* t_3 t_2)
(* (exp (- (* y.re (log x.re)) t_0)) t_2))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = y_46_im * atan2(x_46_im, x_46_re);
double t_1 = y_46_re * atan2(x_46_im, x_46_re);
double t_2 = sin(fma(y_46_im, log(x_46_re), t_1));
double t_3 = exp(((y_46_re * log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im))))) - t_0));
double t_4 = log((-1.0 / x_46_re));
double tmp;
if (x_46_re <= -6.5e+23) {
tmp = exp(-fma(y_46_re, t_4, t_0)) * sin(fma(-y_46_im, t_4, t_1));
} else if (x_46_re <= 5e-282) {
tmp = t_3 * sin(t_1);
} else if (x_46_re <= 0.92) {
tmp = t_3 * t_2;
} else {
tmp = exp(((y_46_re * log(x_46_re)) - t_0)) * t_2;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(y_46_im * atan(x_46_im, x_46_re)) t_1 = Float64(y_46_re * atan(x_46_im, x_46_re)) t_2 = sin(fma(y_46_im, log(x_46_re), t_1)) t_3 = exp(Float64(Float64(y_46_re * log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im))))) - t_0)) t_4 = log(Float64(-1.0 / x_46_re)) tmp = 0.0 if (x_46_re <= -6.5e+23) tmp = Float64(exp(Float64(-fma(y_46_re, t_4, t_0))) * sin(fma(Float64(-y_46_im), t_4, t_1))); elseif (x_46_re <= 5e-282) tmp = Float64(t_3 * sin(t_1)); elseif (x_46_re <= 0.92) tmp = Float64(t_3 * t_2); else tmp = Float64(exp(Float64(Float64(y_46_re * log(x_46_re)) - t_0)) * t_2); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(y$46$im * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(y$46$im * N[Log[x$46$re], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Exp[N[(N[(y$46$re * N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Log[N[(-1.0 / x$46$re), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x$46$re, -6.5e+23], N[(N[Exp[(-N[(y$46$re * t$95$4 + t$95$0), $MachinePrecision])], $MachinePrecision] * N[Sin[N[((-y$46$im) * t$95$4 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$re, 5e-282], N[(t$95$3 * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$re, 0.92], N[(t$95$3 * t$95$2), $MachinePrecision], N[(N[Exp[N[(N[(y$46$re * N[Log[x$46$re], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] * t$95$2), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}\\
t_1 := y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\\
t_2 := \sin \left(\mathsf{fma}\left(y.im, \log x.re, t\_1\right)\right)\\
t_3 := e^{y.re \cdot \log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) - t\_0}\\
t_4 := \log \left(\frac{-1}{x.re}\right)\\
\mathbf{if}\;x.re \leq -6.5 \cdot 10^{+23}:\\
\;\;\;\;e^{-\mathsf{fma}\left(y.re, t\_4, t\_0\right)} \cdot \sin \left(\mathsf{fma}\left(-y.im, t\_4, t\_1\right)\right)\\
\mathbf{elif}\;x.re \leq 5 \cdot 10^{-282}:\\
\;\;\;\;t\_3 \cdot \sin t\_1\\
\mathbf{elif}\;x.re \leq 0.92:\\
\;\;\;\;t\_3 \cdot t\_2\\
\mathbf{else}:\\
\;\;\;\;e^{y.re \cdot \log x.re - t\_0} \cdot t\_2\\
\end{array}
\end{array}
if x.re < -6.4999999999999996e23Initial program 27.5%
Taylor expanded in y.im around 0
lower-*.f64N/A
lower-atan2.f6456.1
Applied rewrites56.1%
Taylor expanded in x.re around -inf
lower-*.f64N/A
lower-exp.f64N/A
sub-negN/A
mul-1-negN/A
distribute-neg-outN/A
lower-neg.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-atan2.f64N/A
lower-sin.f64N/A
Applied rewrites73.8%
if -6.4999999999999996e23 < x.re < 5.0000000000000001e-282Initial program 46.0%
Taylor expanded in y.im around 0
lower-*.f64N/A
lower-atan2.f6464.9
Applied rewrites64.9%
if 5.0000000000000001e-282 < x.re < 0.92000000000000004Initial program 62.0%
Taylor expanded in x.im around 0
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-atan2.f6471.1
Applied rewrites71.1%
if 0.92000000000000004 < x.re Initial program 32.7%
Taylor expanded in x.im around 0
lower-*.f64N/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-atan2.f64N/A
lower-sin.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-atan2.f6473.1
Applied rewrites73.1%
Final simplification70.4%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (* y.im (atan2 x.im x.re)))
(t_1 (* y.re (atan2 x.im x.re)))
(t_2 (sin (fma y.im (log x.re) t_1)))
(t_3
(exp (- (* y.re (log (sqrt (+ (* x.re x.re) (* x.im x.im))))) t_0)))
(t_4 (log (/ -1.0 x.re))))
(if (<= x.re -2.1e+52)
(*
(exp (- (fma y.re t_4 t_0)))
(sin (fma y.re (atan2 x.im x.re) (* t_4 (- y.im)))))
(if (<= x.re 5e-282)
(* t_3 (sin t_1))
(if (<= x.re 0.92)
(* t_3 t_2)
(* (exp (- (* y.re (log x.re)) t_0)) t_2))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = y_46_im * atan2(x_46_im, x_46_re);
double t_1 = y_46_re * atan2(x_46_im, x_46_re);
double t_2 = sin(fma(y_46_im, log(x_46_re), t_1));
double t_3 = exp(((y_46_re * log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im))))) - t_0));
double t_4 = log((-1.0 / x_46_re));
double tmp;
if (x_46_re <= -2.1e+52) {
tmp = exp(-fma(y_46_re, t_4, t_0)) * sin(fma(y_46_re, atan2(x_46_im, x_46_re), (t_4 * -y_46_im)));
} else if (x_46_re <= 5e-282) {
tmp = t_3 * sin(t_1);
} else if (x_46_re <= 0.92) {
tmp = t_3 * t_2;
} else {
tmp = exp(((y_46_re * log(x_46_re)) - t_0)) * t_2;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(y_46_im * atan(x_46_im, x_46_re)) t_1 = Float64(y_46_re * atan(x_46_im, x_46_re)) t_2 = sin(fma(y_46_im, log(x_46_re), t_1)) t_3 = exp(Float64(Float64(y_46_re * log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im))))) - t_0)) t_4 = log(Float64(-1.0 / x_46_re)) tmp = 0.0 if (x_46_re <= -2.1e+52) tmp = Float64(exp(Float64(-fma(y_46_re, t_4, t_0))) * sin(fma(y_46_re, atan(x_46_im, x_46_re), Float64(t_4 * Float64(-y_46_im))))); elseif (x_46_re <= 5e-282) tmp = Float64(t_3 * sin(t_1)); elseif (x_46_re <= 0.92) tmp = Float64(t_3 * t_2); else tmp = Float64(exp(Float64(Float64(y_46_re * log(x_46_re)) - t_0)) * t_2); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(y$46$im * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[(y$46$im * N[Log[x$46$re], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Exp[N[(N[(y$46$re * N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Log[N[(-1.0 / x$46$re), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x$46$re, -2.1e+52], N[(N[Exp[(-N[(y$46$re * t$95$4 + t$95$0), $MachinePrecision])], $MachinePrecision] * N[Sin[N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision] + N[(t$95$4 * (-y$46$im)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$re, 5e-282], N[(t$95$3 * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$re, 0.92], N[(t$95$3 * t$95$2), $MachinePrecision], N[(N[Exp[N[(N[(y$46$re * N[Log[x$46$re], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] * t$95$2), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}\\
t_1 := y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\\
t_2 := \sin \left(\mathsf{fma}\left(y.im, \log x.re, t\_1\right)\right)\\
t_3 := e^{y.re \cdot \log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) - t\_0}\\
t_4 := \log \left(\frac{-1}{x.re}\right)\\
\mathbf{if}\;x.re \leq -2.1 \cdot 10^{+52}:\\
\;\;\;\;e^{-\mathsf{fma}\left(y.re, t\_4, t\_0\right)} \cdot \sin \left(\mathsf{fma}\left(y.re, \tan^{-1}_* \frac{x.im}{x.re}, t\_4 \cdot \left(-y.im\right)\right)\right)\\
\mathbf{elif}\;x.re \leq 5 \cdot 10^{-282}:\\
\;\;\;\;t\_3 \cdot \sin t\_1\\
\mathbf{elif}\;x.re \leq 0.92:\\
\;\;\;\;t\_3 \cdot t\_2\\
\mathbf{else}:\\
\;\;\;\;e^{y.re \cdot \log x.re - t\_0} \cdot t\_2\\
\end{array}
\end{array}
if x.re < -2.1e52Initial program 23.8%
Taylor expanded in x.re around -inf
lower-*.f64N/A
lower-exp.f64N/A
sub-negN/A
mul-1-negN/A
distribute-neg-outN/A
lower-neg.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-atan2.f64N/A
lower-sin.f64N/A
Applied rewrites77.0%
if -2.1e52 < x.re < 5.0000000000000001e-282Initial program 51.6%
Taylor expanded in y.im around 0
lower-*.f64N/A
lower-atan2.f6458.3
Applied rewrites58.3%
if 5.0000000000000001e-282 < x.re < 0.92000000000000004Initial program 51.3%
Taylor expanded in x.im around 0
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-atan2.f6461.4
Applied rewrites61.4%
if 0.92000000000000004 < x.re Initial program 29.0%
Taylor expanded in x.im around 0
lower-*.f64N/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-atan2.f64N/A
lower-sin.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lower-atan2.f6473.5
Applied rewrites73.5%
Final simplification66.7%
herbie shell --seed 2024226
(FPCore (x.re x.im y.re y.im)
:name "powComplex, imaginary part"
:precision binary64
(* (exp (- (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re) (* (atan2 x.im x.re) y.im))) (sin (+ (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.im) (* (atan2 x.im x.re) y.re)))))