
(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 9 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 (* im (log (pow (exp (cos re)) (fma -0.3333333333333333 (pow im 2.0) -2.0))))))
double code(double re, double im) {
return 0.5 * (im * log(pow(exp(cos(re)), fma(-0.3333333333333333, pow(im, 2.0), -2.0))));
}
function code(re, im) return Float64(0.5 * Float64(im * log((exp(cos(re)) ^ fma(-0.3333333333333333, (im ^ 2.0), -2.0))))) end
code[re_, im_] := N[(0.5 * N[(im * N[Log[N[Power[N[Exp[N[Cos[re], $MachinePrecision]], $MachinePrecision], N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision] + -2.0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(im \cdot \log \left({\left(e^{\cos re}\right)}^{\left(\mathsf{fma}\left(-0.3333333333333333, {im}^{2}, -2\right)\right)}\right)\right)
\end{array}
Initial program 57.5%
/-rgt-identity57.5%
exp-057.5%
associate-*l/57.5%
cos-neg57.5%
associate-*l*57.5%
associate-*r/57.5%
exp-057.5%
/-rgt-identity57.5%
*-commutative57.5%
neg-sub057.5%
cos-neg57.5%
Simplified57.5%
Taylor expanded in im around 0 82.9%
associate-*r*82.9%
distribute-rgt-out82.9%
+-commutative82.9%
metadata-eval82.9%
sub-neg82.9%
*-commutative82.9%
fma-neg82.9%
metadata-eval82.9%
Simplified82.9%
metadata-eval82.9%
fma-neg82.9%
add-log-exp82.7%
log-pow99.8%
fma-neg99.8%
metadata-eval99.8%
Applied egg-rr99.8%
(FPCore (re im) :precision binary64 (* 0.5 (log1p (expm1 (* im (* (cos re) -2.0))))))
double code(double re, double im) {
return 0.5 * log1p(expm1((im * (cos(re) * -2.0))));
}
public static double code(double re, double im) {
return 0.5 * Math.log1p(Math.expm1((im * (Math.cos(re) * -2.0))));
}
def code(re, im): return 0.5 * math.log1p(math.expm1((im * (math.cos(re) * -2.0))))
function code(re, im) return Float64(0.5 * log1p(expm1(Float64(im * Float64(cos(re) * -2.0))))) end
code[re_, im_] := N[(0.5 * N[Log[1 + N[(Exp[N[(im * N[(N[Cos[re], $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot \left(\cos re \cdot -2\right)\right)\right)
\end{array}
Initial program 57.5%
/-rgt-identity57.5%
exp-057.5%
associate-*l/57.5%
cos-neg57.5%
associate-*l*57.5%
associate-*r/57.5%
exp-057.5%
/-rgt-identity57.5%
*-commutative57.5%
neg-sub057.5%
cos-neg57.5%
Simplified57.5%
Taylor expanded in im around 0 49.0%
log1p-expm1-u99.5%
*-commutative99.5%
associate-*l*99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (re im)
:precision binary64
(if (<= im 460.0)
(* 0.5 (* im (* (cos re) (- (* -0.3333333333333333 (pow im 2.0)) 2.0))))
(if (<= im 5.8e+102)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* 0.5 (* (cos re) (* -0.3333333333333333 (pow im 3.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 460.0) {
tmp = 0.5 * (im * (cos(re) * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0)));
} else if (im <= 5.8e+102) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = 0.5 * (cos(re) * (-0.3333333333333333 * pow(im, 3.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 460.0) {
tmp = 0.5 * (im * (Math.cos(re) * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0)));
} else if (im <= 5.8e+102) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = 0.5 * (Math.cos(re) * (-0.3333333333333333 * Math.pow(im, 3.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 460.0: tmp = 0.5 * (im * (math.cos(re) * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0))) elif im <= 5.8e+102: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = 0.5 * (math.cos(re) * (-0.3333333333333333 * math.pow(im, 3.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 460.0) tmp = Float64(0.5 * Float64(im * Float64(cos(re) * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0)))); elseif (im <= 5.8e+102) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(0.5 * Float64(cos(re) * Float64(-0.3333333333333333 * (im ^ 3.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 460.0], N[(0.5 * N[(im * N[(N[Cos[re], $MachinePrecision] * N[(N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5.8e+102], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 460:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(\cos re \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\
\mathbf{elif}\;im \leq 5.8 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\right)\\
\end{array}
\end{array}
if im < 460Initial program 45.4%
/-rgt-identity45.4%
exp-045.4%
associate-*l/45.4%
cos-neg45.4%
associate-*l*45.4%
associate-*r/45.4%
exp-045.4%
/-rgt-identity45.4%
*-commutative45.4%
neg-sub045.4%
cos-neg45.4%
Simplified45.4%
Taylor expanded in im around 0 87.0%
associate-*r*87.0%
distribute-rgt-out87.0%
+-commutative87.0%
metadata-eval87.0%
sub-neg87.0%
*-commutative87.0%
fma-neg87.0%
metadata-eval87.0%
Simplified87.0%
Taylor expanded in im around 0 87.0%
if 460 < im < 5.8000000000000005e102Initial 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.6%
add-sqr-sqrt1.1%
pow21.1%
*-commutative1.1%
associate-*l*1.1%
Applied egg-rr1.1%
log1p-expm1-u31.6%
unpow231.6%
add-sqr-sqrt100.0%
associate-*r*100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 68.4%
if 5.8000000000000005e102 < 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%
associate-*r*100.0%
distribute-rgt-out100.0%
+-commutative100.0%
metadata-eval100.0%
sub-neg100.0%
*-commutative100.0%
fma-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification87.6%
(FPCore (re im)
:precision binary64
(if (<= im 430.0)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 5.8e+102)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* 0.5 (* (cos re) (* -0.3333333333333333 (pow im 3.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 430.0) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 5.8e+102) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = 0.5 * (cos(re) * (-0.3333333333333333 * pow(im, 3.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 430.0) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 5.8e+102) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = 0.5 * (Math.cos(re) * (-0.3333333333333333 * Math.pow(im, 3.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 430.0: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 5.8e+102: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = 0.5 * (math.cos(re) * (-0.3333333333333333 * math.pow(im, 3.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 430.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 5.8e+102) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(0.5 * Float64(cos(re) * Float64(-0.3333333333333333 * (im ^ 3.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 430.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5.8e+102], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 430:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 5.8 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\right)\\
\end{array}
\end{array}
if im < 430Initial program 45.4%
/-rgt-identity45.4%
exp-045.4%
associate-*l/45.4%
cos-neg45.4%
associate-*l*45.4%
associate-*r/45.4%
exp-045.4%
/-rgt-identity45.4%
*-commutative45.4%
neg-sub045.4%
cos-neg45.4%
Simplified45.4%
Taylor expanded in im around 0 61.4%
if 430 < im < 5.8000000000000005e102Initial 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.6%
add-sqr-sqrt1.1%
pow21.1%
*-commutative1.1%
associate-*l*1.1%
Applied egg-rr1.1%
log1p-expm1-u31.6%
unpow231.6%
add-sqr-sqrt100.0%
associate-*r*100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 68.4%
if 5.8000000000000005e102 < 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%
associate-*r*100.0%
distribute-rgt-out100.0%
+-commutative100.0%
metadata-eval100.0%
sub-neg100.0%
*-commutative100.0%
fma-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification67.7%
(FPCore (re im) :precision binary64 (if (<= im 420.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 <= 420.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 <= 420.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 <= 420.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 <= 420.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, 420.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 420:\\
\;\;\;\;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 < 420Initial program 45.4%
/-rgt-identity45.4%
exp-045.4%
associate-*l/45.4%
cos-neg45.4%
associate-*l*45.4%
associate-*r/45.4%
exp-045.4%
/-rgt-identity45.4%
*-commutative45.4%
neg-sub045.4%
cos-neg45.4%
Simplified45.4%
Taylor expanded in im around 0 61.4%
if 420 < 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%
add-sqr-sqrt1.6%
pow21.6%
*-commutative1.6%
associate-*l*1.6%
Applied egg-rr1.6%
log1p-expm1-u28.1%
unpow228.1%
add-sqr-sqrt100.0%
associate-*r*100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 71.9%
Final simplification63.8%
(FPCore (re im)
:precision binary64
(if (<= im 29000000000000.0)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 1.05e+85)
(* 0.5 (+ (* im -2.0) (* re (* im re))))
(* 0.5 (* -0.3333333333333333 (pow im 3.0))))))
double code(double re, double im) {
double tmp;
if (im <= 29000000000000.0) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 1.05e+85) {
tmp = 0.5 * ((im * -2.0) + (re * (im * re)));
} else {
tmp = 0.5 * (-0.3333333333333333 * pow(im, 3.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 29000000000000.0d0) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else if (im <= 1.05d+85) then
tmp = 0.5d0 * ((im * (-2.0d0)) + (re * (im * re)))
else
tmp = 0.5d0 * ((-0.3333333333333333d0) * (im ** 3.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 29000000000000.0) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 1.05e+85) {
tmp = 0.5 * ((im * -2.0) + (re * (im * re)));
} else {
tmp = 0.5 * (-0.3333333333333333 * Math.pow(im, 3.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 29000000000000.0: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 1.05e+85: tmp = 0.5 * ((im * -2.0) + (re * (im * re))) else: tmp = 0.5 * (-0.3333333333333333 * math.pow(im, 3.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 29000000000000.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 1.05e+85) tmp = Float64(0.5 * Float64(Float64(im * -2.0) + Float64(re * Float64(im * re)))); else tmp = Float64(0.5 * Float64(-0.3333333333333333 * (im ^ 3.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 29000000000000.0) tmp = 0.5 * (cos(re) * (im * -2.0)); elseif (im <= 1.05e+85) tmp = 0.5 * ((im * -2.0) + (re * (im * re))); else tmp = 0.5 * (-0.3333333333333333 * (im ^ 3.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 29000000000000.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.05e+85], N[(0.5 * N[(N[(im * -2.0), $MachinePrecision] + N[(re * N[(im * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 29000000000000:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 1.05 \cdot 10^{+85}:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2 + re \cdot \left(im \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\
\end{array}
\end{array}
if im < 2.9e13Initial program 45.9%
/-rgt-identity45.9%
exp-045.9%
associate-*l/45.9%
cos-neg45.9%
associate-*l*45.9%
associate-*r/45.9%
exp-045.9%
/-rgt-identity45.9%
*-commutative45.9%
neg-sub045.9%
cos-neg45.9%
Simplified45.9%
Taylor expanded in im around 0 60.9%
if 2.9e13 < im < 1.05000000000000005e85Initial 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.5%
Taylor expanded in re around 0 25.8%
add-sqr-sqrt25.8%
pow225.8%
*-commutative25.8%
sqrt-prod25.8%
sqrt-pow125.8%
metadata-eval25.8%
pow125.8%
Applied egg-rr25.8%
unpow225.8%
*-commutative25.8%
*-commutative25.8%
swap-sqr25.8%
add-sqr-sqrt25.8%
associate-*r*25.8%
Applied egg-rr25.8%
if 1.05000000000000005e85 < 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 91.3%
associate-*r*91.3%
distribute-rgt-out91.3%
+-commutative91.3%
metadata-eval91.3%
sub-neg91.3%
*-commutative91.3%
fma-neg91.3%
metadata-eval91.3%
Simplified91.3%
Taylor expanded in re around 0 67.5%
Taylor expanded in im around inf 67.5%
Final simplification60.2%
(FPCore (re im)
:precision binary64
(if (<= im 29000000000000.0)
(* 0.5 (* im -2.0))
(if (<= im 9e+84)
(* 0.5 (+ (* im -2.0) (* re (* im re))))
(* 0.5 (* -0.3333333333333333 (pow im 3.0))))))
double code(double re, double im) {
double tmp;
if (im <= 29000000000000.0) {
tmp = 0.5 * (im * -2.0);
} else if (im <= 9e+84) {
tmp = 0.5 * ((im * -2.0) + (re * (im * re)));
} else {
tmp = 0.5 * (-0.3333333333333333 * pow(im, 3.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 29000000000000.0d0) then
tmp = 0.5d0 * (im * (-2.0d0))
else if (im <= 9d+84) then
tmp = 0.5d0 * ((im * (-2.0d0)) + (re * (im * re)))
else
tmp = 0.5d0 * ((-0.3333333333333333d0) * (im ** 3.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 29000000000000.0) {
tmp = 0.5 * (im * -2.0);
} else if (im <= 9e+84) {
tmp = 0.5 * ((im * -2.0) + (re * (im * re)));
} else {
tmp = 0.5 * (-0.3333333333333333 * Math.pow(im, 3.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 29000000000000.0: tmp = 0.5 * (im * -2.0) elif im <= 9e+84: tmp = 0.5 * ((im * -2.0) + (re * (im * re))) else: tmp = 0.5 * (-0.3333333333333333 * math.pow(im, 3.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 29000000000000.0) tmp = Float64(0.5 * Float64(im * -2.0)); elseif (im <= 9e+84) tmp = Float64(0.5 * Float64(Float64(im * -2.0) + Float64(re * Float64(im * re)))); else tmp = Float64(0.5 * Float64(-0.3333333333333333 * (im ^ 3.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 29000000000000.0) tmp = 0.5 * (im * -2.0); elseif (im <= 9e+84) tmp = 0.5 * ((im * -2.0) + (re * (im * re))); else tmp = 0.5 * (-0.3333333333333333 * (im ^ 3.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 29000000000000.0], N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 9e+84], N[(0.5 * N[(N[(im * -2.0), $MachinePrecision] + N[(re * N[(im * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 29000000000000:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\mathbf{elif}\;im \leq 9 \cdot 10^{+84}:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2 + re \cdot \left(im \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right)\\
\end{array}
\end{array}
if im < 2.9e13Initial program 45.9%
/-rgt-identity45.9%
exp-045.9%
associate-*l/45.9%
cos-neg45.9%
associate-*l*45.9%
associate-*r/45.9%
exp-045.9%
/-rgt-identity45.9%
*-commutative45.9%
neg-sub045.9%
cos-neg45.9%
Simplified45.9%
Taylor expanded in im around 0 60.9%
Taylor expanded in re around 0 33.3%
if 2.9e13 < im < 8.9999999999999994e84Initial 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.5%
Taylor expanded in re around 0 25.8%
add-sqr-sqrt25.8%
pow225.8%
*-commutative25.8%
sqrt-prod25.8%
sqrt-pow125.8%
metadata-eval25.8%
pow125.8%
Applied egg-rr25.8%
unpow225.8%
*-commutative25.8%
*-commutative25.8%
swap-sqr25.8%
add-sqr-sqrt25.8%
associate-*r*25.8%
Applied egg-rr25.8%
if 8.9999999999999994e84 < 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 91.3%
associate-*r*91.3%
distribute-rgt-out91.3%
+-commutative91.3%
metadata-eval91.3%
sub-neg91.3%
*-commutative91.3%
fma-neg91.3%
metadata-eval91.3%
Simplified91.3%
Taylor expanded in re around 0 67.5%
Taylor expanded in im around inf 67.5%
Final simplification38.5%
(FPCore (re im) :precision binary64 (if (<= (cos re) -0.01) (* 0.5 (+ (* im -2.0) (* re (* im re)))) (* 0.5 (* im -2.0))))
double code(double re, double im) {
double tmp;
if (cos(re) <= -0.01) {
tmp = 0.5 * ((im * -2.0) + (re * (im * 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.01d0)) then
tmp = 0.5d0 * ((im * (-2.0d0)) + (re * (im * 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.01) {
tmp = 0.5 * ((im * -2.0) + (re * (im * re)));
} else {
tmp = 0.5 * (im * -2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= -0.01: tmp = 0.5 * ((im * -2.0) + (re * (im * re))) else: tmp = 0.5 * (im * -2.0) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= -0.01) tmp = Float64(0.5 * Float64(Float64(im * -2.0) + Float64(re * Float64(im * 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.01) tmp = 0.5 * ((im * -2.0) + (re * (im * re))); else tmp = 0.5 * (im * -2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], -0.01], N[(0.5 * N[(N[(im * -2.0), $MachinePrecision] + N[(re * N[(im * 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.01:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2 + re \cdot \left(im \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\end{array}
\end{array}
if (cos.f64 re) < -0.0100000000000000002Initial program 57.2%
/-rgt-identity57.2%
exp-057.2%
associate-*l/57.2%
cos-neg57.2%
associate-*l*57.2%
associate-*r/57.2%
exp-057.2%
/-rgt-identity57.2%
*-commutative57.2%
neg-sub057.2%
cos-neg57.2%
Simplified57.2%
Taylor expanded in im around 0 48.7%
Taylor expanded in re around 0 46.7%
add-sqr-sqrt18.5%
pow218.5%
*-commutative18.5%
sqrt-prod18.5%
sqrt-pow118.5%
metadata-eval18.5%
pow118.5%
Applied egg-rr18.5%
unpow218.5%
*-commutative18.5%
*-commutative18.5%
swap-sqr18.5%
add-sqr-sqrt46.7%
associate-*r*46.8%
Applied egg-rr46.8%
if -0.0100000000000000002 < (cos.f64 re) Initial program 57.7%
/-rgt-identity57.7%
exp-057.7%
associate-*l/57.7%
cos-neg57.7%
associate-*l*57.7%
associate-*r/57.7%
exp-057.7%
/-rgt-identity57.7%
*-commutative57.7%
neg-sub057.7%
cos-neg57.7%
Simplified57.7%
Taylor expanded in im around 0 49.0%
Taylor expanded in re around 0 36.4%
Final simplification39.2%
(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 57.5%
/-rgt-identity57.5%
exp-057.5%
associate-*l/57.5%
cos-neg57.5%
associate-*l*57.5%
associate-*r/57.5%
exp-057.5%
/-rgt-identity57.5%
*-commutative57.5%
neg-sub057.5%
cos-neg57.5%
Simplified57.5%
Taylor expanded in im around 0 49.0%
Taylor expanded in re around 0 27.0%
Final simplification27.0%
(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 2024087
(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))))