
(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 7 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.6%
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 (* (* 0.5 (cos re)) (- (exp (- 0.0 (fabs im))) (exp (fabs im))))))
(*
(copysign 1.0 im)
(if (<= t_0 (- INFINITY))
(sinh (- (fabs im)))
(if (<= t_0 4e-11)
(* (- (cos re)) (fabs im))
(*
0.5
(*
(- 1.0 (exp (+ (fabs im) (fabs im))))
(+ 1.0 (* -1.0 (fabs im))))))))))double code(double re, double im) {
double t_0 = (0.5 * cos(re)) * (exp((0.0 - fabs(im))) - exp(fabs(im)));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = sinh(-fabs(im));
} else if (t_0 <= 4e-11) {
tmp = -cos(re) * fabs(im);
} else {
tmp = 0.5 * ((1.0 - exp((fabs(im) + fabs(im)))) * (1.0 + (-1.0 * fabs(im))));
}
return copysign(1.0, im) * tmp;
}
public static double code(double re, double im) {
double t_0 = (0.5 * Math.cos(re)) * (Math.exp((0.0 - Math.abs(im))) - Math.exp(Math.abs(im)));
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = Math.sinh(-Math.abs(im));
} else if (t_0 <= 4e-11) {
tmp = -Math.cos(re) * Math.abs(im);
} else {
tmp = 0.5 * ((1.0 - Math.exp((Math.abs(im) + Math.abs(im)))) * (1.0 + (-1.0 * Math.abs(im))));
}
return Math.copySign(1.0, im) * tmp;
}
def code(re, im): t_0 = (0.5 * math.cos(re)) * (math.exp((0.0 - math.fabs(im))) - math.exp(math.fabs(im))) tmp = 0 if t_0 <= -math.inf: tmp = math.sinh(-math.fabs(im)) elif t_0 <= 4e-11: tmp = -math.cos(re) * math.fabs(im) else: tmp = 0.5 * ((1.0 - math.exp((math.fabs(im) + math.fabs(im)))) * (1.0 + (-1.0 * math.fabs(im)))) return math.copysign(1.0, im) * tmp
function code(re, im) t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - abs(im))) - exp(abs(im)))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = sinh(Float64(-abs(im))); elseif (t_0 <= 4e-11) tmp = Float64(Float64(-cos(re)) * abs(im)); else tmp = Float64(0.5 * Float64(Float64(1.0 - exp(Float64(abs(im) + abs(im)))) * Float64(1.0 + Float64(-1.0 * abs(im))))); end return Float64(copysign(1.0, im) * tmp) end
function tmp_2 = code(re, im) t_0 = (0.5 * cos(re)) * (exp((0.0 - abs(im))) - exp(abs(im))); tmp = 0.0; if (t_0 <= -Inf) tmp = sinh(-abs(im)); elseif (t_0 <= 4e-11) tmp = -cos(re) * abs(im); else tmp = 0.5 * ((1.0 - exp((abs(im) + abs(im)))) * (1.0 + (-1.0 * abs(im)))); end tmp_2 = (sign(im) * abs(1.0)) * tmp; end
code[re_, im_] := Block[{t$95$0 = 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$0, (-Infinity)], N[Sinh[(-N[Abs[im], $MachinePrecision])], $MachinePrecision], If[LessEqual[t$95$0, 4e-11], N[((-N[Cos[re], $MachinePrecision]) * N[Abs[im], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(1.0 - N[Exp[N[(N[Abs[im], $MachinePrecision] + N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-1.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \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\_0 \leq -\infty:\\
\;\;\;\;\sinh \left(-\left|im\right|\right)\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-11}:\\
\;\;\;\;\left(-\cos re\right) \cdot \left|im\right|\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(1 - e^{\left|im\right| + \left|im\right|}\right) \cdot \left(1 + -1 \cdot \left|im\right|\right)\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))) < -inf.0Initial program 54.6%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6440.6%
Applied rewrites40.6%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
metadata-evalN/A
mult-flip-revN/A
fp-cancel-sub-signN/A
metadata-evalN/A
mult-flipN/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.f6464.4%
Applied rewrites64.4%
if -inf.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 3.99999999999999976e-11Initial program 54.6%
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 3.99999999999999976e-11 < (*.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.6%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6440.6%
Applied rewrites40.6%
lift--.f64N/A
sub-to-multN/A
lower-unsound-*.f64N/A
lower-unsound--.f64N/A
lower-unsound-/.f3221.6%
lower-/.f32N/A
mult-flip-revN/A
lift-exp.f64N/A
exp-negN/A
lift-neg.f64N/A
remove-double-negN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-+.f6422.3%
Applied rewrites22.3%
Taylor expanded in im around 0
lower-+.f64N/A
lower-*.f6411.2%
Applied rewrites11.2%
(FPCore (re im)
:precision binary64
(*
(copysign 1.0 im)
(if (<= (* 0.5 (cos re)) -0.02)
(*
0.5
(* (- 1.0 (exp (+ (fabs im) (fabs im)))) (+ 1.0 (* -1.0 (fabs im)))))
(sinh (- (fabs im))))))double code(double re, double im) {
double tmp;
if ((0.5 * cos(re)) <= -0.02) {
tmp = 0.5 * ((1.0 - exp((fabs(im) + fabs(im)))) * (1.0 + (-1.0 * fabs(im))));
} else {
tmp = sinh(-fabs(im));
}
return copysign(1.0, im) * tmp;
}
public static double code(double re, double im) {
double tmp;
if ((0.5 * Math.cos(re)) <= -0.02) {
tmp = 0.5 * ((1.0 - Math.exp((Math.abs(im) + Math.abs(im)))) * (1.0 + (-1.0 * Math.abs(im))));
} else {
tmp = Math.sinh(-Math.abs(im));
}
return Math.copySign(1.0, im) * tmp;
}
def code(re, im): tmp = 0 if (0.5 * math.cos(re)) <= -0.02: tmp = 0.5 * ((1.0 - math.exp((math.fabs(im) + math.fabs(im)))) * (1.0 + (-1.0 * math.fabs(im)))) else: tmp = math.sinh(-math.fabs(im)) return math.copysign(1.0, im) * tmp
function code(re, im) tmp = 0.0 if (Float64(0.5 * cos(re)) <= -0.02) tmp = Float64(0.5 * Float64(Float64(1.0 - exp(Float64(abs(im) + abs(im)))) * Float64(1.0 + Float64(-1.0 * abs(im))))); else tmp = sinh(Float64(-abs(im))); end return Float64(copysign(1.0, im) * tmp) end
function tmp_2 = code(re, im) tmp = 0.0; if ((0.5 * cos(re)) <= -0.02) tmp = 0.5 * ((1.0 - exp((abs(im) + abs(im)))) * (1.0 + (-1.0 * abs(im)))); else tmp = sinh(-abs(im)); end tmp_2 = (sign(im) * abs(1.0)) * 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[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.02], N[(0.5 * N[(N[(1.0 - N[Exp[N[(N[Abs[im], $MachinePrecision] + N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-1.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sinh[(-N[Abs[im], $MachinePrecision])], $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq -0.02:\\
\;\;\;\;0.5 \cdot \left(\left(1 - e^{\left|im\right| + \left|im\right|}\right) \cdot \left(1 + -1 \cdot \left|im\right|\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sinh \left(-\left|im\right|\right)\\
\end{array}
if (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) < -0.0200000000000000004Initial program 54.6%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6440.6%
Applied rewrites40.6%
lift--.f64N/A
sub-to-multN/A
lower-unsound-*.f64N/A
lower-unsound--.f64N/A
lower-unsound-/.f3221.6%
lower-/.f32N/A
mult-flip-revN/A
lift-exp.f64N/A
exp-negN/A
lift-neg.f64N/A
remove-double-negN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
lower-+.f6422.3%
Applied rewrites22.3%
Taylor expanded in im around 0
lower-+.f64N/A
lower-*.f6411.2%
Applied rewrites11.2%
if -0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 54.6%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6440.6%
Applied rewrites40.6%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
metadata-evalN/A
mult-flip-revN/A
fp-cancel-sub-signN/A
metadata-evalN/A
mult-flipN/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.f6464.4%
Applied rewrites64.4%
(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.6%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6440.6%
Applied rewrites40.6%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
metadata-evalN/A
mult-flip-revN/A
fp-cancel-sub-signN/A
metadata-evalN/A
mult-flipN/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.f6464.4%
Applied rewrites64.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.6%
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.f6435.9%
Applied rewrites35.9%
rem-square-sqrtN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f6436.7%
lift-pow.f64N/A
unpow2N/A
lower-*.f6436.7%
lift-pow.f64N/A
unpow2N/A
lower-*.f6436.7%
Applied rewrites36.7%
(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)))
(- (* (* (* re re) (fabs im)) 0.5) (fabs im)))))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 = (((re * re) * fabs(im)) * 0.5) - fabs(im);
}
return copysign(1.0, im) * tmp;
}
public static double code(double re, double im) {
double tmp;
if (((0.5 * Math.cos(re)) * (Math.exp((0.0 - Math.abs(im))) - Math.exp(Math.abs(im)))) <= 0.0) {
tmp = Math.sinh(-Math.abs(im));
} else {
tmp = (((re * re) * Math.abs(im)) * 0.5) - Math.abs(im);
}
return Math.copySign(1.0, im) * tmp;
}
def code(re, im): tmp = 0 if ((0.5 * math.cos(re)) * (math.exp((0.0 - math.fabs(im))) - math.exp(math.fabs(im)))) <= 0.0: tmp = math.sinh(-math.fabs(im)) else: tmp = (((re * re) * math.fabs(im)) * 0.5) - math.fabs(im) return math.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 = Float64(Float64(Float64(Float64(re * re) * abs(im)) * 0.5) - abs(im)); end return Float64(copysign(1.0, im) * tmp) end
function tmp_2 = code(re, im) tmp = 0.0; if (((0.5 * cos(re)) * (exp((0.0 - abs(im))) - exp(abs(im)))) <= 0.0) tmp = sinh(-abs(im)); else tmp = (((re * re) * abs(im)) * 0.5) - abs(im); end tmp_2 = (sign(im) * abs(1.0)) * 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[(N[(N[(N[(re * re), $MachinePrecision] * N[Abs[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] - N[Abs[im], $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}:\\
\;\;\;\;\left(\left(re \cdot re\right) \cdot \left|im\right|\right) \cdot 0.5 - \left|im\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.6%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-exp.f6440.6%
Applied rewrites40.6%
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
metadata-evalN/A
mult-flip-revN/A
fp-cancel-sub-signN/A
metadata-evalN/A
mult-flipN/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.f6464.4%
Applied rewrites64.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.6%
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.f6435.9%
Applied rewrites35.9%
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6435.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6435.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6435.9%
lift-pow.f64N/A
unpow2N/A
lower-*.f6435.9%
Applied rewrites35.9%
(FPCore (re im)
:precision binary64
(*
(copysign 1.0 im)
(if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 (fabs im))) (exp (fabs im)))) 0.0)
(- (fabs im))
(- (* (* (* re re) (fabs im)) 0.5) (fabs im)))))double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp((0.0 - fabs(im))) - exp(fabs(im)))) <= 0.0) {
tmp = -fabs(im);
} else {
tmp = (((re * re) * fabs(im)) * 0.5) - fabs(im);
}
return copysign(1.0, im) * tmp;
}
public static double code(double re, double im) {
double tmp;
if (((0.5 * Math.cos(re)) * (Math.exp((0.0 - Math.abs(im))) - Math.exp(Math.abs(im)))) <= 0.0) {
tmp = -Math.abs(im);
} else {
tmp = (((re * re) * Math.abs(im)) * 0.5) - Math.abs(im);
}
return Math.copySign(1.0, im) * tmp;
}
def code(re, im): tmp = 0 if ((0.5 * math.cos(re)) * (math.exp((0.0 - math.fabs(im))) - math.exp(math.fabs(im)))) <= 0.0: tmp = -math.fabs(im) else: tmp = (((re * re) * math.fabs(im)) * 0.5) - math.fabs(im) return math.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 = Float64(-abs(im)); else tmp = Float64(Float64(Float64(Float64(re * re) * abs(im)) * 0.5) - abs(im)); end return Float64(copysign(1.0, im) * tmp) end
function tmp_2 = code(re, im) tmp = 0.0; if (((0.5 * cos(re)) * (exp((0.0 - abs(im))) - exp(abs(im)))) <= 0.0) tmp = -abs(im); else tmp = (((re * re) * abs(im)) * 0.5) - abs(im); end tmp_2 = (sign(im) * abs(1.0)) * 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[Abs[im], $MachinePrecision]), N[(N[(N[(N[(re * re), $MachinePrecision] * N[Abs[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] - N[Abs[im], $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:\\
\;\;\;\;-\left|im\right|\\
\mathbf{else}:\\
\;\;\;\;\left(\left(re \cdot re\right) \cdot \left|im\right|\right) \cdot 0.5 - \left|im\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.6%
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.2%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6429.2%
Applied rewrites29.2%
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.6%
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.f6435.9%
Applied rewrites35.9%
lift-fma.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6435.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6435.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6435.9%
lift-pow.f64N/A
unpow2N/A
lower-*.f6435.9%
Applied rewrites35.9%
(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.6%
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.2%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6429.2%
Applied rewrites29.2%
herbie shell --seed 2025183
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))