
(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 6 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 (* (sinh (- im)) (cos re)))
double code(double re, double im) {
return sinh(-im) * cos(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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sinh(-im) * cos(re)
end function
public static double code(double re, double im) {
return Math.sinh(-im) * Math.cos(re);
}
def code(re, im): return math.sinh(-im) * math.cos(re)
function code(re, im) return Float64(sinh(Float64(-im)) * cos(re)) end
function tmp = code(re, im) tmp = sinh(-im) * cos(re); end
code[re_, im_] := N[(N[Sinh[(-im)], $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sinh \left(-im\right) \cdot \cos re
\end{array}
Initial program 53.3%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
--rgt-identityN/A
sub-negate-revN/A
lift--.f64N/A
sinh-defN/A
lower-*.f64N/A
lower-sinh.f6499.9
lift--.f64N/A
sub0-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sinh (- im)))
(t_1 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
(if (<= t_1 -0.005)
t_0
(if (<= t_1 200000.0)
(* (- (cos re)) im)
(* t_0 (fma (* re re) -0.5 1.0))))))
double code(double re, double im) {
double t_0 = sinh(-im);
double t_1 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
double tmp;
if (t_1 <= -0.005) {
tmp = t_0;
} else if (t_1 <= 200000.0) {
tmp = -cos(re) * im;
} else {
tmp = t_0 * fma((re * re), -0.5, 1.0);
}
return tmp;
}
function code(re, im) t_0 = sinh(Float64(-im)) t_1 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) tmp = 0.0 if (t_1 <= -0.005) tmp = t_0; elseif (t_1 <= 200000.0) tmp = Float64(Float64(-cos(re)) * im); else tmp = Float64(t_0 * fma(Float64(re * re), -0.5, 1.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[Sinh[(-im)], $MachinePrecision]}, Block[{t$95$1 = 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$1, -0.005], t$95$0, If[LessEqual[t$95$1, 200000.0], N[((-N[Cos[re], $MachinePrecision]) * im), $MachinePrecision], N[(t$95$0 * N[(N[(re * re), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sinh \left(-im\right)\\
t_1 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\mathbf{if}\;t\_1 \leq -0.005:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 200000:\\
\;\;\;\;\left(-\cos re\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\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.0050000000000000001Initial program 53.3%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6440.5
Applied rewrites40.5%
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flip-revN/A
lift--.f64N/A
sub-divN/A
lift-exp.f64N/A
remove-double-negN/A
lift-neg.f64N/A
div-subN/A
lift-exp.f64N/A
sinh-defN/A
lift-sinh.f6465.3
Applied rewrites65.3%
if -0.0050000000000000001 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 2e5Initial program 53.3%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6453.2
Applied rewrites53.2%
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6453.2
Applied rewrites53.2%
if 2e5 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 53.3%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
--rgt-identityN/A
sub-negate-revN/A
lift--.f64N/A
sinh-defN/A
lower-*.f64N/A
lower-sinh.f6499.9
lift--.f64N/A
sub0-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6463.1
Applied rewrites63.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6463.1
lift-pow.f64N/A
unpow2N/A
lower-*.f6463.1
Applied rewrites63.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sinh (- im))))
(if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0)
t_0
(* t_0 (fma (* re re) -0.5 1.0)))))
double code(double re, double im) {
double t_0 = sinh(-im);
double tmp;
if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
tmp = t_0;
} else {
tmp = t_0 * fma((re * re), -0.5, 1.0);
}
return tmp;
}
function code(re, im) t_0 = sinh(Float64(-im)) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0) tmp = t_0; else tmp = Float64(t_0 * fma(Float64(re * re), -0.5, 1.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[Sinh[(-im)], $MachinePrecision]}, 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], t$95$0, N[(t$95$0 * N[(N[(re * re), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sinh \left(-im\right)\\
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\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 53.3%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6440.5
Applied rewrites40.5%
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flip-revN/A
lift--.f64N/A
sub-divN/A
lift-exp.f64N/A
remove-double-negN/A
lift-neg.f64N/A
div-subN/A
lift-exp.f64N/A
sinh-defN/A
lift-sinh.f6465.3
Applied rewrites65.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 53.3%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
--rgt-identityN/A
sub-negate-revN/A
lift--.f64N/A
sinh-defN/A
lower-*.f64N/A
lower-sinh.f6499.9
lift--.f64N/A
sub0-negN/A
lower-neg.f6499.9
Applied rewrites99.9%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6463.1
Applied rewrites63.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6463.1
lift-pow.f64N/A
unpow2N/A
lower-*.f6463.1
Applied rewrites63.1%
(FPCore (re im) :precision binary64 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0) (sinh (- im)) (- (* (* (* re re) im) 0.5) im)))
double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
tmp = sinh(-im);
} else {
tmp = (((re * re) * im) * 0.5) - im;
}
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 = sinh(-im)
else
tmp = (((re * re) * im) * 0.5d0) - im
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 = Math.sinh(-im);
} else {
tmp = (((re * re) * im) * 0.5) - im;
}
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 = math.sinh(-im) else: tmp = (((re * re) * im) * 0.5) - im 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 = sinh(Float64(-im)); else tmp = Float64(Float64(Float64(Float64(re * re) * im) * 0.5) - im); 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 = sinh(-im); else tmp = (((re * re) * im) * 0.5) - im; 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[Sinh[(-im)], $MachinePrecision], N[(N[(N[(N[(re * re), $MachinePrecision] * im), $MachinePrecision] * 0.5), $MachinePrecision] - im), $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:\\
\;\;\;\;\sinh \left(-im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(re \cdot re\right) \cdot im\right) \cdot 0.5 - im\\
\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 53.3%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6440.5
Applied rewrites40.5%
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
mult-flip-revN/A
lift--.f64N/A
sub-divN/A
lift-exp.f64N/A
remove-double-negN/A
lift-neg.f64N/A
div-subN/A
lift-exp.f64N/A
sinh-defN/A
lift-sinh.f6465.3
Applied rewrites65.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 53.3%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6453.2
Applied rewrites53.2%
Taylor expanded in re around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.3
Applied rewrites36.3%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6436.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.3
lift-pow.f64N/A
unpow2N/A
lower-*.f6436.3
Applied rewrites36.3%
(FPCore (re im) :precision binary64 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0) (- im) (- (* (* (* re re) im) 0.5) im)))
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) - im;
}
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) - im
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) - im;
}
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) - im 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(Float64(re * re) * im) * 0.5) - im); 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) - im; 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[(N[(re * re), $MachinePrecision] * im), $MachinePrecision] * 0.5), $MachinePrecision] - im), $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 - im\\
\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 53.3%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6453.2
Applied rewrites53.2%
Taylor expanded in re around 0
Applied rewrites30.3%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6430.3
Applied rewrites30.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 53.3%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6453.2
Applied rewrites53.2%
Taylor expanded in re around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.3
Applied rewrites36.3%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6436.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.3
lift-pow.f64N/A
unpow2N/A
lower-*.f6436.3
Applied rewrites36.3%
(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.3%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6453.2
Applied rewrites53.2%
Taylor expanded in re around 0
Applied rewrites30.3%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6430.3
Applied rewrites30.3%
herbie shell --seed 2025155
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))