
(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]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
Herbie found 10 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]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
(FPCore (re im) :precision binary64 (* (cosh im) (cos re)))
double code(double re, double im) {
return cosh(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 = cosh(im) * cos(re)
end function
public static double code(double re, double im) {
return Math.cosh(im) * Math.cos(re);
}
def code(re, im): return math.cosh(im) * math.cos(re)
function code(re, im) return Float64(cosh(im) * cos(re)) end
function tmp = code(re, im) tmp = cosh(im) * cos(re); end
code[re_, im_] := N[(N[Cosh[im], $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision]
\cosh im \cdot \cos re
Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift-+.f64N/A
+-commutativeN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
cosh-defN/A
lower-*.f64N/A
lower-cosh.f64100.0%
Applied rewrites100.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (cos re)))
(t_1 (exp (fabs im)))
(t_2 (* t_0 (+ (exp (- (fabs im))) t_1))))
(if (<= t_2 (- INFINITY))
(* (* (fma -2.0 (fabs im) 2.0) t_1) 0.5)
(if (<= t_2 0.9999999999999998)
(* t_0 2.0)
(* (fma (exp (* -2.0 (fabs im))) 0.5 0.5) t_1)))))double code(double re, double im) {
double t_0 = 0.5 * cos(re);
double t_1 = exp(fabs(im));
double t_2 = t_0 * (exp(-fabs(im)) + t_1);
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = (fma(-2.0, fabs(im), 2.0) * t_1) * 0.5;
} else if (t_2 <= 0.9999999999999998) {
tmp = t_0 * 2.0;
} else {
tmp = fma(exp((-2.0 * fabs(im))), 0.5, 0.5) * t_1;
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * cos(re)) t_1 = exp(abs(im)) t_2 = Float64(t_0 * Float64(exp(Float64(-abs(im))) + t_1)) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = Float64(Float64(fma(-2.0, abs(im), 2.0) * t_1) * 0.5); elseif (t_2 <= 0.9999999999999998) tmp = Float64(t_0 * 2.0); else tmp = Float64(fma(exp(Float64(-2.0 * abs(im))), 0.5, 0.5) * t_1); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * N[(N[Exp[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(N[(-2.0 * N[Abs[im], $MachinePrecision] + 2.0), $MachinePrecision] * t$95$1), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$2, 0.9999999999999998], N[(t$95$0 * 2.0), $MachinePrecision], N[(N[(N[Exp[N[(-2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
t_1 := e^{\left|im\right|}\\
t_2 := t\_0 \cdot \left(e^{-\left|im\right|} + t\_1\right)\\
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;\left(\mathsf{fma}\left(-2, \left|im\right|, 2\right) \cdot t\_1\right) \cdot 0.5\\
\mathbf{elif}\;t\_2 \leq 0.9999999999999998:\\
\;\;\;\;t\_0 \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(e^{-2 \cdot \left|im\right|}, 0.5, 0.5\right) \cdot t\_1\\
\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
Applied rewrites65.2%
lift-+.f64N/A
*-lft-identityN/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
inv-powN/A
metadata-evalN/A
pow-plusN/A
lift-exp.f64N/A
exp-prodN/A
lift-*.f64N/A
lift-exp.f64N/A
distribute-rgt-inN/A
+-commutativeN/A
lift-+.f64N/A
*-commutativeN/A
lift-*.f6446.6%
Applied rewrites46.6%
Taylor expanded in im around 0
lower-+.f64N/A
lower-*.f6433.7%
Applied rewrites33.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6433.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6433.7%
Applied rewrites33.7%
if -inf.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 0.99999999999999978Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites51.1%
if 0.99999999999999978 < (*.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
Applied rewrites65.2%
lift-+.f64N/A
*-lft-identityN/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
inv-powN/A
metadata-evalN/A
pow-plusN/A
lift-exp.f64N/A
exp-prodN/A
lift-*.f64N/A
lift-exp.f64N/A
distribute-rgt-inN/A
+-commutativeN/A
lift-+.f64N/A
*-commutativeN/A
lift-*.f6446.6%
Applied rewrites46.6%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
lift--.f64N/A
sub-flipN/A
metadata-evalN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6446.6%
Applied rewrites46.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (exp (fabs im))))
(if (<= (* (* 0.5 (cos re)) (+ (exp (- (fabs im))) t_0)) -0.1)
(* (cosh (fabs im)) (fma (* re re) -0.5 1.0))
(* (fma (exp (* -2.0 (fabs im))) 0.5 0.5) t_0))))double code(double re, double im) {
double t_0 = exp(fabs(im));
double tmp;
if (((0.5 * cos(re)) * (exp(-fabs(im)) + t_0)) <= -0.1) {
tmp = cosh(fabs(im)) * fma((re * re), -0.5, 1.0);
} else {
tmp = fma(exp((-2.0 * fabs(im))), 0.5, 0.5) * t_0;
}
return tmp;
}
function code(re, im) t_0 = exp(abs(im)) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-abs(im))) + t_0)) <= -0.1) tmp = Float64(cosh(abs(im)) * fma(Float64(re * re), -0.5, 1.0)); else tmp = Float64(fma(exp(Float64(-2.0 * abs(im))), 0.5, 0.5) * t_0); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], -0.1], N[(N[Cosh[N[Abs[im], $MachinePrecision]], $MachinePrecision] * N[(N[(re * re), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Exp[N[(-2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]
\begin{array}{l}
t_0 := e^{\left|im\right|}\\
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-\left|im\right|} + t\_0\right) \leq -0.1:\\
\;\;\;\;\cosh \left(\left|im\right|\right) \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(e^{-2 \cdot \left|im\right|}, 0.5, 0.5\right) \cdot t\_0\\
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.10000000000000001Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift-+.f64N/A
+-commutativeN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
cosh-defN/A
lower-*.f64N/A
lower-cosh.f64100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6463.1%
Applied rewrites63.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6463.1%
lift-pow.f64N/A
unpow2N/A
lower-*.f6463.1%
Applied rewrites63.1%
if -0.10000000000000001 < (*.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
Applied rewrites65.2%
lift-+.f64N/A
*-lft-identityN/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
inv-powN/A
metadata-evalN/A
pow-plusN/A
lift-exp.f64N/A
exp-prodN/A
lift-*.f64N/A
lift-exp.f64N/A
distribute-rgt-inN/A
+-commutativeN/A
lift-+.f64N/A
*-commutativeN/A
lift-*.f6446.6%
Applied rewrites46.6%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
lift--.f64N/A
sub-flipN/A
metadata-evalN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6446.6%
Applied rewrites46.6%
(FPCore (re im) :precision binary64 (if (<= (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))) -0.1) (* (cosh im) (fma (* re re) -0.5 1.0)) (* (cosh im) 1.0)))
double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.1) {
tmp = cosh(im) * fma((re * re), -0.5, 1.0);
} else {
tmp = cosh(im) * 1.0;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) <= -0.1) tmp = Float64(cosh(im) * fma(Float64(re * re), -0.5, 1.0)); else tmp = Float64(cosh(im) * 1.0); end return tmp end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.1], N[(N[Cosh[im], $MachinePrecision] * N[(N[(re * re), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Cosh[im], $MachinePrecision] * 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.1:\\
\;\;\;\;\cosh im \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\cosh im \cdot 1\\
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.10000000000000001Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift-+.f64N/A
+-commutativeN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
cosh-defN/A
lower-*.f64N/A
lower-cosh.f64100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6463.1%
Applied rewrites63.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6463.1%
lift-pow.f64N/A
unpow2N/A
lower-*.f6463.1%
Applied rewrites63.1%
if -0.10000000000000001 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift-+.f64N/A
+-commutativeN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
cosh-defN/A
lower-*.f64N/A
lower-cosh.f64100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites65.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (exp (fabs im))))
(if (<= (* (* 0.5 (cos re)) (+ (exp (- (fabs im))) t_0)) -0.2)
(* (* (fma -2.0 (fabs im) 2.0) t_0) 0.5)
(* (cosh (fabs im)) 1.0))))double code(double re, double im) {
double t_0 = exp(fabs(im));
double tmp;
if (((0.5 * cos(re)) * (exp(-fabs(im)) + t_0)) <= -0.2) {
tmp = (fma(-2.0, fabs(im), 2.0) * t_0) * 0.5;
} else {
tmp = cosh(fabs(im)) * 1.0;
}
return tmp;
}
function code(re, im) t_0 = exp(abs(im)) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-abs(im))) + t_0)) <= -0.2) tmp = Float64(Float64(fma(-2.0, abs(im), 2.0) * t_0) * 0.5); else tmp = Float64(cosh(abs(im)) * 1.0); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], -0.2], N[(N[(N[(-2.0 * N[Abs[im], $MachinePrecision] + 2.0), $MachinePrecision] * t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Cosh[N[Abs[im], $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]]]
\begin{array}{l}
t_0 := e^{\left|im\right|}\\
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-\left|im\right|} + t\_0\right) \leq -0.2:\\
\;\;\;\;\left(\mathsf{fma}\left(-2, \left|im\right|, 2\right) \cdot t\_0\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\cosh \left(\left|im\right|\right) \cdot 1\\
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.20000000000000001Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites65.2%
lift-+.f64N/A
*-lft-identityN/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
inv-powN/A
metadata-evalN/A
pow-plusN/A
lift-exp.f64N/A
exp-prodN/A
lift-*.f64N/A
lift-exp.f64N/A
distribute-rgt-inN/A
+-commutativeN/A
lift-+.f64N/A
*-commutativeN/A
lift-*.f6446.6%
Applied rewrites46.6%
Taylor expanded in im around 0
lower-+.f64N/A
lower-*.f6433.7%
Applied rewrites33.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6433.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6433.7%
Applied rewrites33.7%
if -0.20000000000000001 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift-+.f64N/A
+-commutativeN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
cosh-defN/A
lower-*.f64N/A
lower-cosh.f64100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites65.2%
(FPCore (re im) :precision binary64 (if (<= (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))) -0.1) (* (+ 0.5 (* -0.25 (sqrt (* (* re re) (* re re))))) 2.0) (* (cosh im) 1.0)))
double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.1) {
tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
} else {
tmp = cosh(im) * 1.0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (((0.5d0 * cos(re)) * (exp(-im) + exp(im))) <= (-0.1d0)) then
tmp = (0.5d0 + ((-0.25d0) * sqrt(((re * re) * (re * re))))) * 2.0d0
else
tmp = cosh(im) * 1.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (((0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im))) <= -0.1) {
tmp = (0.5 + (-0.25 * Math.sqrt(((re * re) * (re * re))))) * 2.0;
} else {
tmp = Math.cosh(im) * 1.0;
}
return tmp;
}
def code(re, im): tmp = 0 if ((0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))) <= -0.1: tmp = (0.5 + (-0.25 * math.sqrt(((re * re) * (re * re))))) * 2.0 else: tmp = math.cosh(im) * 1.0 return tmp
function code(re, im) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) <= -0.1) tmp = Float64(Float64(0.5 + Float64(-0.25 * sqrt(Float64(Float64(re * re) * Float64(re * re))))) * 2.0); else tmp = Float64(cosh(im) * 1.0); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.1) tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0; else tmp = cosh(im) * 1.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.1], N[(N[(0.5 + N[(-0.25 * N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[Cosh[im], $MachinePrecision] * 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.1:\\
\;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\cosh im \cdot 1\\
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.10000000000000001Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites51.1%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6432.0%
Applied rewrites32.0%
rem-square-sqrtN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f6434.9%
lift-pow.f64N/A
unpow2N/A
lower-*.f6434.9%
lift-pow.f64N/A
unpow2N/A
lower-*.f6434.9%
Applied rewrites34.9%
if -0.10000000000000001 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift-+.f64N/A
+-commutativeN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
cosh-defN/A
lower-*.f64N/A
lower-cosh.f64100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites65.2%
(FPCore (re im) :precision binary64 (if (<= (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))) -0.1) (* (fma (* -0.25 re) re 0.5) 2.0) (* (cosh im) 1.0)))
double code(double re, double im) {
double tmp;
if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.1) {
tmp = fma((-0.25 * re), re, 0.5) * 2.0;
} else {
tmp = cosh(im) * 1.0;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) <= -0.1) tmp = Float64(fma(Float64(-0.25 * re), re, 0.5) * 2.0); else tmp = Float64(cosh(im) * 1.0); end return tmp end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.1], N[(N[(N[(-0.25 * re), $MachinePrecision] * re + 0.5), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[Cosh[im], $MachinePrecision] * 1.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.1:\\
\;\;\;\;\mathsf{fma}\left(-0.25 \cdot re, re, 0.5\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\cosh im \cdot 1\\
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.10000000000000001Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites51.1%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6432.0%
Applied rewrites32.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6432.0%
Applied rewrites32.0%
if -0.10000000000000001 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 100.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lift-+.f64N/A
+-commutativeN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
cosh-defN/A
lower-*.f64N/A
lower-cosh.f64100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites65.2%
(FPCore (re im) :precision binary64 (if (<= (fabs re) 2.8e+157) (* 0.5 (* (+ 2.0 (* -2.0 im)) (+ 1.0 im))) (* (fma (* -0.25 (fabs re)) (fabs re) 0.5) 2.0)))
double code(double re, double im) {
double tmp;
if (fabs(re) <= 2.8e+157) {
tmp = 0.5 * ((2.0 + (-2.0 * im)) * (1.0 + im));
} else {
tmp = fma((-0.25 * fabs(re)), fabs(re), 0.5) * 2.0;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (abs(re) <= 2.8e+157) tmp = Float64(0.5 * Float64(Float64(2.0 + Float64(-2.0 * im)) * Float64(1.0 + im))); else tmp = Float64(fma(Float64(-0.25 * abs(re)), abs(re), 0.5) * 2.0); end return tmp end
code[re_, im_] := If[LessEqual[N[Abs[re], $MachinePrecision], 2.8e+157], N[(0.5 * N[(N[(2.0 + N[(-2.0 * im), $MachinePrecision]), $MachinePrecision] * N[(1.0 + im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-0.25 * N[Abs[re], $MachinePrecision]), $MachinePrecision] * N[Abs[re], $MachinePrecision] + 0.5), $MachinePrecision] * 2.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|re\right| \leq 2.8 \cdot 10^{+157}:\\
\;\;\;\;0.5 \cdot \left(\left(2 + -2 \cdot im\right) \cdot \left(1 + im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.25 \cdot \left|re\right|, \left|re\right|, 0.5\right) \cdot 2\\
\end{array}
if re < 2.8000000000000003e157Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites65.2%
lift-+.f64N/A
*-lft-identityN/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
inv-powN/A
metadata-evalN/A
pow-plusN/A
lift-exp.f64N/A
exp-prodN/A
lift-*.f64N/A
lift-exp.f64N/A
distribute-rgt-inN/A
+-commutativeN/A
lift-+.f64N/A
*-commutativeN/A
lift-*.f6446.6%
Applied rewrites46.6%
Taylor expanded in im around 0
lower-+.f64N/A
lower-*.f6433.7%
Applied rewrites33.7%
Taylor expanded in im around 0
lower-+.f6433.8%
Applied rewrites33.8%
if 2.8000000000000003e157 < re Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites51.1%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6432.0%
Applied rewrites32.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6432.0%
Applied rewrites32.0%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (cos re)) -0.02) (* (fma (* -0.25 re) re 0.5) 2.0) (* (* 0.5 1.0) 2.0)))
double code(double re, double im) {
double tmp;
if ((0.5 * cos(re)) <= -0.02) {
tmp = fma((-0.25 * re), re, 0.5) * 2.0;
} else {
tmp = (0.5 * 1.0) * 2.0;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * cos(re)) <= -0.02) tmp = Float64(fma(Float64(-0.25 * re), re, 0.5) * 2.0); else tmp = Float64(Float64(0.5 * 1.0) * 2.0); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(N[(-0.25 * re), $MachinePrecision] * re + 0.5), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(0.5 * 1.0), $MachinePrecision] * 2.0), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq -0.02:\\
\;\;\;\;\mathsf{fma}\left(-0.25 \cdot re, re, 0.5\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot 1\right) \cdot 2\\
\end{array}
if (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) < -0.02Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites51.1%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6432.0%
Applied rewrites32.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6432.0%
Applied rewrites32.0%
if -0.02 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites51.1%
Taylor expanded in re around 0
Applied rewrites28.4%
(FPCore (re im) :precision binary64 (* (* 0.5 1.0) 2.0))
double code(double re, double im) {
return (0.5 * 1.0) * 2.0;
}
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 * 1.0d0) * 2.0d0
end function
public static double code(double re, double im) {
return (0.5 * 1.0) * 2.0;
}
def code(re, im): return (0.5 * 1.0) * 2.0
function code(re, im) return Float64(Float64(0.5 * 1.0) * 2.0) end
function tmp = code(re, im) tmp = (0.5 * 1.0) * 2.0; end
code[re_, im_] := N[(N[(0.5 * 1.0), $MachinePrecision] * 2.0), $MachinePrecision]
\left(0.5 \cdot 1\right) \cdot 2
Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites51.1%
Taylor expanded in re around 0
Applied rewrites28.4%
herbie shell --seed 2025259
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))