
(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 10 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.5%
/-rgt-identity50.5%
exp-050.5%
associate-*l/50.5%
cos-neg50.5%
associate-*l*50.5%
associate-*r/50.5%
exp-050.5%
/-rgt-identity50.5%
*-commutative50.5%
neg-sub050.5%
cos-neg50.5%
Simplified50.5%
Taylor expanded in im around 0 55.4%
log1p-expm1-u99.0%
*-commutative99.0%
associate-*l*99.0%
Applied egg-rr99.0%
Final simplification99.0%
(FPCore (re im) :precision binary64 (if (<= (cos re) 0.992) (* 0.5 (* (cos re) (* im (- (* -0.016666666666666666 (pow im 4.0)) 2.0)))) (* 0.5 (log1p (expm1 (* im -2.0))))))
double code(double re, double im) {
double tmp;
if (cos(re) <= 0.992) {
tmp = 0.5 * (cos(re) * (im * ((-0.016666666666666666 * pow(im, 4.0)) - 2.0)));
} else {
tmp = 0.5 * log1p(expm1((im * -2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.cos(re) <= 0.992) {
tmp = 0.5 * (Math.cos(re) * (im * ((-0.016666666666666666 * Math.pow(im, 4.0)) - 2.0)));
} else {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= 0.992: tmp = 0.5 * (math.cos(re) * (im * ((-0.016666666666666666 * math.pow(im, 4.0)) - 2.0))) else: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= 0.992) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * Float64(Float64(-0.016666666666666666 * (im ^ 4.0)) - 2.0)))); else tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); end return tmp end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], 0.992], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * N[(N[(-0.016666666666666666 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.992:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.016666666666666666 \cdot {im}^{4} - 2\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\end{array}
\end{array}
if (cos.f64 re) < 0.99199999999999999Initial program 51.4%
/-rgt-identity51.4%
exp-051.4%
associate-*l/51.4%
cos-neg51.4%
associate-*l*51.4%
associate-*r/51.4%
exp-051.4%
/-rgt-identity51.4%
*-commutative51.4%
neg-sub051.4%
cos-neg51.4%
Simplified51.4%
Taylor expanded in im around 0 91.4%
Taylor expanded in im around inf 91.0%
if 0.99199999999999999 < (cos.f64 re) Initial program 49.5%
/-rgt-identity49.5%
exp-049.5%
associate-*l/49.5%
cos-neg49.5%
associate-*l*49.5%
associate-*r/49.5%
exp-049.5%
/-rgt-identity49.5%
*-commutative49.5%
neg-sub049.5%
cos-neg49.5%
Simplified49.5%
Taylor expanded in im around 0 56.7%
log1p-expm1-u98.6%
*-commutative98.6%
associate-*l*98.6%
Applied egg-rr98.6%
Taylor expanded in re around 0 48.2%
expm1-define98.6%
Simplified98.6%
Final simplification94.9%
(FPCore (re im)
:precision binary64
(if (<= im 8000.0)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 4.4e+61)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* 0.5 (* -0.016666666666666666 (* (cos re) (pow im 5.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 4.4e+61) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = 0.5 * (-0.016666666666666666 * (cos(re) * pow(im, 5.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 4.4e+61) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = 0.5 * (-0.016666666666666666 * (Math.cos(re) * Math.pow(im, 5.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 8000.0: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 4.4e+61: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = 0.5 * (-0.016666666666666666 * (math.cos(re) * math.pow(im, 5.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 8000.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 4.4e+61) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(0.5 * Float64(-0.016666666666666666 * Float64(cos(re) * (im ^ 5.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 8000.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4.4e+61], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-0.016666666666666666 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8000:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 4.4 \cdot 10^{+61}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(-0.016666666666666666 \cdot \left(\cos re \cdot {im}^{5}\right)\right)\\
\end{array}
\end{array}
if im < 8e3Initial 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 69.3%
if 8e3 < im < 4.4000000000000001e61Initial 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 3.4%
log1p-expm1-u100.0%
*-commutative100.0%
associate-*l*100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 63.6%
expm1-define63.6%
Simplified63.6%
if 4.4000000000000001e61 < 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 100.0%
Taylor expanded in im around inf 100.0%
Final simplification74.5%
(FPCore (re im)
:precision binary64
(if (<= im 8000.0)
(* 0.5 (* (cos re) (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0))))
(if (<= im 4.4e+61)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* 0.5 (* -0.016666666666666666 (* (cos re) (pow im 5.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = 0.5 * (cos(re) * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0)));
} else if (im <= 4.4e+61) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = 0.5 * (-0.016666666666666666 * (cos(re) * pow(im, 5.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = 0.5 * (Math.cos(re) * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0)));
} else if (im <= 4.4e+61) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = 0.5 * (-0.016666666666666666 * (Math.cos(re) * Math.pow(im, 5.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 8000.0: tmp = 0.5 * (math.cos(re) * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0))) elif im <= 4.4e+61: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = 0.5 * (-0.016666666666666666 * (math.cos(re) * math.pow(im, 5.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 8000.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0)))); elseif (im <= 4.4e+61) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(0.5 * Float64(-0.016666666666666666 * Float64(cos(re) * (im ^ 5.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 8000.0], 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], If[LessEqual[im, 4.4e+61], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-0.016666666666666666 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8000:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\
\mathbf{elif}\;im \leq 4.4 \cdot 10^{+61}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(-0.016666666666666666 \cdot \left(\cos re \cdot {im}^{5}\right)\right)\\
\end{array}
\end{array}
if im < 8e3Initial 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 86.7%
if 8e3 < im < 4.4000000000000001e61Initial 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 3.4%
log1p-expm1-u100.0%
*-commutative100.0%
associate-*l*100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 63.6%
expm1-define63.6%
Simplified63.6%
if 4.4000000000000001e61 < 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 100.0%
Taylor expanded in im around inf 100.0%
Final simplification88.0%
(FPCore (re im) :precision binary64 (if (<= (cos re) -0.06) (* 0.5 (* im (pow re 2.0))) (* 0.5 (* im -2.0))))
double code(double re, double im) {
double tmp;
if (cos(re) <= -0.06) {
tmp = 0.5 * (im * pow(re, 2.0));
} else {
tmp = 0.5 * (im * -2.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (cos(re) <= (-0.06d0)) then
tmp = 0.5d0 * (im * (re ** 2.0d0))
else
tmp = 0.5d0 * (im * (-2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.cos(re) <= -0.06) {
tmp = 0.5 * (im * Math.pow(re, 2.0));
} else {
tmp = 0.5 * (im * -2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= -0.06: tmp = 0.5 * (im * math.pow(re, 2.0)) else: tmp = 0.5 * (im * -2.0) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= -0.06) tmp = Float64(0.5 * Float64(im * (re ^ 2.0))); else tmp = Float64(0.5 * Float64(im * -2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (cos(re) <= -0.06) tmp = 0.5 * (im * (re ^ 2.0)); else tmp = 0.5 * (im * -2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], -0.06], N[(0.5 * N[(im * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq -0.06:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{2}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\end{array}
\end{array}
if (cos.f64 re) < -0.059999999999999998Initial program 57.0%
/-rgt-identity57.0%
exp-057.0%
associate-*l/57.0%
cos-neg57.0%
associate-*l*57.0%
associate-*r/57.0%
exp-057.0%
/-rgt-identity57.0%
*-commutative57.0%
neg-sub057.0%
cos-neg57.0%
Simplified57.0%
Taylor expanded in im around 0 48.7%
Taylor expanded in re around 0 40.3%
+-commutative40.3%
*-commutative40.3%
distribute-lft-out40.3%
Simplified40.3%
Taylor expanded in re around inf 40.3%
if -0.059999999999999998 < (cos.f64 re) Initial program 48.3%
/-rgt-identity48.3%
exp-048.3%
associate-*l/48.3%
cos-neg48.3%
associate-*l*48.3%
associate-*r/48.3%
exp-048.3%
/-rgt-identity48.3%
*-commutative48.3%
neg-sub048.3%
cos-neg48.3%
Simplified48.3%
Taylor expanded in im around 0 57.6%
log1p-expm1-u99.0%
*-commutative99.0%
associate-*l*99.0%
Applied egg-rr99.0%
Taylor expanded in re around 0 43.0%
Final simplification42.3%
(FPCore (re im) :precision binary64 (if (<= im 8000.0) (* 0.5 (* (cos re) (* im -2.0))) (* 0.5 (log1p (expm1 (* im -2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = 0.5 * log1p(expm1((im * -2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 8000.0: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 8000.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 8000.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8000:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\end{array}
\end{array}
if im < 8e3Initial 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 69.3%
if 8e3 < 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.4%
log1p-expm1-u100.0%
*-commutative100.0%
associate-*l*100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 66.1%
expm1-define66.1%
Simplified66.1%
Final simplification68.6%
(FPCore (re im)
:precision binary64
(if (<= im 1.85)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 1e+61)
(* 0.5 (* im (+ -2.0 (* re re))))
(* 0.5 (* im (- (* -0.016666666666666666 (pow im 4.0)) 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 1.85) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 1e+61) {
tmp = 0.5 * (im * (-2.0 + (re * re)));
} else {
tmp = 0.5 * (im * ((-0.016666666666666666 * pow(im, 4.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 <= 1.85d0) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else if (im <= 1d+61) then
tmp = 0.5d0 * (im * ((-2.0d0) + (re * re)))
else
tmp = 0.5d0 * (im * (((-0.016666666666666666d0) * (im ** 4.0d0)) - 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.85) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 1e+61) {
tmp = 0.5 * (im * (-2.0 + (re * re)));
} else {
tmp = 0.5 * (im * ((-0.016666666666666666 * Math.pow(im, 4.0)) - 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.85: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 1e+61: tmp = 0.5 * (im * (-2.0 + (re * re))) else: tmp = 0.5 * (im * ((-0.016666666666666666 * math.pow(im, 4.0)) - 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.85) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 1e+61) tmp = Float64(0.5 * Float64(im * Float64(-2.0 + Float64(re * re)))); else tmp = Float64(0.5 * Float64(im * Float64(Float64(-0.016666666666666666 * (im ^ 4.0)) - 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.85) tmp = 0.5 * (cos(re) * (im * -2.0)); elseif (im <= 1e+61) tmp = 0.5 * (im * (-2.0 + (re * re))); else tmp = 0.5 * (im * ((-0.016666666666666666 * (im ^ 4.0)) - 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.85], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1e+61], N[(0.5 * N[(im * N[(-2.0 + N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(N[(-0.016666666666666666 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.85:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 10^{+61}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-2 + re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-0.016666666666666666 \cdot {im}^{4} - 2\right)\right)\\
\end{array}
\end{array}
if im < 1.8500000000000001Initial program 36.0%
/-rgt-identity36.0%
exp-036.0%
associate-*l/36.0%
cos-neg36.0%
associate-*l*36.0%
associate-*r/36.0%
exp-036.0%
/-rgt-identity36.0%
*-commutative36.0%
neg-sub036.0%
cos-neg36.0%
Simplified36.0%
Taylor expanded in im around 0 69.9%
if 1.8500000000000001 < im < 9.99999999999999949e60Initial 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.0%
Taylor expanded in re around 0 36.7%
+-commutative36.7%
*-commutative36.7%
distribute-lft-out36.7%
Simplified36.7%
unpow236.7%
Applied egg-rr36.7%
if 9.99999999999999949e60 < 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 98.1%
Taylor expanded in im around inf 98.1%
Taylor expanded in re around 0 65.5%
Final simplification67.6%
(FPCore (re im) :precision binary64 (if (<= (cos re) -0.06) (* 0.5 (* im (+ -2.0 (* re re)))) (* 0.5 (* im -2.0))))
double code(double re, double im) {
double tmp;
if (cos(re) <= -0.06) {
tmp = 0.5 * (im * (-2.0 + (re * re)));
} else {
tmp = 0.5 * (im * -2.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (cos(re) <= (-0.06d0)) then
tmp = 0.5d0 * (im * ((-2.0d0) + (re * re)))
else
tmp = 0.5d0 * (im * (-2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.cos(re) <= -0.06) {
tmp = 0.5 * (im * (-2.0 + (re * re)));
} else {
tmp = 0.5 * (im * -2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= -0.06: tmp = 0.5 * (im * (-2.0 + (re * re))) else: tmp = 0.5 * (im * -2.0) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= -0.06) tmp = Float64(0.5 * Float64(im * Float64(-2.0 + Float64(re * re)))); else tmp = Float64(0.5 * Float64(im * -2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (cos(re) <= -0.06) tmp = 0.5 * (im * (-2.0 + (re * re))); else tmp = 0.5 * (im * -2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], -0.06], N[(0.5 * N[(im * N[(-2.0 + N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq -0.06:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-2 + re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\end{array}
\end{array}
if (cos.f64 re) < -0.059999999999999998Initial program 57.0%
/-rgt-identity57.0%
exp-057.0%
associate-*l/57.0%
cos-neg57.0%
associate-*l*57.0%
associate-*r/57.0%
exp-057.0%
/-rgt-identity57.0%
*-commutative57.0%
neg-sub057.0%
cos-neg57.0%
Simplified57.0%
Taylor expanded in im around 0 48.7%
Taylor expanded in re around 0 40.3%
+-commutative40.3%
*-commutative40.3%
distribute-lft-out40.3%
Simplified40.3%
unpow240.3%
Applied egg-rr40.3%
if -0.059999999999999998 < (cos.f64 re) Initial program 48.3%
/-rgt-identity48.3%
exp-048.3%
associate-*l/48.3%
cos-neg48.3%
associate-*l*48.3%
associate-*r/48.3%
exp-048.3%
/-rgt-identity48.3%
*-commutative48.3%
neg-sub048.3%
cos-neg48.3%
Simplified48.3%
Taylor expanded in im around 0 57.6%
log1p-expm1-u99.0%
*-commutative99.0%
associate-*l*99.0%
Applied egg-rr99.0%
Taylor expanded in re around 0 43.0%
Final simplification42.3%
(FPCore (re im) :precision binary64 (if (<= im 1.85) (* 0.5 (* (cos re) (* im -2.0))) (* 0.5 (* im (+ -2.0 (* re re))))))
double code(double re, double im) {
double tmp;
if (im <= 1.85) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = 0.5 * (im * (-2.0 + (re * re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.85d0) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else
tmp = 0.5d0 * (im * ((-2.0d0) + (re * re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.85) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = 0.5 * (im * (-2.0 + (re * re)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.85: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = 0.5 * (im * (-2.0 + (re * re))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.85) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64(0.5 * Float64(im * Float64(-2.0 + Float64(re * re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.85) tmp = 0.5 * (cos(re) * (im * -2.0)); else tmp = 0.5 * (im * (-2.0 + (re * re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.85], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(-2.0 + N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.85:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-2 + re \cdot re\right)\right)\\
\end{array}
\end{array}
if im < 1.8500000000000001Initial program 36.0%
/-rgt-identity36.0%
exp-036.0%
associate-*l/36.0%
cos-neg36.0%
associate-*l*36.0%
associate-*r/36.0%
exp-036.0%
/-rgt-identity36.0%
*-commutative36.0%
neg-sub036.0%
cos-neg36.0%
Simplified36.0%
Taylor expanded in im around 0 69.9%
if 1.8500000000000001 < 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.7%
Taylor expanded in re around 0 26.0%
+-commutative26.0%
*-commutative26.0%
distribute-lft-out26.0%
Simplified26.0%
unpow226.0%
Applied egg-rr26.0%
Final simplification60.0%
(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.5%
/-rgt-identity50.5%
exp-050.5%
associate-*l/50.5%
cos-neg50.5%
associate-*l*50.5%
associate-*r/50.5%
exp-050.5%
/-rgt-identity50.5%
*-commutative50.5%
neg-sub050.5%
cos-neg50.5%
Simplified50.5%
Taylor expanded in im around 0 55.4%
log1p-expm1-u99.0%
*-commutative99.0%
associate-*l*99.0%
Applied egg-rr99.0%
Taylor expanded in re around 0 32.8%
Final simplification32.8%
(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 2024110
(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))))