
(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 10 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 54.7%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
sub0-negN/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
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 -2e+30)
(* (* -2.0 (sinh im)) 0.5)
(if (<= t_0 0.5)
(* (* (cos re) im) (fma (* im im) -0.16666666666666666 -1.0))
(* (* 0.25 (* re re)) (* (sinh im) 2.0))))))
double code(double re, double im) {
double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
double tmp;
if (t_0 <= -2e+30) {
tmp = (-2.0 * sinh(im)) * 0.5;
} else if (t_0 <= 0.5) {
tmp = (cos(re) * im) * fma((im * im), -0.16666666666666666, -1.0);
} else {
tmp = (0.25 * (re * re)) * (sinh(im) * 2.0);
}
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 <= -2e+30) tmp = Float64(Float64(-2.0 * sinh(im)) * 0.5); elseif (t_0 <= 0.5) tmp = Float64(Float64(cos(re) * im) * fma(Float64(im * im), -0.16666666666666666, -1.0)); else tmp = Float64(Float64(0.25 * Float64(re * re)) * Float64(sinh(im) * 2.0)); 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, -2e+30], N[(N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 0.5], N[(N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] * -0.16666666666666666 + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision] * N[(N[Sinh[im], $MachinePrecision] * 2.0), $MachinePrecision]), $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 -2 \cdot 10^{+30}:\\
\;\;\;\;\left(-2 \cdot \sinh im\right) \cdot 0.5\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;\left(\cos re \cdot im\right) \cdot \mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.25 \cdot \left(re \cdot re\right)\right) \cdot \left(\sinh im \cdot 2\right)\\
\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))) < -2e30Initial program 54.7%
Taylor expanded in re around 0
Applied rewrites41.5%
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
sub-negate-revN/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6465.4
Applied rewrites65.4%
if -2e30 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.5Initial program 54.7%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift--.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
sub0-negN/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
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%
Taylor expanded in im around 0
+-commutativeN/A
associate-*r*N/A
pow2N/A
associate-*l*N/A
distribute-rgt-inN/A
add-flipN/A
associate-*l*N/A
pow2N/A
metadata-evalN/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
sub-flipN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
Applied rewrites84.1%
if 0.5 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 54.7%
Taylor expanded in re around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
sub0-negN/A
sub-negate-revN/A
lower-neg.f64N/A
sub0-negN/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.7%
Taylor expanded in re around inf
associate-*r*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
rec-expN/A
sinh-undef-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-sinh.f6414.3
Applied rewrites14.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
(if (<= t_0 -2e+30)
(* (* -2.0 (sinh im)) 0.5)
(if (<= t_0 0.5)
(* (- im) (cos re))
(* (* 0.25 (* re re)) (* (sinh im) 2.0))))))
double code(double re, double im) {
double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
double tmp;
if (t_0 <= -2e+30) {
tmp = (-2.0 * sinh(im)) * 0.5;
} else if (t_0 <= 0.5) {
tmp = -im * cos(re);
} else {
tmp = (0.25 * (re * re)) * (sinh(im) * 2.0);
}
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 <= (-2d+30)) then
tmp = ((-2.0d0) * sinh(im)) * 0.5d0
else if (t_0 <= 0.5d0) then
tmp = -im * cos(re)
else
tmp = (0.25d0 * (re * re)) * (sinh(im) * 2.0d0)
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 <= -2e+30) {
tmp = (-2.0 * Math.sinh(im)) * 0.5;
} else if (t_0 <= 0.5) {
tmp = -im * Math.cos(re);
} else {
tmp = (0.25 * (re * re)) * (Math.sinh(im) * 2.0);
}
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 <= -2e+30: tmp = (-2.0 * math.sinh(im)) * 0.5 elif t_0 <= 0.5: tmp = -im * math.cos(re) else: tmp = (0.25 * (re * re)) * (math.sinh(im) * 2.0) 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 <= -2e+30) tmp = Float64(Float64(-2.0 * sinh(im)) * 0.5); elseif (t_0 <= 0.5) tmp = Float64(Float64(-im) * cos(re)); else tmp = Float64(Float64(0.25 * Float64(re * re)) * Float64(sinh(im) * 2.0)); 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 <= -2e+30) tmp = (-2.0 * sinh(im)) * 0.5; elseif (t_0 <= 0.5) tmp = -im * cos(re); else tmp = (0.25 * (re * re)) * (sinh(im) * 2.0); 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, -2e+30], N[(N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 0.5], N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision], N[(N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision] * N[(N[Sinh[im], $MachinePrecision] * 2.0), $MachinePrecision]), $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 -2 \cdot 10^{+30}:\\
\;\;\;\;\left(-2 \cdot \sinh im\right) \cdot 0.5\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\
\mathbf{else}:\\
\;\;\;\;\left(0.25 \cdot \left(re \cdot re\right)\right) \cdot \left(\sinh im \cdot 2\right)\\
\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))) < -2e30Initial program 54.7%
Taylor expanded in re around 0
Applied rewrites41.5%
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
sub-negate-revN/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6465.4
Applied rewrites65.4%
if -2e30 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.5Initial program 54.7%
Taylor expanded in im around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-cos.f6451.6
Applied rewrites51.6%
if 0.5 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 54.7%
Taylor expanded in re around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
sub0-negN/A
sub-negate-revN/A
lower-neg.f64N/A
sub0-negN/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.7%
Taylor expanded in re around inf
associate-*r*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
rec-expN/A
sinh-undef-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-sinh.f6414.3
Applied rewrites14.3%
(FPCore (re im) :precision binary64 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0) (* (* -2.0 (sinh im)) 0.5) (* (* 0.25 (* re re)) (* (sinh im) 2.0))))
double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
tmp = (-2.0 * sinh(im)) * 0.5;
} else {
tmp = (0.25 * (re * re)) * (sinh(im) * 2.0);
}
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)) * (exp((0.0d0 - im)) - exp(im))) <= 0.0d0) then
tmp = ((-2.0d0) * sinh(im)) * 0.5d0
else
tmp = (0.25d0 * (re * re)) * (sinh(im) * 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (((0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im))) <= 0.0) {
tmp = (-2.0 * Math.sinh(im)) * 0.5;
} else {
tmp = (0.25 * (re * re)) * (Math.sinh(im) * 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if ((0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))) <= 0.0: tmp = (-2.0 * math.sinh(im)) * 0.5 else: tmp = (0.25 * (re * re)) * (math.sinh(im) * 2.0) return tmp
function code(re, im) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0) tmp = Float64(Float64(-2.0 * sinh(im)) * 0.5); else tmp = Float64(Float64(0.25 * Float64(re * re)) * Float64(sinh(im) * 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) tmp = (-2.0 * sinh(im)) * 0.5; else tmp = (0.25 * (re * re)) * (sinh(im) * 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision] * N[(N[Sinh[im], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;\left(-2 \cdot \sinh im\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(0.25 \cdot \left(re \cdot re\right)\right) \cdot \left(\sinh im \cdot 2\right)\\
\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))) < 0.0Initial program 54.7%
Taylor expanded in re around 0
Applied rewrites41.5%
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
sub-negate-revN/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6465.4
Applied rewrites65.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 54.7%
Taylor expanded in re around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
sub0-negN/A
sub-negate-revN/A
lower-neg.f64N/A
sub0-negN/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.7%
Taylor expanded in re around inf
associate-*r*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
rec-expN/A
sinh-undef-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-sinh.f6414.3
Applied rewrites14.3%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (cos re)) -0.005) (* (* (* (* im im) im) -0.3333333333333333) (fma (* re re) -0.25 0.5)) (* (* -2.0 (sinh im)) 0.5)))
double code(double re, double im) {
double tmp;
if ((0.5 * cos(re)) <= -0.005) {
tmp = (((im * im) * im) * -0.3333333333333333) * fma((re * re), -0.25, 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.005) tmp = Float64(Float64(Float64(Float64(im * im) * im) * -0.3333333333333333) * fma(Float64(re * re), -0.25, 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.005], N[(N[(N[(N[(im * im), $MachinePrecision] * im), $MachinePrecision] * -0.3333333333333333), $MachinePrecision] * N[(N[(re * re), $MachinePrecision] * -0.25 + 0.5), $MachinePrecision]), $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.005:\\
\;\;\;\;\left(\left(\left(im \cdot im\right) \cdot im\right) \cdot -0.3333333333333333\right) \cdot \mathsf{fma}\left(re \cdot re, -0.25, 0.5\right)\\
\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.0050000000000000001Initial program 54.7%
Taylor expanded in re around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
sub0-negN/A
sub-negate-revN/A
lower-neg.f64N/A
sub0-negN/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.7%
Taylor expanded in im around 0
sinh-undef-revN/A
sub-negate-revN/A
sub0-negN/A
*-commutativeN/A
lower-*.f64N/A
sub-flipN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6454.2
Applied rewrites54.2%
Taylor expanded in im around inf
*-commutativeN/A
lower-*.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6431.6
Applied rewrites31.6%
if -0.0050000000000000001 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 54.7%
Taylor expanded in re around 0
Applied rewrites41.5%
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
sub-negate-revN/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6465.4
Applied rewrites65.4%
(FPCore (re im) :precision binary64 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0) (* (* -2.0 (sinh im)) 0.5) (* (* (* re re) im) 0.5)))
double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
tmp = (-2.0 * sinh(im)) * 0.5;
} else {
tmp = ((re * re) * 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)) * (exp((0.0d0 - im)) - exp(im))) <= 0.0d0) then
tmp = ((-2.0d0) * sinh(im)) * 0.5d0
else
tmp = ((re * re) * 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)) * (Math.exp((0.0 - im)) - Math.exp(im))) <= 0.0) {
tmp = (-2.0 * Math.sinh(im)) * 0.5;
} else {
tmp = ((re * re) * im) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if ((0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))) <= 0.0: tmp = (-2.0 * math.sinh(im)) * 0.5 else: tmp = ((re * re) * im) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0) tmp = Float64(Float64(-2.0 * sinh(im)) * 0.5); else tmp = Float64(Float64(Float64(re * re) * im) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) tmp = (-2.0 * sinh(im)) * 0.5; else tmp = ((re * re) * im) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(-2.0 * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(re * re), $MachinePrecision] * im), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;\left(-2 \cdot \sinh im\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\left(re \cdot re\right) \cdot im\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))) < 0.0Initial program 54.7%
Taylor expanded in re around 0
Applied rewrites41.5%
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift--.f64N/A
lift-exp.f64N/A
*-commutativeN/A
sub0-negN/A
sub-negate-revN/A
sinh-undef-revN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-sinh.f6465.4
Applied rewrites65.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 54.7%
Taylor expanded in re around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
sub0-negN/A
sub-negate-revN/A
lower-neg.f64N/A
sub0-negN/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.7%
Taylor expanded in re around inf
associate-*r*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
rec-expN/A
sinh-undef-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-sinh.f6414.3
Applied rewrites14.3%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6411.6
Applied rewrites11.6%
(FPCore (re im) :precision binary64 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0) (* (fma (* im im) -0.16666666666666666 -1.0) im) (* (* (* re re) im) 0.5)))
double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
tmp = fma((im * im), -0.16666666666666666, -1.0) * im;
} else {
tmp = ((re * re) * im) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0) tmp = Float64(fma(Float64(im * im), -0.16666666666666666, -1.0) * im); else tmp = Float64(Float64(Float64(re * re) * im) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(im * im), $MachinePrecision] * -0.16666666666666666 + -1.0), $MachinePrecision] * im), $MachinePrecision], N[(N[(N[(re * re), $MachinePrecision] * im), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;\mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;\left(\left(re \cdot re\right) \cdot im\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))) < 0.0Initial program 54.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
sub0-negN/A
sub-negate-revN/A
lower-neg.f64N/A
sub0-negN/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f6465.4
Applied rewrites65.4%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
sub-flipN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6453.8
Applied rewrites53.8%
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 54.7%
Taylor expanded in re around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
sub0-negN/A
sub-negate-revN/A
lower-neg.f64N/A
sub0-negN/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.7%
Taylor expanded in re around inf
associate-*r*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
rec-expN/A
sinh-undef-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-sinh.f6414.3
Applied rewrites14.3%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6411.6
Applied rewrites11.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
(if (<= t_0 -2e+30)
(* (* (* im im) -0.16666666666666666) im)
(if (<= t_0 0.0) (- im) (* (* (* re re) im) 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 <= -2e+30) {
tmp = ((im * im) * -0.16666666666666666) * im;
} else if (t_0 <= 0.0) {
tmp = -im;
} else {
tmp = ((re * re) * 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) :: t_0
real(8) :: tmp
t_0 = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
if (t_0 <= (-2d+30)) then
tmp = ((im * im) * (-0.16666666666666666d0)) * im
else if (t_0 <= 0.0d0) then
tmp = -im
else
tmp = ((re * re) * im) * 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 <= -2e+30) {
tmp = ((im * im) * -0.16666666666666666) * im;
} else if (t_0 <= 0.0) {
tmp = -im;
} else {
tmp = ((re * re) * im) * 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 <= -2e+30: tmp = ((im * im) * -0.16666666666666666) * im elif t_0 <= 0.0: tmp = -im else: tmp = ((re * re) * im) * 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 <= -2e+30) tmp = Float64(Float64(Float64(im * im) * -0.16666666666666666) * im); elseif (t_0 <= 0.0) tmp = Float64(-im); else tmp = Float64(Float64(Float64(re * re) * im) * 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 <= -2e+30) tmp = ((im * im) * -0.16666666666666666) * im; elseif (t_0 <= 0.0) tmp = -im; else tmp = ((re * re) * im) * 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, -2e+30], N[(N[(N[(im * im), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] * im), $MachinePrecision], If[LessEqual[t$95$0, 0.0], (-im), N[(N[(N[(re * re), $MachinePrecision] * im), $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 -2 \cdot 10^{+30}:\\
\;\;\;\;\left(\left(im \cdot im\right) \cdot -0.16666666666666666\right) \cdot im\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;-im\\
\mathbf{else}:\\
\;\;\;\;\left(\left(re \cdot re\right) \cdot im\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))) < -2e30Initial program 54.7%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6484.1
Applied rewrites84.1%
Taylor expanded in re around 0
sub-flipN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6453.8
Applied rewrites53.8%
Taylor expanded in im around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6429.4
Applied rewrites29.4%
if -2e30 < (*.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 54.7%
Taylor expanded in im around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-cos.f6451.6
Applied rewrites51.6%
Taylor expanded in re around 0
mul-1-negN/A
lift-neg.f6429.4
Applied rewrites29.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 54.7%
Taylor expanded in re around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
sub0-negN/A
sub-negate-revN/A
lower-neg.f64N/A
sub0-negN/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.7%
Taylor expanded in re around inf
associate-*r*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
rec-expN/A
sinh-undef-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-sinh.f6414.3
Applied rewrites14.3%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6411.6
Applied rewrites11.6%
(FPCore (re im) :precision binary64 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0) (- im) (* (* (* re re) im) 0.5)))
double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
tmp = -im;
} else {
tmp = ((re * re) * 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)) * (exp((0.0d0 - im)) - exp(im))) <= 0.0d0) then
tmp = -im
else
tmp = ((re * re) * 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)) * (Math.exp((0.0 - im)) - Math.exp(im))) <= 0.0) {
tmp = -im;
} else {
tmp = ((re * re) * im) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if ((0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))) <= 0.0: tmp = -im else: tmp = ((re * re) * im) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0) tmp = Float64(-im); else tmp = Float64(Float64(Float64(re * re) * im) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) tmp = -im; else tmp = ((re * re) * im) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], (-im), N[(N[(N[(re * re), $MachinePrecision] * im), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;-im\\
\mathbf{else}:\\
\;\;\;\;\left(\left(re \cdot re\right) \cdot im\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))) < 0.0Initial program 54.7%
Taylor expanded in im around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-cos.f6451.6
Applied rewrites51.6%
Taylor expanded in re around 0
mul-1-negN/A
lift-neg.f6429.4
Applied rewrites29.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 54.7%
Taylor expanded in re around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
sub0-negN/A
sub-negate-revN/A
lower-neg.f64N/A
sub0-negN/A
sinh-undefN/A
lower-*.f64N/A
lower-sinh.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.7%
Taylor expanded in re around inf
associate-*r*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
rec-expN/A
sinh-undef-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-sinh.f6414.3
Applied rewrites14.3%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6411.6
Applied rewrites11.6%
(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 54.7%
Taylor expanded in im around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-cos.f6451.6
Applied rewrites51.6%
Taylor expanded in re around 0
mul-1-negN/A
lift-neg.f6429.4
Applied rewrites29.4%
herbie shell --seed 2025132
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))