
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(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 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[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 \sin re\right) \cdot \left(e^{0 - 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 (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(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 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[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 \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (sin re) (fma 0.5 (exp im) (/ 0.5 (exp im)))))
double code(double re, double im) {
return sin(re) * fma(0.5, exp(im), (0.5 / exp(im)));
}
function code(re, im) return Float64(sin(re) * fma(0.5, exp(im), Float64(0.5 / exp(im)))) end
code[re_, im_] := N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)
\end{array}
Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (if (<= im 1.3) (fma (* im (* (sin re) 0.5)) im (sin re)) (* (sin re) (fma 0.5 (exp im) 0.0))))
double code(double re, double im) {
double tmp;
if (im <= 1.3) {
tmp = fma((im * (sin(re) * 0.5)), im, sin(re));
} else {
tmp = sin(re) * fma(0.5, exp(im), 0.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1.3) tmp = fma(Float64(im * Float64(sin(re) * 0.5)), im, sin(re)); else tmp = Float64(sin(re) * fma(0.5, exp(im), 0.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 1.3], N[(N[(im * N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] * im + N[Sin[re], $MachinePrecision]), $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + 0.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.3:\\
\;\;\;\;\mathsf{fma}\left(im \cdot \left(\sin re \cdot 0.5\right), im, \sin re\right)\\
\mathbf{else}:\\
\;\;\;\;\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, 0\right)\\
\end{array}
\end{array}
if im < 1.30000000000000004Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Taylor expanded in im around 0 87.6%
+-commutative87.6%
associate-*r*87.6%
associate-*r*87.6%
distribute-rgt-out87.6%
fma-def87.6%
Simplified87.6%
Taylor expanded in im around 0 77.7%
+-commutative77.7%
associate-*r*77.7%
unpow277.7%
associate-*r*74.7%
fma-def74.7%
Applied egg-rr74.7%
if 1.30000000000000004 < im Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Applied egg-rr99.9%
Final simplification81.7%
(FPCore (re im) :precision binary64 (* (* (sin re) 0.5) (+ (exp im) (exp (- im)))))
double code(double re, double im) {
return (sin(re) * 0.5) * (exp(im) + exp(-im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (sin(re) * 0.5d0) * (exp(im) + exp(-im))
end function
public static double code(double re, double im) {
return (Math.sin(re) * 0.5) * (Math.exp(im) + Math.exp(-im));
}
def code(re, im): return (math.sin(re) * 0.5) * (math.exp(im) + math.exp(-im))
function code(re, im) return Float64(Float64(sin(re) * 0.5) * Float64(exp(im) + exp(Float64(-im)))) end
function tmp = code(re, im) tmp = (sin(re) * 0.5) * (exp(im) + exp(-im)); end
code[re_, im_] := N[(N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\sin re \cdot 0.5\right) \cdot \left(e^{im} + e^{-im}\right)
\end{array}
Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (if (<= im 1.3) (* (* (sin re) 0.5) (fma im im 2.0)) (* (sin re) (fma 0.5 (exp im) 0.0))))
double code(double re, double im) {
double tmp;
if (im <= 1.3) {
tmp = (sin(re) * 0.5) * fma(im, im, 2.0);
} else {
tmp = sin(re) * fma(0.5, exp(im), 0.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1.3) tmp = Float64(Float64(sin(re) * 0.5) * fma(im, im, 2.0)); else tmp = Float64(sin(re) * fma(0.5, exp(im), 0.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 1.3], N[(N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + 0.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.3:\\
\;\;\;\;\left(\sin re \cdot 0.5\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{else}:\\
\;\;\;\;\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, 0\right)\\
\end{array}
\end{array}
if im < 1.30000000000000004Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 77.7%
+-commutative77.7%
unpow277.7%
fma-def77.7%
Simplified77.7%
if 1.30000000000000004 < im Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Applied egg-rr99.9%
Final simplification83.9%
(FPCore (re im) :precision binary64 (if (or (<= im 1950.0) (not (<= im 1.32e+154))) (* (* (sin re) 0.5) (fma im im 2.0)) (* 0.5 (* re (+ (exp im) (exp (- im)))))))
double code(double re, double im) {
double tmp;
if ((im <= 1950.0) || !(im <= 1.32e+154)) {
tmp = (sin(re) * 0.5) * fma(im, im, 2.0);
} else {
tmp = 0.5 * (re * (exp(im) + exp(-im)));
}
return tmp;
}
function code(re, im) tmp = 0.0 if ((im <= 1950.0) || !(im <= 1.32e+154)) tmp = Float64(Float64(sin(re) * 0.5) * fma(im, im, 2.0)); else tmp = Float64(0.5 * Float64(re * Float64(exp(im) + exp(Float64(-im))))); end return tmp end
code[re_, im_] := If[Or[LessEqual[im, 1950.0], N[Not[LessEqual[im, 1.32e+154]], $MachinePrecision]], N[(N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(re * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1950 \lor \neg \left(im \leq 1.32 \cdot 10^{+154}\right):\\
\;\;\;\;\left(\sin re \cdot 0.5\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)\\
\end{array}
\end{array}
if im < 1950 or 1.31999999999999998e154 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 80.9%
+-commutative80.9%
unpow280.9%
fma-def80.9%
Simplified80.9%
if 1950 < im < 1.31999999999999998e154Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 67.7%
Final simplification79.3%
(FPCore (re im) :precision binary64 (if (or (<= im 1100.0) (not (<= im 2.02e+149))) (* (* (sin re) 0.5) (fma im im 2.0)) (* 0.5 (pow (pow re 4.0) 0.25))))
double code(double re, double im) {
double tmp;
if ((im <= 1100.0) || !(im <= 2.02e+149)) {
tmp = (sin(re) * 0.5) * fma(im, im, 2.0);
} else {
tmp = 0.5 * pow(pow(re, 4.0), 0.25);
}
return tmp;
}
function code(re, im) tmp = 0.0 if ((im <= 1100.0) || !(im <= 2.02e+149)) tmp = Float64(Float64(sin(re) * 0.5) * fma(im, im, 2.0)); else tmp = Float64(0.5 * ((re ^ 4.0) ^ 0.25)); end return tmp end
code[re_, im_] := If[Or[LessEqual[im, 1100.0], N[Not[LessEqual[im, 2.02e+149]], $MachinePrecision]], N[(N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[N[Power[re, 4.0], $MachinePrecision], 0.25], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1100 \lor \neg \left(im \leq 2.02 \cdot 10^{+149}\right):\\
\;\;\;\;\left(\sin re \cdot 0.5\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {\left({re}^{4}\right)}^{0.25}\\
\end{array}
\end{array}
if im < 1100 or 2.02e149 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 81.2%
+-commutative81.2%
unpow281.2%
fma-def81.2%
Simplified81.2%
if 1100 < im < 2.02e149Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 65.6%
Applied egg-rr16.8%
log1p-expm1-u2.0%
add-sqr-sqrt1.1%
sqrt-unprod20.5%
pow220.5%
Applied egg-rr20.5%
pow1/220.5%
sqr-pow20.5%
pow-prod-down32.2%
pow-prod-up32.2%
metadata-eval32.2%
metadata-eval32.2%
Applied egg-rr32.2%
Final simplification75.1%
(FPCore (re im)
:precision binary64
(if (<= im 700.0)
(sin re)
(if (<= im 3.55e+92)
(* 0.5 (pow (pow re 3.0) 0.3333333333333333))
(* 0.5 (* re (+ 2.0 (pow im 2.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 700.0) {
tmp = sin(re);
} else if (im <= 3.55e+92) {
tmp = 0.5 * pow(pow(re, 3.0), 0.3333333333333333);
} else {
tmp = 0.5 * (re * (2.0 + pow(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 (im <= 700.0d0) then
tmp = sin(re)
else if (im <= 3.55d+92) then
tmp = 0.5d0 * ((re ** 3.0d0) ** 0.3333333333333333d0)
else
tmp = 0.5d0 * (re * (2.0d0 + (im ** 2.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 700.0) {
tmp = Math.sin(re);
} else if (im <= 3.55e+92) {
tmp = 0.5 * Math.pow(Math.pow(re, 3.0), 0.3333333333333333);
} else {
tmp = 0.5 * (re * (2.0 + Math.pow(im, 2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 700.0: tmp = math.sin(re) elif im <= 3.55e+92: tmp = 0.5 * math.pow(math.pow(re, 3.0), 0.3333333333333333) else: tmp = 0.5 * (re * (2.0 + math.pow(im, 2.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 700.0) tmp = sin(re); elseif (im <= 3.55e+92) tmp = Float64(0.5 * ((re ^ 3.0) ^ 0.3333333333333333)); else tmp = Float64(0.5 * Float64(re * Float64(2.0 + (im ^ 2.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 700.0) tmp = sin(re); elseif (im <= 3.55e+92) tmp = 0.5 * ((re ^ 3.0) ^ 0.3333333333333333); else tmp = 0.5 * (re * (2.0 + (im ^ 2.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 700.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 3.55e+92], N[(0.5 * N[Power[N[Power[re, 3.0], $MachinePrecision], 0.3333333333333333], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(re * N[(2.0 + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 700:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 3.55 \cdot 10^{+92}:\\
\;\;\;\;0.5 \cdot {\left({re}^{3}\right)}^{0.3333333333333333}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \left(2 + {im}^{2}\right)\right)\\
\end{array}
\end{array}
if im < 700Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Taylor expanded in im around 0 63.0%
if 700 < im < 3.55e92Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 57.1%
Applied egg-rr15.4%
log1p-expm1-u1.9%
add-cbrt-cube15.3%
pow1/334.2%
pow334.2%
Applied egg-rr34.2%
if 3.55e92 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 78.8%
+-commutative78.8%
unpow278.8%
fma-def78.8%
Simplified78.8%
Taylor expanded in re around 0 57.9%
Final simplification59.7%
(FPCore (re im)
:precision binary64
(if (<= im 660.0)
(sin re)
(if (<= im 5.2e+89)
(* 0.5 (pow (pow re 4.0) 0.25))
(* 0.5 (* re (+ 2.0 (pow im 2.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 660.0) {
tmp = sin(re);
} else if (im <= 5.2e+89) {
tmp = 0.5 * pow(pow(re, 4.0), 0.25);
} else {
tmp = 0.5 * (re * (2.0 + pow(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 (im <= 660.0d0) then
tmp = sin(re)
else if (im <= 5.2d+89) then
tmp = 0.5d0 * ((re ** 4.0d0) ** 0.25d0)
else
tmp = 0.5d0 * (re * (2.0d0 + (im ** 2.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 660.0) {
tmp = Math.sin(re);
} else if (im <= 5.2e+89) {
tmp = 0.5 * Math.pow(Math.pow(re, 4.0), 0.25);
} else {
tmp = 0.5 * (re * (2.0 + Math.pow(im, 2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 660.0: tmp = math.sin(re) elif im <= 5.2e+89: tmp = 0.5 * math.pow(math.pow(re, 4.0), 0.25) else: tmp = 0.5 * (re * (2.0 + math.pow(im, 2.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 660.0) tmp = sin(re); elseif (im <= 5.2e+89) tmp = Float64(0.5 * ((re ^ 4.0) ^ 0.25)); else tmp = Float64(0.5 * Float64(re * Float64(2.0 + (im ^ 2.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 660.0) tmp = sin(re); elseif (im <= 5.2e+89) tmp = 0.5 * ((re ^ 4.0) ^ 0.25); else tmp = 0.5 * (re * (2.0 + (im ^ 2.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 660.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 5.2e+89], N[(0.5 * N[Power[N[Power[re, 4.0], $MachinePrecision], 0.25], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(re * N[(2.0 + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 660:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 5.2 \cdot 10^{+89}:\\
\;\;\;\;0.5 \cdot {\left({re}^{4}\right)}^{0.25}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \left(2 + {im}^{2}\right)\right)\\
\end{array}
\end{array}
if im < 660Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Taylor expanded in im around 0 63.0%
if 660 < im < 5.2000000000000001e89Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 60.0%
Applied egg-rr16.2%
log1p-expm1-u2.0%
add-sqr-sqrt1.1%
sqrt-unprod26.6%
pow226.6%
Applied egg-rr26.6%
pow1/226.6%
sqr-pow26.6%
pow-prod-down36.0%
pow-prod-up36.0%
metadata-eval36.0%
metadata-eval36.0%
Applied egg-rr36.0%
if 5.2000000000000001e89 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 77.3%
+-commutative77.3%
unpow277.3%
fma-def77.3%
Simplified77.3%
Taylor expanded in re around 0 56.7%
Final simplification59.7%
(FPCore (re im)
:precision binary64
(if (<= im 1950.0)
(sin re)
(if (<= im 9.6e+114)
(* 0.5 (log1p (expm1 re)))
(* 0.5 (* re (+ 2.0 (pow im 2.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 1950.0) {
tmp = sin(re);
} else if (im <= 9.6e+114) {
tmp = 0.5 * log1p(expm1(re));
} else {
tmp = 0.5 * (re * (2.0 + pow(im, 2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 1950.0) {
tmp = Math.sin(re);
} else if (im <= 9.6e+114) {
tmp = 0.5 * Math.log1p(Math.expm1(re));
} else {
tmp = 0.5 * (re * (2.0 + Math.pow(im, 2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1950.0: tmp = math.sin(re) elif im <= 9.6e+114: tmp = 0.5 * math.log1p(math.expm1(re)) else: tmp = 0.5 * (re * (2.0 + math.pow(im, 2.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1950.0) tmp = sin(re); elseif (im <= 9.6e+114) tmp = Float64(0.5 * log1p(expm1(re))); else tmp = Float64(0.5 * Float64(re * Float64(2.0 + (im ^ 2.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 1950.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 9.6e+114], N[(0.5 * N[Log[1 + N[(Exp[re] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(re * N[(2.0 + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1950:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 9.6 \cdot 10^{+114}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \left(2 + {im}^{2}\right)\right)\\
\end{array}
\end{array}
if im < 1950Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Taylor expanded in im around 0 62.7%
if 1950 < im < 9.6e114Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 69.2%
Applied egg-rr16.7%
if 9.6e114 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 89.2%
+-commutative89.2%
unpow289.2%
fma-def89.2%
Simplified89.2%
Taylor expanded in re around 0 65.3%
Final simplification58.5%
(FPCore (re im)
:precision binary64
(if (<= im 360000000.0)
(sin re)
(if (<= im 4.4e+136)
(* -0.5 (pow re 2.0))
(* 0.5 (* re (+ 2.0 (pow im 2.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 360000000.0) {
tmp = sin(re);
} else if (im <= 4.4e+136) {
tmp = -0.5 * pow(re, 2.0);
} else {
tmp = 0.5 * (re * (2.0 + pow(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 (im <= 360000000.0d0) then
tmp = sin(re)
else if (im <= 4.4d+136) then
tmp = (-0.5d0) * (re ** 2.0d0)
else
tmp = 0.5d0 * (re * (2.0d0 + (im ** 2.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 360000000.0) {
tmp = Math.sin(re);
} else if (im <= 4.4e+136) {
tmp = -0.5 * Math.pow(re, 2.0);
} else {
tmp = 0.5 * (re * (2.0 + Math.pow(im, 2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 360000000.0: tmp = math.sin(re) elif im <= 4.4e+136: tmp = -0.5 * math.pow(re, 2.0) else: tmp = 0.5 * (re * (2.0 + math.pow(im, 2.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 360000000.0) tmp = sin(re); elseif (im <= 4.4e+136) tmp = Float64(-0.5 * (re ^ 2.0)); else tmp = Float64(0.5 * Float64(re * Float64(2.0 + (im ^ 2.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 360000000.0) tmp = sin(re); elseif (im <= 4.4e+136) tmp = -0.5 * (re ^ 2.0); else tmp = 0.5 * (re * (2.0 + (im ^ 2.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 360000000.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 4.4e+136], N[(-0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(re * N[(2.0 + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 360000000:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 4.4 \cdot 10^{+136}:\\
\;\;\;\;-0.5 \cdot {re}^{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \left(2 + {im}^{2}\right)\right)\\
\end{array}
\end{array}
if im < 3.6e8Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Taylor expanded in im around 0 61.2%
if 3.6e8 < im < 4.3999999999999999e136Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 3.7%
+-commutative3.7%
unpow23.7%
fma-def3.7%
Simplified3.7%
Applied egg-rr1.7%
Taylor expanded in re around 0 10.8%
if 4.3999999999999999e136 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 89.2%
+-commutative89.2%
unpow289.2%
fma-def89.2%
Simplified89.2%
Taylor expanded in re around 0 65.3%
Final simplification57.7%
(FPCore (re im) :precision binary64 (if (<= im 380000000.0) (sin re) (* -0.5 (pow re 2.0))))
double code(double re, double im) {
double tmp;
if (im <= 380000000.0) {
tmp = sin(re);
} else {
tmp = -0.5 * 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 <= 380000000.0d0) then
tmp = sin(re)
else
tmp = (-0.5d0) * (re ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 380000000.0) {
tmp = Math.sin(re);
} else {
tmp = -0.5 * Math.pow(re, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 380000000.0: tmp = math.sin(re) else: tmp = -0.5 * math.pow(re, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 380000000.0) tmp = sin(re); else tmp = Float64(-0.5 * (re ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 380000000.0) tmp = sin(re); else tmp = -0.5 * (re ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 380000000.0], N[Sin[re], $MachinePrecision], N[(-0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 380000000:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot {re}^{2}\\
\end{array}
\end{array}
if im < 3.8e8Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Taylor expanded in im around 0 61.2%
if 3.8e8 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 61.2%
+-commutative61.2%
unpow261.2%
fma-def61.2%
Simplified61.2%
Applied egg-rr1.7%
Taylor expanded in re around 0 15.2%
Final simplification49.7%
(FPCore (re im) :precision binary64 (sin re))
double code(double re, double im) {
return sin(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sin(re)
end function
public static double code(double re, double im) {
return Math.sin(re);
}
def code(re, im): return math.sin(re)
function code(re, im) return sin(re) end
function tmp = code(re, im) tmp = sin(re); end
code[re_, im_] := N[Sin[re], $MachinePrecision]
\begin{array}{l}
\\
\sin re
\end{array}
Initial program 100.0%
distribute-rgt-in100.0%
+-commutative100.0%
associate-*r*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
neg-mul-1100.0%
*-commutative100.0%
sub-neg100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Taylor expanded in im around 0 46.6%
Final simplification46.6%
(FPCore (re im) :precision binary64 (* 0.5 (+ re re)))
double code(double re, double im) {
return 0.5 * (re + re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (re + re)
end function
public static double code(double re, double im) {
return 0.5 * (re + re);
}
def code(re, im): return 0.5 * (re + re)
function code(re, im) return Float64(0.5 * Float64(re + re)) end
function tmp = code(re, im) tmp = 0.5 * (re + re); end
code[re_, im_] := N[(0.5 * N[(re + re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(re + re\right)
\end{array}
Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 62.9%
Applied egg-rr27.0%
Final simplification27.0%
(FPCore (re im) :precision binary64 (* re 0.5))
double code(double re, double im) {
return re * 0.5;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re * 0.5d0
end function
public static double code(double re, double im) {
return re * 0.5;
}
def code(re, im): return re * 0.5
function code(re, im) return Float64(re * 0.5) end
function tmp = code(re, im) tmp = re * 0.5; end
code[re_, im_] := N[(re * 0.5), $MachinePrecision]
\begin{array}{l}
\\
re \cdot 0.5
\end{array}
Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 62.9%
Applied egg-rr17.6%
Taylor expanded in re around 0 6.9%
Final simplification6.9%
herbie shell --seed 2023320
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))