
(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]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
Herbie found 8 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]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
(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]
\sinh \left(-im\right) \cdot \cos re
Initial program 54.5%
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 (- (fabs im))))
(t_1
(*
(* 0.5 (cos re))
(- (exp (- 0.0 (fabs im))) (exp (fabs im))))))
(*
(copysign 1.0 im)
(if (<= t_1 -1e-7)
t_0
(if (<= t_1 4e-9)
(* (- (cos re)) (fabs im))
(* t_0 (fma (* re re) -0.5 1.0)))))))double code(double re, double im) {
double t_0 = sinh(-fabs(im));
double t_1 = (0.5 * cos(re)) * (exp((0.0 - fabs(im))) - exp(fabs(im)));
double tmp;
if (t_1 <= -1e-7) {
tmp = t_0;
} else if (t_1 <= 4e-9) {
tmp = -cos(re) * fabs(im);
} else {
tmp = t_0 * fma((re * re), -0.5, 1.0);
}
return copysign(1.0, im) * tmp;
}
function code(re, im) t_0 = sinh(Float64(-abs(im))) t_1 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - abs(im))) - exp(abs(im)))) tmp = 0.0 if (t_1 <= -1e-7) tmp = t_0; elseif (t_1 <= 4e-9) tmp = Float64(Float64(-cos(re)) * abs(im)); else tmp = Float64(t_0 * fma(Float64(re * re), -0.5, 1.0)); end return Float64(copysign(1.0, im) * tmp) end
code[re_, im_] := Block[{t$95$0 = N[Sinh[(-N[Abs[im], $MachinePrecision])], $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$1, -1e-7], t$95$0, If[LessEqual[t$95$1, 4e-9], N[((-N[Cos[re], $MachinePrecision]) * N[Abs[im], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[(re * re), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \sinh \left(-\left|im\right|\right)\\
t_1 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - \left|im\right|} - e^{\left|im\right|}\right)\\
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{-9}:\\
\;\;\;\;\left(-\cos re\right) \cdot \left|im\right|\\
\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))) < -9.9999999999999995e-8Initial program 54.5%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6441.1%
Applied rewrites41.1%
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 -9.9999999999999995e-8 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 4.0000000000000002e-9Initial program 54.5%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6451.9%
Applied rewrites51.9%
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6451.9%
Applied rewrites51.9%
if 4.0000000000000002e-9 < (*.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.5%
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.5%
Applied rewrites63.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6463.5%
lift-pow.f64N/A
unpow2N/A
lower-*.f6463.5%
Applied rewrites63.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sinh (- im))))
(if (<= (* 0.5 (cos re)) -0.01)
(* t_0 (fma (* re re) -0.5 1.0))
t_0)))double code(double re, double im) {
double t_0 = sinh(-im);
double tmp;
if ((0.5 * cos(re)) <= -0.01) {
tmp = t_0 * fma((re * re), -0.5, 1.0);
} else {
tmp = t_0;
}
return tmp;
}
function code(re, im) t_0 = sinh(Float64(-im)) tmp = 0.0 if (Float64(0.5 * cos(re)) <= -0.01) tmp = Float64(t_0 * fma(Float64(re * re), -0.5, 1.0)); else tmp = t_0; end return tmp end
code[re_, im_] := Block[{t$95$0 = N[Sinh[(-im)], $MachinePrecision]}, If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(t$95$0 * N[(N[(re * re), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
t_0 := \sinh \left(-im\right)\\
\mathbf{if}\;0.5 \cdot \cos re \leq -0.01:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) < -0.01Initial program 54.5%
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.5%
Applied rewrites63.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6463.5%
lift-pow.f64N/A
unpow2N/A
lower-*.f6463.5%
Applied rewrites63.5%
if -0.01 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 54.5%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6441.1%
Applied rewrites41.1%
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%
(FPCore (re im)
:precision binary64
(*
(copysign 1.0 im)
(if (<=
(* (* 0.5 (cos re)) (- (exp (- 0.0 (fabs im))) (exp (fabs im))))
0.0)
(sinh (- (fabs im)))
(fma
-1.0
(fabs im)
(* 0.5 (* (fabs im) (sqrt (* (* re re) (* re re)))))))))double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp((0.0 - fabs(im))) - exp(fabs(im)))) <= 0.0) {
tmp = sinh(-fabs(im));
} else {
tmp = fma(-1.0, fabs(im), (0.5 * (fabs(im) * sqrt(((re * re) * (re * re))))));
}
return copysign(1.0, im) * tmp;
}
function code(re, im) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - abs(im))) - exp(abs(im)))) <= 0.0) tmp = sinh(Float64(-abs(im))); else tmp = fma(-1.0, abs(im), Float64(0.5 * Float64(abs(im) * sqrt(Float64(Float64(re * re) * Float64(re * re)))))); end return Float64(copysign(1.0, im) * tmp) end
code[re_, im_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[Sinh[(-N[Abs[im], $MachinePrecision])], $MachinePrecision], N[(-1.0 * N[Abs[im], $MachinePrecision] + N[(0.5 * N[(N[Abs[im], $MachinePrecision] * N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - \left|im\right|} - e^{\left|im\right|}\right) \leq 0:\\
\;\;\;\;\sinh \left(-\left|im\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \left|im\right|, 0.5 \cdot \left(\left|im\right| \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right)\right)\\
\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.5%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6441.1%
Applied rewrites41.1%
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 54.5%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6451.9%
Applied rewrites51.9%
Taylor expanded in re around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.4%
Applied rewrites36.4%
rem-square-sqrtN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f6437.0%
lift-pow.f64N/A
unpow2N/A
lower-*.f6437.0%
lift-pow.f64N/A
unpow2N/A
lower-*.f6437.0%
Applied rewrites37.0%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (cos re)) -0.01) (fma (* (* im 0.5) re) re (- im)) (sinh (- im))))
double code(double re, double im) {
double tmp;
if ((0.5 * cos(re)) <= -0.01) {
tmp = fma(((im * 0.5) * re), re, -im);
} else {
tmp = sinh(-im);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * cos(re)) <= -0.01) tmp = fma(Float64(Float64(im * 0.5) * re), re, Float64(-im)); else tmp = sinh(Float64(-im)); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[(im * 0.5), $MachinePrecision] * re), $MachinePrecision] * re + (-im)), $MachinePrecision], N[Sinh[(-im)], $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(\left(im \cdot 0.5\right) \cdot re, re, -im\right)\\
\mathbf{else}:\\
\;\;\;\;\sinh \left(-im\right)\\
\end{array}
if (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) < -0.01Initial program 54.5%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6451.9%
Applied rewrites51.9%
Taylor expanded in re around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.4%
Applied rewrites36.4%
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6436.4%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6436.4%
Applied rewrites36.4%
if -0.01 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 54.5%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6441.1%
Applied rewrites41.1%
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%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (cos re)) -0.01) (fma (* (* im 0.5) re) re (- im)) (- im)))
double code(double re, double im) {
double tmp;
if ((0.5 * cos(re)) <= -0.01) {
tmp = fma(((im * 0.5) * re), re, -im);
} else {
tmp = -im;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * cos(re)) <= -0.01) tmp = fma(Float64(Float64(im * 0.5) * re), re, Float64(-im)); else tmp = Float64(-im); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[(im * 0.5), $MachinePrecision] * re), $MachinePrecision] * re + (-im)), $MachinePrecision], (-im)]
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(\left(im \cdot 0.5\right) \cdot re, re, -im\right)\\
\mathbf{else}:\\
\;\;\;\;-im\\
\end{array}
if (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) < -0.01Initial program 54.5%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6451.9%
Applied rewrites51.9%
Taylor expanded in re around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.4%
Applied rewrites36.4%
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6436.4%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6436.4%
Applied rewrites36.4%
if -0.01 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 54.5%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6451.9%
Applied rewrites51.9%
Taylor expanded in re around 0
Applied rewrites29.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6429.6%
Applied rewrites29.6%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (cos re)) -0.01) (- (* (* (* re re) im) 0.5) im) (- im)))
double code(double re, double im) {
double tmp;
if ((0.5 * cos(re)) <= -0.01) {
tmp = (((re * re) * im) * 0.5) - im;
} else {
tmp = -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)) <= (-0.01d0)) then
tmp = (((re * re) * im) * 0.5d0) - im
else
tmp = -im
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 = (((re * re) * im) * 0.5) - im;
} else {
tmp = -im;
}
return tmp;
}
def code(re, im): tmp = 0 if (0.5 * math.cos(re)) <= -0.01: tmp = (((re * re) * im) * 0.5) - im else: tmp = -im return tmp
function code(re, im) tmp = 0.0 if (Float64(0.5 * cos(re)) <= -0.01) tmp = Float64(Float64(Float64(Float64(re * re) * im) * 0.5) - im); else tmp = Float64(-im); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((0.5 * cos(re)) <= -0.01) tmp = (((re * re) * im) * 0.5) - im; else tmp = -im; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[(N[(re * re), $MachinePrecision] * im), $MachinePrecision] * 0.5), $MachinePrecision] - im), $MachinePrecision], (-im)]
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq -0.01:\\
\;\;\;\;\left(\left(re \cdot re\right) \cdot im\right) \cdot 0.5 - im\\
\mathbf{else}:\\
\;\;\;\;-im\\
\end{array}
if (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) < -0.01Initial program 54.5%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6451.9%
Applied rewrites51.9%
Taylor expanded in re around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.4%
Applied rewrites36.4%
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6436.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.4%
lift-pow.f64N/A
unpow2N/A
lower-*.f6436.4%
Applied rewrites36.4%
if -0.01 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 54.5%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6451.9%
Applied rewrites51.9%
Taylor expanded in re around 0
Applied rewrites29.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6429.6%
Applied rewrites29.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)
-im
Initial program 54.5%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f6451.9%
Applied rewrites51.9%
Taylor expanded in re around 0
Applied rewrites29.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6429.6%
Applied rewrites29.6%
herbie shell --seed 2025240
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))