
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-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(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-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(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (let* ((t_0 (* (cos re) 0.5))) (fma t_0 (fma (fma im_m 0.5 -1.0) im_m 1.0) (* t_0 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = cos(re) * 0.5;
return fma(t_0, fma(fma(im_m, 0.5, -1.0), im_m, 1.0), (t_0 * exp(im_m)));
}
im_m = abs(im) function code(re, im_m) t_0 = Float64(cos(re) * 0.5) return fma(t_0, fma(fma(im_m, 0.5, -1.0), im_m, 1.0), Float64(t_0 * exp(im_m))) end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision]}, N[(t$95$0 * N[(N[(im$95$m * 0.5 + -1.0), $MachinePrecision] * im$95$m + 1.0), $MachinePrecision] + N[(t$95$0 * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := \cos re \cdot 0.5\\
\mathsf{fma}\left(t\_0, \mathsf{fma}\left(\mathsf{fma}\left(im\_m, 0.5, -1\right), im\_m, 1\right), t\_0 \cdot e^{im\_m}\right)
\end{array}
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-cos.f64N/A
lift-exp.f64100.0
Applied rewrites100.0%
Taylor expanded in im around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-flipN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f6499.5
Applied rewrites99.5%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* 0.5 (cos re))) (t_1 (* t_0 (+ (exp (- im_m)) (exp im_m)))))
(if (<= t_1 (- INFINITY))
(* (fma (* re re) -0.25 0.5) (* (cosh im_m) 2.0))
(if (<= t_1 0.999999999999999)
(* t_0 (fma im_m im_m 2.0))
(* (* 2.0 (cosh im_m)) 0.5)))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = 0.5 * cos(re);
double t_1 = t_0 * (exp(-im_m) + exp(im_m));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = fma((re * re), -0.25, 0.5) * (cosh(im_m) * 2.0);
} else if (t_1 <= 0.999999999999999) {
tmp = t_0 * fma(im_m, im_m, 2.0);
} else {
tmp = (2.0 * cosh(im_m)) * 0.5;
}
return tmp;
}
im_m = abs(im) function code(re, im_m) t_0 = Float64(0.5 * cos(re)) t_1 = Float64(t_0 * Float64(exp(Float64(-im_m)) + exp(im_m))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(fma(Float64(re * re), -0.25, 0.5) * Float64(cosh(im_m) * 2.0)); elseif (t_1 <= 0.999999999999999) tmp = Float64(t_0 * fma(im_m, im_m, 2.0)); else tmp = Float64(Float64(2.0 * cosh(im_m)) * 0.5); end return tmp end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(re * re), $MachinePrecision] * -0.25 + 0.5), $MachinePrecision] * N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.999999999999999], N[(t$95$0 * N[(im$95$m * im$95$m + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Cosh[im$95$m], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
t_1 := t\_0 \cdot \left(e^{-im\_m} + e^{im\_m}\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(re \cdot re, -0.25, 0.5\right) \cdot \left(\cosh im\_m \cdot 2\right)\\
\mathbf{elif}\;t\_1 \leq 0.999999999999999:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(im\_m, im\_m, 2\right)\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \cosh im\_m\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -inf.0Initial program 100.0%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6463.8
Applied rewrites63.8%
lift-+.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
+-commutativeN/A
cosh-undef-revN/A
lift-cosh.f64N/A
*-commutativeN/A
lower-*.f6463.8
Applied rewrites63.8%
if -inf.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 0.999999999999999001Initial program 100.0%
Taylor expanded in im around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6476.0
Applied rewrites76.0%
if 0.999999999999999001 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im_m)) (exp im_m))))
im_m = fabs(im);
double code(double re, double im_m) {
return (0.5 * cos(re)) * (exp(-im_m) + exp(im_m));
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = (0.5d0 * cos(re)) * (exp(-im_m) + exp(im_m))
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return (0.5 * Math.cos(re)) * (Math.exp(-im_m) + Math.exp(im_m));
}
im_m = math.fabs(im) def code(re, im_m): return (0.5 * math.cos(re)) * (math.exp(-im_m) + math.exp(im_m))
im_m = abs(im) function code(re, im_m) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im_m)) + exp(im_m))) end
im_m = abs(im); function tmp = code(re, im_m) tmp = (0.5 * cos(re)) * (exp(-im_m) + exp(im_m)); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im\_m} + e^{im\_m}\right)
\end{array}
Initial program 100.0%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* 0.5 (cos re))) (t_1 (* t_0 (+ (exp (- im_m)) (exp im_m)))))
(if (<= t_1 (- INFINITY))
(* (fma (* re re) -0.25 0.5) (* (cosh im_m) 2.0))
(if (<= t_1 0.999999999999999) (* t_0 2.0) (* (* 2.0 (cosh im_m)) 0.5)))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = 0.5 * cos(re);
double t_1 = t_0 * (exp(-im_m) + exp(im_m));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = fma((re * re), -0.25, 0.5) * (cosh(im_m) * 2.0);
} else if (t_1 <= 0.999999999999999) {
tmp = t_0 * 2.0;
} else {
tmp = (2.0 * cosh(im_m)) * 0.5;
}
return tmp;
}
im_m = abs(im) function code(re, im_m) t_0 = Float64(0.5 * cos(re)) t_1 = Float64(t_0 * Float64(exp(Float64(-im_m)) + exp(im_m))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(fma(Float64(re * re), -0.25, 0.5) * Float64(cosh(im_m) * 2.0)); elseif (t_1 <= 0.999999999999999) tmp = Float64(t_0 * 2.0); else tmp = Float64(Float64(2.0 * cosh(im_m)) * 0.5); end return tmp end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(re * re), $MachinePrecision] * -0.25 + 0.5), $MachinePrecision] * N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.999999999999999], N[(t$95$0 * 2.0), $MachinePrecision], N[(N[(2.0 * N[Cosh[im$95$m], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
t_1 := t\_0 \cdot \left(e^{-im\_m} + e^{im\_m}\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(re \cdot re, -0.25, 0.5\right) \cdot \left(\cosh im\_m \cdot 2\right)\\
\mathbf{elif}\;t\_1 \leq 0.999999999999999:\\
\;\;\;\;t\_0 \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \cosh im\_m\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -inf.0Initial program 100.0%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6463.8
Applied rewrites63.8%
lift-+.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
+-commutativeN/A
cosh-undef-revN/A
lift-cosh.f64N/A
*-commutativeN/A
lower-*.f6463.8
Applied rewrites63.8%
if -inf.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 0.999999999999999001Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.7%
if 0.999999999999999001 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (* (* 0.5 (cos re)) (+ (exp (- im_m)) (exp im_m))) -0.05) (* (fma (* re re) -0.25 0.5) (* (cosh im_m) 2.0)) (* (* 2.0 (cosh im_m)) 0.5)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (((0.5 * cos(re)) * (exp(-im_m) + exp(im_m))) <= -0.05) {
tmp = fma((re * re), -0.25, 0.5) * (cosh(im_m) * 2.0);
} else {
tmp = (2.0 * cosh(im_m)) * 0.5;
}
return tmp;
}
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im_m)) + exp(im_m))) <= -0.05) tmp = Float64(fma(Float64(re * re), -0.25, 0.5) * Float64(cosh(im_m) * 2.0)); else tmp = Float64(Float64(2.0 * cosh(im_m)) * 0.5); end return tmp end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.05], N[(N[(N[(re * re), $MachinePrecision] * -0.25 + 0.5), $MachinePrecision] * N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Cosh[im$95$m], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im\_m} + e^{im\_m}\right) \leq -0.05:\\
\;\;\;\;\mathsf{fma}\left(re \cdot re, -0.25, 0.5\right) \cdot \left(\cosh im\_m \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \cosh im\_m\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.050000000000000003Initial program 100.0%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6463.8
Applied rewrites63.8%
lift-+.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
+-commutativeN/A
cosh-undef-revN/A
lift-cosh.f64N/A
*-commutativeN/A
lower-*.f6463.8
Applied rewrites63.8%
if -0.050000000000000003 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (* (* 0.5 (cos re)) (+ (exp (- im_m)) (exp im_m))) -0.05) (* (* 0.5 (fma -0.5 (sqrt (* (* re re) (* re re))) 1.0)) 2.0) (* (* 2.0 (cosh im_m)) 0.5)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (((0.5 * cos(re)) * (exp(-im_m) + exp(im_m))) <= -0.05) {
tmp = (0.5 * fma(-0.5, sqrt(((re * re) * (re * re))), 1.0)) * 2.0;
} else {
tmp = (2.0 * cosh(im_m)) * 0.5;
}
return tmp;
}
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im_m)) + exp(im_m))) <= -0.05) tmp = Float64(Float64(0.5 * fma(-0.5, sqrt(Float64(Float64(re * re) * Float64(re * re))), 1.0)) * 2.0); else tmp = Float64(Float64(2.0 * cosh(im_m)) * 0.5); end return tmp end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.05], N[(N[(0.5 * N[(-0.5 * N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(2.0 * N[Cosh[im$95$m], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im\_m} + e^{im\_m}\right) \leq -0.05:\\
\;\;\;\;\left(0.5 \cdot \mathsf{fma}\left(-0.5, \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}, 1\right)\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \cosh im\_m\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.050000000000000003Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.7%
Taylor expanded in re around 0
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6432.9
Applied rewrites32.9%
lift-*.f64N/A
pow2N/A
fabs-pow2-revN/A
rem-sqrt-square-revN/A
lower-sqrt.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6435.7
Applied rewrites35.7%
if -0.050000000000000003 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (* (* 0.5 (cos re)) (+ (exp (- im_m)) (exp im_m))) -0.05) (* (* 0.5 (* (* re re) -0.5)) 2.0) (* (* 2.0 (cosh im_m)) 0.5)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (((0.5 * cos(re)) * (exp(-im_m) + exp(im_m))) <= -0.05) {
tmp = (0.5 * ((re * re) * -0.5)) * 2.0;
} else {
tmp = (2.0 * cosh(im_m)) * 0.5;
}
return tmp;
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (((0.5d0 * cos(re)) * (exp(-im_m) + exp(im_m))) <= (-0.05d0)) then
tmp = (0.5d0 * ((re * re) * (-0.5d0))) * 2.0d0
else
tmp = (2.0d0 * cosh(im_m)) * 0.5d0
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (((0.5 * Math.cos(re)) * (Math.exp(-im_m) + Math.exp(im_m))) <= -0.05) {
tmp = (0.5 * ((re * re) * -0.5)) * 2.0;
} else {
tmp = (2.0 * Math.cosh(im_m)) * 0.5;
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if ((0.5 * math.cos(re)) * (math.exp(-im_m) + math.exp(im_m))) <= -0.05: tmp = (0.5 * ((re * re) * -0.5)) * 2.0 else: tmp = (2.0 * math.cosh(im_m)) * 0.5 return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im_m)) + exp(im_m))) <= -0.05) tmp = Float64(Float64(0.5 * Float64(Float64(re * re) * -0.5)) * 2.0); else tmp = Float64(Float64(2.0 * cosh(im_m)) * 0.5); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (((0.5 * cos(re)) * (exp(-im_m) + exp(im_m))) <= -0.05) tmp = (0.5 * ((re * re) * -0.5)) * 2.0; else tmp = (2.0 * cosh(im_m)) * 0.5; end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.05], N[(N[(0.5 * N[(N[(re * re), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(2.0 * N[Cosh[im$95$m], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im\_m} + e^{im\_m}\right) \leq -0.05:\\
\;\;\;\;\left(0.5 \cdot \left(\left(re \cdot re\right) \cdot -0.5\right)\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot \cosh im\_m\right) \cdot 0.5\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.050000000000000003Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.7%
Taylor expanded in re around 0
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6432.9
Applied rewrites32.9%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f648.2
Applied rewrites8.2%
if -0.050000000000000003 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (* (* 0.5 (cos re)) (+ (exp (- im_m)) (exp im_m))) -0.05) (* (* 0.5 (* (* re re) -0.5)) 2.0) (fma (* (fma (* im_m im_m) 0.041666666666666664 0.5) im_m) im_m 1.0)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (((0.5 * cos(re)) * (exp(-im_m) + exp(im_m))) <= -0.05) {
tmp = (0.5 * ((re * re) * -0.5)) * 2.0;
} else {
tmp = fma((fma((im_m * im_m), 0.041666666666666664, 0.5) * im_m), im_m, 1.0);
}
return tmp;
}
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im_m)) + exp(im_m))) <= -0.05) tmp = Float64(Float64(0.5 * Float64(Float64(re * re) * -0.5)) * 2.0); else tmp = fma(Float64(fma(Float64(im_m * im_m), 0.041666666666666664, 0.5) * im_m), im_m, 1.0); end return tmp end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.05], N[(N[(0.5 * N[(N[(re * re), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(N[(N[(im$95$m * im$95$m), $MachinePrecision] * 0.041666666666666664 + 0.5), $MachinePrecision] * im$95$m), $MachinePrecision] * im$95$m + 1.0), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im\_m} + e^{im\_m}\right) \leq -0.05:\\
\;\;\;\;\left(0.5 \cdot \left(\left(re \cdot re\right) \cdot -0.5\right)\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(im\_m \cdot im\_m, 0.041666666666666664, 0.5\right) \cdot im\_m, im\_m, 1\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.050000000000000003Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.7%
Taylor expanded in re around 0
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6432.9
Applied rewrites32.9%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f648.2
Applied rewrites8.2%
if -0.050000000000000003 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
Taylor expanded in im around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6457.0
Applied rewrites57.0%
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-fma.f64N/A
lift-*.f6457.0
Applied rewrites57.0%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (* (* 0.5 (cos re)) (+ (exp (- im_m)) (exp im_m))) -0.05) (* (* 0.5 (* (* re re) -0.5)) 2.0) (fma (* (* 0.041666666666666664 im_m) im_m) (* im_m im_m) 1.0)))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (((0.5 * cos(re)) * (exp(-im_m) + exp(im_m))) <= -0.05) {
tmp = (0.5 * ((re * re) * -0.5)) * 2.0;
} else {
tmp = fma(((0.041666666666666664 * im_m) * im_m), (im_m * im_m), 1.0);
}
return tmp;
}
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im_m)) + exp(im_m))) <= -0.05) tmp = Float64(Float64(0.5 * Float64(Float64(re * re) * -0.5)) * 2.0); else tmp = fma(Float64(Float64(0.041666666666666664 * im_m) * im_m), Float64(im_m * im_m), 1.0); end return tmp end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.05], N[(N[(0.5 * N[(N[(re * re), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(N[(0.041666666666666664 * im$95$m), $MachinePrecision] * im$95$m), $MachinePrecision] * N[(im$95$m * im$95$m), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im\_m} + e^{im\_m}\right) \leq -0.05:\\
\;\;\;\;\left(0.5 \cdot \left(\left(re \cdot re\right) \cdot -0.5\right)\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(0.041666666666666664 \cdot im\_m\right) \cdot im\_m, im\_m \cdot im\_m, 1\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.050000000000000003Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.7%
Taylor expanded in re around 0
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6432.9
Applied rewrites32.9%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f648.2
Applied rewrites8.2%
if -0.050000000000000003 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
Taylor expanded in im around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6457.0
Applied rewrites57.0%
Taylor expanded in im around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6456.8
Applied rewrites56.8%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f6456.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6456.8
Applied rewrites56.8%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(let* ((t_0 (* (* 0.5 (cos re)) (+ (exp (- im_m)) (exp im_m)))))
(if (<= t_0 -0.05)
(* (* 0.5 (* (* re re) -0.5)) 2.0)
(if (<= t_0 2.0)
(* (* 0.5 1.0) 2.0)
(* (* im_m im_m) (* (* im_m im_m) 0.041666666666666664))))))im_m = fabs(im);
double code(double re, double im_m) {
double t_0 = (0.5 * cos(re)) * (exp(-im_m) + exp(im_m));
double tmp;
if (t_0 <= -0.05) {
tmp = (0.5 * ((re * re) * -0.5)) * 2.0;
} else if (t_0 <= 2.0) {
tmp = (0.5 * 1.0) * 2.0;
} else {
tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664);
}
return tmp;
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: t_0
real(8) :: tmp
t_0 = (0.5d0 * cos(re)) * (exp(-im_m) + exp(im_m))
if (t_0 <= (-0.05d0)) then
tmp = (0.5d0 * ((re * re) * (-0.5d0))) * 2.0d0
else if (t_0 <= 2.0d0) then
tmp = (0.5d0 * 1.0d0) * 2.0d0
else
tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664d0)
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double t_0 = (0.5 * Math.cos(re)) * (Math.exp(-im_m) + Math.exp(im_m));
double tmp;
if (t_0 <= -0.05) {
tmp = (0.5 * ((re * re) * -0.5)) * 2.0;
} else if (t_0 <= 2.0) {
tmp = (0.5 * 1.0) * 2.0;
} else {
tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): t_0 = (0.5 * math.cos(re)) * (math.exp(-im_m) + math.exp(im_m)) tmp = 0 if t_0 <= -0.05: tmp = (0.5 * ((re * re) * -0.5)) * 2.0 elif t_0 <= 2.0: tmp = (0.5 * 1.0) * 2.0 else: tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664) return tmp
im_m = abs(im) function code(re, im_m) t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im_m)) + exp(im_m))) tmp = 0.0 if (t_0 <= -0.05) tmp = Float64(Float64(0.5 * Float64(Float64(re * re) * -0.5)) * 2.0); elseif (t_0 <= 2.0) tmp = Float64(Float64(0.5 * 1.0) * 2.0); else tmp = Float64(Float64(im_m * im_m) * Float64(Float64(im_m * im_m) * 0.041666666666666664)); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) t_0 = (0.5 * cos(re)) * (exp(-im_m) + exp(im_m)); tmp = 0.0; if (t_0 <= -0.05) tmp = (0.5 * ((re * re) * -0.5)) * 2.0; elseif (t_0 <= 2.0) tmp = (0.5 * 1.0) * 2.0; else tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.05], N[(N[(0.5 * N[(N[(re * re), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(N[(0.5 * 1.0), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(im$95$m * im$95$m), $MachinePrecision] * N[(N[(im$95$m * im$95$m), $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{-im\_m} + e^{im\_m}\right)\\
\mathbf{if}\;t\_0 \leq -0.05:\\
\;\;\;\;\left(0.5 \cdot \left(\left(re \cdot re\right) \cdot -0.5\right)\right) \cdot 2\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\left(0.5 \cdot 1\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(im\_m \cdot im\_m\right) \cdot \left(\left(im\_m \cdot im\_m\right) \cdot 0.041666666666666664\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.050000000000000003Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.7%
Taylor expanded in re around 0
+-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6432.9
Applied rewrites32.9%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f648.2
Applied rewrites8.2%
if -0.050000000000000003 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 2Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.7%
Taylor expanded in re around 0
Applied rewrites28.8%
if 2 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
Taylor expanded in im around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6457.0
Applied rewrites57.0%
Taylor expanded in im around inf
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
pow-prod-upN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6431.0
Applied rewrites31.0%
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f64N/A
unpow-prod-downN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
pow2N/A
lift-*.f64N/A
lift-*.f6431.0
Applied rewrites31.0%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (* (* 0.5 (cos re)) (+ (exp (- im_m)) (exp im_m))) 2.0) (* (* 0.5 1.0) 2.0) (* (* im_m im_m) (* (* im_m im_m) 0.041666666666666664))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (((0.5 * cos(re)) * (exp(-im_m) + exp(im_m))) <= 2.0) {
tmp = (0.5 * 1.0) * 2.0;
} else {
tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664);
}
return tmp;
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (((0.5d0 * cos(re)) * (exp(-im_m) + exp(im_m))) <= 2.0d0) then
tmp = (0.5d0 * 1.0d0) * 2.0d0
else
tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664d0)
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (((0.5 * Math.cos(re)) * (Math.exp(-im_m) + Math.exp(im_m))) <= 2.0) {
tmp = (0.5 * 1.0) * 2.0;
} else {
tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664);
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if ((0.5 * math.cos(re)) * (math.exp(-im_m) + math.exp(im_m))) <= 2.0: tmp = (0.5 * 1.0) * 2.0 else: tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im_m)) + exp(im_m))) <= 2.0) tmp = Float64(Float64(0.5 * 1.0) * 2.0); else tmp = Float64(Float64(im_m * im_m) * Float64(Float64(im_m * im_m) * 0.041666666666666664)); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (((0.5 * cos(re)) * (exp(-im_m) + exp(im_m))) <= 2.0) tmp = (0.5 * 1.0) * 2.0; else tmp = (im_m * im_m) * ((im_m * im_m) * 0.041666666666666664); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im$95$m)], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[(0.5 * 1.0), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(im$95$m * im$95$m), $MachinePrecision] * N[(N[(im$95$m * im$95$m), $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im\_m} + e^{im\_m}\right) \leq 2:\\
\;\;\;\;\left(0.5 \cdot 1\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(im\_m \cdot im\_m\right) \cdot \left(\left(im\_m \cdot im\_m\right) \cdot 0.041666666666666664\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 2Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.7%
Taylor expanded in re around 0
Applied rewrites28.8%
if 2 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
Taylor expanded in im around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6457.0
Applied rewrites57.0%
Taylor expanded in im around inf
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
pow-prod-upN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6431.0
Applied rewrites31.0%
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f64N/A
unpow-prod-downN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
pow2N/A
lift-*.f64N/A
lift-*.f6431.0
Applied rewrites31.0%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (* (fma im_m im_m 2.0) 0.5))
im_m = fabs(im);
double code(double re, double im_m) {
return fma(im_m, im_m, 2.0) * 0.5;
}
im_m = abs(im) function code(re, im_m) return Float64(fma(im_m, im_m, 2.0) * 0.5) end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(N[(im$95$m * im$95$m + 2.0), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\mathsf{fma}\left(im\_m, im\_m, 2\right) \cdot 0.5
\end{array}
Initial program 100.0%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
cosh-undefN/A
lower-*.f64N/A
lower-cosh.f6465.5
Applied rewrites65.5%
Taylor expanded in im around 0
cosh-undef-revN/A
+-commutativeN/A
+-commutativeN/A
unpow2N/A
lower-fma.f6447.7
Applied rewrites47.7%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (* (* 0.5 1.0) 2.0))
im_m = fabs(im);
double code(double re, double im_m) {
return (0.5 * 1.0) * 2.0;
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = (0.5d0 * 1.0d0) * 2.0d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return (0.5 * 1.0) * 2.0;
}
im_m = math.fabs(im) def code(re, im_m): return (0.5 * 1.0) * 2.0
im_m = abs(im) function code(re, im_m) return Float64(Float64(0.5 * 1.0) * 2.0) end
im_m = abs(im); function tmp = code(re, im_m) tmp = (0.5 * 1.0) * 2.0; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(N[(0.5 * 1.0), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\left(0.5 \cdot 1\right) \cdot 2
\end{array}
Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.7%
Taylor expanded in re around 0
Applied rewrites28.8%
herbie shell --seed 2025130
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))