
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* 0.5 (log1p (expm1 (* im (* -2.0 (cos re)))))))
double code(double re, double im) {
return 0.5 * log1p(expm1((im * (-2.0 * cos(re)))));
}
public static double code(double re, double im) {
return 0.5 * Math.log1p(Math.expm1((im * (-2.0 * Math.cos(re)))));
}
def code(re, im): return 0.5 * math.log1p(math.expm1((im * (-2.0 * math.cos(re)))))
function code(re, im) return Float64(0.5 * log1p(expm1(Float64(im * Float64(-2.0 * cos(re)))))) end
code[re_, im_] := N[(0.5 * N[Log[1 + N[(Exp[N[(im * N[(-2.0 * N[Cos[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot \left(-2 \cdot \cos re\right)\right)\right)
\end{array}
Initial program 50.4%
/-rgt-identity50.4%
exp-050.4%
associate-*l/50.4%
cos-neg50.4%
associate-*l*50.4%
associate-*r/50.4%
exp-050.4%
/-rgt-identity50.4%
*-commutative50.4%
neg-sub050.4%
cos-neg50.4%
Simplified50.4%
Taylor expanded in im around 0 56.3%
log1p-expm1-u98.9%
*-commutative98.9%
associate-*l*98.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (re im) :precision binary64 (if (<= im 5.5e-7) (* 0.5 (* (cos re) (* im -2.0))) (* 0.5 (fma im -2.0 (* -0.3333333333333333 (pow im 3.0))))))
double code(double re, double im) {
double tmp;
if (im <= 5.5e-7) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = 0.5 * fma(im, -2.0, (-0.3333333333333333 * pow(im, 3.0)));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 5.5e-7) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64(0.5 * fma(im, -2.0, Float64(-0.3333333333333333 * (im ^ 3.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 5.5e-7], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * -2.0 + N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5.5 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, -2, -0.3333333333333333 \cdot {im}^{3}\right)\\
\end{array}
\end{array}
if im < 5.5000000000000003e-7Initial program 36.6%
/-rgt-identity36.6%
exp-036.6%
associate-*l/36.6%
cos-neg36.6%
associate-*l*36.6%
associate-*r/36.6%
exp-036.6%
/-rgt-identity36.6%
*-commutative36.6%
neg-sub036.6%
cos-neg36.6%
Simplified36.6%
Taylor expanded in im around 0 70.0%
if 5.5000000000000003e-7 < im Initial program 99.5%
/-rgt-identity99.5%
exp-099.5%
associate-*l/99.5%
cos-neg99.5%
associate-*l*99.5%
associate-*r/99.5%
exp-099.5%
/-rgt-identity99.5%
*-commutative99.5%
neg-sub099.5%
cos-neg99.5%
Simplified99.5%
Taylor expanded in im around 0 61.8%
Taylor expanded in re around 0 50.4%
sub-neg50.4%
*-commutative50.4%
metadata-eval50.4%
+-commutative50.4%
distribute-lft-out50.4%
fma-define50.4%
associate-*r*50.4%
unpow250.4%
cube-mult50.4%
*-commutative50.4%
Simplified50.4%
Final simplification65.7%
(FPCore (re im) :precision binary64 (* 0.5 (* (cos re) (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0)))))
double code(double re, double im) {
return 0.5 * (cos(re) * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (cos(re) * (im * (((-0.3333333333333333d0) * (im ** 2.0d0)) - 2.0d0)))
end function
public static double code(double re, double im) {
return 0.5 * (Math.cos(re) * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0)));
}
def code(re, im): return 0.5 * (math.cos(re) * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0)))
function code(re, im) return Float64(0.5 * Float64(cos(re) * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0)))) end
function tmp = code(re, im) tmp = 0.5 * (cos(re) * (im * ((-0.3333333333333333 * (im ^ 2.0)) - 2.0))); end
code[re_, im_] := N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * N[(N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)
\end{array}
Initial program 50.4%
/-rgt-identity50.4%
exp-050.4%
associate-*l/50.4%
cos-neg50.4%
associate-*l*50.4%
associate-*r/50.4%
exp-050.4%
/-rgt-identity50.4%
*-commutative50.4%
neg-sub050.4%
cos-neg50.4%
Simplified50.4%
Taylor expanded in im around 0 83.7%
Final simplification83.7%
(FPCore (re im) :precision binary64 (if (<= im 5.8e+36) (* 0.5 (* (cos re) (* im -2.0))) (sqrt (* 6.944444444444444e-5 (pow im 10.0)))))
double code(double re, double im) {
double tmp;
if (im <= 5.8e+36) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = sqrt((6.944444444444444e-5 * pow(im, 10.0)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 5.8d+36) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else
tmp = sqrt((6.944444444444444d-5 * (im ** 10.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 5.8e+36) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = Math.sqrt((6.944444444444444e-5 * Math.pow(im, 10.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 5.8e+36: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = math.sqrt((6.944444444444444e-5 * math.pow(im, 10.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 5.8e+36) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = sqrt(Float64(6.944444444444444e-5 * (im ^ 10.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 5.8e+36) tmp = 0.5 * (cos(re) * (im * -2.0)); else tmp = sqrt((6.944444444444444e-5 * (im ^ 10.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 5.8e+36], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(6.944444444444444e-5 * N[Power[im, 10.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5.8 \cdot 10^{+36}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{6.944444444444444 \cdot 10^{-5} \cdot {im}^{10}}\\
\end{array}
\end{array}
if im < 5.8e36Initial program 38.9%
/-rgt-identity38.9%
exp-038.9%
associate-*l/38.9%
cos-neg38.9%
associate-*l*38.9%
associate-*r/38.9%
exp-038.9%
/-rgt-identity38.9%
*-commutative38.9%
neg-sub038.9%
cos-neg38.9%
Simplified38.9%
Taylor expanded in im around 0 68.0%
if 5.8e36 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 92.2%
distribute-lft-in92.2%
+-commutative92.2%
associate-*r*92.2%
*-commutative92.2%
fma-undefine92.2%
Simplified92.2%
Taylor expanded in im around inf 92.2%
associate-*r*92.2%
*-commutative92.2%
Simplified92.2%
Taylor expanded in re around 0 69.2%
add-sqr-sqrt0.0%
sqrt-unprod25.0%
associate-*r*25.0%
associate-*r*25.0%
swap-sqr25.0%
metadata-eval25.0%
metadata-eval25.0%
metadata-eval25.0%
pow-prod-up25.0%
metadata-eval25.0%
Applied egg-rr25.0%
Final simplification60.0%
(FPCore (re im) :precision binary64 (* 0.5 (log1p (expm1 (* im -2.0)))))
double code(double re, double im) {
return 0.5 * log1p(expm1((im * -2.0)));
}
public static double code(double re, double im) {
return 0.5 * Math.log1p(Math.expm1((im * -2.0)));
}
def code(re, im): return 0.5 * math.log1p(math.expm1((im * -2.0)))
function code(re, im) return Float64(0.5 * log1p(expm1(Float64(im * -2.0)))) end
code[re_, im_] := N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)
\end{array}
Initial program 50.4%
/-rgt-identity50.4%
exp-050.4%
associate-*l/50.4%
cos-neg50.4%
associate-*l*50.4%
associate-*r/50.4%
exp-050.4%
/-rgt-identity50.4%
*-commutative50.4%
neg-sub050.4%
cos-neg50.4%
Simplified50.4%
Taylor expanded in im around 0 56.3%
log1p-expm1-u98.9%
*-commutative98.9%
associate-*l*98.9%
Applied egg-rr98.9%
Taylor expanded in re around 0 66.5%
Final simplification66.5%
(FPCore (re im) :precision binary64 (if (<= im 5.5e-7) (* 0.5 (* (cos re) (* im -2.0))) (* 0.5 (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 5.5e-7) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = 0.5 * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 5.5d-7) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else
tmp = 0.5d0 * (im * (((-0.3333333333333333d0) * (im ** 2.0d0)) - 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 5.5e-7) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = 0.5 * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 5.5e-7: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = 0.5 * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 5.5e-7) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64(0.5 * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 5.5e-7) tmp = 0.5 * (cos(re) * (im * -2.0)); else tmp = 0.5 * (im * ((-0.3333333333333333 * (im ^ 2.0)) - 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 5.5e-7], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5.5 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\\
\end{array}
\end{array}
if im < 5.5000000000000003e-7Initial program 36.6%
/-rgt-identity36.6%
exp-036.6%
associate-*l/36.6%
cos-neg36.6%
associate-*l*36.6%
associate-*r/36.6%
exp-036.6%
/-rgt-identity36.6%
*-commutative36.6%
neg-sub036.6%
cos-neg36.6%
Simplified36.6%
Taylor expanded in im around 0 70.0%
if 5.5000000000000003e-7 < im Initial program 99.5%
/-rgt-identity99.5%
exp-099.5%
associate-*l/99.5%
cos-neg99.5%
associate-*l*99.5%
associate-*r/99.5%
exp-099.5%
/-rgt-identity99.5%
*-commutative99.5%
neg-sub099.5%
cos-neg99.5%
Simplified99.5%
Taylor expanded in im around 0 61.8%
Taylor expanded in re around 0 50.4%
Final simplification65.7%
(FPCore (re im) :precision binary64 (if (<= im 1.22e+17) (* 0.5 (* (cos re) (* im -2.0))) (* 0.5 (* im (+ -2.0 (pow re 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 1.22e+17) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = 0.5 * (im * (-2.0 + pow(re, 2.0)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.22d+17) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else
tmp = 0.5d0 * (im * ((-2.0d0) + (re ** 2.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.22e+17) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = 0.5 * (im * (-2.0 + Math.pow(re, 2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.22e+17: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = 0.5 * (im * (-2.0 + math.pow(re, 2.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.22e+17) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64(0.5 * Float64(im * Float64(-2.0 + (re ^ 2.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.22e+17) tmp = 0.5 * (cos(re) * (im * -2.0)); else tmp = 0.5 * (im * (-2.0 + (re ^ 2.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.22e+17], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(-2.0 + N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.22 \cdot 10^{+17}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-2 + {re}^{2}\right)\right)\\
\end{array}
\end{array}
if im < 1.22e17Initial program 38.0%
/-rgt-identity38.0%
exp-038.0%
associate-*l/38.0%
cos-neg38.0%
associate-*l*38.0%
associate-*r/38.0%
exp-038.0%
/-rgt-identity38.0%
*-commutative38.0%
neg-sub038.0%
cos-neg38.0%
Simplified38.0%
Taylor expanded in im around 0 69.0%
if 1.22e17 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 5.3%
Taylor expanded in re around 0 17.6%
*-commutative17.6%
distribute-lft-out17.6%
Simplified17.6%
Final simplification58.7%
(FPCore (re im) :precision binary64 (if (<= im 720.0) (* 0.5 (* (cos re) (* im -2.0))) (* 0.5 (* (pow re 4.0) (* im -0.08333333333333333)))))
double code(double re, double im) {
double tmp;
if (im <= 720.0) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = 0.5 * (pow(re, 4.0) * (im * -0.08333333333333333));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 720.0d0) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else
tmp = 0.5d0 * ((re ** 4.0d0) * (im * (-0.08333333333333333d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 720.0) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = 0.5 * (Math.pow(re, 4.0) * (im * -0.08333333333333333));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 720.0: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = 0.5 * (math.pow(re, 4.0) * (im * -0.08333333333333333)) return tmp
function code(re, im) tmp = 0.0 if (im <= 720.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64(0.5 * Float64((re ^ 4.0) * Float64(im * -0.08333333333333333))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 720.0) tmp = 0.5 * (cos(re) * (im * -2.0)); else tmp = 0.5 * ((re ^ 4.0) * (im * -0.08333333333333333)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 720.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Power[re, 4.0], $MachinePrecision] * N[(im * -0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 720:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left({re}^{4} \cdot \left(im \cdot -0.08333333333333333\right)\right)\\
\end{array}
\end{array}
if im < 720Initial program 37.4%
/-rgt-identity37.4%
exp-037.4%
associate-*l/37.4%
cos-neg37.4%
associate-*l*37.4%
associate-*r/37.4%
exp-037.4%
/-rgt-identity37.4%
*-commutative37.4%
neg-sub037.4%
cos-neg37.4%
Simplified37.4%
Taylor expanded in im around 0 69.6%
if 720 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 5.3%
Taylor expanded in re around 0 25.8%
distribute-rgt-in6.9%
associate-+r+6.9%
*-commutative6.9%
distribute-lft-out6.9%
associate-*r*6.9%
associate-*l*6.9%
*-commutative6.9%
pow-sqr6.9%
metadata-eval6.9%
Simplified6.9%
Taylor expanded in re around inf 23.9%
*-commutative23.9%
*-commutative23.9%
associate-*r*23.9%
Simplified23.9%
Final simplification60.2%
(FPCore (re im) :precision binary64 (if (<= im 3.15) (* 0.5 (* im -2.0)) (* 0.5 (* -0.016666666666666666 (pow im 5.0)))))
double code(double re, double im) {
double tmp;
if (im <= 3.15) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = 0.5 * (-0.016666666666666666 * pow(im, 5.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 3.15d0) then
tmp = 0.5d0 * (im * (-2.0d0))
else
tmp = 0.5d0 * ((-0.016666666666666666d0) * (im ** 5.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3.15) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = 0.5 * (-0.016666666666666666 * Math.pow(im, 5.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3.15: tmp = 0.5 * (im * -2.0) else: tmp = 0.5 * (-0.016666666666666666 * math.pow(im, 5.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 3.15) tmp = Float64(0.5 * Float64(im * -2.0)); else tmp = Float64(0.5 * Float64(-0.016666666666666666 * (im ^ 5.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3.15) tmp = 0.5 * (im * -2.0); else tmp = 0.5 * (-0.016666666666666666 * (im ^ 5.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3.15], N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-0.016666666666666666 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.15:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(-0.016666666666666666 \cdot {im}^{5}\right)\\
\end{array}
\end{array}
if im < 3.14999999999999991Initial program 37.1%
/-rgt-identity37.1%
exp-037.1%
associate-*l/37.1%
cos-neg37.1%
associate-*l*37.1%
associate-*r/37.1%
exp-037.1%
/-rgt-identity37.1%
*-commutative37.1%
neg-sub037.1%
cos-neg37.1%
Simplified37.1%
Taylor expanded in im around 0 69.9%
Taylor expanded in re around 0 41.5%
*-commutative41.5%
Simplified41.5%
if 3.14999999999999991 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 82.8%
distribute-lft-in82.8%
+-commutative82.8%
associate-*r*82.8%
*-commutative82.8%
fma-undefine82.8%
Simplified82.8%
Taylor expanded in im around inf 82.7%
associate-*r*82.7%
*-commutative82.7%
Simplified82.7%
Taylor expanded in re around 0 62.2%
Final simplification45.8%
(FPCore (re im) :precision binary64 (if (<= im 550.0) (* 0.5 (* im -2.0)) (* (pow re 4.0) (* im -0.041666666666666664))))
double code(double re, double im) {
double tmp;
if (im <= 550.0) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = pow(re, 4.0) * (im * -0.041666666666666664);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 550.0d0) then
tmp = 0.5d0 * (im * (-2.0d0))
else
tmp = (re ** 4.0d0) * (im * (-0.041666666666666664d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 550.0) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = Math.pow(re, 4.0) * (im * -0.041666666666666664);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 550.0: tmp = 0.5 * (im * -2.0) else: tmp = math.pow(re, 4.0) * (im * -0.041666666666666664) return tmp
function code(re, im) tmp = 0.0 if (im <= 550.0) tmp = Float64(0.5 * Float64(im * -2.0)); else tmp = Float64((re ^ 4.0) * Float64(im * -0.041666666666666664)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 550.0) tmp = 0.5 * (im * -2.0); else tmp = (re ^ 4.0) * (im * -0.041666666666666664); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 550.0], N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[Power[re, 4.0], $MachinePrecision] * N[(im * -0.041666666666666664), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 550:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;{re}^{4} \cdot \left(im \cdot -0.041666666666666664\right)\\
\end{array}
\end{array}
if im < 550Initial program 37.4%
/-rgt-identity37.4%
exp-037.4%
associate-*l/37.4%
cos-neg37.4%
associate-*l*37.4%
associate-*r/37.4%
exp-037.4%
/-rgt-identity37.4%
*-commutative37.4%
neg-sub037.4%
cos-neg37.4%
Simplified37.4%
Taylor expanded in im around 0 69.6%
Taylor expanded in re around 0 41.3%
*-commutative41.3%
Simplified41.3%
if 550 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 5.3%
Taylor expanded in re around 0 25.8%
distribute-rgt-in6.9%
associate-+r+6.9%
*-commutative6.9%
distribute-lft-out6.9%
associate-*r*6.9%
associate-*l*6.9%
*-commutative6.9%
pow-sqr6.9%
metadata-eval6.9%
Simplified6.9%
Taylor expanded in re around inf 23.9%
*-commutative23.9%
*-commutative23.9%
associate-*r*23.9%
Simplified23.9%
Taylor expanded in re around 0 23.9%
*-commutative23.9%
*-commutative23.9%
associate-*l*23.9%
Simplified23.9%
Final simplification37.7%
(FPCore (re im) :precision binary64 (* 0.5 (* (cos re) (* im -2.0))))
double code(double re, double im) {
return 0.5 * (cos(re) * (im * -2.0));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (cos(re) * (im * (-2.0d0)))
end function
public static double code(double re, double im) {
return 0.5 * (Math.cos(re) * (im * -2.0));
}
def code(re, im): return 0.5 * (math.cos(re) * (im * -2.0))
function code(re, im) return Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))) end
function tmp = code(re, im) tmp = 0.5 * (cos(re) * (im * -2.0)); end
code[re_, im_] := N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)
\end{array}
Initial program 50.4%
/-rgt-identity50.4%
exp-050.4%
associate-*l/50.4%
cos-neg50.4%
associate-*l*50.4%
associate-*r/50.4%
exp-050.4%
/-rgt-identity50.4%
*-commutative50.4%
neg-sub050.4%
cos-neg50.4%
Simplified50.4%
Taylor expanded in im around 0 56.3%
Final simplification56.3%
(FPCore (re im) :precision binary64 (* 0.5 (* im -2.0)))
double code(double re, double im) {
return 0.5 * (im * -2.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (im * (-2.0d0))
end function
public static double code(double re, double im) {
return 0.5 * (im * -2.0);
}
def code(re, im): return 0.5 * (im * -2.0)
function code(re, im) return Float64(0.5 * Float64(im * -2.0)) end
function tmp = code(re, im) tmp = 0.5 * (im * -2.0); end
code[re_, im_] := N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(im \cdot -2\right)
\end{array}
Initial program 50.4%
/-rgt-identity50.4%
exp-050.4%
associate-*l/50.4%
cos-neg50.4%
associate-*l*50.4%
associate-*r/50.4%
exp-050.4%
/-rgt-identity50.4%
*-commutative50.4%
neg-sub050.4%
cos-neg50.4%
Simplified50.4%
Taylor expanded in im around 0 56.3%
Taylor expanded in re around 0 33.7%
*-commutative33.7%
Simplified33.7%
Final simplification33.7%
(FPCore (re im)
:precision binary64
(if (< (fabs im) 1.0)
(-
(*
(cos re)
(+
(+ im (* (* (* 0.16666666666666666 im) im) im))
(* (* (* (* (* 0.008333333333333333 im) im) im) im) im))))
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (fabs(im) < 1.0) {
tmp = -(cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (abs(im) < 1.0d0) then
tmp = -(cos(re) * ((im + (((0.16666666666666666d0 * im) * im) * im)) + (((((0.008333333333333333d0 * im) * im) * im) * im) * im)))
else
tmp = (0.5d0 * cos(re)) * (exp((0.0d0 - 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.cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if math.fabs(im) < 1.0: tmp = -(math.cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))) else: tmp = (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (abs(im) < 1.0) tmp = Float64(-Float64(cos(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 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (abs(im) < 1.0) tmp = -(cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))); else tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Less[N[Abs[im], $MachinePrecision], 1.0], (-N[(N[Cos[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[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|im\right| < 1:\\
\;\;\;\;-\cos 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 \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\end{array}
\end{array}
herbie shell --seed 2024066
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
:alt
(if (< (fabs im) 1.0) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))