
(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 8 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 (* (sinh (- im)) (sin re)))
double code(double re, double im) {
return sinh(-im) * sin(re);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sinh(-im) * sin(re)
end function
public static double code(double re, double im) {
return Math.sinh(-im) * Math.sin(re);
}
def code(re, im): return math.sinh(-im) * math.sin(re)
function code(re, im) return Float64(sinh(Float64(-im)) * sin(re)) end
function tmp = code(re, im) tmp = sinh(-im) * sin(re); end
code[re_, im_] := N[(N[Sinh[(-im)], $MachinePrecision] * N[Sin[re], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sinh \left(-im\right) \cdot \sin re
\end{array}
Initial program 66.2%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift--.f64N/A
sub-negate-revN/A
distribute-lft-neg-outN/A
metadata-evalN/A
mult-flipN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-defN/A
sinh-negN/A
lift-neg.f64N/A
lower-*.f64N/A
lower-sinh.f6499.9
Applied rewrites99.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))))
(if (<= t_0 -2e-85)
(* (sinh (- im)) re)
(if (<= t_0 5e-6)
(* (sin re) (- im))
(*
(* re (+ 0.5 (* -0.08333333333333333 (pow re 2.0))))
(- 1.0 (exp im)))))))
double code(double re, double im) {
double t_0 = (0.5 * sin(re)) * (exp(-im) - exp(im));
double tmp;
if (t_0 <= -2e-85) {
tmp = sinh(-im) * re;
} else if (t_0 <= 5e-6) {
tmp = sin(re) * -im;
} else {
tmp = (re * (0.5 + (-0.08333333333333333 * pow(re, 2.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)) * (exp(-im) - exp(im))
if (t_0 <= (-2d-85)) then
tmp = sinh(-im) * re
else if (t_0 <= 5d-6) then
tmp = sin(re) * -im
else
tmp = (re * (0.5d0 + ((-0.08333333333333333d0) * (re ** 2.0d0)))) * (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)) * (Math.exp(-im) - Math.exp(im));
double tmp;
if (t_0 <= -2e-85) {
tmp = Math.sinh(-im) * re;
} else if (t_0 <= 5e-6) {
tmp = Math.sin(re) * -im;
} else {
tmp = (re * (0.5 + (-0.08333333333333333 * Math.pow(re, 2.0)))) * (1.0 - Math.exp(im));
}
return tmp;
}
def code(re, im): t_0 = (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im)) tmp = 0 if t_0 <= -2e-85: tmp = math.sinh(-im) * re elif t_0 <= 5e-6: tmp = math.sin(re) * -im else: tmp = (re * (0.5 + (-0.08333333333333333 * math.pow(re, 2.0)))) * (1.0 - math.exp(im)) return tmp
function code(re, im) t_0 = Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im))) tmp = 0.0 if (t_0 <= -2e-85) tmp = Float64(sinh(Float64(-im)) * re); elseif (t_0 <= 5e-6) tmp = Float64(sin(re) * Float64(-im)); else tmp = Float64(Float64(re * Float64(0.5 + Float64(-0.08333333333333333 * (re ^ 2.0)))) * Float64(1.0 - exp(im))); end return tmp end
function tmp_2 = code(re, im) t_0 = (0.5 * sin(re)) * (exp(-im) - exp(im)); tmp = 0.0; if (t_0 <= -2e-85) tmp = sinh(-im) * re; elseif (t_0 <= 5e-6) tmp = sin(re) * -im; else tmp = (re * (0.5 + (-0.08333333333333333 * (re ^ 2.0)))) * (1.0 - exp(im)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-85], N[(N[Sinh[(-im)], $MachinePrecision] * re), $MachinePrecision], If[LessEqual[t$95$0, 5e-6], N[(N[Sin[re], $MachinePrecision] * (-im)), $MachinePrecision], N[(N[(re * N[(0.5 + N[(-0.08333333333333333 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-85}:\\
\;\;\;\;\sinh \left(-im\right) \cdot re\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-6}:\\
\;\;\;\;\sin re \cdot \left(-im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right) \cdot \left(1 - e^{im}\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -2e-85Initial program 66.2%
Taylor expanded in re around 0
Applied rewrites53.1%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flipN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-defN/A
distribute-lft-neg-outN/A
Applied rewrites63.6%
if -2e-85 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 5.00000000000000041e-6Initial program 66.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6450.9
Applied rewrites50.9%
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lift-neg.f64N/A
lower-*.f6450.9
Applied rewrites50.9%
if 5.00000000000000041e-6 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 66.2%
Taylor expanded in re around 0
Applied rewrites53.1%
Taylor expanded in im around 0
Applied rewrites34.4%
Taylor expanded in re around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6437.1
Applied rewrites37.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))))
(if (<= t_0 -2e-85)
(* (sinh (- im)) re)
(if (<= t_0 5e-6)
(* (sin re) (- im))
(* 0.16666666666666666 (* (* re re) (* im re)))))))
double code(double re, double im) {
double t_0 = (0.5 * sin(re)) * (exp(-im) - exp(im));
double tmp;
if (t_0 <= -2e-85) {
tmp = sinh(-im) * re;
} else if (t_0 <= 5e-6) {
tmp = sin(re) * -im;
} else {
tmp = 0.16666666666666666 * ((re * re) * (im * re));
}
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)) * (exp(-im) - exp(im))
if (t_0 <= (-2d-85)) then
tmp = sinh(-im) * re
else if (t_0 <= 5d-6) then
tmp = sin(re) * -im
else
tmp = 0.16666666666666666d0 * ((re * re) * (im * re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
double tmp;
if (t_0 <= -2e-85) {
tmp = Math.sinh(-im) * re;
} else if (t_0 <= 5e-6) {
tmp = Math.sin(re) * -im;
} else {
tmp = 0.16666666666666666 * ((re * re) * (im * re));
}
return tmp;
}
def code(re, im): t_0 = (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im)) tmp = 0 if t_0 <= -2e-85: tmp = math.sinh(-im) * re elif t_0 <= 5e-6: tmp = math.sin(re) * -im else: tmp = 0.16666666666666666 * ((re * re) * (im * re)) return tmp
function code(re, im) t_0 = Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im))) tmp = 0.0 if (t_0 <= -2e-85) tmp = Float64(sinh(Float64(-im)) * re); elseif (t_0 <= 5e-6) tmp = Float64(sin(re) * Float64(-im)); else tmp = Float64(0.16666666666666666 * Float64(Float64(re * re) * Float64(im * re))); end return tmp end
function tmp_2 = code(re, im) t_0 = (0.5 * sin(re)) * (exp(-im) - exp(im)); tmp = 0.0; if (t_0 <= -2e-85) tmp = sinh(-im) * re; elseif (t_0 <= 5e-6) tmp = sin(re) * -im; else tmp = 0.16666666666666666 * ((re * re) * (im * re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-85], N[(N[Sinh[(-im)], $MachinePrecision] * re), $MachinePrecision], If[LessEqual[t$95$0, 5e-6], N[(N[Sin[re], $MachinePrecision] * (-im)), $MachinePrecision], N[(0.16666666666666666 * N[(N[(re * re), $MachinePrecision] * N[(im * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-85}:\\
\;\;\;\;\sinh \left(-im\right) \cdot re\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-6}:\\
\;\;\;\;\sin re \cdot \left(-im\right)\\
\mathbf{else}:\\
\;\;\;\;0.16666666666666666 \cdot \left(\left(re \cdot re\right) \cdot \left(im \cdot re\right)\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -2e-85Initial program 66.2%
Taylor expanded in re around 0
Applied rewrites53.1%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flipN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-defN/A
distribute-lft-neg-outN/A
Applied rewrites63.6%
if -2e-85 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 5.00000000000000041e-6Initial program 66.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6450.9
Applied rewrites50.9%
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lift-neg.f64N/A
lower-*.f6450.9
Applied rewrites50.9%
if 5.00000000000000041e-6 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 66.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6450.9
Applied rewrites50.9%
Taylor expanded in re around 0
lower-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.1
Applied rewrites36.1%
Taylor expanded in re around inf
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6424.0
Applied rewrites24.0%
lift-*.f64N/A
*-commutativeN/A
lift-pow.f64N/A
unpow3N/A
unpow2N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6424.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6424.0
Applied rewrites24.0%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) -0.0002) (* re (fma (* (* 0.16666666666666666 im) re) re (- im))) (* (sinh (- im)) re)))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.0002) {
tmp = re * fma(((0.16666666666666666 * im) * re), re, -im);
} else {
tmp = sinh(-im) * re;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.0002) tmp = Float64(re * fma(Float64(Float64(0.16666666666666666 * im) * re), re, Float64(-im))); else tmp = Float64(sinh(Float64(-im)) * re); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.0002], N[(re * N[(N[(N[(0.16666666666666666 * im), $MachinePrecision] * re), $MachinePrecision] * re + (-im)), $MachinePrecision]), $MachinePrecision], N[(N[Sinh[(-im)], $MachinePrecision] * re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.0002:\\
\;\;\;\;re \cdot \mathsf{fma}\left(\left(0.16666666666666666 \cdot im\right) \cdot re, re, -im\right)\\
\mathbf{else}:\\
\;\;\;\;\sinh \left(-im\right) \cdot re\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -2.0000000000000001e-4Initial program 66.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6450.9
Applied rewrites50.9%
Taylor expanded in re around 0
lower-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.1
Applied rewrites36.1%
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6436.1
Applied rewrites36.1%
if -2.0000000000000001e-4 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 66.2%
Taylor expanded in re around 0
Applied rewrites53.1%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
sub-negate-revN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
mult-flipN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-defN/A
distribute-lft-neg-outN/A
Applied rewrites63.6%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) 5e-7) (* re (fma (* (* 0.16666666666666666 im) re) re (- im))) (* (* 0.5 re) (- 1.0 (+ 1.0 im)))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= 5e-7) {
tmp = re * fma(((0.16666666666666666 * im) * re), re, -im);
} else {
tmp = (0.5 * re) * (1.0 - (1.0 + im));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= 5e-7) tmp = Float64(re * fma(Float64(Float64(0.16666666666666666 * im) * re), re, Float64(-im))); else tmp = Float64(Float64(0.5 * re) * Float64(1.0 - Float64(1.0 + im))); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], 5e-7], N[(re * N[(N[(N[(0.16666666666666666 * im), $MachinePrecision] * re), $MachinePrecision] * re + (-im)), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(1.0 - N[(1.0 + im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq 5 \cdot 10^{-7}:\\
\;\;\;\;re \cdot \mathsf{fma}\left(\left(0.16666666666666666 \cdot im\right) \cdot re, re, -im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(1 - \left(1 + im\right)\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < 4.99999999999999977e-7Initial program 66.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6450.9
Applied rewrites50.9%
Taylor expanded in re around 0
lower-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.1
Applied rewrites36.1%
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6436.1
Applied rewrites36.1%
if 4.99999999999999977e-7 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 66.2%
Taylor expanded in re around 0
Applied rewrites53.1%
Taylor expanded in im around 0
Applied rewrites34.4%
Taylor expanded in im around 0
lower-+.f6421.9
Applied rewrites21.9%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) 5e-7) (* (* im (fma (* re re) 0.16666666666666666 -1.0)) re) (* (* 0.5 re) (- 1.0 (+ 1.0 im)))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= 5e-7) {
tmp = (im * fma((re * re), 0.16666666666666666, -1.0)) * re;
} else {
tmp = (0.5 * re) * (1.0 - (1.0 + im));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= 5e-7) tmp = Float64(Float64(im * fma(Float64(re * re), 0.16666666666666666, -1.0)) * re); else tmp = Float64(Float64(0.5 * re) * Float64(1.0 - Float64(1.0 + im))); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], 5e-7], N[(N[(im * N[(N[(re * re), $MachinePrecision] * 0.16666666666666666 + -1.0), $MachinePrecision]), $MachinePrecision] * re), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(1.0 - N[(1.0 + im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\left(im \cdot \mathsf{fma}\left(re \cdot re, 0.16666666666666666, -1\right)\right) \cdot re\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(1 - \left(1 + im\right)\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < 4.99999999999999977e-7Initial program 66.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6450.9
Applied rewrites50.9%
Taylor expanded in re around 0
lower-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.1
Applied rewrites36.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.1
Applied rewrites36.1%
if 4.99999999999999977e-7 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 66.2%
Taylor expanded in re around 0
Applied rewrites53.1%
Taylor expanded in im around 0
Applied rewrites34.4%
Taylor expanded in im around 0
lower-+.f6421.9
Applied rewrites21.9%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) -0.0002) (* 0.16666666666666666 (* (* re re) (* im re))) (- (* re im))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.0002) {
tmp = 0.16666666666666666 * ((re * re) * (im * re));
} else {
tmp = -(re * 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 ((0.5d0 * sin(re)) <= (-0.0002d0)) then
tmp = 0.16666666666666666d0 * ((re * re) * (im * re))
else
tmp = -(re * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((0.5 * Math.sin(re)) <= -0.0002) {
tmp = 0.16666666666666666 * ((re * re) * (im * re));
} else {
tmp = -(re * im);
}
return tmp;
}
def code(re, im): tmp = 0 if (0.5 * math.sin(re)) <= -0.0002: tmp = 0.16666666666666666 * ((re * re) * (im * re)) else: tmp = -(re * im) return tmp
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.0002) tmp = Float64(0.16666666666666666 * Float64(Float64(re * re) * Float64(im * re))); else tmp = Float64(-Float64(re * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((0.5 * sin(re)) <= -0.0002) tmp = 0.16666666666666666 * ((re * re) * (im * re)); else tmp = -(re * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.0002], N[(0.16666666666666666 * N[(N[(re * re), $MachinePrecision] * N[(im * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[(re * im), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.0002:\\
\;\;\;\;0.16666666666666666 \cdot \left(\left(re \cdot re\right) \cdot \left(im \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-re \cdot im\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -2.0000000000000001e-4Initial program 66.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6450.9
Applied rewrites50.9%
Taylor expanded in re around 0
lower-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.1
Applied rewrites36.1%
Taylor expanded in re around inf
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6424.0
Applied rewrites24.0%
lift-*.f64N/A
*-commutativeN/A
lift-pow.f64N/A
unpow3N/A
unpow2N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6424.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6424.0
Applied rewrites24.0%
if -2.0000000000000001e-4 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 66.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6450.9
Applied rewrites50.9%
Taylor expanded in re around 0
lower-*.f6432.7
Applied rewrites32.7%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6432.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6432.7
Applied rewrites32.7%
(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}
\\
-re \cdot im
\end{array}
Initial program 66.2%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6450.9
Applied rewrites50.9%
Taylor expanded in re around 0
lower-*.f6432.7
Applied rewrites32.7%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6432.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6432.7
Applied rewrites32.7%
herbie shell --seed 2025162
(FPCore (re im)
:name "math.cos on complex, imaginary part"
:precision binary64
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))