
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
double code(double re, double im) {
return exp(re) * sin(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 = exp(re) * sin(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
def code(re, im): return math.exp(re) * math.sin(im)
function code(re, im) return Float64(exp(re) * sin(im)) end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
e^{re} \cdot \sin im
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
double code(double re, double im) {
return exp(re) * sin(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 = exp(re) * sin(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
def code(re, im): return math.exp(re) * math.sin(im)
function code(re, im) return Float64(exp(re) * sin(im)) end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
e^{re} \cdot \sin im
(FPCore (re im) :precision binary64 (* (sqrt (exp (+ re re))) (sin im)))
double code(double re, double im) {
return sqrt(exp((re + re))) * sin(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 = sqrt(exp((re + re))) * sin(im)
end function
public static double code(double re, double im) {
return Math.sqrt(Math.exp((re + re))) * Math.sin(im);
}
def code(re, im): return math.sqrt(math.exp((re + re))) * math.sin(im)
function code(re, im) return Float64(sqrt(exp(Float64(re + re))) * sin(im)) end
function tmp = code(re, im) tmp = sqrt(exp((re + re))) * sin(im); end
code[re_, im_] := N[(N[Sqrt[N[Exp[N[(re + re), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
\sqrt{e^{re + re}} \cdot \sin im
Initial program 100.0%
lift-exp.f64N/A
exp-fabsN/A
lift-exp.f64N/A
rem-sqrt-square-revN/A
lower-sqrt.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
exp-lft-sqr-revN/A
lower-exp.f64N/A
*-commutativeN/A
count-2N/A
lower-+.f6499.9%
Applied rewrites99.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sin (fabs im))) (t_1 (* (exp re) t_0)))
(*
(copysign 1.0 im)
(if (<= t_1 (- INFINITY))
(*
(exp re)
(*
(fabs im)
(fma (* -0.16666666666666666 (fabs im)) (fabs im) 1.0)))
(if (<= t_1 -0.05)
(* (/ -1.0 (- re 1.0)) t_0)
(if (<= t_1 1e-101)
(/ (fabs im) (exp (- re)))
(if (<= t_1 20.0)
(* (+ 1.0 re) t_0)
(* (fabs im) (exp re)))))))))double code(double re, double im) {
double t_0 = sin(fabs(im));
double t_1 = exp(re) * t_0;
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = exp(re) * (fabs(im) * fma((-0.16666666666666666 * fabs(im)), fabs(im), 1.0));
} else if (t_1 <= -0.05) {
tmp = (-1.0 / (re - 1.0)) * t_0;
} else if (t_1 <= 1e-101) {
tmp = fabs(im) / exp(-re);
} else if (t_1 <= 20.0) {
tmp = (1.0 + re) * t_0;
} else {
tmp = fabs(im) * exp(re);
}
return copysign(1.0, im) * tmp;
}
function code(re, im) t_0 = sin(abs(im)) t_1 = Float64(exp(re) * t_0) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(exp(re) * Float64(abs(im) * fma(Float64(-0.16666666666666666 * abs(im)), abs(im), 1.0))); elseif (t_1 <= -0.05) tmp = Float64(Float64(-1.0 / Float64(re - 1.0)) * t_0); elseif (t_1 <= 1e-101) tmp = Float64(abs(im) / exp(Float64(-re))); elseif (t_1 <= 20.0) tmp = Float64(Float64(1.0 + re) * t_0); else tmp = Float64(abs(im) * exp(re)); end return Float64(copysign(1.0, im) * tmp) end
code[re_, im_] := Block[{t$95$0 = N[Sin[N[Abs[im], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[re], $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$1, (-Infinity)], N[(N[Exp[re], $MachinePrecision] * N[(N[Abs[im], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Abs[im], $MachinePrecision]), $MachinePrecision] * N[Abs[im], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -0.05], N[(N[(-1.0 / N[(re - 1.0), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[t$95$1, 1e-101], N[(N[Abs[im], $MachinePrecision] / N[Exp[(-re)], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 20.0], N[(N[(1.0 + re), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[Abs[im], $MachinePrecision] * N[Exp[re], $MachinePrecision]), $MachinePrecision]]]]]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \sin \left(\left|im\right|\right)\\
t_1 := e^{re} \cdot t\_0\\
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;e^{re} \cdot \left(\left|im\right| \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left|im\right|, \left|im\right|, 1\right)\right)\\
\mathbf{elif}\;t\_1 \leq -0.05:\\
\;\;\;\;\frac{-1}{re - 1} \cdot t\_0\\
\mathbf{elif}\;t\_1 \leq 10^{-101}:\\
\;\;\;\;\frac{\left|im\right|}{e^{-re}}\\
\mathbf{elif}\;t\_1 \leq 20:\\
\;\;\;\;\left(1 + re\right) \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\left|im\right| \cdot e^{re}\\
\end{array}
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -inf.0Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6460.6%
Applied rewrites60.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6460.6%
Applied rewrites60.6%
if -inf.0 < (*.f64 (exp.f64 re) (sin.f64 im)) < -0.050000000000000003Initial program 100.0%
Taylor expanded in re around 0
lower-+.f6451.8%
Applied rewrites51.8%
lift-+.f64N/A
+-commutativeN/A
flip-+N/A
lower-unsound-/.f64N/A
lower-unsound--.f64N/A
lower-unsound-*.f64N/A
lower-unsound-*.f64N/A
lower-unsound--.f6463.7%
Applied rewrites63.7%
Taylor expanded in re around 0
Applied rewrites57.3%
if -0.050000000000000003 < (*.f64 (exp.f64 re) (sin.f64 im)) < 1.0000000000000001e-101Initial program 100.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
add-flipN/A
cosh-neg-revN/A
sinh-neg-revN/A
sinh---cosh-revN/A
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0%
Applied rewrites100.0%
Taylor expanded in im around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6469.1%
Applied rewrites69.1%
if 1.0000000000000001e-101 < (*.f64 (exp.f64 re) (sin.f64 im)) < 20Initial program 100.0%
Taylor expanded in re around 0
lower-+.f6451.8%
Applied rewrites51.8%
if 20 < (*.f64 (exp.f64 re) (sin.f64 im)) Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sin (fabs im)))
(t_1 (* (+ 1.0 re) t_0))
(t_2 (* (exp re) t_0)))
(*
(copysign 1.0 im)
(if (<= t_2 (- INFINITY))
(*
(exp re)
(*
(fabs im)
(fma (* -0.16666666666666666 (fabs im)) (fabs im) 1.0)))
(if (<= t_2 -0.05)
t_1
(if (<= t_2 1e-101)
(/ (fabs im) (exp (- re)))
(if (<= t_2 20.0) t_1 (* (fabs im) (exp re)))))))))double code(double re, double im) {
double t_0 = sin(fabs(im));
double t_1 = (1.0 + re) * t_0;
double t_2 = exp(re) * t_0;
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = exp(re) * (fabs(im) * fma((-0.16666666666666666 * fabs(im)), fabs(im), 1.0));
} else if (t_2 <= -0.05) {
tmp = t_1;
} else if (t_2 <= 1e-101) {
tmp = fabs(im) / exp(-re);
} else if (t_2 <= 20.0) {
tmp = t_1;
} else {
tmp = fabs(im) * exp(re);
}
return copysign(1.0, im) * tmp;
}
function code(re, im) t_0 = sin(abs(im)) t_1 = Float64(Float64(1.0 + re) * t_0) t_2 = Float64(exp(re) * t_0) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = Float64(exp(re) * Float64(abs(im) * fma(Float64(-0.16666666666666666 * abs(im)), abs(im), 1.0))); elseif (t_2 <= -0.05) tmp = t_1; elseif (t_2 <= 1e-101) tmp = Float64(abs(im) / exp(Float64(-re))); elseif (t_2 <= 20.0) tmp = t_1; else tmp = Float64(abs(im) * exp(re)); end return Float64(copysign(1.0, im) * tmp) end
code[re_, im_] := Block[{t$95$0 = N[Sin[N[Abs[im], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 + re), $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[re], $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$2, (-Infinity)], N[(N[Exp[re], $MachinePrecision] * N[(N[Abs[im], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Abs[im], $MachinePrecision]), $MachinePrecision] * N[Abs[im], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.05], t$95$1, If[LessEqual[t$95$2, 1e-101], N[(N[Abs[im], $MachinePrecision] / N[Exp[(-re)], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 20.0], t$95$1, N[(N[Abs[im], $MachinePrecision] * N[Exp[re], $MachinePrecision]), $MachinePrecision]]]]]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \sin \left(\left|im\right|\right)\\
t_1 := \left(1 + re\right) \cdot t\_0\\
t_2 := e^{re} \cdot t\_0\\
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;e^{re} \cdot \left(\left|im\right| \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left|im\right|, \left|im\right|, 1\right)\right)\\
\mathbf{elif}\;t\_2 \leq -0.05:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 10^{-101}:\\
\;\;\;\;\frac{\left|im\right|}{e^{-re}}\\
\mathbf{elif}\;t\_2 \leq 20:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\left|im\right| \cdot e^{re}\\
\end{array}
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -inf.0Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6460.6%
Applied rewrites60.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6460.6%
Applied rewrites60.6%
if -inf.0 < (*.f64 (exp.f64 re) (sin.f64 im)) < -0.050000000000000003 or 1.0000000000000001e-101 < (*.f64 (exp.f64 re) (sin.f64 im)) < 20Initial program 100.0%
Taylor expanded in re around 0
lower-+.f6451.8%
Applied rewrites51.8%
if -0.050000000000000003 < (*.f64 (exp.f64 re) (sin.f64 im)) < 1.0000000000000001e-101Initial program 100.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
add-flipN/A
cosh-neg-revN/A
sinh-neg-revN/A
sinh---cosh-revN/A
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0%
Applied rewrites100.0%
Taylor expanded in im around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6469.1%
Applied rewrites69.1%
if 20 < (*.f64 (exp.f64 re) (sin.f64 im)) Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (fabs im) (exp re)))
(t_1 (sin (fabs im)))
(t_2 (* (exp re) t_1)))
(*
(copysign 1.0 im)
(if (<= t_2 (- INFINITY))
(*
(exp re)
(*
(fabs im)
(fma (* -0.16666666666666666 (fabs im)) (fabs im) 1.0)))
(if (<= t_2 -0.05)
t_1
(if (<= t_2 2e-79) t_0 (if (<= t_2 20.0) t_1 t_0)))))))double code(double re, double im) {
double t_0 = fabs(im) * exp(re);
double t_1 = sin(fabs(im));
double t_2 = exp(re) * t_1;
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = exp(re) * (fabs(im) * fma((-0.16666666666666666 * fabs(im)), fabs(im), 1.0));
} else if (t_2 <= -0.05) {
tmp = t_1;
} else if (t_2 <= 2e-79) {
tmp = t_0;
} else if (t_2 <= 20.0) {
tmp = t_1;
} else {
tmp = t_0;
}
return copysign(1.0, im) * tmp;
}
function code(re, im) t_0 = Float64(abs(im) * exp(re)) t_1 = sin(abs(im)) t_2 = Float64(exp(re) * t_1) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = Float64(exp(re) * Float64(abs(im) * fma(Float64(-0.16666666666666666 * abs(im)), abs(im), 1.0))); elseif (t_2 <= -0.05) tmp = t_1; elseif (t_2 <= 2e-79) tmp = t_0; elseif (t_2 <= 20.0) tmp = t_1; else tmp = t_0; end return Float64(copysign(1.0, im) * tmp) end
code[re_, im_] := Block[{t$95$0 = N[(N[Abs[im], $MachinePrecision] * N[Exp[re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[Abs[im], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Exp[re], $MachinePrecision] * t$95$1), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$2, (-Infinity)], N[(N[Exp[re], $MachinePrecision] * N[(N[Abs[im], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Abs[im], $MachinePrecision]), $MachinePrecision] * N[Abs[im], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.05], t$95$1, If[LessEqual[t$95$2, 2e-79], t$95$0, If[LessEqual[t$95$2, 20.0], t$95$1, t$95$0]]]]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \left|im\right| \cdot e^{re}\\
t_1 := \sin \left(\left|im\right|\right)\\
t_2 := e^{re} \cdot t\_1\\
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;e^{re} \cdot \left(\left|im\right| \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left|im\right|, \left|im\right|, 1\right)\right)\\
\mathbf{elif}\;t\_2 \leq -0.05:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{-79}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_2 \leq 20:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -inf.0Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6460.6%
Applied rewrites60.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6460.6%
Applied rewrites60.6%
if -inf.0 < (*.f64 (exp.f64 re) (sin.f64 im)) < -0.050000000000000003 or 2e-79 < (*.f64 (exp.f64 re) (sin.f64 im)) < 20Initial program 100.0%
Taylor expanded in re around 0
lower-sin.f6451.2%
Applied rewrites51.2%
if -0.050000000000000003 < (*.f64 (exp.f64 re) (sin.f64 im)) < 2e-79 or 20 < (*.f64 (exp.f64 re) (sin.f64 im)) Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
(FPCore (re im)
:precision binary64
(*
(copysign 1.0 im)
(if (<= (* (exp re) (sin (fabs im))) -0.05)
(*
(exp re)
(*
(fabs im)
(fma (* -0.16666666666666666 (fabs im)) (fabs im) 1.0)))
(* (fabs im) (exp re)))))double code(double re, double im) {
double tmp;
if ((exp(re) * sin(fabs(im))) <= -0.05) {
tmp = exp(re) * (fabs(im) * fma((-0.16666666666666666 * fabs(im)), fabs(im), 1.0));
} else {
tmp = fabs(im) * exp(re);
}
return copysign(1.0, im) * tmp;
}
function code(re, im) tmp = 0.0 if (Float64(exp(re) * sin(abs(im))) <= -0.05) tmp = Float64(exp(re) * Float64(abs(im) * fma(Float64(-0.16666666666666666 * abs(im)), abs(im), 1.0))); else tmp = Float64(abs(im) * exp(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[Exp[re], $MachinePrecision] * N[Sin[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.05], N[(N[Exp[re], $MachinePrecision] * N[(N[Abs[im], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Abs[im], $MachinePrecision]), $MachinePrecision] * N[Abs[im], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Abs[im], $MachinePrecision] * N[Exp[re], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;e^{re} \cdot \sin \left(\left|im\right|\right) \leq -0.05:\\
\;\;\;\;e^{re} \cdot \left(\left|im\right| \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left|im\right|, \left|im\right|, 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left|im\right| \cdot e^{re}\\
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -0.050000000000000003Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6460.6%
Applied rewrites60.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6460.6%
Applied rewrites60.6%
if -0.050000000000000003 < (*.f64 (exp.f64 re) (sin.f64 im)) Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
(FPCore (re im)
:precision binary64
(*
(copysign 1.0 im)
(if (<= (* (exp re) (sin (fabs im))) -0.05)
(*
(+ 1.0 re)
(fma
(* (fabs im) (fabs im))
(* -0.16666666666666666 (fabs im))
(fabs im)))
(* (fabs im) (exp re)))))double code(double re, double im) {
double tmp;
if ((exp(re) * sin(fabs(im))) <= -0.05) {
tmp = (1.0 + re) * fma((fabs(im) * fabs(im)), (-0.16666666666666666 * fabs(im)), fabs(im));
} else {
tmp = fabs(im) * exp(re);
}
return copysign(1.0, im) * tmp;
}
function code(re, im) tmp = 0.0 if (Float64(exp(re) * sin(abs(im))) <= -0.05) tmp = Float64(Float64(1.0 + re) * fma(Float64(abs(im) * abs(im)), Float64(-0.16666666666666666 * abs(im)), abs(im))); else tmp = Float64(abs(im) * exp(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[Exp[re], $MachinePrecision] * N[Sin[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.05], N[(N[(1.0 + re), $MachinePrecision] * N[(N[(N[Abs[im], $MachinePrecision] * N[Abs[im], $MachinePrecision]), $MachinePrecision] * N[(-0.16666666666666666 * N[Abs[im], $MachinePrecision]), $MachinePrecision] + N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Abs[im], $MachinePrecision] * N[Exp[re], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;e^{re} \cdot \sin \left(\left|im\right|\right) \leq -0.05:\\
\;\;\;\;\left(1 + re\right) \cdot \mathsf{fma}\left(\left|im\right| \cdot \left|im\right|, -0.16666666666666666 \cdot \left|im\right|, \left|im\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\left|im\right| \cdot e^{re}\\
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -0.050000000000000003Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6460.6%
Applied rewrites60.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6460.6%
Applied rewrites60.6%
lift-*.f64N/A
lift-fma.f64N/A
distribute-rgt-inN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
sub-flipN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
distribute-lft-neg-outN/A
*-lft-identityN/A
remove-double-negN/A
lower-fma.f6460.6%
Applied rewrites60.6%
Taylor expanded in re around 0
lower-+.f6431.7%
Applied rewrites31.7%
if -0.050000000000000003 < (*.f64 (exp.f64 re) (sin.f64 im)) Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
(FPCore (re im)
:precision binary64
(*
(copysign 1.0 im)
(if (<= (* (exp re) (sin (fabs im))) -0.05)
(*
(fabs im)
(fma (* -0.16666666666666666 (fabs im)) (fabs im) 1.0))
(* (fabs im) (exp re)))))double code(double re, double im) {
double tmp;
if ((exp(re) * sin(fabs(im))) <= -0.05) {
tmp = fabs(im) * fma((-0.16666666666666666 * fabs(im)), fabs(im), 1.0);
} else {
tmp = fabs(im) * exp(re);
}
return copysign(1.0, im) * tmp;
}
function code(re, im) tmp = 0.0 if (Float64(exp(re) * sin(abs(im))) <= -0.05) tmp = Float64(abs(im) * fma(Float64(-0.16666666666666666 * abs(im)), abs(im), 1.0)); else tmp = Float64(abs(im) * exp(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[Exp[re], $MachinePrecision] * N[Sin[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.05], N[(N[Abs[im], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Abs[im], $MachinePrecision]), $MachinePrecision] * N[Abs[im], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Abs[im], $MachinePrecision] * N[Exp[re], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;e^{re} \cdot \sin \left(\left|im\right|\right) \leq -0.05:\\
\;\;\;\;\left|im\right| \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left|im\right|, \left|im\right|, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left|im\right| \cdot e^{re}\\
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -0.050000000000000003Initial program 100.0%
Taylor expanded in re around 0
lower-sin.f6451.2%
Applied rewrites51.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6430.7%
Applied rewrites30.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
associate-*r*N/A
lift-*.f64N/A
*-rgt-identityN/A
associate-*r*N/A
lift-*.f64N/A
associate-*r*N/A
pow2N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
associate-*r*N/A
lift-*.f64N/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f6430.7%
Applied rewrites30.7%
if -0.050000000000000003 < (*.f64 (exp.f64 re) (sin.f64 im)) Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (exp re) (sin (fabs im)))))
(*
(copysign 1.0 im)
(if (<= t_0 -0.05)
(*
(fabs im)
(fma (* -0.16666666666666666 (fabs im)) (fabs im) 1.0))
(if (<= t_0 0.0)
(/ (fabs im) (+ 1.0 (* -1.0 re)))
(fma (fabs im) re (fabs im)))))))double code(double re, double im) {
double t_0 = exp(re) * sin(fabs(im));
double tmp;
if (t_0 <= -0.05) {
tmp = fabs(im) * fma((-0.16666666666666666 * fabs(im)), fabs(im), 1.0);
} else if (t_0 <= 0.0) {
tmp = fabs(im) / (1.0 + (-1.0 * re));
} else {
tmp = fma(fabs(im), re, fabs(im));
}
return copysign(1.0, im) * tmp;
}
function code(re, im) t_0 = Float64(exp(re) * sin(abs(im))) tmp = 0.0 if (t_0 <= -0.05) tmp = Float64(abs(im) * fma(Float64(-0.16666666666666666 * abs(im)), abs(im), 1.0)); elseif (t_0 <= 0.0) tmp = Float64(abs(im) / Float64(1.0 + Float64(-1.0 * re))); else tmp = fma(abs(im), re, abs(im)); end return Float64(copysign(1.0, im) * tmp) end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[re], $MachinePrecision] * N[Sin[N[Abs[im], $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, -0.05], N[(N[Abs[im], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Abs[im], $MachinePrecision]), $MachinePrecision] * N[Abs[im], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(N[Abs[im], $MachinePrecision] / N[(1.0 + N[(-1.0 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Abs[im], $MachinePrecision] * re + N[Abs[im], $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
t_0 := e^{re} \cdot \sin \left(\left|im\right|\right)\\
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -0.05:\\
\;\;\;\;\left|im\right| \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left|im\right|, \left|im\right|, 1\right)\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\frac{\left|im\right|}{1 + -1 \cdot re}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|im\right|, re, \left|im\right|\right)\\
\end{array}
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -0.050000000000000003Initial program 100.0%
Taylor expanded in re around 0
lower-sin.f6451.2%
Applied rewrites51.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6430.7%
Applied rewrites30.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
associate-*r*N/A
lift-*.f64N/A
*-rgt-identityN/A
associate-*r*N/A
lift-*.f64N/A
associate-*r*N/A
pow2N/A
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
pow2N/A
associate-*r*N/A
lift-*.f64N/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f6430.7%
Applied rewrites30.7%
if -0.050000000000000003 < (*.f64 (exp.f64 re) (sin.f64 im)) < -0.0Initial program 100.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
add-flipN/A
cosh-neg-revN/A
sinh-neg-revN/A
sinh---cosh-revN/A
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0%
Applied rewrites100.0%
Taylor expanded in im around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6469.1%
Applied rewrites69.1%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f6432.7%
Applied rewrites32.7%
if -0.0 < (*.f64 (exp.f64 re) (sin.f64 im)) Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
Taylor expanded in re around 0
Applied rewrites26.9%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f6430.0%
Applied rewrites30.0%
*-lft-identity30.0%
*-commutative30.0%
lift-exp.f64N/A
associate-*r*N/A
remove-double-divN/A
lift-exp.f6430.0%
exp-neg30.0%
*-rgt-identity30.0%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
remove-double-negN/A
lower-fma.f6430.0%
Applied rewrites30.0%
(FPCore (re im) :precision binary64 (* (copysign 1.0 im) (if (<= (* (exp re) (sin (fabs im))) 0.0) (/ (fabs im) (+ 1.0 (* -1.0 re))) (fma (fabs im) re (fabs im)))))
double code(double re, double im) {
double tmp;
if ((exp(re) * sin(fabs(im))) <= 0.0) {
tmp = fabs(im) / (1.0 + (-1.0 * re));
} else {
tmp = fma(fabs(im), re, fabs(im));
}
return copysign(1.0, im) * tmp;
}
function code(re, im) tmp = 0.0 if (Float64(exp(re) * sin(abs(im))) <= 0.0) tmp = Float64(abs(im) / Float64(1.0 + Float64(-1.0 * re))); else tmp = fma(abs(im), re, abs(im)); 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[Exp[re], $MachinePrecision] * N[Sin[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0], N[(N[Abs[im], $MachinePrecision] / N[(1.0 + N[(-1.0 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Abs[im], $MachinePrecision] * re + N[Abs[im], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;e^{re} \cdot \sin \left(\left|im\right|\right) \leq 0:\\
\;\;\;\;\frac{\left|im\right|}{1 + -1 \cdot re}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|im\right|, re, \left|im\right|\right)\\
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -0.0Initial program 100.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
add-flipN/A
cosh-neg-revN/A
sinh-neg-revN/A
sinh---cosh-revN/A
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0%
Applied rewrites100.0%
Taylor expanded in im around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6469.1%
Applied rewrites69.1%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f6432.7%
Applied rewrites32.7%
if -0.0 < (*.f64 (exp.f64 re) (sin.f64 im)) Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
Taylor expanded in re around 0
Applied rewrites26.9%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f6430.0%
Applied rewrites30.0%
*-lft-identity30.0%
*-commutative30.0%
lift-exp.f64N/A
associate-*r*N/A
remove-double-divN/A
lift-exp.f6430.0%
exp-neg30.0%
*-rgt-identity30.0%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
remove-double-negN/A
lower-fma.f6430.0%
Applied rewrites30.0%
(FPCore (re im) :precision binary64 (fma im re im))
double code(double re, double im) {
return fma(im, re, im);
}
function code(re, im) return fma(im, re, im) end
code[re_, im_] := N[(im * re + im), $MachinePrecision]
\mathsf{fma}\left(im, re, im\right)
Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
Taylor expanded in re around 0
Applied rewrites26.9%
Taylor expanded in re around 0
lower-+.f64N/A
lower-*.f6430.0%
Applied rewrites30.0%
*-lft-identity30.0%
*-commutative30.0%
lift-exp.f64N/A
associate-*r*N/A
remove-double-divN/A
lift-exp.f6430.0%
exp-neg30.0%
*-rgt-identity30.0%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
remove-double-negN/A
lower-fma.f6430.0%
Applied rewrites30.0%
(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 im end
function tmp = code(re, im) tmp = im; end
code[re_, im_] := im
im
Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6469.1%
Applied rewrites69.1%
Taylor expanded in re around 0
Applied rewrites26.9%
herbie shell --seed 2025216
(FPCore (re im)
:name "math.exp on complex, imaginary part"
:precision binary64
(* (exp re) (sin im)))