
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
:precision binary64
(let* ((t_0 (* 0.5 (sin re_m)))
(t_1 (* t_0 (+ (exp (- 0.0 im_m)) (exp im_m)))))
(*
re_s
(if (<= t_1 -0.998)
(*
(*
(* (cosh im_m) 2.0)
(* (- -0.16666666666666666 2.0) -0.16666666666666666))
0.5)
(if (<= t_1 1.0)
(* t_0 2.0)
(*
(* re_m (+ 0.5 (* -0.08333333333333333 (pow re_m 2.0))))
(+ 1.0 (exp im_m))))))))im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
double t_0 = 0.5 * sin(re_m);
double t_1 = t_0 * (exp((0.0 - im_m)) + exp(im_m));
double tmp;
if (t_1 <= -0.998) {
tmp = ((cosh(im_m) * 2.0) * ((-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5;
} else if (t_1 <= 1.0) {
tmp = t_0 * 2.0;
} else {
tmp = (re_m * (0.5 + (-0.08333333333333333 * pow(re_m, 2.0)))) * (1.0 + exp(im_m));
}
return re_s * tmp;
}
im_m = private
re\_m = private
re\_s = 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_s, re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sin(re_m)
t_1 = t_0 * (exp((0.0d0 - im_m)) + exp(im_m))
if (t_1 <= (-0.998d0)) then
tmp = ((cosh(im_m) * 2.0d0) * (((-0.16666666666666666d0) - 2.0d0) * (-0.16666666666666666d0))) * 0.5d0
else if (t_1 <= 1.0d0) then
tmp = t_0 * 2.0d0
else
tmp = (re_m * (0.5d0 + ((-0.08333333333333333d0) * (re_m ** 2.0d0)))) * (1.0d0 + exp(im_m))
end if
code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
double t_0 = 0.5 * Math.sin(re_m);
double t_1 = t_0 * (Math.exp((0.0 - im_m)) + Math.exp(im_m));
double tmp;
if (t_1 <= -0.998) {
tmp = ((Math.cosh(im_m) * 2.0) * ((-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5;
} else if (t_1 <= 1.0) {
tmp = t_0 * 2.0;
} else {
tmp = (re_m * (0.5 + (-0.08333333333333333 * Math.pow(re_m, 2.0)))) * (1.0 + Math.exp(im_m));
}
return re_s * tmp;
}
im_m = math.fabs(im) re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) def code(re_s, re_m, im_m): t_0 = 0.5 * math.sin(re_m) t_1 = t_0 * (math.exp((0.0 - im_m)) + math.exp(im_m)) tmp = 0 if t_1 <= -0.998: tmp = ((math.cosh(im_m) * 2.0) * ((-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5 elif t_1 <= 1.0: tmp = t_0 * 2.0 else: tmp = (re_m * (0.5 + (-0.08333333333333333 * math.pow(re_m, 2.0)))) * (1.0 + math.exp(im_m)) return re_s * tmp
im_m = abs(im) re\_m = abs(re) re\_s = copysign(1.0, re) function code(re_s, re_m, im_m) t_0 = Float64(0.5 * sin(re_m)) t_1 = Float64(t_0 * Float64(exp(Float64(0.0 - im_m)) + exp(im_m))) tmp = 0.0 if (t_1 <= -0.998) tmp = Float64(Float64(Float64(cosh(im_m) * 2.0) * Float64(Float64(-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5); elseif (t_1 <= 1.0) tmp = Float64(t_0 * 2.0); else tmp = Float64(Float64(re_m * Float64(0.5 + Float64(-0.08333333333333333 * (re_m ^ 2.0)))) * Float64(1.0 + exp(im_m))); end return Float64(re_s * tmp) end
im_m = abs(im); re\_m = abs(re); re\_s = sign(re) * abs(1.0); function tmp_2 = code(re_s, re_m, im_m) t_0 = 0.5 * sin(re_m); t_1 = t_0 * (exp((0.0 - im_m)) + exp(im_m)); tmp = 0.0; if (t_1 <= -0.998) tmp = ((cosh(im_m) * 2.0) * ((-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5; elseif (t_1 <= 1.0) tmp = t_0 * 2.0; else tmp = (re_m * (0.5 + (-0.08333333333333333 * (re_m ^ 2.0)))) * (1.0 + exp(im_m)); end tmp_2 = re_s * tmp; end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[Sin[re$95$m], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[Exp[N[(0.0 - im$95$m), $MachinePrecision]], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(re$95$s * If[LessEqual[t$95$1, -0.998], N[(N[(N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision] * N[(N[(-0.16666666666666666 - 2.0), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$1, 1.0], N[(t$95$0 * 2.0), $MachinePrecision], N[(N[(re$95$m * N[(0.5 + N[(-0.08333333333333333 * N[Power[re$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\_m\\
t_1 := t\_0 \cdot \left(e^{0 - im\_m} + e^{im\_m}\right)\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -0.998:\\
\;\;\;\;\left(\left(\cosh im\_m \cdot 2\right) \cdot \left(\left(-0.16666666666666666 - 2\right) \cdot -0.16666666666666666\right)\right) \cdot 0.5\\
\mathbf{elif}\;t\_1 \leq 1:\\
\;\;\;\;t\_0 \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(re\_m \cdot \left(0.5 + -0.08333333333333333 \cdot {re\_m}^{2}\right)\right) \cdot \left(1 + e^{im\_m}\right)\\
\end{array}
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (+.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < -0.998Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites63.7%
Applied rewrites41.5%
if -0.998 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (+.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 1Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.2%
if 1 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (+.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites98.8%
Taylor expanded in re around 0
Applied rewrites63.1%
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
:precision binary64
(let* ((t_0 (* (cosh im_m) 2.0)))
(*
re_s
(if (<= im_m 3.05e-5)
(* (* 0.5 (sin re_m)) 2.0)
(if (<= im_m 1.6e+181)
(* (* t_0 (* -0.16666666666666666 -0.16666666666666666)) 0.5)
(* (* t_0 (- -0.16666666666666666 2.0)) 0.5))))))im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
double t_0 = cosh(im_m) * 2.0;
double tmp;
if (im_m <= 3.05e-5) {
tmp = (0.5 * sin(re_m)) * 2.0;
} else if (im_m <= 1.6e+181) {
tmp = (t_0 * (-0.16666666666666666 * -0.16666666666666666)) * 0.5;
} else {
tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
}
return re_s * tmp;
}
im_m = private
re\_m = private
re\_s = 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_s, re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
real(8) :: t_0
real(8) :: tmp
t_0 = cosh(im_m) * 2.0d0
if (im_m <= 3.05d-5) then
tmp = (0.5d0 * sin(re_m)) * 2.0d0
else if (im_m <= 1.6d+181) then
tmp = (t_0 * ((-0.16666666666666666d0) * (-0.16666666666666666d0))) * 0.5d0
else
tmp = (t_0 * ((-0.16666666666666666d0) - 2.0d0)) * 0.5d0
end if
code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
double t_0 = Math.cosh(im_m) * 2.0;
double tmp;
if (im_m <= 3.05e-5) {
tmp = (0.5 * Math.sin(re_m)) * 2.0;
} else if (im_m <= 1.6e+181) {
tmp = (t_0 * (-0.16666666666666666 * -0.16666666666666666)) * 0.5;
} else {
tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
}
return re_s * tmp;
}
im_m = math.fabs(im) re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) def code(re_s, re_m, im_m): t_0 = math.cosh(im_m) * 2.0 tmp = 0 if im_m <= 3.05e-5: tmp = (0.5 * math.sin(re_m)) * 2.0 elif im_m <= 1.6e+181: tmp = (t_0 * (-0.16666666666666666 * -0.16666666666666666)) * 0.5 else: tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5 return re_s * tmp
im_m = abs(im) re\_m = abs(re) re\_s = copysign(1.0, re) function code(re_s, re_m, im_m) t_0 = Float64(cosh(im_m) * 2.0) tmp = 0.0 if (im_m <= 3.05e-5) tmp = Float64(Float64(0.5 * sin(re_m)) * 2.0); elseif (im_m <= 1.6e+181) tmp = Float64(Float64(t_0 * Float64(-0.16666666666666666 * -0.16666666666666666)) * 0.5); else tmp = Float64(Float64(t_0 * Float64(-0.16666666666666666 - 2.0)) * 0.5); end return Float64(re_s * tmp) end
im_m = abs(im); re\_m = abs(re); re\_s = sign(re) * abs(1.0); function tmp_2 = code(re_s, re_m, im_m) t_0 = cosh(im_m) * 2.0; tmp = 0.0; if (im_m <= 3.05e-5) tmp = (0.5 * sin(re_m)) * 2.0; elseif (im_m <= 1.6e+181) tmp = (t_0 * (-0.16666666666666666 * -0.16666666666666666)) * 0.5; else tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5; end tmp_2 = re_s * tmp; end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := Block[{t$95$0 = N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision]}, N[(re$95$s * If[LessEqual[im$95$m, 3.05e-5], N[(N[(0.5 * N[Sin[re$95$m], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], If[LessEqual[im$95$m, 1.6e+181], N[(N[(t$95$0 * N[(-0.16666666666666666 * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(t$95$0 * N[(-0.16666666666666666 - 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
\begin{array}{l}
t_0 := \cosh im\_m \cdot 2\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;im\_m \leq 3.05 \cdot 10^{-5}:\\
\;\;\;\;\left(0.5 \cdot \sin re\_m\right) \cdot 2\\
\mathbf{elif}\;im\_m \leq 1.6 \cdot 10^{+181}:\\
\;\;\;\;\left(t\_0 \cdot \left(-0.16666666666666666 \cdot -0.16666666666666666\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot \left(-0.16666666666666666 - 2\right)\right) \cdot 0.5\\
\end{array}
\end{array}
\end{array}
if im < 3.04999999999999994e-5Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.2%
if 3.04999999999999994e-5 < im < 1.6e181Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites63.7%
Applied rewrites41.1%
if 1.6e181 < im Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites63.7%
Applied rewrites15.5%
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
:precision binary64
(let* ((t_0 (* (cosh im_m) 2.0)))
(*
re_s
(if (<= (* 0.5 (sin re_m)) 0.02)
(* (* t_0 re_m) 0.5)
(* (* t_0 (- -0.16666666666666666 2.0)) 0.5)))))im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
double t_0 = cosh(im_m) * 2.0;
double tmp;
if ((0.5 * sin(re_m)) <= 0.02) {
tmp = (t_0 * re_m) * 0.5;
} else {
tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
}
return re_s * tmp;
}
im_m = private
re\_m = private
re\_s = 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_s, re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
real(8) :: t_0
real(8) :: tmp
t_0 = cosh(im_m) * 2.0d0
if ((0.5d0 * sin(re_m)) <= 0.02d0) then
tmp = (t_0 * re_m) * 0.5d0
else
tmp = (t_0 * ((-0.16666666666666666d0) - 2.0d0)) * 0.5d0
end if
code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
double t_0 = Math.cosh(im_m) * 2.0;
double tmp;
if ((0.5 * Math.sin(re_m)) <= 0.02) {
tmp = (t_0 * re_m) * 0.5;
} else {
tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
}
return re_s * tmp;
}
im_m = math.fabs(im) re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) def code(re_s, re_m, im_m): t_0 = math.cosh(im_m) * 2.0 tmp = 0 if (0.5 * math.sin(re_m)) <= 0.02: tmp = (t_0 * re_m) * 0.5 else: tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5 return re_s * tmp
im_m = abs(im) re\_m = abs(re) re\_s = copysign(1.0, re) function code(re_s, re_m, im_m) t_0 = Float64(cosh(im_m) * 2.0) tmp = 0.0 if (Float64(0.5 * sin(re_m)) <= 0.02) tmp = Float64(Float64(t_0 * re_m) * 0.5); else tmp = Float64(Float64(t_0 * Float64(-0.16666666666666666 - 2.0)) * 0.5); end return Float64(re_s * tmp) end
im_m = abs(im); re\_m = abs(re); re\_s = sign(re) * abs(1.0); function tmp_2 = code(re_s, re_m, im_m) t_0 = cosh(im_m) * 2.0; tmp = 0.0; if ((0.5 * sin(re_m)) <= 0.02) tmp = (t_0 * re_m) * 0.5; else tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5; end tmp_2 = re_s * tmp; end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := Block[{t$95$0 = N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision]}, N[(re$95$s * If[LessEqual[N[(0.5 * N[Sin[re$95$m], $MachinePrecision]), $MachinePrecision], 0.02], N[(N[(t$95$0 * re$95$m), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(t$95$0 * N[(-0.16666666666666666 - 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
\begin{array}{l}
t_0 := \cosh im\_m \cdot 2\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re\_m \leq 0.02:\\
\;\;\;\;\left(t\_0 \cdot re\_m\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot \left(-0.16666666666666666 - 2\right)\right) \cdot 0.5\\
\end{array}
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < 0.0200000000000000004Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites63.5%
if 0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites63.7%
Applied rewrites15.5%
im_m = (fabs.f64 im) re\_m = (fabs.f64 re) re\_s = (copysign.f64 #s(literal 1 binary64) re) (FPCore (re_s re_m im_m) :precision binary64 (* re_s (* (* (* (cosh im_m) 2.0) re_m) 0.5)))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
return re_s * (((cosh(im_m) * 2.0) * re_m) * 0.5);
}
im_m = private
re\_m = private
re\_s = 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_s, re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
code = re_s * (((cosh(im_m) * 2.0d0) * re_m) * 0.5d0)
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
return re_s * (((Math.cosh(im_m) * 2.0) * re_m) * 0.5);
}
im_m = math.fabs(im) re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) def code(re_s, re_m, im_m): return re_s * (((math.cosh(im_m) * 2.0) * re_m) * 0.5)
im_m = abs(im) re\_m = abs(re) re\_s = copysign(1.0, re) function code(re_s, re_m, im_m) return Float64(re_s * Float64(Float64(Float64(cosh(im_m) * 2.0) * re_m) * 0.5)) end
im_m = abs(im); re\_m = abs(re); re\_s = sign(re) * abs(1.0); function tmp = code(re_s, re_m, im_m) tmp = re_s * (((cosh(im_m) * 2.0) * re_m) * 0.5); end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * N[(N[(N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision] * re$95$m), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
re\_s \cdot \left(\left(\left(\cosh im\_m \cdot 2\right) \cdot re\_m\right) \cdot 0.5\right)
\end{array}
Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites63.5%
im_m = (fabs.f64 im) re\_m = (fabs.f64 re) re\_s = (copysign.f64 #s(literal 1 binary64) re) (FPCore (re_s re_m im_m) :precision binary64 (* re_s (* (* 0.5 re_m) (+ 1.0 (exp im_m)))))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
return re_s * ((0.5 * re_m) * (1.0 + exp(im_m)));
}
im_m = private
re\_m = private
re\_s = 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_s, re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
code = re_s * ((0.5d0 * re_m) * (1.0d0 + exp(im_m)))
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
return re_s * ((0.5 * re_m) * (1.0 + Math.exp(im_m)));
}
im_m = math.fabs(im) re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) def code(re_s, re_m, im_m): return re_s * ((0.5 * re_m) * (1.0 + math.exp(im_m)))
im_m = abs(im) re\_m = abs(re) re\_s = copysign(1.0, re) function code(re_s, re_m, im_m) return Float64(re_s * Float64(Float64(0.5 * re_m) * Float64(1.0 + exp(im_m)))) end
im_m = abs(im); re\_m = abs(re); re\_s = sign(re) * abs(1.0); function tmp = code(re_s, re_m, im_m) tmp = re_s * ((0.5 * re_m) * (1.0 + exp(im_m))); end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * N[(N[(0.5 * re$95$m), $MachinePrecision] * N[(1.0 + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
re\_s \cdot \left(\left(0.5 \cdot re\_m\right) \cdot \left(1 + e^{im\_m}\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites98.8%
Taylor expanded in re around 0
Applied rewrites62.9%
im_m = (fabs.f64 im) re\_m = (fabs.f64 re) re\_s = (copysign.f64 #s(literal 1 binary64) re) (FPCore (re_s re_m im_m) :precision binary64 (* re_s (if (<= re_m 1.2e+40) (* (* 0.5 re_m) 2.0) (* (* im_m re_m) 0.5))))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
double tmp;
if (re_m <= 1.2e+40) {
tmp = (0.5 * re_m) * 2.0;
} else {
tmp = (im_m * re_m) * 0.5;
}
return re_s * tmp;
}
im_m = private
re\_m = private
re\_s = 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_s, re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
real(8) :: tmp
if (re_m <= 1.2d+40) then
tmp = (0.5d0 * re_m) * 2.0d0
else
tmp = (im_m * re_m) * 0.5d0
end if
code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
double tmp;
if (re_m <= 1.2e+40) {
tmp = (0.5 * re_m) * 2.0;
} else {
tmp = (im_m * re_m) * 0.5;
}
return re_s * tmp;
}
im_m = math.fabs(im) re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) def code(re_s, re_m, im_m): tmp = 0 if re_m <= 1.2e+40: tmp = (0.5 * re_m) * 2.0 else: tmp = (im_m * re_m) * 0.5 return re_s * tmp
im_m = abs(im) re\_m = abs(re) re\_s = copysign(1.0, re) function code(re_s, re_m, im_m) tmp = 0.0 if (re_m <= 1.2e+40) tmp = Float64(Float64(0.5 * re_m) * 2.0); else tmp = Float64(Float64(im_m * re_m) * 0.5); end return Float64(re_s * tmp) end
im_m = abs(im); re\_m = abs(re); re\_s = sign(re) * abs(1.0); function tmp_2 = code(re_s, re_m, im_m) tmp = 0.0; if (re_m <= 1.2e+40) tmp = (0.5 * re_m) * 2.0; else tmp = (im_m * re_m) * 0.5; end tmp_2 = re_s * tmp; end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * If[LessEqual[re$95$m, 1.2e+40], N[(N[(0.5 * re$95$m), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(im$95$m * re$95$m), $MachinePrecision] * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;re\_m \leq 1.2 \cdot 10^{+40}:\\
\;\;\;\;\left(0.5 \cdot re\_m\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;\left(im\_m \cdot re\_m\right) \cdot 0.5\\
\end{array}
\end{array}
if re < 1.2e40Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.2%
Taylor expanded in re around 0
Applied rewrites26.7%
if 1.2e40 < re Initial program 100.0%
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites63.5%
Applied rewrites10.3%
im_m = (fabs.f64 im) re\_m = (fabs.f64 re) re\_s = (copysign.f64 #s(literal 1 binary64) re) (FPCore (re_s re_m im_m) :precision binary64 (* re_s (if (<= re_m 1.12e-18) (* (* 0.5 re_m) 2.0) (* 2.0 0.5))))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
double tmp;
if (re_m <= 1.12e-18) {
tmp = (0.5 * re_m) * 2.0;
} else {
tmp = 2.0 * 0.5;
}
return re_s * tmp;
}
im_m = private
re\_m = private
re\_s = 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_s, re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
real(8) :: tmp
if (re_m <= 1.12d-18) then
tmp = (0.5d0 * re_m) * 2.0d0
else
tmp = 2.0d0 * 0.5d0
end if
code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
double tmp;
if (re_m <= 1.12e-18) {
tmp = (0.5 * re_m) * 2.0;
} else {
tmp = 2.0 * 0.5;
}
return re_s * tmp;
}
im_m = math.fabs(im) re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) def code(re_s, re_m, im_m): tmp = 0 if re_m <= 1.12e-18: tmp = (0.5 * re_m) * 2.0 else: tmp = 2.0 * 0.5 return re_s * tmp
im_m = abs(im) re\_m = abs(re) re\_s = copysign(1.0, re) function code(re_s, re_m, im_m) tmp = 0.0 if (re_m <= 1.12e-18) tmp = Float64(Float64(0.5 * re_m) * 2.0); else tmp = Float64(2.0 * 0.5); end return Float64(re_s * tmp) end
im_m = abs(im); re\_m = abs(re); re\_s = sign(re) * abs(1.0); function tmp_2 = code(re_s, re_m, im_m) tmp = 0.0; if (re_m <= 1.12e-18) tmp = (0.5 * re_m) * 2.0; else tmp = 2.0 * 0.5; end tmp_2 = re_s * tmp; end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * If[LessEqual[re$95$m, 1.12e-18], N[(N[(0.5 * re$95$m), $MachinePrecision] * 2.0), $MachinePrecision], N[(2.0 * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;re\_m \leq 1.12 \cdot 10^{-18}:\\
\;\;\;\;\left(0.5 \cdot re\_m\right) \cdot 2\\
\mathbf{else}:\\
\;\;\;\;2 \cdot 0.5\\
\end{array}
\end{array}
if re < 1.12000000000000001e-18Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites50.2%
Taylor expanded in re around 0
Applied rewrites26.7%
if 1.12000000000000001e-18 < re Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites63.5%
Applied rewrites5.3%
im_m = (fabs.f64 im) re\_m = (fabs.f64 re) re\_s = (copysign.f64 #s(literal 1 binary64) re) (FPCore (re_s re_m im_m) :precision binary64 (* re_s (* 2.0 0.5)))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
return re_s * (2.0 * 0.5);
}
im_m = private
re\_m = private
re\_s = 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_s, re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
code = re_s * (2.0d0 * 0.5d0)
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
return re_s * (2.0 * 0.5);
}
im_m = math.fabs(im) re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) def code(re_s, re_m, im_m): return re_s * (2.0 * 0.5)
im_m = abs(im) re\_m = abs(re) re\_s = copysign(1.0, re) function code(re_s, re_m, im_m) return Float64(re_s * Float64(2.0 * 0.5)) end
im_m = abs(im); re\_m = abs(re); re\_s = sign(re) * abs(1.0); function tmp = code(re_s, re_m, im_m) tmp = re_s * (2.0 * 0.5); end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * N[(2.0 * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
re\_s \cdot \left(2 \cdot 0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites63.5%
Applied rewrites5.3%
im_m = (fabs.f64 im) re\_m = (fabs.f64 re) re\_s = (copysign.f64 #s(literal 1 binary64) re) (FPCore (re_s re_m im_m) :precision binary64 (* re_s 2.0))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
return re_s * 2.0;
}
im_m = private
re\_m = private
re\_s = 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_s, re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_s
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
code = re_s * 2.0d0
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
return re_s * 2.0;
}
im_m = math.fabs(im) re\_m = math.fabs(re) re\_s = math.copysign(1.0, re) def code(re_s, re_m, im_m): return re_s * 2.0
im_m = abs(im) re\_m = abs(re) re\_s = copysign(1.0, re) function code(re_s, re_m, im_m) return Float64(re_s * 2.0) end
im_m = abs(im); re\_m = abs(re); re\_s = sign(re) * abs(1.0); function tmp = code(re_s, re_m, im_m) tmp = re_s * 2.0; end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * 2.0), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)
\\
re\_s \cdot 2
\end{array}
Initial program 100.0%
Taylor expanded in re around 0
Applied rewrites63.5%
Applied rewrites5.3%
Applied rewrites4.9%
herbie shell --seed 2025159
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))