
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(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 * sin(re)) * (exp(-im) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp(-im) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\end{array}
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(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 * sin(re)) * (exp(-im) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp(-im) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\end{array}
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im -1.25)
(* t_0 (- (exp (- im)) 1.0))
(if (<= im 1.25) (* (- (sin re)) im) (* t_0 (- 1.0 (exp im)))))))
double code(double re, double im) {
double t_0 = 0.5 * sin(re);
double tmp;
if (im <= -1.25) {
tmp = t_0 * (exp(-im) - 1.0);
} else if (im <= 1.25) {
tmp = -sin(re) * im;
} else {
tmp = t_0 * (1.0 - exp(im));
}
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) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * sin(re)
if (im <= (-1.25d0)) then
tmp = t_0 * (exp(-im) - 1.0d0)
else if (im <= 1.25d0) then
tmp = -sin(re) * im
else
tmp = t_0 * (1.0d0 - exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sin(re);
double tmp;
if (im <= -1.25) {
tmp = t_0 * (Math.exp(-im) - 1.0);
} else if (im <= 1.25) {
tmp = -Math.sin(re) * im;
} else {
tmp = t_0 * (1.0 - Math.exp(im));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sin(re) tmp = 0 if im <= -1.25: tmp = t_0 * (math.exp(-im) - 1.0) elif im <= 1.25: tmp = -math.sin(re) * im else: tmp = t_0 * (1.0 - math.exp(im)) return tmp
function code(re, im) t_0 = Float64(0.5 * sin(re)) tmp = 0.0 if (im <= -1.25) tmp = Float64(t_0 * Float64(exp(Float64(-im)) - 1.0)); elseif (im <= 1.25) tmp = Float64(Float64(-sin(re)) * im); else tmp = Float64(t_0 * Float64(1.0 - exp(im))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sin(re); tmp = 0.0; if (im <= -1.25) tmp = t_0 * (exp(-im) - 1.0); elseif (im <= 1.25) tmp = -sin(re) * im; else tmp = t_0 * (1.0 - exp(im)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.25], N[(t$95$0 * N[(N[Exp[(-im)], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.25], N[((-N[Sin[re], $MachinePrecision]) * im), $MachinePrecision], N[(t$95$0 * N[(1.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;im \leq -1.25:\\
\;\;\;\;t\_0 \cdot \left(e^{-im} - 1\right)\\
\mathbf{elif}\;im \leq 1.25:\\
\;\;\;\;\left(-\sin re\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(1 - e^{im}\right)\\
\end{array}
\end{array}
if im < -1.25Initial program 99.9%
Taylor expanded in im around 0
Applied rewrites99.5%
if -1.25 < im < 1.25Initial program 31.2%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-sin.f6498.9
Applied rewrites98.9%
if 1.25 < im Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites99.7%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 3.8)
(*
t_0
(*
(-
(*
(-
(*
(* (- (* -0.0003968253968253968 (* im im)) 0.016666666666666666) im)
im)
0.3333333333333333)
(* im im))
2.0)
im))
(* t_0 (- 1.0 (exp im))))))
double code(double re, double im) {
double t_0 = 0.5 * sin(re);
double tmp;
if (im <= 3.8) {
tmp = t_0 * ((((((((-0.0003968253968253968 * (im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im);
} else {
tmp = t_0 * (1.0 - exp(im));
}
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) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * sin(re)
if (im <= 3.8d0) then
tmp = t_0 * (((((((((-0.0003968253968253968d0) * (im * im)) - 0.016666666666666666d0) * im) * im) - 0.3333333333333333d0) * (im * im)) - 2.0d0) * im)
else
tmp = t_0 * (1.0d0 - exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sin(re);
double tmp;
if (im <= 3.8) {
tmp = t_0 * ((((((((-0.0003968253968253968 * (im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im);
} else {
tmp = t_0 * (1.0 - Math.exp(im));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sin(re) tmp = 0 if im <= 3.8: tmp = t_0 * ((((((((-0.0003968253968253968 * (im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im) else: tmp = t_0 * (1.0 - math.exp(im)) return tmp
function code(re, im) t_0 = Float64(0.5 * sin(re)) tmp = 0.0 if (im <= 3.8) tmp = Float64(t_0 * Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(-0.0003968253968253968 * Float64(im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * Float64(im * im)) - 2.0) * im)); else tmp = Float64(t_0 * Float64(1.0 - exp(im))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sin(re); tmp = 0.0; if (im <= 3.8) tmp = t_0 * ((((((((-0.0003968253968253968 * (im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im); else tmp = t_0 * (1.0 - exp(im)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 3.8], N[(t$95$0 * N[(N[(N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * N[(im * im), $MachinePrecision]), $MachinePrecision] - 0.016666666666666666), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(1.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;im \leq 3.8:\\
\;\;\;\;t\_0 \cdot \left(\left(\left(\left(\left(-0.0003968253968253968 \cdot \left(im \cdot im\right) - 0.016666666666666666\right) \cdot im\right) \cdot im - 0.3333333333333333\right) \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(1 - e^{im}\right)\\
\end{array}
\end{array}
if im < 3.7999999999999998Initial program 53.5%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites95.2%
if 3.7999999999999998 < im Initial program 100.0%
Taylor expanded in im around 0
Applied rewrites99.8%
(FPCore (re im)
:precision binary64
(if (<= (* 0.5 (sin re)) -0.01)
(*
(*
(* (fma (* re re) -0.16666666666666666 1.0) re)
(fma (* -0.16666666666666666 im) im -1.0))
im)
(*
(* (fma (* (* re re) 0.004166666666666667) (* re re) 0.5) re)
(*
(-
(*
(-
(* (* (* (* -0.0003968253968253968 im) im) im) im)
0.3333333333333333)
(* im im))
2.0)
im))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.01) {
tmp = ((fma((re * re), -0.16666666666666666, 1.0) * re) * fma((-0.16666666666666666 * im), im, -1.0)) * im;
} else {
tmp = (fma(((re * re) * 0.004166666666666667), (re * re), 0.5) * re) * ((((((((-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.01) tmp = Float64(Float64(Float64(fma(Float64(re * re), -0.16666666666666666, 1.0) * re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im); else tmp = Float64(Float64(fma(Float64(Float64(re * re) * 0.004166666666666667), Float64(re * re), 0.5) * re) * Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * Float64(im * im)) - 2.0) * im)); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[(N[(N[(re * re), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * re), $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision], N[(N[(N[(N[(N[(re * re), $MachinePrecision] * 0.004166666666666667), $MachinePrecision] * N[(re * re), $MachinePrecision] + 0.5), $MachinePrecision] * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.01:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(re \cdot re, -0.16666666666666666, 1\right) \cdot re\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(\left(re \cdot re\right) \cdot 0.004166666666666667, re \cdot re, 0.5\right) \cdot re\right) \cdot \left(\left(\left(\left(\left(\left(-0.0003968253968253968 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im - 0.3333333333333333\right) \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0100000000000000002Initial program 54.9%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6483.8
Applied rewrites83.8%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6425.1
Applied rewrites25.1%
if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 68.9%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.1%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6470.4
Applied rewrites70.4%
Taylor expanded in im around inf
pow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6470.3
Applied rewrites70.3%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6470.1
Applied rewrites70.1%
(FPCore (re im)
:precision binary64
(if (<= (* 0.5 (sin re)) -0.02)
(*
(*
(* (fma (* re re) -0.16666666666666666 1.0) re)
(fma (* -0.16666666666666666 im) im -1.0))
im)
(*
(* 0.5 re)
(*
(-
(*
(-
(* (* (* (* -0.0003968253968253968 im) im) im) im)
0.3333333333333333)
(* im im))
2.0)
im))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.02) {
tmp = ((fma((re * re), -0.16666666666666666, 1.0) * re) * fma((-0.16666666666666666 * im), im, -1.0)) * im;
} else {
tmp = (0.5 * re) * ((((((((-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.02) tmp = Float64(Float64(Float64(fma(Float64(re * re), -0.16666666666666666, 1.0) * re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im); else tmp = Float64(Float64(0.5 * re) * Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * Float64(im * im)) - 2.0) * im)); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(N[(N[(N[(re * re), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * re), $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.02:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(re \cdot re, -0.16666666666666666, 1\right) \cdot re\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\left(\left(\left(\left(\left(-0.0003968253968253968 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im - 0.3333333333333333\right) \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0200000000000000004Initial program 55.0%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6483.9
Applied rewrites83.9%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6425.1
Applied rewrites25.1%
if -0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 68.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.2%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6470.3
Applied rewrites70.3%
Taylor expanded in im around inf
pow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6470.2
Applied rewrites70.2%
Taylor expanded in re around 0
Applied rewrites69.8%
(FPCore (re im)
:precision binary64
(*
(* 0.5 (sin re))
(*
(-
(*
(-
(*
(* (- (* -0.0003968253968253968 (* im im)) 0.016666666666666666) im)
im)
0.3333333333333333)
(* im im))
2.0)
im)))
double code(double re, double im) {
return (0.5 * sin(re)) * ((((((((-0.0003968253968253968 * (im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * 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)) * (((((((((-0.0003968253968253968d0) * (im * im)) - 0.016666666666666666d0) * im) * im) - 0.3333333333333333d0) * (im * im)) - 2.0d0) * im)
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * ((((((((-0.0003968253968253968 * (im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im);
}
def code(re, im): return (0.5 * math.sin(re)) * ((((((((-0.0003968253968253968 * (im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im)
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(-0.0003968253968253968 * Float64(im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * Float64(im * im)) - 2.0) * im)) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * ((((((((-0.0003968253968253968 * (im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * N[(im * im), $MachinePrecision]), $MachinePrecision] - 0.016666666666666666), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(\left(\left(\left(\left(-0.0003968253968253968 \cdot \left(im \cdot im\right) - 0.016666666666666666\right) \cdot im\right) \cdot im - 0.3333333333333333\right) \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)
\end{array}
Initial program 65.5%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.0%
(FPCore (re im)
:precision binary64
(let* ((t_0
(*
(* (fma (* (* re re) 0.004166666666666667) (* re re) 0.5) re)
(*
(-
(*
(-
(* (* (* (* -0.0003968253968253968 im) im) im) im)
0.3333333333333333)
(* im im))
2.0)
im)))
(t_1
(*
(* 0.5 (sin re))
(* (- (* -0.3333333333333333 (* im im)) 2.0) im))))
(if (<= im -2.2e+92)
t_1
(if (<= im -2.85e+20)
t_0
(if (<= im 600.0)
(* (* (sin re) (fma (* -0.16666666666666666 im) im -1.0)) im)
(if (<= im 3.85e+102) t_0 t_1))))))
double code(double re, double im) {
double t_0 = (fma(((re * re) * 0.004166666666666667), (re * re), 0.5) * re) * ((((((((-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im);
double t_1 = (0.5 * sin(re)) * (((-0.3333333333333333 * (im * im)) - 2.0) * im);
double tmp;
if (im <= -2.2e+92) {
tmp = t_1;
} else if (im <= -2.85e+20) {
tmp = t_0;
} else if (im <= 600.0) {
tmp = (sin(re) * fma((-0.16666666666666666 * im), im, -1.0)) * im;
} else if (im <= 3.85e+102) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(re, im) t_0 = Float64(Float64(fma(Float64(Float64(re * re) * 0.004166666666666667), Float64(re * re), 0.5) * re) * Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * Float64(im * im)) - 2.0) * im)) t_1 = Float64(Float64(0.5 * sin(re)) * Float64(Float64(Float64(-0.3333333333333333 * Float64(im * im)) - 2.0) * im)) tmp = 0.0 if (im <= -2.2e+92) tmp = t_1; elseif (im <= -2.85e+20) tmp = t_0; elseif (im <= 600.0) tmp = Float64(Float64(sin(re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im); elseif (im <= 3.85e+102) tmp = t_0; else tmp = t_1; end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[(N[(N[(N[(re * re), $MachinePrecision] * 0.004166666666666667), $MachinePrecision] * N[(re * re), $MachinePrecision] + 0.5), $MachinePrecision] * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(-0.3333333333333333 * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.2e+92], t$95$1, If[LessEqual[im, -2.85e+20], t$95$0, If[LessEqual[im, 600.0], N[(N[(N[Sin[re], $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision], If[LessEqual[im, 3.85e+102], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{fma}\left(\left(re \cdot re\right) \cdot 0.004166666666666667, re \cdot re, 0.5\right) \cdot re\right) \cdot \left(\left(\left(\left(\left(\left(-0.0003968253968253968 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im - 0.3333333333333333\right) \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
t_1 := \left(0.5 \cdot \sin re\right) \cdot \left(\left(-0.3333333333333333 \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
\mathbf{if}\;im \leq -2.2 \cdot 10^{+92}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;im \leq -2.85 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;im \leq 600:\\
\;\;\;\;\left(\sin re \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im\\
\mathbf{elif}\;im \leq 3.85 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if im < -2.19999999999999992e92 or 3.85000000000000007e102 < im Initial program 100.0%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6498.2
Applied rewrites98.2%
if -2.19999999999999992e92 < im < -2.85e20 or 600 < im < 3.85000000000000007e102Initial program 100.0%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites63.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6455.2
Applied rewrites55.2%
Taylor expanded in im around inf
pow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6455.2
Applied rewrites55.2%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6455.2
Applied rewrites55.2%
if -2.85e20 < im < 600Initial program 33.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6495.9
Applied rewrites95.9%
(FPCore (re im)
:precision binary64
(if (<= (* 0.5 (sin re)) -0.02)
(*
(*
(* (fma (* re re) -0.16666666666666666 1.0) re)
(fma (* -0.16666666666666666 im) im -1.0))
im)
(*
(* 0.5 re)
(* (- (* (* (* im im) -0.016666666666666666) (* im im)) 2.0) im))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.02) {
tmp = ((fma((re * re), -0.16666666666666666, 1.0) * re) * fma((-0.16666666666666666 * im), im, -1.0)) * im;
} else {
tmp = (0.5 * re) * (((((im * im) * -0.016666666666666666) * (im * im)) - 2.0) * im);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.02) tmp = Float64(Float64(Float64(fma(Float64(re * re), -0.16666666666666666, 1.0) * re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im); else tmp = Float64(Float64(0.5 * re) * Float64(Float64(Float64(Float64(Float64(im * im) * -0.016666666666666666) * Float64(im * im)) - 2.0) * im)); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(N[(N[(N[(re * re), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * re), $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(N[(N[(im * im), $MachinePrecision] * -0.016666666666666666), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.02:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(re \cdot re, -0.16666666666666666, 1\right) \cdot re\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\left(\left(\left(im \cdot im\right) \cdot -0.016666666666666666\right) \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0200000000000000004Initial program 55.0%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6483.9
Applied rewrites83.9%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6425.1
Applied rewrites25.1%
if -0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 68.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6490.4
Applied rewrites90.4%
Taylor expanded in re around 0
Applied rewrites67.8%
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6467.8
Applied rewrites67.8%
Taylor expanded in im around inf
*-commutativeN/A
pow2N/A
lift-*.f64N/A
lift-*.f6467.6
Applied rewrites67.6%
(FPCore (re im)
:precision binary64
(if (<= (* 0.5 (sin re)) -0.02)
(*
(*
(* (fma (* re re) -0.16666666666666666 1.0) re)
(fma (* -0.16666666666666666 im) im -1.0))
im)
(* (* 0.5 re) (* (- (* -0.3333333333333333 (* im im)) 2.0) im))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.02) {
tmp = ((fma((re * re), -0.16666666666666666, 1.0) * re) * fma((-0.16666666666666666 * im), im, -1.0)) * im;
} else {
tmp = (0.5 * re) * (((-0.3333333333333333 * (im * im)) - 2.0) * im);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.02) tmp = Float64(Float64(Float64(fma(Float64(re * re), -0.16666666666666666, 1.0) * re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im); else tmp = Float64(Float64(0.5 * re) * Float64(Float64(Float64(-0.3333333333333333 * Float64(im * im)) - 2.0) * im)); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(N[(N[(N[(re * re), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * re), $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(-0.3333333333333333 * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.02:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(re \cdot re, -0.16666666666666666, 1\right) \cdot re\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\left(-0.3333333333333333 \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0200000000000000004Initial program 55.0%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6483.9
Applied rewrites83.9%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6425.1
Applied rewrites25.1%
if -0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 68.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6484.2
Applied rewrites84.2%
Taylor expanded in re around 0
Applied rewrites63.4%
(FPCore (re im)
:precision binary64
(*
(* 0.5 (sin re))
(*
(-
(* (* (- (* -0.016666666666666666 (* im im)) 0.3333333333333333) im) im)
2.0)
im)))
double code(double re, double im) {
return (0.5 * sin(re)) * ((((((-0.016666666666666666 * (im * im)) - 0.3333333333333333) * im) * im) - 2.0) * 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)) * (((((((-0.016666666666666666d0) * (im * im)) - 0.3333333333333333d0) * im) * im) - 2.0d0) * im)
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * ((((((-0.016666666666666666 * (im * im)) - 0.3333333333333333) * im) * im) - 2.0) * im);
}
def code(re, im): return (0.5 * math.sin(re)) * ((((((-0.016666666666666666 * (im * im)) - 0.3333333333333333) * im) * im) - 2.0) * im)
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(Float64(Float64(Float64(Float64(Float64(-0.016666666666666666 * Float64(im * im)) - 0.3333333333333333) * im) * im) - 2.0) * im)) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * ((((((-0.016666666666666666 * (im * im)) - 0.3333333333333333) * im) * im) - 2.0) * im); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(N[(N[(-0.016666666666666666 * N[(im * im), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(\left(\left(\left(-0.016666666666666666 \cdot \left(im \cdot im\right) - 0.3333333333333333\right) \cdot im\right) \cdot im - 2\right) \cdot im\right)
\end{array}
Initial program 65.5%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6490.3
Applied rewrites90.3%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) -0.02) (* (fma (* (* re re) im) 0.16666666666666666 (- im)) re) (* (* 0.5 re) (* (- (* -0.3333333333333333 (* im im)) 2.0) im))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.02) {
tmp = fma(((re * re) * im), 0.16666666666666666, -im) * re;
} else {
tmp = (0.5 * re) * (((-0.3333333333333333 * (im * im)) - 2.0) * im);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.02) tmp = Float64(fma(Float64(Float64(re * re) * im), 0.16666666666666666, Float64(-im)) * re); else tmp = Float64(Float64(0.5 * re) * Float64(Float64(Float64(-0.3333333333333333 * Float64(im * im)) - 2.0) * im)); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(N[(N[(re * re), $MachinePrecision] * im), $MachinePrecision] * 0.16666666666666666 + (-im)), $MachinePrecision] * re), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(-0.3333333333333333 * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.02:\\
\;\;\;\;\mathsf{fma}\left(\left(re \cdot re\right) \cdot im, 0.16666666666666666, -im\right) \cdot re\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\left(-0.3333333333333333 \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0200000000000000004Initial program 55.0%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-sin.f6451.4
Applied rewrites51.4%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6421.9
Applied rewrites21.9%
if -0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 68.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6484.2
Applied rewrites84.2%
Taylor expanded in re around 0
Applied rewrites63.4%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) -0.02) (* (fma (* (* re re) im) 0.16666666666666666 (- im)) re) (* (* re (fma (* -0.16666666666666666 im) im -1.0)) im)))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.02) {
tmp = fma(((re * re) * im), 0.16666666666666666, -im) * re;
} else {
tmp = (re * fma((-0.16666666666666666 * im), im, -1.0)) * im;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.02) tmp = Float64(fma(Float64(Float64(re * re) * im), 0.16666666666666666, Float64(-im)) * re); else tmp = Float64(Float64(re * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(N[(N[(re * re), $MachinePrecision] * im), $MachinePrecision] * 0.16666666666666666 + (-im)), $MachinePrecision] * re), $MachinePrecision], N[(N[(re * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.02:\\
\;\;\;\;\mathsf{fma}\left(\left(re \cdot re\right) \cdot im, 0.16666666666666666, -im\right) \cdot re\\
\mathbf{else}:\\
\;\;\;\;\left(re \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0200000000000000004Initial program 55.0%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-sin.f6451.4
Applied rewrites51.4%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6421.9
Applied rewrites21.9%
if -0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 68.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6480.2
Applied rewrites80.2%
Taylor expanded in re around 0
Applied rewrites59.4%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) -0.02) (* (- (* (* (* re re) -0.16666666666666666) re)) im) (* (* re (fma (* -0.16666666666666666 im) im -1.0)) im)))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.02) {
tmp = -(((re * re) * -0.16666666666666666) * re) * im;
} else {
tmp = (re * fma((-0.16666666666666666 * im), im, -1.0)) * im;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.02) tmp = Float64(Float64(-Float64(Float64(Float64(re * re) * -0.16666666666666666) * re)) * im); else tmp = Float64(Float64(re * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.02], N[((-N[(N[(N[(re * re), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] * re), $MachinePrecision]) * im), $MachinePrecision], N[(N[(re * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.02:\\
\;\;\;\;\left(-\left(\left(re \cdot re\right) \cdot -0.16666666666666666\right) \cdot re\right) \cdot im\\
\mathbf{else}:\\
\;\;\;\;\left(re \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0200000000000000004Initial program 55.0%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-sin.f6451.4
Applied rewrites51.4%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6421.9
Applied rewrites21.9%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6421.8
Applied rewrites21.8%
if -0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 68.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6480.2
Applied rewrites80.2%
Taylor expanded in re around 0
Applied rewrites59.4%
(FPCore (re im)
:precision binary64
(if (<= re 0.0072)
(*
(* 0.5 re)
(*
(-
(*
(-
(* (* (* (* -0.0003968253968253968 im) im) im) im)
0.3333333333333333)
(* im im))
2.0)
im))
(* (* (sin re) (fma (* -0.16666666666666666 im) im -1.0)) im)))
double code(double re, double im) {
double tmp;
if (re <= 0.0072) {
tmp = (0.5 * re) * ((((((((-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im);
} else {
tmp = (sin(re) * fma((-0.16666666666666666 * im), im, -1.0)) * im;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= 0.0072) tmp = Float64(Float64(0.5 * re) * Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * Float64(im * im)) - 2.0) * im)); else tmp = Float64(Float64(sin(re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im); end return tmp end
code[re_, im_] := If[LessEqual[re, 0.0072], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[re], $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 0.0072:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\left(\left(\left(\left(\left(-0.0003968253968253968 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im - 0.3333333333333333\right) \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\sin re \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im\\
\end{array}
\end{array}
if re < 0.0071999999999999998Initial program 69.2%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.2%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6470.7
Applied rewrites70.7%
Taylor expanded in im around inf
pow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6470.7
Applied rewrites70.7%
Taylor expanded in re around 0
Applied rewrites70.2%
if 0.0071999999999999998 < re Initial program 54.2%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6483.5
Applied rewrites83.5%
(FPCore (re im)
:precision binary64
(let* ((t_0
(*
(* (fma (* (* re re) 0.004166666666666667) (* re re) 0.5) re)
(*
(-
(*
(-
(* (* (* (* -0.0003968253968253968 im) im) im) im)
0.3333333333333333)
(* im im))
2.0)
im)))
(t_1
(*
(*
(* (fma (* re re) -0.16666666666666666 1.0) re)
(fma (* -0.16666666666666666 im) im -1.0))
im)))
(if (<= im -5e+172)
t_1
(if (<= im -2.85e+20)
t_0
(if (<= im 600.0) (* (- (sin re)) im) (if (<= im 2e+151) t_0 t_1))))))
double code(double re, double im) {
double t_0 = (fma(((re * re) * 0.004166666666666667), (re * re), 0.5) * re) * ((((((((-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * (im * im)) - 2.0) * im);
double t_1 = ((fma((re * re), -0.16666666666666666, 1.0) * re) * fma((-0.16666666666666666 * im), im, -1.0)) * im;
double tmp;
if (im <= -5e+172) {
tmp = t_1;
} else if (im <= -2.85e+20) {
tmp = t_0;
} else if (im <= 600.0) {
tmp = -sin(re) * im;
} else if (im <= 2e+151) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(re, im) t_0 = Float64(Float64(fma(Float64(Float64(re * re) * 0.004166666666666667), Float64(re * re), 0.5) * re) * Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(-0.0003968253968253968 * im) * im) * im) * im) - 0.3333333333333333) * Float64(im * im)) - 2.0) * im)) t_1 = Float64(Float64(Float64(fma(Float64(re * re), -0.16666666666666666, 1.0) * re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im) tmp = 0.0 if (im <= -5e+172) tmp = t_1; elseif (im <= -2.85e+20) tmp = t_0; elseif (im <= 600.0) tmp = Float64(Float64(-sin(re)) * im); elseif (im <= 2e+151) tmp = t_0; else tmp = t_1; end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[(N[(N[(N[(re * re), $MachinePrecision] * 0.004166666666666667), $MachinePrecision] * N[(re * re), $MachinePrecision] + 0.5), $MachinePrecision] * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[(N[(re * re), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * re), $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]}, If[LessEqual[im, -5e+172], t$95$1, If[LessEqual[im, -2.85e+20], t$95$0, If[LessEqual[im, 600.0], N[((-N[Sin[re], $MachinePrecision]) * im), $MachinePrecision], If[LessEqual[im, 2e+151], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{fma}\left(\left(re \cdot re\right) \cdot 0.004166666666666667, re \cdot re, 0.5\right) \cdot re\right) \cdot \left(\left(\left(\left(\left(\left(-0.0003968253968253968 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im - 0.3333333333333333\right) \cdot \left(im \cdot im\right) - 2\right) \cdot im\right)\\
t_1 := \left(\left(\mathsf{fma}\left(re \cdot re, -0.16666666666666666, 1\right) \cdot re\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im\\
\mathbf{if}\;im \leq -5 \cdot 10^{+172}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;im \leq -2.85 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;im \leq 600:\\
\;\;\;\;\left(-\sin re\right) \cdot im\\
\mathbf{elif}\;im \leq 2 \cdot 10^{+151}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if im < -5.0000000000000001e172 or 2.00000000000000003e151 < im Initial program 100.0%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.7
Applied rewrites99.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6474.8
Applied rewrites74.8%
if -5.0000000000000001e172 < im < -2.85e20 or 600 < im < 2.00000000000000003e151Initial program 100.0%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites79.1%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6463.6
Applied rewrites63.6%
Taylor expanded in im around inf
pow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6463.6
Applied rewrites63.6%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6463.6
Applied rewrites63.6%
if -2.85e20 < im < 600Initial program 33.8%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-sin.f6495.3
Applied rewrites95.3%
(FPCore (re im) :precision binary64 (* (* re (fma (* -0.16666666666666666 im) im -1.0)) im))
double code(double re, double im) {
return (re * fma((-0.16666666666666666 * im), im, -1.0)) * im;
}
function code(re, im) return Float64(Float64(re * fma(Float64(-0.16666666666666666 * im), im, -1.0)) * im) end
code[re_, im_] := N[(N[(re * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]
\begin{array}{l}
\\
\left(re \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\right) \cdot im
\end{array}
Initial program 65.5%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lift-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6481.1
Applied rewrites81.1%
Taylor expanded in re around 0
Applied rewrites50.6%
(FPCore (re im) :precision binary64 (* (- re) im))
double code(double re, double im) {
return -re * 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 = -re * im
end function
public static double code(double re, double im) {
return -re * im;
}
def code(re, im): return -re * im
function code(re, im) return Float64(Float64(-re) * im) end
function tmp = code(re, im) tmp = -re * im; end
code[re_, im_] := N[((-re) * im), $MachinePrecision]
\begin{array}{l}
\\
\left(-re\right) \cdot im
\end{array}
Initial program 65.5%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-sin.f6451.8
Applied rewrites51.8%
Taylor expanded in re around 0
Applied rewrites33.5%
(FPCore (re im) :precision binary64 (* 0.0 im))
double code(double re, double im) {
return 0.0 * 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.0d0 * im
end function
public static double code(double re, double im) {
return 0.0 * im;
}
def code(re, im): return 0.0 * im
function code(re, im) return Float64(0.0 * im) end
function tmp = code(re, im) tmp = 0.0 * im; end
code[re_, im_] := N[(0.0 * im), $MachinePrecision]
\begin{array}{l}
\\
0 \cdot im
\end{array}
Initial program 65.5%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-sin.f6451.8
Applied rewrites51.8%
lift-neg.f64N/A
lift-sin.f64N/A
sin-+PI-revN/A
lower-sin.f64N/A
lower-+.f64N/A
lower-PI.f645.5
Applied rewrites5.5%
Taylor expanded in re around 0
sin-+PI-revN/A
sin-PI14.9
Applied rewrites14.9%
(FPCore (re im)
:precision binary64
(if (< (fabs im) 1.0)
(-
(*
(sin re)
(+
(+ im (* (* (* 0.16666666666666666 im) im) im))
(* (* (* (* (* 0.008333333333333333 im) im) im) im) im))))
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (fabs(im) < 1.0) {
tmp = -(sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * sin(re)) * (exp(-im) - exp(im));
}
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 (abs(im) < 1.0d0) then
tmp = -(sin(re) * ((im + (((0.16666666666666666d0 * im) * im) * im)) + (((((0.008333333333333333d0 * im) * im) * im) * im) * im)))
else
tmp = (0.5d0 * sin(re)) * (exp(-im) - exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.abs(im) < 1.0) {
tmp = -(Math.sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if math.fabs(im) < 1.0: tmp = -(math.sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))) else: tmp = (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (abs(im) < 1.0) tmp = Float64(-Float64(sin(re) * Float64(Float64(im + Float64(Float64(Float64(0.16666666666666666 * im) * im) * im)) + Float64(Float64(Float64(Float64(Float64(0.008333333333333333 * im) * im) * im) * im) * im)))); else tmp = Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (abs(im) < 1.0) tmp = -(sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))); else tmp = (0.5 * sin(re)) * (exp(-im) - exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Less[N[Abs[im], $MachinePrecision], 1.0], (-N[(N[Sin[re], $MachinePrecision] * N[(N[(im + N[(N[(N[(0.16666666666666666 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(0.008333333333333333 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|im\right| < 1:\\
\;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\
\end{array}
\end{array}
herbie shell --seed 2025093
(FPCore (re im)
:name "math.cos on complex, imaginary part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs im) 1) (- (* (sin re) (+ im (* 1/6 im im im) (* 1/120 im im im im im)))) (* (* 1/2 (sin re)) (- (exp (- im)) (exp im)))))
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))