
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (* (cos re) (* -2.0 (sinh im))) 0.5))
double code(double re, double im) {
return (cos(re) * (-2.0 * sinh(im))) * 0.5;
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (cos(re) * ((-2.0d0) * sinh(im))) * 0.5d0
end function
public static double code(double re, double im) {
return (Math.cos(re) * (-2.0 * Math.sinh(im))) * 0.5;
}
def code(re, im): return (math.cos(re) * (-2.0 * math.sinh(im))) * 0.5
function code(re, im) return Float64(Float64(cos(re) * Float64(-2.0 * sinh(im))) * 0.5) end
function tmp = code(re, im) tmp = (cos(re) * (-2.0 * sinh(im))) * 0.5; end
code[re_, im_] := N[(N[(N[Cos[re], $MachinePrecision] * N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(\cos re \cdot \left(-2 \cdot \sinh im\right)\right) \cdot 0.5
\end{array}
Initial program 53.1%
lift-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift--.f64N/A
sub0-negN/A
lower-exp.f64N/A
lift-exp.f64N/A
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f64N/A
lift-cos.f6499.9
Applied rewrites99.9%
lift-*.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
lift-sinh.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6499.9
Applied rewrites99.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
(if (<= t_0 -100.0)
(* (* -2.0 (sinh im)) 0.5)
(if (<= t_0 0.0)
(* (* (cos re) (fma -0.16666666666666666 (* im im) -1.0)) im)
(* (- (cosh im) (fma 2.0 im 1.0)) 0.5)))))
double code(double re, double im) {
double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
double tmp;
if (t_0 <= -100.0) {
tmp = (-2.0 * sinh(im)) * 0.5;
} else if (t_0 <= 0.0) {
tmp = (cos(re) * fma(-0.16666666666666666, (im * im), -1.0)) * im;
} else {
tmp = (cosh(im) - fma(2.0, im, 1.0)) * 0.5;
}
return tmp;
}
function code(re, im) t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) tmp = 0.0 if (t_0 <= -100.0) tmp = Float64(Float64(-2.0 * sinh(im)) * 0.5); elseif (t_0 <= 0.0) tmp = Float64(Float64(cos(re) * fma(-0.16666666666666666, Float64(im * im), -1.0)) * im); else tmp = Float64(Float64(cosh(im) - fma(2.0, im, 1.0)) * 0.5); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -100.0], N[(N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(N[(N[Cos[re], $MachinePrecision] * N[(-0.16666666666666666 * N[(im * im), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision], N[(N[(N[Cosh[im], $MachinePrecision] - N[(2.0 * im + 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\mathbf{if}\;t\_0 \leq -100:\\
\;\;\;\;\left(-2 \cdot \sinh im\right) \cdot 0.5\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\left(\cos re \cdot \mathsf{fma}\left(-0.16666666666666666, im \cdot im, -1\right)\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;\left(\cosh im - \mathsf{fma}\left(2, im, 1\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < -100Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites74.3%
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
negate-sub2N/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6474.3
Applied rewrites74.3%
if -100 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0Initial program 6.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-cos.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.6
Applied rewrites99.6%
if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 97.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f6473.2
Applied rewrites73.2%
lift-neg.f64N/A
lift-*.f64N/A
lift-sinh.f64N/A
sinh-undef-revN/A
negate-sub2N/A
negate-subN/A
sinh---cosh-revN/A
associate--r-N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift--.f6472.0
Applied rewrites72.0%
Taylor expanded in im around 0
+-commutativeN/A
lower-fma.f6495.1
Applied rewrites95.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
(if (<= t_0 -100.0)
(* (* -2.0 (sinh im)) 0.5)
(if (<= t_0 0.0)
(* (* (cos re) im) (fma (* im im) -0.16666666666666666 -1.0))
(* (- (cosh im) (fma 2.0 im 1.0)) 0.5)))))
double code(double re, double im) {
double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
double tmp;
if (t_0 <= -100.0) {
tmp = (-2.0 * sinh(im)) * 0.5;
} else if (t_0 <= 0.0) {
tmp = (cos(re) * im) * fma((im * im), -0.16666666666666666, -1.0);
} else {
tmp = (cosh(im) - fma(2.0, im, 1.0)) * 0.5;
}
return tmp;
}
function code(re, im) t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) tmp = 0.0 if (t_0 <= -100.0) tmp = Float64(Float64(-2.0 * sinh(im)) * 0.5); elseif (t_0 <= 0.0) tmp = Float64(Float64(cos(re) * im) * fma(Float64(im * im), -0.16666666666666666, -1.0)); else tmp = Float64(Float64(cosh(im) - fma(2.0, im, 1.0)) * 0.5); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -100.0], N[(N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] * -0.16666666666666666 + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cosh[im], $MachinePrecision] - N[(2.0 * im + 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\mathbf{if}\;t\_0 \leq -100:\\
\;\;\;\;\left(-2 \cdot \sinh im\right) \cdot 0.5\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\left(\cos re \cdot im\right) \cdot \mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cosh im - \mathsf{fma}\left(2, im, 1\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < -100Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites74.3%
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
negate-sub2N/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6474.3
Applied rewrites74.3%
if -100 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0Initial program 6.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-cos.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.6
Applied rewrites99.6%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
pow2N/A
metadata-evalN/A
negate-subN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
negate-subN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6499.6
Applied rewrites99.6%
if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 97.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f6473.2
Applied rewrites73.2%
lift-neg.f64N/A
lift-*.f64N/A
lift-sinh.f64N/A
sinh-undef-revN/A
negate-sub2N/A
negate-subN/A
sinh---cosh-revN/A
associate--r-N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift--.f6472.0
Applied rewrites72.0%
Taylor expanded in im around 0
+-commutativeN/A
lower-fma.f6495.1
Applied rewrites95.1%
(FPCore (re im) :precision binary64 (if (<= im 2.1) (* (* (cos re) (fma -0.16666666666666666 (* im im) -1.0)) im) (* (* 0.5 (cos re)) (- 1.0 (exp im)))))
double code(double re, double im) {
double tmp;
if (im <= 2.1) {
tmp = (cos(re) * fma(-0.16666666666666666, (im * im), -1.0)) * im;
} else {
tmp = (0.5 * cos(re)) * (1.0 - exp(im));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 2.1) tmp = Float64(Float64(cos(re) * fma(-0.16666666666666666, Float64(im * im), -1.0)) * im); else tmp = Float64(Float64(0.5 * cos(re)) * Float64(1.0 - exp(im))); end return tmp end
code[re_, im_] := If[LessEqual[im, 2.1], N[(N[(N[Cos[re], $MachinePrecision] * N[(-0.16666666666666666 * N[(im * im), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.1:\\
\;\;\;\;\left(\cos re \cdot \mathsf{fma}\left(-0.16666666666666666, im \cdot im, -1\right)\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(1 - e^{im}\right)\\
\end{array}
\end{array}
if im < 2.10000000000000009Initial program 37.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-cos.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6489.3
Applied rewrites89.3%
if 2.10000000000000009 < im Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites99.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
(if (<= t_0 -100.0)
(* (* -2.0 (sinh im)) 0.5)
(if (<= t_0 0.0)
(* (- (cos re)) im)
(* (- (cosh im) (fma 2.0 im 1.0)) 0.5)))))
double code(double re, double im) {
double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
double tmp;
if (t_0 <= -100.0) {
tmp = (-2.0 * sinh(im)) * 0.5;
} else if (t_0 <= 0.0) {
tmp = -cos(re) * im;
} else {
tmp = (cosh(im) - fma(2.0, im, 1.0)) * 0.5;
}
return tmp;
}
function code(re, im) t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) tmp = 0.0 if (t_0 <= -100.0) tmp = Float64(Float64(-2.0 * sinh(im)) * 0.5); elseif (t_0 <= 0.0) tmp = Float64(Float64(-cos(re)) * im); else tmp = Float64(Float64(cosh(im) - fma(2.0, im, 1.0)) * 0.5); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -100.0], N[(N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[((-N[Cos[re], $MachinePrecision]) * im), $MachinePrecision], N[(N[(N[Cosh[im], $MachinePrecision] - N[(2.0 * im + 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\mathbf{if}\;t\_0 \leq -100:\\
\;\;\;\;\left(-2 \cdot \sinh im\right) \cdot 0.5\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\left(-\cos re\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;\left(\cosh im - \mathsf{fma}\left(2, im, 1\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < -100Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites74.3%
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
negate-sub2N/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6474.3
Applied rewrites74.3%
if -100 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0Initial program 6.8%
Taylor expanded in im around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-cos.f6499.3
Applied rewrites99.3%
if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 97.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f6473.2
Applied rewrites73.2%
lift-neg.f64N/A
lift-*.f64N/A
lift-sinh.f64N/A
sinh-undef-revN/A
negate-sub2N/A
negate-subN/A
sinh---cosh-revN/A
associate--r-N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift--.f6472.0
Applied rewrites72.0%
Taylor expanded in im around 0
+-commutativeN/A
lower-fma.f6495.1
Applied rewrites95.1%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (cos re)) -0.01) (* (- (cosh im) (fma 2.0 im 1.0)) 0.5) (* (* -2.0 (sinh im)) 0.5)))
double code(double re, double im) {
double tmp;
if ((0.5 * cos(re)) <= -0.01) {
tmp = (cosh(im) - fma(2.0, im, 1.0)) * 0.5;
} else {
tmp = (-2.0 * sinh(im)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * cos(re)) <= -0.01) tmp = Float64(Float64(cosh(im) - fma(2.0, im, 1.0)) * 0.5); else tmp = Float64(Float64(-2.0 * sinh(im)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[Cosh[im], $MachinePrecision] - N[(2.0 * im + 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq -0.01:\\
\;\;\;\;\left(\cosh im - \mathsf{fma}\left(2, im, 1\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \sinh im\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) < -0.0100000000000000002Initial program 54.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f642.0
Applied rewrites2.0%
lift-neg.f64N/A
lift-*.f64N/A
lift-sinh.f64N/A
sinh-undef-revN/A
negate-sub2N/A
negate-subN/A
sinh---cosh-revN/A
associate--r-N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift--.f642.7
Applied rewrites2.7%
Taylor expanded in im around 0
+-commutativeN/A
lower-fma.f6426.8
Applied rewrites26.8%
if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 52.8%
Taylor expanded in re around 0
Applied rewrites52.1%
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
negate-sub2N/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6485.5
Applied rewrites85.5%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (cos re)) -0.01) (* (- (cosh im) 1.0) 0.5) (* (* -2.0 (sinh im)) 0.5)))
double code(double re, double im) {
double tmp;
if ((0.5 * cos(re)) <= -0.01) {
tmp = (cosh(im) - 1.0) * 0.5;
} else {
tmp = (-2.0 * sinh(im)) * 0.5;
}
return tmp;
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((0.5d0 * cos(re)) <= (-0.01d0)) then
tmp = (cosh(im) - 1.0d0) * 0.5d0
else
tmp = ((-2.0d0) * sinh(im)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((0.5 * Math.cos(re)) <= -0.01) {
tmp = (Math.cosh(im) - 1.0) * 0.5;
} else {
tmp = (-2.0 * Math.sinh(im)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if (0.5 * math.cos(re)) <= -0.01: tmp = (math.cosh(im) - 1.0) * 0.5 else: tmp = (-2.0 * math.sinh(im)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (Float64(0.5 * cos(re)) <= -0.01) tmp = Float64(Float64(cosh(im) - 1.0) * 0.5); else tmp = Float64(Float64(-2.0 * sinh(im)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((0.5 * cos(re)) <= -0.01) tmp = (cosh(im) - 1.0) * 0.5; else tmp = (-2.0 * sinh(im)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[Cosh[im], $MachinePrecision] - 1.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq -0.01:\\
\;\;\;\;\left(\cosh im - 1\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \sinh im\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) < -0.0100000000000000002Initial program 54.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f642.0
Applied rewrites2.0%
lift-neg.f64N/A
lift-*.f64N/A
lift-sinh.f64N/A
sinh-undef-revN/A
negate-sub2N/A
negate-subN/A
sinh---cosh-revN/A
associate--r-N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift--.f642.7
Applied rewrites2.7%
Taylor expanded in im around 0
Applied rewrites26.9%
if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 52.8%
Taylor expanded in re around 0
Applied rewrites52.1%
lift-*.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
negate-sub2N/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6485.5
Applied rewrites85.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
(if (<= t_0 -100.0)
(* 0.5 (- 1.0 (exp im)))
(if (<= t_0 0.0) (- im) (* (- (cosh im) 1.0) 0.5)))))
double code(double re, double im) {
double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
double tmp;
if (t_0 <= -100.0) {
tmp = 0.5 * (1.0 - exp(im));
} else if (t_0 <= 0.0) {
tmp = -im;
} else {
tmp = (cosh(im) - 1.0) * 0.5;
}
return tmp;
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
if (t_0 <= (-100.0d0)) then
tmp = 0.5d0 * (1.0d0 - exp(im))
else if (t_0 <= 0.0d0) then
tmp = -im
else
tmp = (cosh(im) - 1.0d0) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
double tmp;
if (t_0 <= -100.0) {
tmp = 0.5 * (1.0 - Math.exp(im));
} else if (t_0 <= 0.0) {
tmp = -im;
} else {
tmp = (Math.cosh(im) - 1.0) * 0.5;
}
return tmp;
}
def code(re, im): t_0 = (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im)) tmp = 0 if t_0 <= -100.0: tmp = 0.5 * (1.0 - math.exp(im)) elif t_0 <= 0.0: tmp = -im else: tmp = (math.cosh(im) - 1.0) * 0.5 return tmp
function code(re, im) t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) tmp = 0.0 if (t_0 <= -100.0) tmp = Float64(0.5 * Float64(1.0 - exp(im))); elseif (t_0 <= 0.0) tmp = Float64(-im); else tmp = Float64(Float64(cosh(im) - 1.0) * 0.5); end return tmp end
function tmp_2 = code(re, im) t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); tmp = 0.0; if (t_0 <= -100.0) tmp = 0.5 * (1.0 - exp(im)); elseif (t_0 <= 0.0) tmp = -im; else tmp = (cosh(im) - 1.0) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -100.0], N[(0.5 * N[(1.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], (-im), N[(N[(N[Cosh[im], $MachinePrecision] - 1.0), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\mathbf{if}\;t\_0 \leq -100:\\
\;\;\;\;0.5 \cdot \left(1 - e^{im}\right)\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;-im\\
\mathbf{else}:\\
\;\;\;\;\left(\cosh im - 1\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < -100Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites74.3%
Taylor expanded in im around 0
Applied rewrites74.4%
if -100 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0Initial program 6.8%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f6455.6
Applied rewrites55.6%
Taylor expanded in im around 0
mul-1-negN/A
lower-neg.f6455.4
Applied rewrites55.4%
if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 97.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f6473.2
Applied rewrites73.2%
lift-neg.f64N/A
lift-*.f64N/A
lift-sinh.f64N/A
sinh-undef-revN/A
negate-sub2N/A
negate-subN/A
sinh---cosh-revN/A
associate--r-N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift--.f6472.0
Applied rewrites72.0%
Taylor expanded in im around 0
Applied rewrites93.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
(if (<= t_0 -100.0)
(* 0.5 (- 1.0 (exp im)))
(if (<= t_0 0.0) (- im) (* (- (fma (* im im) 0.5 1.0) 1.0) 0.5)))))
double code(double re, double im) {
double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
double tmp;
if (t_0 <= -100.0) {
tmp = 0.5 * (1.0 - exp(im));
} else if (t_0 <= 0.0) {
tmp = -im;
} else {
tmp = (fma((im * im), 0.5, 1.0) - 1.0) * 0.5;
}
return tmp;
}
function code(re, im) t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) tmp = 0.0 if (t_0 <= -100.0) tmp = Float64(0.5 * Float64(1.0 - exp(im))); elseif (t_0 <= 0.0) tmp = Float64(-im); else tmp = Float64(Float64(fma(Float64(im * im), 0.5, 1.0) - 1.0) * 0.5); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -100.0], N[(0.5 * N[(1.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], (-im), N[(N[(N[(N[(im * im), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision] - 1.0), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\mathbf{if}\;t\_0 \leq -100:\\
\;\;\;\;0.5 \cdot \left(1 - e^{im}\right)\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;-im\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(im \cdot im, 0.5, 1\right) - 1\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < -100Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites74.3%
Taylor expanded in im around 0
Applied rewrites74.4%
if -100 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0Initial program 6.8%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f6455.6
Applied rewrites55.6%
Taylor expanded in im around 0
mul-1-negN/A
lower-neg.f6455.4
Applied rewrites55.4%
if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 97.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f6473.2
Applied rewrites73.2%
lift-neg.f64N/A
lift-*.f64N/A
lift-sinh.f64N/A
sinh-undef-revN/A
negate-sub2N/A
negate-subN/A
sinh---cosh-revN/A
associate--r-N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift--.f6472.0
Applied rewrites72.0%
Taylor expanded in im around 0
Applied rewrites93.9%
Taylor expanded in im around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6447.4
Applied rewrites47.4%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (cos re)) 5.8e-254) (* (- (fma (* im im) 0.5 1.0) 1.0) 0.5) (* (fma (* im im) -0.16666666666666666 -1.0) im)))
double code(double re, double im) {
double tmp;
if ((0.5 * cos(re)) <= 5.8e-254) {
tmp = (fma((im * im), 0.5, 1.0) - 1.0) * 0.5;
} else {
tmp = fma((im * im), -0.16666666666666666, -1.0) * im;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * cos(re)) <= 5.8e-254) tmp = Float64(Float64(fma(Float64(im * im), 0.5, 1.0) - 1.0) * 0.5); else tmp = Float64(fma(Float64(im * im), -0.16666666666666666, -1.0) * im); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], 5.8e-254], N[(N[(N[(N[(im * im), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision] - 1.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(im * im), $MachinePrecision] * -0.16666666666666666 + -1.0), $MachinePrecision] * im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq 5.8 \cdot 10^{-254}:\\
\;\;\;\;\left(\mathsf{fma}\left(im \cdot im, 0.5, 1\right) - 1\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right) \cdot im\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) < 5.7999999999999999e-254Initial program 54.1%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f642.0
Applied rewrites2.0%
lift-neg.f64N/A
lift-*.f64N/A
lift-sinh.f64N/A
sinh-undef-revN/A
negate-sub2N/A
negate-subN/A
sinh---cosh-revN/A
associate--r-N/A
lift-cosh.f64N/A
lift-sinh.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift--.f642.7
Applied rewrites2.7%
Taylor expanded in im around 0
Applied rewrites26.9%
Taylor expanded in im around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6415.1
Applied rewrites15.1%
if 5.7999999999999999e-254 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 52.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-cos.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6484.0
Applied rewrites84.0%
Taylor expanded in re around 0
negate-subN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6470.1
Applied rewrites70.1%
(FPCore (re im) :precision binary64 (* (fma (* im im) -0.16666666666666666 -1.0) im))
double code(double re, double im) {
return fma((im * im), -0.16666666666666666, -1.0) * im;
}
function code(re, im) return Float64(fma(Float64(im * im), -0.16666666666666666, -1.0) * im) end
code[re_, im_] := N[(N[(N[(im * im), $MachinePrecision] * -0.16666666666666666 + -1.0), $MachinePrecision] * im), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right) \cdot im
\end{array}
Initial program 53.1%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-cos.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6484.2
Applied rewrites84.2%
Taylor expanded in re around 0
negate-subN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6453.0
Applied rewrites53.0%
(FPCore (re im) :precision binary64 (- im))
double code(double re, double im) {
return -im;
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = -im
end function
public static double code(double re, double im) {
return -im;
}
def code(re, im): return -im
function code(re, im) return Float64(-im) end
function tmp = code(re, im) tmp = -im; end
code[re_, im_] := (-im)
\begin{array}{l}
\\
-im
\end{array}
Initial program 53.1%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
negate-sub2N/A
lower-neg.f64N/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f6464.7
Applied rewrites64.7%
Taylor expanded in im around 0
mul-1-negN/A
lower-neg.f6430.2
Applied rewrites30.2%
herbie shell --seed 2025110
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))