
(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 9 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 (* (* 0.5 (sin re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp(-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(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* 0.5 (sin re)) (fma im im 2.0))))
(if (<= im 640.0)
t_0
(if (<= im 3.4e+63)
(pow (* (sin re) -2.0) -2.0)
(if (<= im 1.35e+154)
(+ re (* re (* 0.041666666666666664 (pow im 4.0))))
t_0)))))
double code(double re, double im) {
double t_0 = (0.5 * sin(re)) * fma(im, im, 2.0);
double tmp;
if (im <= 640.0) {
tmp = t_0;
} else if (im <= 3.4e+63) {
tmp = pow((sin(re) * -2.0), -2.0);
} else if (im <= 1.35e+154) {
tmp = re + (re * (0.041666666666666664 * pow(im, 4.0)));
} else {
tmp = t_0;
}
return tmp;
}
function code(re, im) t_0 = Float64(Float64(0.5 * sin(re)) * fma(im, im, 2.0)) tmp = 0.0 if (im <= 640.0) tmp = t_0; elseif (im <= 3.4e+63) tmp = Float64(sin(re) * -2.0) ^ -2.0; elseif (im <= 1.35e+154) tmp = Float64(re + Float64(re * Float64(0.041666666666666664 * (im ^ 4.0)))); else tmp = t_0; end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 640.0], t$95$0, If[LessEqual[im, 3.4e+63], N[Power[N[(N[Sin[re], $MachinePrecision] * -2.0), $MachinePrecision], -2.0], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(re + N[(re * N[(0.041666666666666664 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{if}\;im \leq 640:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;im \leq 3.4 \cdot 10^{+63}:\\
\;\;\;\;{\left(\sin re \cdot -2\right)}^{-2}\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;re + re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if im < 640 or 1.35000000000000003e154 < im Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 88.8%
Simplified88.8%
if 640 < im < 3.3999999999999999e63Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Applied egg-rr34.1%
if 3.3999999999999999e63 < im < 1.35000000000000003e154Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 76.9%
Simplified76.9%
Taylor expanded in im around 0 76.9%
+-commutative76.9%
associate-*r*76.9%
associate-*r*76.9%
distribute-rgt-out76.9%
Simplified76.9%
Taylor expanded in im around inf 76.9%
associate-*r*76.9%
*-commutative76.9%
Simplified76.9%
Final simplification86.2%
(FPCore (re im) :precision binary64 (if (or (<= im 0.022) (not (<= im 1.35e+154))) (* (* 0.5 (sin re)) (fma im im 2.0)) (* (* 0.5 re) (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if ((im <= 0.022) || !(im <= 1.35e+154)) {
tmp = (0.5 * sin(re)) * 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 <= 0.022) || !(im <= 1.35e+154)) tmp = Float64(Float64(0.5 * sin(re)) * fma(im, im, 2.0)); else tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im))); end return tmp end
code[re_, im_] := If[Or[LessEqual[im, 0.022], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.022 \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 0.021999999999999999 or 1.35000000000000003e154 < im Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 89.1%
Simplified89.1%
if 0.021999999999999999 < im < 1.35000000000000003e154Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 82.8%
Simplified82.8%
Final simplification88.6%
(FPCore (re im)
:precision binary64
(if (<= im 1050.0)
(sin re)
(if (<= im 9.5e+63)
(pow (* (sin re) -2.0) -2.0)
(+ re (* re (* 0.041666666666666664 (pow im 4.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 1050.0) {
tmp = sin(re);
} else if (im <= 9.5e+63) {
tmp = pow((sin(re) * -2.0), -2.0);
} else {
tmp = re + (re * (0.041666666666666664 * pow(im, 4.0)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1050.0d0) then
tmp = sin(re)
else if (im <= 9.5d+63) then
tmp = (sin(re) * (-2.0d0)) ** (-2.0d0)
else
tmp = re + (re * (0.041666666666666664d0 * (im ** 4.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1050.0) {
tmp = Math.sin(re);
} else if (im <= 9.5e+63) {
tmp = Math.pow((Math.sin(re) * -2.0), -2.0);
} else {
tmp = re + (re * (0.041666666666666664 * Math.pow(im, 4.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1050.0: tmp = math.sin(re) elif im <= 9.5e+63: tmp = math.pow((math.sin(re) * -2.0), -2.0) else: tmp = re + (re * (0.041666666666666664 * math.pow(im, 4.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1050.0) tmp = sin(re); elseif (im <= 9.5e+63) tmp = Float64(sin(re) * -2.0) ^ -2.0; else tmp = Float64(re + Float64(re * Float64(0.041666666666666664 * (im ^ 4.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1050.0) tmp = sin(re); elseif (im <= 9.5e+63) tmp = (sin(re) * -2.0) ^ -2.0; else tmp = re + (re * (0.041666666666666664 * (im ^ 4.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1050.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 9.5e+63], N[Power[N[(N[Sin[re], $MachinePrecision] * -2.0), $MachinePrecision], -2.0], $MachinePrecision], N[(re + N[(re * N[(0.041666666666666664 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1050:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 9.5 \cdot 10^{+63}:\\
\;\;\;\;{\left(\sin re \cdot -2\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;re + re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 1050Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 72.6%
if 1050 < im < 9.5000000000000003e63Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Applied egg-rr34.1%
if 9.5000000000000003e63 < im Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 70.4%
Simplified70.4%
Taylor expanded in im around 0 70.4%
+-commutative70.4%
associate-*r*70.4%
associate-*r*70.4%
distribute-rgt-out70.4%
Simplified70.4%
Taylor expanded in im around inf 70.4%
associate-*r*70.4%
*-commutative70.4%
Simplified70.4%
Final simplification70.8%
(FPCore (re im)
:precision binary64
(if (<= im 720.0)
(sin re)
(if (<= im 8.2e+61)
(/ 0.25 (pow re 2.0))
(+ re (* re (* 0.041666666666666664 (pow im 4.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 720.0) {
tmp = sin(re);
} else if (im <= 8.2e+61) {
tmp = 0.25 / pow(re, 2.0);
} else {
tmp = re + (re * (0.041666666666666664 * pow(im, 4.0)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 720.0d0) then
tmp = sin(re)
else if (im <= 8.2d+61) then
tmp = 0.25d0 / (re ** 2.0d0)
else
tmp = re + (re * (0.041666666666666664d0 * (im ** 4.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 720.0) {
tmp = Math.sin(re);
} else if (im <= 8.2e+61) {
tmp = 0.25 / Math.pow(re, 2.0);
} else {
tmp = re + (re * (0.041666666666666664 * Math.pow(im, 4.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 720.0: tmp = math.sin(re) elif im <= 8.2e+61: tmp = 0.25 / math.pow(re, 2.0) else: tmp = re + (re * (0.041666666666666664 * math.pow(im, 4.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 720.0) tmp = sin(re); elseif (im <= 8.2e+61) tmp = Float64(0.25 / (re ^ 2.0)); else tmp = Float64(re + Float64(re * Float64(0.041666666666666664 * (im ^ 4.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 720.0) tmp = sin(re); elseif (im <= 8.2e+61) tmp = 0.25 / (re ^ 2.0); else tmp = re + (re * (0.041666666666666664 * (im ^ 4.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 720.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 8.2e+61], N[(0.25 / N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision], N[(re + N[(re * N[(0.041666666666666664 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 720:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 8.2 \cdot 10^{+61}:\\
\;\;\;\;\frac{0.25}{{re}^{2}}\\
\mathbf{else}:\\
\;\;\;\;re + re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 720Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 72.6%
if 720 < im < 8.19999999999999944e61Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Applied egg-rr34.1%
Taylor expanded in re around 0 34.2%
if 8.19999999999999944e61 < im Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 70.4%
Simplified70.4%
Taylor expanded in im around 0 70.4%
+-commutative70.4%
associate-*r*70.4%
associate-*r*70.4%
distribute-rgt-out70.4%
Simplified70.4%
Taylor expanded in im around inf 70.4%
associate-*r*70.4%
*-commutative70.4%
Simplified70.4%
Final simplification70.8%
(FPCore (re im)
:precision binary64
(if (<= im 520.0)
(sin re)
(if (<= im 6.5e+98)
(/ 0.25 (pow re 2.0))
(* re (+ 1.0 (* im (* 0.5 im)))))))
double code(double re, double im) {
double tmp;
if (im <= 520.0) {
tmp = sin(re);
} else if (im <= 6.5e+98) {
tmp = 0.25 / pow(re, 2.0);
} else {
tmp = re * (1.0 + (im * (0.5 * im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 520.0d0) then
tmp = sin(re)
else if (im <= 6.5d+98) then
tmp = 0.25d0 / (re ** 2.0d0)
else
tmp = re * (1.0d0 + (im * (0.5d0 * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 520.0) {
tmp = Math.sin(re);
} else if (im <= 6.5e+98) {
tmp = 0.25 / Math.pow(re, 2.0);
} else {
tmp = re * (1.0 + (im * (0.5 * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 520.0: tmp = math.sin(re) elif im <= 6.5e+98: tmp = 0.25 / math.pow(re, 2.0) else: tmp = re * (1.0 + (im * (0.5 * im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 520.0) tmp = sin(re); elseif (im <= 6.5e+98) tmp = Float64(0.25 / (re ^ 2.0)); else tmp = Float64(re * Float64(1.0 + Float64(im * Float64(0.5 * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 520.0) tmp = sin(re); elseif (im <= 6.5e+98) tmp = 0.25 / (re ^ 2.0); else tmp = re * (1.0 + (im * (0.5 * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 520.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 6.5e+98], N[(0.25 / N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision], N[(re * N[(1.0 + N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 520:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 6.5 \cdot 10^{+98}:\\
\;\;\;\;\frac{0.25}{{re}^{2}}\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(1 + im \cdot \left(0.5 \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 520Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 72.6%
if 520 < im < 6.4999999999999999e98Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Applied egg-rr21.6%
Taylor expanded in re around 0 21.5%
if 6.4999999999999999e98 < im Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 86.3%
Simplified86.3%
Taylor expanded in re around 0 60.8%
add-sqr-sqrt60.8%
pow260.8%
*-commutative60.8%
sqrt-prod60.8%
unpow260.8%
sqrt-prod60.8%
add-sqr-sqrt60.8%
Applied egg-rr60.8%
unpow260.8%
*-commutative60.8%
*-commutative60.8%
swap-sqr60.8%
rem-square-sqrt60.8%
associate-*r*60.8%
Applied egg-rr60.8%
Final simplification67.4%
(FPCore (re im) :precision binary64 (if (<= im 0.112) (sin re) (* re (+ 1.0 (* im (* 0.5 im))))))
double code(double re, double im) {
double tmp;
if (im <= 0.112) {
tmp = sin(re);
} else {
tmp = re * (1.0 + (im * (0.5 * im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.112d0) then
tmp = sin(re)
else
tmp = re * (1.0d0 + (im * (0.5d0 * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.112) {
tmp = Math.sin(re);
} else {
tmp = re * (1.0 + (im * (0.5 * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.112: tmp = math.sin(re) else: tmp = re * (1.0 + (im * (0.5 * im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.112) tmp = sin(re); else tmp = Float64(re * Float64(1.0 + Float64(im * Float64(0.5 * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.112) tmp = sin(re); else tmp = re * (1.0 + (im * (0.5 * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.112], N[Sin[re], $MachinePrecision], N[(re * N[(1.0 + N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.112:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(1 + im \cdot \left(0.5 \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 0.112000000000000002Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 72.9%
if 0.112000000000000002 < im Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 65.5%
Simplified65.5%
Taylor expanded in re around 0 47.9%
add-sqr-sqrt47.9%
pow247.9%
*-commutative47.9%
sqrt-prod47.9%
unpow247.9%
sqrt-prod47.9%
add-sqr-sqrt47.9%
Applied egg-rr47.9%
unpow247.9%
*-commutative47.9%
*-commutative47.9%
swap-sqr47.9%
rem-square-sqrt47.9%
associate-*r*47.9%
Applied egg-rr47.9%
Final simplification66.7%
(FPCore (re im) :precision binary64 (* re (+ 1.0 (* im (* 0.5 im)))))
double code(double re, double im) {
return re * (1.0 + (im * (0.5 * im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re * (1.0d0 + (im * (0.5d0 * im)))
end function
public static double code(double re, double im) {
return re * (1.0 + (im * (0.5 * im)));
}
def code(re, im): return re * (1.0 + (im * (0.5 * im)))
function code(re, im) return Float64(re * Float64(1.0 + Float64(im * Float64(0.5 * im)))) end
function tmp = code(re, im) tmp = re * (1.0 + (im * (0.5 * im))); end
code[re_, im_] := N[(re * N[(1.0 + N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot \left(1 + im \cdot \left(0.5 \cdot im\right)\right)
\end{array}
Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 81.5%
Simplified81.5%
Taylor expanded in re around 0 48.7%
add-sqr-sqrt48.7%
pow248.7%
*-commutative48.7%
sqrt-prod48.7%
unpow248.7%
sqrt-prod25.6%
add-sqr-sqrt48.7%
Applied egg-rr48.7%
unpow248.7%
*-commutative48.7%
*-commutative48.7%
swap-sqr48.7%
rem-square-sqrt48.7%
associate-*r*48.7%
Applied egg-rr48.7%
Final simplification48.7%
(FPCore (re im) :precision binary64 re)
double code(double re, double im) {
return re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re
end function
public static double code(double re, double im) {
return re;
}
def code(re, im): return re
function code(re, im) return re end
function tmp = code(re, im) tmp = re; end
code[re_, im_] := re
\begin{array}{l}
\\
re
\end{array}
Initial program 100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 81.5%
Simplified81.5%
Taylor expanded in re around 0 48.7%
Taylor expanded in im around 0 27.7%
Final simplification27.7%
herbie shell --seed 2024026
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))