
(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 10 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 (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re)
(* (atan2 x.im x.re) y.im))))
(t_1 (log (hypot x.im x.re))))
(if (<= y.re -4.5e-17)
(* t_0 (cos (* (fma y.im (/ t_1 y.re) (atan2 x.im x.re)) y.re)))
(if (<= y.re 1e-28)
(*
(exp (* (- y.im) (atan2 x.im x.re)))
(sin (fma (PI) 0.5 (* (- y.im) t_1))))
(* t_0 (sin (* 0.5 (PI))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 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}\\
t_1 := \log \left(\mathsf{hypot}\left(x.im, x.re\right)\right)\\
\mathbf{if}\;y.re \leq -4.5 \cdot 10^{-17}:\\
\;\;\;\;t\_0 \cdot \cos \left(\mathsf{fma}\left(y.im, \frac{t\_1}{y.re}, \tan^{-1}_* \frac{x.im}{x.re}\right) \cdot y.re\right)\\
\mathbf{elif}\;y.re \leq 10^{-28}:\\
\;\;\;\;e^{\left(-y.im\right) \cdot \tan^{-1}_* \frac{x.im}{x.re}} \cdot \sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.5, \left(-y.im\right) \cdot t\_1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sin \left(0.5 \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if y.re < -4.49999999999999978e-17Initial program 42.7%
Taylor expanded in y.re around inf
*-commutativeN/A
lower-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
lower-atan2.f6484.1
Applied rewrites84.1%
if -4.49999999999999978e-17 < y.re < 9.99999999999999971e-29Initial program 43.1%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites52.8%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6452.8
Applied rewrites52.8%
Taylor expanded in y.re around 0
distribute-lft-neg-inN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-atan2.f6486.2
Applied rewrites86.2%
if 9.99999999999999971e-29 < y.re Initial program 44.1%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites78.5%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6482.0
Applied rewrites82.0%
Taylor expanded in y.im around 0
Applied rewrites83.6%
Final simplification85.0%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (sin (fma (PI) 0.5 (* (- y.im) (log (hypot x.im x.re))))))
(t_1
(exp
(-
(* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re)
(* (atan2 x.im x.re) y.im)))))
(if (<= y.re -4.5e-17)
(* t_1 t_0)
(if (<= y.re 1e-28)
(* (exp (* (- y.im) (atan2 x.im x.re))) t_0)
(* t_1 (sin (* 0.5 (PI))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.5, \left(-y.im\right) \cdot \log \left(\mathsf{hypot}\left(x.im, x.re\right)\right)\right)\right)\\
t_1 := 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}\\
\mathbf{if}\;y.re \leq -4.5 \cdot 10^{-17}:\\
\;\;\;\;t\_1 \cdot t\_0\\
\mathbf{elif}\;y.re \leq 10^{-28}:\\
\;\;\;\;e^{\left(-y.im\right) \cdot \tan^{-1}_* \frac{x.im}{x.re}} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sin \left(0.5 \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if y.re < -4.49999999999999978e-17Initial program 42.7%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites84.1%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6484.1
Applied rewrites84.1%
if -4.49999999999999978e-17 < y.re < 9.99999999999999971e-29Initial program 43.1%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites52.8%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6452.8
Applied rewrites52.8%
Taylor expanded in y.re around 0
distribute-lft-neg-inN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-atan2.f6486.2
Applied rewrites86.2%
if 9.99999999999999971e-29 < y.re Initial program 44.1%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites78.5%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6482.0
Applied rewrites82.0%
Taylor expanded in y.im around 0
Applied rewrites83.6%
Final simplification85.0%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (log (hypot x.im x.re))))
(if (<= y.re -0.102)
(*
(pow (hypot x.im x.re) y.re)
(cos (* (fma y.im (/ t_0 y.re) (atan2 x.im x.re)) y.re)))
(if (<= y.re 1e-28)
(*
(exp (* (- y.im) (atan2 x.im x.re)))
(sin (fma (PI) 0.5 (* (- y.im) t_0))))
(*
(exp
(-
(* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re)
(* (atan2 x.im x.re) y.im)))
(sin (* 0.5 (PI))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(\mathsf{hypot}\left(x.im, x.re\right)\right)\\
\mathbf{if}\;y.re \leq -0.102:\\
\;\;\;\;{\left(\mathsf{hypot}\left(x.im, x.re\right)\right)}^{y.re} \cdot \cos \left(\mathsf{fma}\left(y.im, \frac{t\_0}{y.re}, \tan^{-1}_* \frac{x.im}{x.re}\right) \cdot y.re\right)\\
\mathbf{elif}\;y.re \leq 10^{-28}:\\
\;\;\;\;e^{\left(-y.im\right) \cdot \tan^{-1}_* \frac{x.im}{x.re}} \cdot \sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.5, \left(-y.im\right) \cdot t\_0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;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 \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if y.re < -0.101999999999999993Initial program 41.6%
Taylor expanded in y.im around 0
lower-pow.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6441.8
Applied rewrites41.8%
Taylor expanded in y.re around inf
*-commutativeN/A
lower-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
lower-atan2.f6483.6
Applied rewrites83.6%
if -0.101999999999999993 < y.re < 9.99999999999999971e-29Initial program 43.7%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites53.9%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6453.9
Applied rewrites53.9%
Taylor expanded in y.re around 0
distribute-lft-neg-inN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-atan2.f6486.0
Applied rewrites86.0%
if 9.99999999999999971e-29 < y.re Initial program 44.1%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites78.5%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6482.0
Applied rewrites82.0%
Taylor expanded in y.im around 0
Applied rewrites83.6%
Final simplification84.8%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.re -1.2e-17)
(*
(pow (fma x.im x.im (* x.re x.re)) (* 0.5 y.re))
(cos (* (atan2 x.im x.re) y.re)))
(if (<= y.re 1e-28)
(*
(exp (* (- y.im) (atan2 x.im x.re)))
(sin (fma (PI) 0.5 (* (- y.im) (log (hypot x.im x.re))))))
(*
(exp
(-
(* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re)
(* (atan2 x.im x.re) y.im)))
(sin (* 0.5 (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -1.2 \cdot 10^{-17}:\\
\;\;\;\;{\left(\mathsf{fma}\left(x.im, x.im, x.re \cdot x.re\right)\right)}^{\left(0.5 \cdot y.re\right)} \cdot \cos \left(\tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)\\
\mathbf{elif}\;y.re \leq 10^{-28}:\\
\;\;\;\;e^{\left(-y.im\right) \cdot \tan^{-1}_* \frac{x.im}{x.re}} \cdot \sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.5, \left(-y.im\right) \cdot \log \left(\mathsf{hypot}\left(x.im, x.re\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;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 \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if y.re < -1.19999999999999993e-17Initial program 42.1%
Taylor expanded in y.im around 0
lower-pow.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6442.3
Applied rewrites42.3%
Taylor expanded in y.im around 0
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-atan2.f6479.0
Applied rewrites79.0%
Applied rewrites80.3%
if -1.19999999999999993e-17 < y.re < 9.99999999999999971e-29Initial program 43.4%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites53.2%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6453.2
Applied rewrites53.2%
Taylor expanded in y.re around 0
distribute-lft-neg-inN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-atan2.f6486.9
Applied rewrites86.9%
if 9.99999999999999971e-29 < y.re Initial program 44.1%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites78.5%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6482.0
Applied rewrites82.0%
Taylor expanded in y.im around 0
Applied rewrites83.6%
Final simplification84.3%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (sin (* 0.5 (PI)))))
(if (<= y.re -7.2e-21)
(*
(pow (fma x.im x.im (* x.re x.re)) (* 0.5 y.re))
(cos (* (atan2 x.im x.re) y.re)))
(if (<= y.re 0.00016)
(* (exp (* (- y.im) (atan2 x.im x.re))) t_0)
(*
(exp
(-
(* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re)
(* (atan2 x.im x.re) y.im)))
t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;y.re \leq -7.2 \cdot 10^{-21}:\\
\;\;\;\;{\left(\mathsf{fma}\left(x.im, x.im, x.re \cdot x.re\right)\right)}^{\left(0.5 \cdot y.re\right)} \cdot \cos \left(\tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)\\
\mathbf{elif}\;y.re \leq 0.00016:\\
\;\;\;\;e^{\left(-y.im\right) \cdot \tan^{-1}_* \frac{x.im}{x.re}} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;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 t\_0\\
\end{array}
\end{array}
if y.re < -7.19999999999999979e-21Initial program 41.5%
Taylor expanded in y.im around 0
lower-pow.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6441.7
Applied rewrites41.7%
Taylor expanded in y.im around 0
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-atan2.f6477.9
Applied rewrites77.9%
Applied rewrites79.3%
if -7.19999999999999979e-21 < y.re < 1.60000000000000013e-4Initial program 43.7%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites54.1%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6454.1
Applied rewrites54.1%
Taylor expanded in y.im around 0
Applied rewrites53.7%
Taylor expanded in y.re around 0
distribute-lft-neg-inN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-atan2.f6484.2
Applied rewrites84.2%
if 1.60000000000000013e-4 < y.re Initial program 44.3%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites78.7%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6482.4
Applied rewrites82.4%
Taylor expanded in y.im around 0
Applied rewrites84.0%
Final simplification82.8%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (sin (* 0.5 (PI)))))
(if (<= y.re -7.2e-21)
(*
(pow (fma x.im x.im (* x.re x.re)) (* 0.5 y.re))
(cos (* (atan2 x.im x.re) y.re)))
(if (<= y.re 90.0)
(* (exp (* (- y.im) (atan2 x.im x.re))) t_0)
(* t_0 (pow (hypot x.im x.re) y.re))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;y.re \leq -7.2 \cdot 10^{-21}:\\
\;\;\;\;{\left(\mathsf{fma}\left(x.im, x.im, x.re \cdot x.re\right)\right)}^{\left(0.5 \cdot y.re\right)} \cdot \cos \left(\tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)\\
\mathbf{elif}\;y.re \leq 90:\\
\;\;\;\;e^{\left(-y.im\right) \cdot \tan^{-1}_* \frac{x.im}{x.re}} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot {\left(\mathsf{hypot}\left(x.im, x.re\right)\right)}^{y.re}\\
\end{array}
\end{array}
if y.re < -7.19999999999999979e-21Initial program 41.5%
Taylor expanded in y.im around 0
lower-pow.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6441.7
Applied rewrites41.7%
Taylor expanded in y.im around 0
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-atan2.f6477.9
Applied rewrites77.9%
Applied rewrites79.3%
if -7.19999999999999979e-21 < y.re < 90Initial program 44.6%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites54.9%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6454.3
Applied rewrites54.3%
Taylor expanded in y.im around 0
Applied rewrites53.8%
Taylor expanded in y.re around 0
distribute-lft-neg-inN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-atan2.f6483.8
Applied rewrites83.8%
if 90 < y.re Initial program 42.4%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites61.1%
Taylor expanded in y.re around 0
lower-sin.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6476.3
Applied rewrites76.3%
Taylor expanded in y.im around 0
lower-*.f64N/A
lower-sin.f64N/A
lower-fma.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-atan2.f64N/A
lower-pow.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6459.5
Applied rewrites59.5%
Taylor expanded in y.re around 0
Applied rewrites79.8%
Final simplification81.6%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (sin (* 0.5 (PI)))))
(if (or (<= y.re -2.05) (not (<= y.re 90.0)))
(* t_0 (pow (hypot x.im x.re) y.re))
(* (exp (* (- y.im) (atan2 x.im x.re))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;y.re \leq -2.05 \lor \neg \left(y.re \leq 90\right):\\
\;\;\;\;t\_0 \cdot {\left(\mathsf{hypot}\left(x.im, x.re\right)\right)}^{y.re}\\
\mathbf{else}:\\
\;\;\;\;e^{\left(-y.im\right) \cdot \tan^{-1}_* \frac{x.im}{x.re}} \cdot t\_0\\
\end{array}
\end{array}
if y.re < -2.0499999999999998 or 90 < y.re Initial program 42.0%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites72.2%
Taylor expanded in y.re around 0
lower-sin.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6478.5
Applied rewrites78.5%
Taylor expanded in y.im around 0
lower-*.f64N/A
lower-sin.f64N/A
lower-fma.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-atan2.f64N/A
lower-pow.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6470.7
Applied rewrites70.7%
Taylor expanded in y.re around 0
Applied rewrites80.2%
if -2.0499999999999998 < y.re < 90Initial program 44.4%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
Applied rewrites55.1%
Taylor expanded in y.re around 0
lower-sin.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-PI.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6454.5
Applied rewrites54.5%
Taylor expanded in y.im around 0
Applied rewrites54.0%
Taylor expanded in y.re around 0
distribute-lft-neg-inN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-atan2.f6482.4
Applied rewrites82.4%
Final simplification81.3%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* (sin (* 0.5 (PI))) (pow (hypot x.im x.re) y.re)))
\begin{array}{l}
\\
\sin \left(0.5 \cdot \mathsf{PI}\left(\right)\right) \cdot {\left(\mathsf{hypot}\left(x.im, x.re\right)\right)}^{y.re}
\end{array}
Initial program 43.2%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.3%
Taylor expanded in y.re around 0
lower-sin.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6465.1
Applied rewrites65.1%
Taylor expanded in y.im around 0
lower-*.f64N/A
lower-sin.f64N/A
lower-fma.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-atan2.f64N/A
lower-pow.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6462.2
Applied rewrites62.2%
Taylor expanded in y.re around 0
Applied rewrites66.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* 1.0 (+ 1.0 (* (* -0.5 (* y.re y.re)) (pow (atan2 x.im x.re) 2.0)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return 1.0 * (1.0 + ((-0.5 * (y_46_re * y_46_re)) * pow(atan2(x_46_im, x_46_re), 2.0)));
}
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
code = 1.0d0 * (1.0d0 + (((-0.5d0) * (y_46re * y_46re)) * (atan2(x_46im, x_46re) ** 2.0d0)))
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return 1.0 * (1.0 + ((-0.5 * (y_46_re * y_46_re)) * Math.pow(Math.atan2(x_46_im, x_46_re), 2.0)));
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return 1.0 * (1.0 + ((-0.5 * (y_46_re * y_46_re)) * math.pow(math.atan2(x_46_im, x_46_re), 2.0)))
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(1.0 * Float64(1.0 + Float64(Float64(-0.5 * Float64(y_46_re * y_46_re)) * (atan(x_46_im, x_46_re) ^ 2.0)))) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 1.0 * (1.0 + ((-0.5 * (y_46_re * y_46_re)) * (atan2(x_46_im, x_46_re) ^ 2.0))); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(1.0 * N[(1.0 + N[(N[(-0.5 * N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision] * N[Power[N[ArcTan[x$46$im / x$46$re], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot \left(1 + \left(-0.5 \cdot \left(y.re \cdot y.re\right)\right) \cdot {\tan^{-1}_* \frac{x.im}{x.re}}^{2}\right)
\end{array}
Initial program 43.2%
Taylor expanded in y.im around 0
lower-pow.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6435.0
Applied rewrites35.0%
Taylor expanded in y.im around 0
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-atan2.f6463.0
Applied rewrites63.0%
Taylor expanded in y.re around 0
Applied rewrites28.1%
Taylor expanded in y.re around 0
Applied rewrites30.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (sin (* 0.5 (PI))))
\begin{array}{l}
\\
\sin \left(0.5 \cdot \mathsf{PI}\left(\right)\right)
\end{array}
Initial program 43.2%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.3%
Taylor expanded in y.re around 0
lower-sin.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6465.1
Applied rewrites65.1%
Taylor expanded in y.im around 0
lower-*.f64N/A
lower-sin.f64N/A
lower-fma.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lower-atan2.f64N/A
lower-pow.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f6462.2
Applied rewrites62.2%
Taylor expanded in y.re around 0
Applied rewrites28.2%
herbie shell --seed 2024363
(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)))))