
(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)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
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)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
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
(exp
(- (* (log (hypot x.re x.im)) y.re) (* (atan2 x.im x.re) y.im)))))
(if (<= y.im 6.8e+30)
(* t_0 (sin (fma y.im (log (hypot (* -1.0 x.im) x.re)) (/ PI 2.0))))
(*
t_0
(-
(sin (fma y.re (atan2 x.im x.re) (/ PI 2.0)))
(*
y.im
(*
(log (hypot (* -1.0 x.im) (* -1.0 x.re)))
(sin (* y.re (atan2 x.im x.re))))))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = exp(((log(hypot(x_46_re, x_46_im)) * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im)));
double tmp;
if (y_46_im <= 6.8e+30) {
tmp = t_0 * sin(fma(y_46_im, log(hypot((-1.0 * x_46_im), x_46_re)), (((double) M_PI) / 2.0)));
} else {
tmp = t_0 * (sin(fma(y_46_re, atan2(x_46_im, x_46_re), (((double) M_PI) / 2.0))) - (y_46_im * (log(hypot((-1.0 * x_46_im), (-1.0 * x_46_re))) * sin((y_46_re * atan2(x_46_im, x_46_re))))));
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = exp(Float64(Float64(log(hypot(x_46_re, x_46_im)) * y_46_re) - Float64(atan(x_46_im, x_46_re) * y_46_im))) tmp = 0.0 if (y_46_im <= 6.8e+30) tmp = Float64(t_0 * sin(fma(y_46_im, log(hypot(Float64(-1.0 * x_46_im), x_46_re)), Float64(pi / 2.0)))); else tmp = Float64(t_0 * Float64(sin(fma(y_46_re, atan(x_46_im, x_46_re), Float64(pi / 2.0))) - Float64(y_46_im * Float64(log(hypot(Float64(-1.0 * x_46_im), Float64(-1.0 * x_46_re))) * sin(Float64(y_46_re * atan(x_46_im, x_46_re))))))); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[Exp[N[(N[(N[Log[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision]], $MachinePrecision] * y$46$re), $MachinePrecision] - N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[y$46$im, 6.8e+30], N[(t$95$0 * N[Sin[N[(y$46$im * N[Log[N[Sqrt[N[(-1.0 * x$46$im), $MachinePrecision] ^ 2 + x$46$re ^ 2], $MachinePrecision]], $MachinePrecision] + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[Sin[N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision] + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(y$46$im * N[(N[Log[N[Sqrt[N[(-1.0 * x$46$im), $MachinePrecision] ^ 2 + N[(-1.0 * x$46$re), $MachinePrecision] ^ 2], $MachinePrecision]], $MachinePrecision] * N[Sin[N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im}\\
\mathbf{if}\;y.im \leq 6.8 \cdot 10^{+30}:\\
\;\;\;\;t\_0 \cdot \sin \left(\mathsf{fma}\left(y.im, \log \left(\mathsf{hypot}\left(-1 \cdot x.im, x.re\right)\right), \frac{\pi}{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(\sin \left(\mathsf{fma}\left(y.re, \tan^{-1}_* \frac{x.im}{x.re}, \frac{\pi}{2}\right)\right) - y.im \cdot \left(\log \left(\mathsf{hypot}\left(-1 \cdot x.im, -1 \cdot x.re\right)\right) \cdot \sin \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)\right)\right)\\
\end{array}
\end{array}
if y.im < 6.8000000000000005e30Initial program 45.8%
Taylor expanded in y.im around 0
fp-cancel-sign-sub-invN/A
lower--.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-fma.f64N/A
lift-atan2.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites52.0%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-hypot.f6452.5
Applied rewrites52.5%
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
unpow1/2N/A
sqr-neg-revN/A
sqr-neg-revN/A
lower-hypot.f64N/A
lower-neg.f64N/A
lower-neg.f6486.1
Applied rewrites86.1%
Taylor expanded in y.re around 0
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lower-fma.f64N/A
Applied rewrites92.4%
if 6.8000000000000005e30 < y.im Initial program 34.5%
Taylor expanded in y.im around 0
fp-cancel-sign-sub-invN/A
lower--.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-fma.f64N/A
lift-atan2.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites46.7%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-hypot.f6452.5
Applied rewrites52.5%
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
unpow1/2N/A
sqr-neg-revN/A
sqr-neg-revN/A
lower-hypot.f64N/A
lower-neg.f64N/A
lower-neg.f6474.0
Applied rewrites74.0%
Final simplification87.5%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* (exp (- (* (log (hypot x.re x.im)) y.re) (* (atan2 x.im x.re) y.im))) (sin (fma y.im (log (hypot (* -1.0 x.im) x.re)) (/ PI 2.0)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return exp(((log(hypot(x_46_re, x_46_im)) * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * sin(fma(y_46_im, log(hypot((-1.0 * x_46_im), x_46_re)), (((double) M_PI) / 2.0)));
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(exp(Float64(Float64(log(hypot(x_46_re, x_46_im)) * y_46_re) - Float64(atan(x_46_im, x_46_re) * y_46_im))) * sin(fma(y_46_im, log(hypot(Float64(-1.0 * x_46_im), x_46_re)), Float64(pi / 2.0)))) end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[Exp[N[(N[(N[Log[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision]], $MachinePrecision] * y$46$re), $MachinePrecision] - N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(y$46$im * N[Log[N[Sqrt[N[(-1.0 * x$46$im), $MachinePrecision] ^ 2 + x$46$re ^ 2], $MachinePrecision]], $MachinePrecision] + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \sin \left(\mathsf{fma}\left(y.im, \log \left(\mathsf{hypot}\left(-1 \cdot x.im, x.re\right)\right), \frac{\pi}{2}\right)\right)
\end{array}
Initial program 42.8%
Taylor expanded in y.im around 0
fp-cancel-sign-sub-invN/A
lower--.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-fma.f64N/A
lift-atan2.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites50.6%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-hypot.f6452.5
Applied rewrites52.5%
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
unpow1/2N/A
sqr-neg-revN/A
sqr-neg-revN/A
lower-hypot.f64N/A
lower-neg.f64N/A
lower-neg.f6482.9
Applied rewrites82.9%
Taylor expanded in y.re around 0
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lower-fma.f64N/A
Applied rewrites85.4%
Final simplification85.4%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= x.im 1.55e+162)
(*
(exp
(-
(* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re)
(* (atan2 x.im x.re) y.im)))
(sin (* 0.5 PI)))
(*
(cos (fma y.im (log x.im) (* y.re (atan2 x.im x.re))))
(/
(exp (* y.re (log x.im)))
(+
1.0
(*
y.im
(fma
y.im
(fma
0.16666666666666666
(* y.im (pow (atan2 x.im x.re) 3.0))
(* 0.5 (pow (atan2 x.im x.re) 2.0)))
(atan2 x.im x.re))))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if (x_46_im <= 1.55e+162) {
tmp = exp(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * sin((0.5 * ((double) M_PI)));
} else {
tmp = cos(fma(y_46_im, log(x_46_im), (y_46_re * atan2(x_46_im, x_46_re)))) * (exp((y_46_re * log(x_46_im))) / (1.0 + (y_46_im * fma(y_46_im, fma(0.16666666666666666, (y_46_im * pow(atan2(x_46_im, x_46_re), 3.0)), (0.5 * pow(atan2(x_46_im, x_46_re), 2.0))), atan2(x_46_im, x_46_re)))));
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if (x_46_im <= 1.55e+162) tmp = Float64(exp(Float64(Float64(log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im)))) * y_46_re) - Float64(atan(x_46_im, x_46_re) * y_46_im))) * sin(Float64(0.5 * pi))); else tmp = Float64(cos(fma(y_46_im, log(x_46_im), Float64(y_46_re * atan(x_46_im, x_46_re)))) * Float64(exp(Float64(y_46_re * log(x_46_im))) / Float64(1.0 + Float64(y_46_im * fma(y_46_im, fma(0.16666666666666666, Float64(y_46_im * (atan(x_46_im, x_46_re) ^ 3.0)), Float64(0.5 * (atan(x_46_im, x_46_re) ^ 2.0))), atan(x_46_im, x_46_re)))))); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[x$46$im, 1.55e+162], N[(N[Exp[N[(N[(N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * y$46$re), $MachinePrecision] - N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(y$46$im * N[Log[x$46$im], $MachinePrecision] + N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[Exp[N[(y$46$re * N[Log[x$46$im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(1.0 + N[(y$46$im * N[(y$46$im * N[(0.16666666666666666 * N[(y$46$im * N[Power[N[ArcTan[x$46$im / x$46$re], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Power[N[ArcTan[x$46$im / x$46$re], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x.im \leq 1.55 \cdot 10^{+162}:\\
\;\;\;\;e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \sin \left(0.5 \cdot \pi\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\mathsf{fma}\left(y.im, \log x.im, y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)\right) \cdot \frac{e^{y.re \cdot \log x.im}}{1 + y.im \cdot \mathsf{fma}\left(y.im, \mathsf{fma}\left(0.16666666666666666, y.im \cdot {\tan^{-1}_* \frac{x.im}{x.re}}^{3}, 0.5 \cdot {\tan^{-1}_* \frac{x.im}{x.re}}^{2}\right), \tan^{-1}_* \frac{x.im}{x.re}\right)}\\
\end{array}
\end{array}
if x.im < 1.55e162Initial program 48.2%
Taylor expanded in y.im around 0
fp-cancel-sign-sub-invN/A
lower--.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-fma.f64N/A
lift-atan2.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites54.4%
Taylor expanded in y.re around 0
lower-sin.f64N/A
lower-*.f64N/A
lift-PI.f6469.7
Applied rewrites69.7%
if 1.55e162 < x.im Initial program 0.0%
Taylor expanded in x.re around 0
lower-*.f64N/A
lower-cos.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lift-atan2.f64N/A
exp-diffN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-exp.f64N/A
Applied rewrites75.9%
Taylor expanded in y.im around 0
lower-+.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lift-atan2.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lift-atan2.f64N/A
lift-atan2.f6479.5
Applied rewrites79.5%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (exp (* y.im (atan2 x.im x.re))))
(t_1 (* y.re (atan2 x.im x.re))))
(if (<= x.im 2.8e-308)
(* (cos (fma y.im (log x.re) t_1)) (/ (exp (* y.re (log x.re))) t_0))
(* (cos (fma y.im (log x.im) t_1)) (/ (exp (* y.re (log x.im))) t_0)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = exp((y_46_im * atan2(x_46_im, x_46_re)));
double t_1 = y_46_re * atan2(x_46_im, x_46_re);
double tmp;
if (x_46_im <= 2.8e-308) {
tmp = cos(fma(y_46_im, log(x_46_re), t_1)) * (exp((y_46_re * log(x_46_re))) / t_0);
} else {
tmp = cos(fma(y_46_im, log(x_46_im), t_1)) * (exp((y_46_re * log(x_46_im))) / t_0);
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = exp(Float64(y_46_im * atan(x_46_im, x_46_re))) t_1 = Float64(y_46_re * atan(x_46_im, x_46_re)) tmp = 0.0 if (x_46_im <= 2.8e-308) tmp = Float64(cos(fma(y_46_im, log(x_46_re), t_1)) * Float64(exp(Float64(y_46_re * log(x_46_re))) / t_0)); else tmp = Float64(cos(fma(y_46_im, log(x_46_im), t_1)) * Float64(exp(Float64(y_46_re * log(x_46_im))) / t_0)); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[Exp[N[(y$46$im * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$46$im, 2.8e-308], N[(N[Cos[N[(y$46$im * N[Log[x$46$re], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] * N[(N[Exp[N[(y$46$re * N[Log[x$46$re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(y$46$im * N[Log[x$46$im], $MachinePrecision] + t$95$1), $MachinePrecision]], $MachinePrecision] * N[(N[Exp[N[(y$46$re * N[Log[x$46$im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}\\
t_1 := y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\\
\mathbf{if}\;x.im \leq 2.8 \cdot 10^{-308}:\\
\;\;\;\;\cos \left(\mathsf{fma}\left(y.im, \log x.re, t\_1\right)\right) \cdot \frac{e^{y.re \cdot \log x.re}}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\mathsf{fma}\left(y.im, \log x.im, t\_1\right)\right) \cdot \frac{e^{y.re \cdot \log x.im}}{t\_0}\\
\end{array}
\end{array}
if x.im < 2.79999999999999984e-308Initial program 41.6%
Taylor expanded in x.im around 0
lower-*.f64N/A
lower-cos.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lift-atan2.f64N/A
exp-diffN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-exp.f64N/A
Applied rewrites30.3%
if 2.79999999999999984e-308 < x.im Initial program 43.9%
Taylor expanded in x.re around 0
lower-*.f64N/A
lower-cos.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lift-atan2.f64N/A
exp-diffN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-exp.f64N/A
Applied rewrites68.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* (cos (fma y.im (log x.im) (* y.re (atan2 x.im x.re)))) (/ (exp (* y.re (log x.im))) (exp (* y.im (atan2 x.im x.re))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return cos(fma(y_46_im, log(x_46_im), (y_46_re * atan2(x_46_im, x_46_re)))) * (exp((y_46_re * log(x_46_im))) / exp((y_46_im * atan2(x_46_im, x_46_re))));
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(cos(fma(y_46_im, log(x_46_im), Float64(y_46_re * atan(x_46_im, x_46_re)))) * Float64(exp(Float64(y_46_re * log(x_46_im))) / exp(Float64(y_46_im * atan(x_46_im, x_46_re))))) end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[Cos[N[(y$46$im * N[Log[x$46$im], $MachinePrecision] + N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[Exp[N[(y$46$re * N[Log[x$46$im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Exp[N[(y$46$im * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(\mathsf{fma}\left(y.im, \log x.im, y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)\right) \cdot \frac{e^{y.re \cdot \log x.im}}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\end{array}
Initial program 42.8%
Taylor expanded in x.re around 0
lower-*.f64N/A
lower-cos.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lift-atan2.f64N/A
exp-diffN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-exp.f64N/A
Applied rewrites34.3%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(*
(cos (fma y.im (log x.im) (* y.re (atan2 x.im x.re))))
(/
(exp (* y.re (log x.im)))
(+
1.0
(*
y.im
(fma
y.im
(fma
0.16666666666666666
(* y.im (pow (atan2 x.im x.re) 3.0))
(* 0.5 (pow (atan2 x.im x.re) 2.0)))
(atan2 x.im x.re)))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return cos(fma(y_46_im, log(x_46_im), (y_46_re * atan2(x_46_im, x_46_re)))) * (exp((y_46_re * log(x_46_im))) / (1.0 + (y_46_im * fma(y_46_im, fma(0.16666666666666666, (y_46_im * pow(atan2(x_46_im, x_46_re), 3.0)), (0.5 * pow(atan2(x_46_im, x_46_re), 2.0))), atan2(x_46_im, x_46_re)))));
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(cos(fma(y_46_im, log(x_46_im), Float64(y_46_re * atan(x_46_im, x_46_re)))) * Float64(exp(Float64(y_46_re * log(x_46_im))) / Float64(1.0 + Float64(y_46_im * fma(y_46_im, fma(0.16666666666666666, Float64(y_46_im * (atan(x_46_im, x_46_re) ^ 3.0)), Float64(0.5 * (atan(x_46_im, x_46_re) ^ 2.0))), atan(x_46_im, x_46_re)))))) end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[Cos[N[(y$46$im * N[Log[x$46$im], $MachinePrecision] + N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[Exp[N[(y$46$re * N[Log[x$46$im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(1.0 + N[(y$46$im * N[(y$46$im * N[(0.16666666666666666 * N[(y$46$im * N[Power[N[ArcTan[x$46$im / x$46$re], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Power[N[ArcTan[x$46$im / x$46$re], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(\mathsf{fma}\left(y.im, \log x.im, y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)\right) \cdot \frac{e^{y.re \cdot \log x.im}}{1 + y.im \cdot \mathsf{fma}\left(y.im, \mathsf{fma}\left(0.16666666666666666, y.im \cdot {\tan^{-1}_* \frac{x.im}{x.re}}^{3}, 0.5 \cdot {\tan^{-1}_* \frac{x.im}{x.re}}^{2}\right), \tan^{-1}_* \frac{x.im}{x.re}\right)}
\end{array}
Initial program 42.8%
Taylor expanded in x.re around 0
lower-*.f64N/A
lower-cos.f64N/A
lower-fma.f64N/A
lower-log.f64N/A
lower-*.f64N/A
lift-atan2.f64N/A
exp-diffN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lower-exp.f64N/A
Applied rewrites34.3%
Taylor expanded in y.im around 0
lower-+.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lift-atan2.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lift-atan2.f64N/A
lift-atan2.f6432.9
Applied rewrites32.9%
herbie shell --seed 2025065
(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)))))