
(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}
Sampling outcomes in binary64 precision:
Herbie found 14 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 63.6%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
associate-/l*N/A
*-commutativeN/A
lift-sinh.f64N/A
sinh-undef-revN/A
sinh-defN/A
lift-sinh.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
(FPCore (re im)
:precision binary64
(if (<= (* 0.5 (sin re)) -0.01)
(*
(* (fma (* (* im re) re) -0.16666666666666666 im) re)
(fma (* -0.16666666666666666 im) im -1.0))
(*
(* 0.5 re)
(*
(fma
(-
(*
(* (fma -0.0003968253968253968 (* im im) -0.016666666666666666) 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(((im * re) * re), -0.16666666666666666, im) * re) * fma((-0.16666666666666666 * im), im, -1.0);
} else {
tmp = (0.5 * re) * (fma((((fma(-0.0003968253968253968, (im * im), -0.016666666666666666) * 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(fma(Float64(Float64(im * re) * re), -0.16666666666666666, im) * re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)); else tmp = Float64(Float64(0.5 * re) * Float64(fma(Float64(Float64(Float64(fma(-0.0003968253968253968, Float64(im * im), -0.016666666666666666) * 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[(im * re), $MachinePrecision] * re), $MachinePrecision] * -0.16666666666666666 + im), $MachinePrecision] * re), $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * N[(im * im), $MachinePrecision] + -0.016666666666666666), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision] + -2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.01:\\
\;\;\;\;\left(\mathsf{fma}\left(\left(im \cdot re\right) \cdot re, -0.16666666666666666, im\right) \cdot re\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\mathsf{fma}\left(\left(\mathsf{fma}\left(-0.0003968253968253968, im \cdot im, -0.016666666666666666\right) \cdot im\right) \cdot im - 0.3333333333333333, im \cdot im, -2\right) \cdot im\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0100000000000000002Initial program 56.8%
Taylor expanded in im around 0
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-rgt-outN/A
+-commutativeN/A
Applied rewrites74.1%
Taylor expanded in re around 0
Applied rewrites32.8%
if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 65.7%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.1%
Applied rewrites93.1%
Taylor expanded in re around 0
lower-*.f6468.5
Applied rewrites68.5%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites68.5%
(FPCore (re im)
:precision binary64
(*
(* 0.5 (sin re))
(*
(fma
(-
(*
(* (- (* -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)) * (fma((((((-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(fma(Float64(Float64(Float64(Float64(Float64(-0.0003968253968253968 * Float64(im * im)) - 0.016666666666666666) * im) * im) - 0.3333333333333333), Float64(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[(-0.0003968253968253968 * N[(im * im), $MachinePrecision]), $MachinePrecision] - 0.016666666666666666), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision] + -2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(\mathsf{fma}\left(\left(\left(-0.0003968253968253968 \cdot \left(im \cdot im\right) - 0.016666666666666666\right) \cdot im\right) \cdot im - 0.3333333333333333, im \cdot im, -2\right) \cdot im\right)
\end{array}
Initial program 63.6%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.1%
(FPCore (re im)
:precision binary64
(if (<= (* 0.5 (sin re)) -0.01)
(*
(* (fma (* (* im re) re) -0.16666666666666666 im) re)
(fma (* -0.16666666666666666 im) im -1.0))
(*
(*
(fma
(fma (* im im) -0.008333333333333333 -0.16666666666666666)
(* im im)
-1.0)
im)
re)))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.01) {
tmp = (fma(((im * re) * re), -0.16666666666666666, im) * re) * fma((-0.16666666666666666 * im), im, -1.0);
} else {
tmp = (fma(fma((im * im), -0.008333333333333333, -0.16666666666666666), (im * im), -1.0) * im) * re;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.01) tmp = Float64(Float64(fma(Float64(Float64(im * re) * re), -0.16666666666666666, im) * re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)); else tmp = Float64(Float64(fma(fma(Float64(im * im), -0.008333333333333333, -0.16666666666666666), Float64(im * im), -1.0) * im) * re); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[(N[(N[(im * re), $MachinePrecision] * re), $MachinePrecision] * -0.16666666666666666 + im), $MachinePrecision] * re), $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(im * im), $MachinePrecision] * -0.008333333333333333 + -0.16666666666666666), $MachinePrecision] * N[(im * im), $MachinePrecision] + -1.0), $MachinePrecision] * im), $MachinePrecision] * re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.01:\\
\;\;\;\;\left(\mathsf{fma}\left(\left(im \cdot re\right) \cdot re, -0.16666666666666666, im\right) \cdot re\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, -0.008333333333333333, -0.16666666666666666\right), im \cdot im, -1\right) \cdot im\right) \cdot re\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0100000000000000002Initial program 56.8%
Taylor expanded in im around 0
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-rgt-outN/A
+-commutativeN/A
Applied rewrites74.1%
Taylor expanded in re around 0
Applied rewrites32.8%
if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 65.7%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.9%
Taylor expanded in re around 0
Applied rewrites64.6%
(FPCore (re im)
:precision binary64
(if (<= re 1e-9)
(*
(* 0.5 re)
(*
(fma
(-
(*
(* (fma -0.0003968253968253968 (* im im) -0.016666666666666666) im)
im)
0.3333333333333333)
(* im im)
-2.0)
im))
(*
(* 0.5 (sin re))
(*
(fma
(- (* -0.016666666666666666 (* im im)) 0.3333333333333333)
(* im im)
-2.0)
im))))
double code(double re, double im) {
double tmp;
if (re <= 1e-9) {
tmp = (0.5 * re) * (fma((((fma(-0.0003968253968253968, (im * im), -0.016666666666666666) * im) * im) - 0.3333333333333333), (im * im), -2.0) * im);
} else {
tmp = (0.5 * sin(re)) * (fma(((-0.016666666666666666 * (im * im)) - 0.3333333333333333), (im * im), -2.0) * im);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= 1e-9) tmp = Float64(Float64(0.5 * re) * Float64(fma(Float64(Float64(Float64(fma(-0.0003968253968253968, Float64(im * im), -0.016666666666666666) * im) * im) - 0.3333333333333333), Float64(im * im), -2.0) * im)); else tmp = Float64(Float64(0.5 * sin(re)) * Float64(fma(Float64(Float64(-0.016666666666666666 * Float64(im * im)) - 0.3333333333333333), Float64(im * im), -2.0) * im)); end return tmp end
code[re_, im_] := If[LessEqual[re, 1e-9], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * N[(im * im), $MachinePrecision] + -0.016666666666666666), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision] + -2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(-0.016666666666666666 * N[(im * im), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision] + -2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 10^{-9}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\mathsf{fma}\left(\left(\mathsf{fma}\left(-0.0003968253968253968, im \cdot im, -0.016666666666666666\right) \cdot im\right) \cdot im - 0.3333333333333333, im \cdot im, -2\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(\mathsf{fma}\left(-0.016666666666666666 \cdot \left(im \cdot im\right) - 0.3333333333333333, im \cdot im, -2\right) \cdot im\right)\\
\end{array}
\end{array}
if re < 1.00000000000000006e-9Initial program 65.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.9%
Applied rewrites93.9%
Taylor expanded in re around 0
lower-*.f6469.4
Applied rewrites69.4%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.4%
if 1.00000000000000006e-9 < re Initial program 57.3%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6482.3
Applied rewrites82.3%
(FPCore (re im)
:precision binary64
(if (<= (* 0.5 (sin re)) -0.01)
(* (* (* (* re im) re) 0.16666666666666666) re)
(*
(*
(fma
(fma (* im im) -0.008333333333333333 -0.16666666666666666)
(* im im)
-1.0)
im)
re)))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.01) {
tmp = (((re * im) * re) * 0.16666666666666666) * re;
} else {
tmp = (fma(fma((im * im), -0.008333333333333333, -0.16666666666666666), (im * im), -1.0) * im) * re;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.01) tmp = Float64(Float64(Float64(Float64(re * im) * re) * 0.16666666666666666) * re); else tmp = Float64(Float64(fma(fma(Float64(im * im), -0.008333333333333333, -0.16666666666666666), Float64(im * im), -1.0) * im) * re); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[(N[(re * im), $MachinePrecision] * re), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] * re), $MachinePrecision], N[(N[(N[(N[(N[(im * im), $MachinePrecision] * -0.008333333333333333 + -0.16666666666666666), $MachinePrecision] * N[(im * im), $MachinePrecision] + -1.0), $MachinePrecision] * im), $MachinePrecision] * re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.01:\\
\;\;\;\;\left(\left(\left(re \cdot im\right) \cdot re\right) \cdot 0.16666666666666666\right) \cdot re\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, -0.008333333333333333, -0.16666666666666666\right), im \cdot im, -1\right) \cdot im\right) \cdot re\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0100000000000000002Initial program 56.8%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f6448.2
Applied rewrites48.2%
Taylor expanded in re around 0
Applied rewrites31.2%
Taylor expanded in re around inf
Applied rewrites30.3%
if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 65.7%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.9%
Taylor expanded in re around 0
Applied rewrites64.6%
(FPCore (re im)
:precision binary64
(if (<= re 1e-9)
(*
(* 0.5 re)
(*
(fma
(-
(*
(* (fma -0.0003968253968253968 (* im im) -0.016666666666666666) im)
im)
0.3333333333333333)
(* im im)
-2.0)
im))
(*
(*
(sin re)
(fma
(* im im)
(fma -0.008333333333333333 (* im im) -0.16666666666666666)
-1.0))
im)))
double code(double re, double im) {
double tmp;
if (re <= 1e-9) {
tmp = (0.5 * re) * (fma((((fma(-0.0003968253968253968, (im * im), -0.016666666666666666) * im) * im) - 0.3333333333333333), (im * im), -2.0) * im);
} else {
tmp = (sin(re) * fma((im * im), fma(-0.008333333333333333, (im * im), -0.16666666666666666), -1.0)) * im;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= 1e-9) tmp = Float64(Float64(0.5 * re) * Float64(fma(Float64(Float64(Float64(fma(-0.0003968253968253968, Float64(im * im), -0.016666666666666666) * im) * im) - 0.3333333333333333), Float64(im * im), -2.0) * im)); else tmp = Float64(Float64(sin(re) * fma(Float64(im * im), fma(-0.008333333333333333, Float64(im * im), -0.16666666666666666), -1.0)) * im); end return tmp end
code[re_, im_] := If[LessEqual[re, 1e-9], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * N[(im * im), $MachinePrecision] + -0.016666666666666666), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision] + -2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[re], $MachinePrecision] * N[(N[(im * im), $MachinePrecision] * N[(-0.008333333333333333 * N[(im * im), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 10^{-9}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\mathsf{fma}\left(\left(\mathsf{fma}\left(-0.0003968253968253968, im \cdot im, -0.016666666666666666\right) \cdot im\right) \cdot im - 0.3333333333333333, im \cdot im, -2\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\sin re \cdot \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(-0.008333333333333333, im \cdot im, -0.16666666666666666\right), -1\right)\right) \cdot im\\
\end{array}
\end{array}
if re < 1.00000000000000006e-9Initial program 65.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.9%
Applied rewrites93.9%
Taylor expanded in re around 0
lower-*.f6469.4
Applied rewrites69.4%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.4%
if 1.00000000000000006e-9 < re Initial program 57.3%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.0%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) -0.01) (* (* (* (* re im) re) 0.16666666666666666) re) (* (* (fma (* im im) -0.16666666666666666 -1.0) im) re)))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.01) {
tmp = (((re * im) * re) * 0.16666666666666666) * re;
} else {
tmp = (fma((im * im), -0.16666666666666666, -1.0) * im) * re;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.01) tmp = Float64(Float64(Float64(Float64(re * im) * re) * 0.16666666666666666) * re); else tmp = Float64(Float64(fma(Float64(im * im), -0.16666666666666666, -1.0) * im) * re); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[(N[(re * im), $MachinePrecision] * re), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] * re), $MachinePrecision], N[(N[(N[(N[(im * im), $MachinePrecision] * -0.16666666666666666 + -1.0), $MachinePrecision] * im), $MachinePrecision] * re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.01:\\
\;\;\;\;\left(\left(\left(re \cdot im\right) \cdot re\right) \cdot 0.16666666666666666\right) \cdot re\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right) \cdot im\right) \cdot re\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0100000000000000002Initial program 56.8%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f6448.2
Applied rewrites48.2%
Taylor expanded in re around 0
Applied rewrites31.2%
Taylor expanded in re around inf
Applied rewrites30.3%
if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 65.7%
Taylor expanded in im around 0
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-rgt-outN/A
+-commutativeN/A
Applied rewrites76.1%
Taylor expanded in re around 0
Applied rewrites58.2%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) -0.01) (* (* (* (* re im) re) 0.16666666666666666) re) (* (* 0.5 re) (* -2.0 im))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.01) {
tmp = (((re * im) * re) * 0.16666666666666666) * re;
} else {
tmp = (0.5 * re) * (-2.0 * 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.01d0)) then
tmp = (((re * im) * re) * 0.16666666666666666d0) * re
else
tmp = (0.5d0 * re) * ((-2.0d0) * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((0.5 * Math.sin(re)) <= -0.01) {
tmp = (((re * im) * re) * 0.16666666666666666) * re;
} else {
tmp = (0.5 * re) * (-2.0 * im);
}
return tmp;
}
def code(re, im): tmp = 0 if (0.5 * math.sin(re)) <= -0.01: tmp = (((re * im) * re) * 0.16666666666666666) * re else: tmp = (0.5 * re) * (-2.0 * im) return tmp
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.01) tmp = Float64(Float64(Float64(Float64(re * im) * re) * 0.16666666666666666) * re); else tmp = Float64(Float64(0.5 * re) * Float64(-2.0 * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((0.5 * sin(re)) <= -0.01) tmp = (((re * im) * re) * 0.16666666666666666) * re; else tmp = (0.5 * re) * (-2.0 * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[(N[(re * im), $MachinePrecision] * re), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] * re), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.01:\\
\;\;\;\;\left(\left(\left(re \cdot im\right) \cdot re\right) \cdot 0.16666666666666666\right) \cdot re\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(-2 \cdot im\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0100000000000000002Initial program 56.8%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f6448.2
Applied rewrites48.2%
Taylor expanded in re around 0
Applied rewrites31.2%
Taylor expanded in re around inf
Applied rewrites30.3%
if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 65.7%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.1%
Applied rewrites93.1%
Taylor expanded in re around 0
lower-*.f6468.5
Applied rewrites68.5%
Taylor expanded in im around 0
lower-*.f6438.0
Applied rewrites38.0%
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sin re)) -0.01) (* (* (* 0.16666666666666666 im) (* re re)) re) (* (* 0.5 re) (* -2.0 im))))
double code(double re, double im) {
double tmp;
if ((0.5 * sin(re)) <= -0.01) {
tmp = ((0.16666666666666666 * im) * (re * re)) * re;
} else {
tmp = (0.5 * re) * (-2.0 * 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.01d0)) then
tmp = ((0.16666666666666666d0 * im) * (re * re)) * re
else
tmp = (0.5d0 * re) * ((-2.0d0) * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((0.5 * Math.sin(re)) <= -0.01) {
tmp = ((0.16666666666666666 * im) * (re * re)) * re;
} else {
tmp = (0.5 * re) * (-2.0 * im);
}
return tmp;
}
def code(re, im): tmp = 0 if (0.5 * math.sin(re)) <= -0.01: tmp = ((0.16666666666666666 * im) * (re * re)) * re else: tmp = (0.5 * re) * (-2.0 * im) return tmp
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(re)) <= -0.01) tmp = Float64(Float64(Float64(0.16666666666666666 * im) * Float64(re * re)) * re); else tmp = Float64(Float64(0.5 * re) * Float64(-2.0 * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((0.5 * sin(re)) <= -0.01) tmp = ((0.16666666666666666 * im) * (re * re)) * re; else tmp = (0.5 * re) * (-2.0 * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(N[(0.16666666666666666 * im), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision] * re), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re \leq -0.01:\\
\;\;\;\;\left(\left(0.16666666666666666 \cdot im\right) \cdot \left(re \cdot re\right)\right) \cdot re\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(-2 \cdot im\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0100000000000000002Initial program 56.8%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f6448.2
Applied rewrites48.2%
Taylor expanded in re around 0
Applied rewrites31.2%
Taylor expanded in re around inf
Applied rewrites30.3%
Applied rewrites30.3%
if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 65.7%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites93.1%
Applied rewrites93.1%
Taylor expanded in re around 0
lower-*.f6468.5
Applied rewrites68.5%
Taylor expanded in im around 0
lower-*.f6438.0
Applied rewrites38.0%
(FPCore (re im)
:precision binary64
(if (<= re 0.0064)
(*
(* 0.5 re)
(*
(fma
(-
(*
(* (fma -0.0003968253968253968 (* im im) -0.016666666666666666) im)
im)
0.3333333333333333)
(* im im)
-2.0)
im))
(* (* (sin re) im) (fma (* -0.16666666666666666 im) im -1.0))))
double code(double re, double im) {
double tmp;
if (re <= 0.0064) {
tmp = (0.5 * re) * (fma((((fma(-0.0003968253968253968, (im * im), -0.016666666666666666) * im) * im) - 0.3333333333333333), (im * im), -2.0) * im);
} else {
tmp = (sin(re) * im) * fma((-0.16666666666666666 * im), im, -1.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= 0.0064) tmp = Float64(Float64(0.5 * re) * Float64(fma(Float64(Float64(Float64(fma(-0.0003968253968253968, Float64(im * im), -0.016666666666666666) * im) * im) - 0.3333333333333333), Float64(im * im), -2.0) * im)); else tmp = Float64(Float64(sin(re) * im) * fma(Float64(-0.16666666666666666 * im), im, -1.0)); end return tmp end
code[re_, im_] := If[LessEqual[re, 0.0064], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * N[(im * im), $MachinePrecision] + -0.016666666666666666), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision] + -2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[re], $MachinePrecision] * im), $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 0.0064:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\mathsf{fma}\left(\left(\mathsf{fma}\left(-0.0003968253968253968, im \cdot im, -0.016666666666666666\right) \cdot im\right) \cdot im - 0.3333333333333333, im \cdot im, -2\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\sin re \cdot im\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\\
\end{array}
\end{array}
if re < 0.00640000000000000031Initial program 65.6%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites94.0%
Applied rewrites94.0%
Taylor expanded in re around 0
lower-*.f6469.5
Applied rewrites69.5%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.5%
if 0.00640000000000000031 < re Initial program 57.4%
Taylor expanded in im around 0
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-rgt-outN/A
+-commutativeN/A
Applied rewrites75.5%
(FPCore (re im)
:precision binary64
(if (<= im -5e+233)
(*
(* (fma (* (* im re) re) -0.16666666666666666 im) re)
(fma (* -0.16666666666666666 im) im -1.0))
(if (or (<= im -5e+21) (not (<= im 430.0)))
(*
(* 0.5 re)
(*
(fma
(-
(*
(* (fma -0.0003968253968253968 (* im im) -0.016666666666666666) im)
im)
0.3333333333333333)
(* im im)
-2.0)
im))
(* (- (sin re)) im))))
double code(double re, double im) {
double tmp;
if (im <= -5e+233) {
tmp = (fma(((im * re) * re), -0.16666666666666666, im) * re) * fma((-0.16666666666666666 * im), im, -1.0);
} else if ((im <= -5e+21) || !(im <= 430.0)) {
tmp = (0.5 * re) * (fma((((fma(-0.0003968253968253968, (im * im), -0.016666666666666666) * im) * im) - 0.3333333333333333), (im * im), -2.0) * im);
} else {
tmp = -sin(re) * im;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= -5e+233) tmp = Float64(Float64(fma(Float64(Float64(im * re) * re), -0.16666666666666666, im) * re) * fma(Float64(-0.16666666666666666 * im), im, -1.0)); elseif ((im <= -5e+21) || !(im <= 430.0)) tmp = Float64(Float64(0.5 * re) * Float64(fma(Float64(Float64(Float64(fma(-0.0003968253968253968, Float64(im * im), -0.016666666666666666) * im) * im) - 0.3333333333333333), Float64(im * im), -2.0) * im)); else tmp = Float64(Float64(-sin(re)) * im); end return tmp end
code[re_, im_] := If[LessEqual[im, -5e+233], N[(N[(N[(N[(N[(im * re), $MachinePrecision] * re), $MachinePrecision] * -0.16666666666666666 + im), $MachinePrecision] * re), $MachinePrecision] * N[(N[(-0.16666666666666666 * im), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, -5e+21], N[Not[LessEqual[im, 430.0]], $MachinePrecision]], N[(N[(0.5 * re), $MachinePrecision] * N[(N[(N[(N[(N[(N[(-0.0003968253968253968 * N[(im * im), $MachinePrecision] + -0.016666666666666666), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(im * im), $MachinePrecision] + -2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision], N[((-N[Sin[re], $MachinePrecision]) * im), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -5 \cdot 10^{+233}:\\
\;\;\;\;\left(\mathsf{fma}\left(\left(im \cdot re\right) \cdot re, -0.16666666666666666, im\right) \cdot re\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot im, im, -1\right)\\
\mathbf{elif}\;im \leq -5 \cdot 10^{+21} \lor \neg \left(im \leq 430\right):\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(\mathsf{fma}\left(\left(\mathsf{fma}\left(-0.0003968253968253968, im \cdot im, -0.016666666666666666\right) \cdot im\right) \cdot im - 0.3333333333333333, im \cdot im, -2\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-\sin re\right) \cdot im\\
\end{array}
\end{array}
if im < -5.00000000000000009e233Initial program 100.0%
Taylor expanded in im around 0
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-rgt-outN/A
+-commutativeN/A
Applied rewrites100.0%
Taylor expanded in re around 0
Applied rewrites75.0%
if -5.00000000000000009e233 < im < -5e21 or 430 < im Initial program 100.0%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites84.9%
Applied rewrites84.9%
Taylor expanded in re around 0
lower-*.f6471.4
Applied rewrites71.4%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites71.4%
if -5e21 < im < 430Initial program 27.8%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f6496.5
Applied rewrites96.5%
Final simplification84.4%
(FPCore (re im) :precision binary64 (* (* 0.5 re) (* -2.0 im)))
double code(double re, double im) {
return (0.5 * re) * (-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 * re) * ((-2.0d0) * im)
end function
public static double code(double re, double im) {
return (0.5 * re) * (-2.0 * im);
}
def code(re, im): return (0.5 * re) * (-2.0 * im)
function code(re, im) return Float64(Float64(0.5 * re) * Float64(-2.0 * im)) end
function tmp = code(re, im) tmp = (0.5 * re) * (-2.0 * im); end
code[re_, im_] := N[(N[(0.5 * re), $MachinePrecision] * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot re\right) \cdot \left(-2 \cdot im\right)
\end{array}
Initial program 63.6%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.1%
Applied rewrites92.1%
Taylor expanded in re around 0
lower-*.f6458.7
Applied rewrites58.7%
Taylor expanded in im around 0
lower-*.f6432.4
Applied rewrites32.4%
(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 63.6%
Taylor expanded in im around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f6450.8
Applied rewrites50.8%
Taylor expanded in re around 0
Applied rewrites32.0%
(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 2024357
(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))))