
(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 12 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 99.6%
distribute-rgt-in99.6%
cancel-sign-sub99.6%
distribute-rgt-out--99.6%
sub-neg99.6%
neg-sub099.6%
remove-double-neg99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 1.4e-5)
(* t_0 (fma im im 2.0))
(if (<= im 1.35e+154)
(* (* 0.5 re) (+ (exp (- im)) (exp im)))
(* t_0 (pow im 2.0))))))
double code(double re, double im) {
double t_0 = 0.5 * sin(re);
double tmp;
if (im <= 1.4e-5) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 1.35e+154) {
tmp = (0.5 * re) * (exp(-im) + exp(im));
} else {
tmp = t_0 * pow(im, 2.0);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * sin(re)) tmp = 0.0 if (im <= 1.4e-5) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 1.35e+154) tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(t_0 * (im ^ 2.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 1.4e-5], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;im \leq 1.4 \cdot 10^{-5}:\\
\;\;\;\;t_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 1.39999999999999998e-5Initial 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 79.7%
Simplified79.7%
if 1.39999999999999998e-5 < im < 1.35000000000000003e154Initial program 97.4%
distribute-rgt-in97.4%
cancel-sign-sub97.4%
distribute-rgt-out--97.4%
sub-neg97.4%
neg-sub097.4%
remove-double-neg97.4%
Simplified97.4%
Taylor expanded in re around 0 62.2%
Simplified62.2%
if 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 100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification79.2%
(FPCore (re im)
:precision binary64
(if (<= im 1.4e-5)
(* (* 0.5 (sin re)) (fma im im 2.0))
(if (<= im 1.8e+51)
(* (* 0.5 re) (+ (exp (- im)) (exp im)))
(+ (* 0.001388888888888889 (* (sin re) (pow im 6.0))) 12.0))))
double code(double re, double im) {
double tmp;
if (im <= 1.4e-5) {
tmp = (0.5 * sin(re)) * fma(im, im, 2.0);
} else if (im <= 1.8e+51) {
tmp = (0.5 * re) * (exp(-im) + exp(im));
} else {
tmp = (0.001388888888888889 * (sin(re) * pow(im, 6.0))) + 12.0;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1.4e-5) tmp = Float64(Float64(0.5 * sin(re)) * fma(im, im, 2.0)); elseif (im <= 1.8e+51) tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(Float64(0.001388888888888889 * Float64(sin(re) * (im ^ 6.0))) + 12.0); end return tmp end
code[re_, im_] := If[LessEqual[im, 1.4e-5], N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.8e+51], N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.001388888888888889 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 12.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.4 \cdot 10^{-5}:\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.8 \cdot 10^{+51}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;0.001388888888888889 \cdot \left(\sin re \cdot {im}^{6}\right) + 12\\
\end{array}
\end{array}
if im < 1.39999999999999998e-5Initial 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 79.7%
Simplified79.7%
if 1.39999999999999998e-5 < im < 1.80000000000000005e51Initial program 91.1%
distribute-rgt-in91.3%
cancel-sign-sub91.3%
distribute-rgt-out--91.1%
sub-neg91.1%
neg-sub091.1%
remove-double-neg91.1%
Simplified91.1%
Taylor expanded in re around 0 45.7%
Simplified45.7%
if 1.80000000000000005e51 < 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 98.3%
Simplified98.3%
Applied egg-rr98.3%
Taylor expanded in im around inf 98.3%
Final simplification82.0%
(FPCore (re im)
:precision binary64
(if (<= im 700.0)
(sin re)
(if (<= im 1.35e+154)
(sqrt (pow (/ 0.5 re) 4.0))
(* (* 0.5 (sin re)) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 700.0) {
tmp = sin(re);
} else if (im <= 1.35e+154) {
tmp = sqrt(pow((0.5 / re), 4.0));
} else {
tmp = (0.5 * sin(re)) * 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 <= 1.35d+154) then
tmp = sqrt(((0.5d0 / re) ** 4.0d0))
else
tmp = (0.5d0 * sin(re)) * (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 <= 1.35e+154) {
tmp = Math.sqrt(Math.pow((0.5 / re), 4.0));
} else {
tmp = (0.5 * Math.sin(re)) * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 700.0: tmp = math.sin(re) elif im <= 1.35e+154: tmp = math.sqrt(math.pow((0.5 / re), 4.0)) else: tmp = (0.5 * math.sin(re)) * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 700.0) tmp = sin(re); elseif (im <= 1.35e+154) tmp = sqrt((Float64(0.5 / re) ^ 4.0)); else tmp = Float64(Float64(0.5 * sin(re)) * (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 <= 1.35e+154) tmp = sqrt(((0.5 / re) ^ 4.0)); else tmp = (0.5 * sin(re)) * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 700.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[Sqrt[N[Power[N[(0.5 / re), $MachinePrecision], 4.0], $MachinePrecision]], $MachinePrecision], N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 700:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\sqrt{{\left(\frac{0.5}{re}\right)}^{4}}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 700Initial 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 62.8%
if 700 < im < 1.35000000000000003e154Initial program 97.3%
distribute-rgt-in97.3%
cancel-sign-sub97.3%
distribute-rgt-out--97.3%
sub-neg97.3%
neg-sub097.3%
remove-double-neg97.3%
Simplified97.3%
Applied egg-rr16.3%
Taylor expanded in re around 0 16.1%
add-sqr-sqrt16.1%
sqrt-div16.1%
metadata-eval16.1%
unpow216.1%
sqrt-prod15.7%
add-sqr-sqrt30.2%
sqrt-div30.2%
metadata-eval30.2%
unpow230.2%
sqrt-prod15.7%
add-sqr-sqrt16.1%
Applied egg-rr16.1%
add-sqr-sqrt16.1%
sqrt-unprod28.7%
pow228.7%
pow228.7%
pow-prod-up28.7%
metadata-eval28.7%
Applied egg-rr28.7%
if 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 100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification61.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 850.0)
(* t_0 (fma im im 2.0))
(if (<= im 1.35e+154) (sqrt (pow (/ 0.5 re) 4.0)) (* t_0 (pow im 2.0))))))
double code(double re, double im) {
double t_0 = 0.5 * sin(re);
double tmp;
if (im <= 850.0) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 1.35e+154) {
tmp = sqrt(pow((0.5 / re), 4.0));
} else {
tmp = t_0 * pow(im, 2.0);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * sin(re)) tmp = 0.0 if (im <= 850.0) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 1.35e+154) tmp = sqrt((Float64(0.5 / re) ^ 4.0)); else tmp = Float64(t_0 * (im ^ 2.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 850.0], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[Sqrt[N[Power[N[(0.5 / re), $MachinePrecision], 4.0], $MachinePrecision]], $MachinePrecision], N[(t$95$0 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;im \leq 850:\\
\;\;\;\;t_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\sqrt{{\left(\frac{0.5}{re}\right)}^{4}}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 850Initial 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 79.6%
Simplified79.6%
if 850 < im < 1.35000000000000003e154Initial program 97.3%
distribute-rgt-in97.3%
cancel-sign-sub97.3%
distribute-rgt-out--97.3%
sub-neg97.3%
neg-sub097.3%
remove-double-neg97.3%
Simplified97.3%
Applied egg-rr16.3%
Taylor expanded in re around 0 16.1%
add-sqr-sqrt16.1%
sqrt-div16.1%
metadata-eval16.1%
unpow216.1%
sqrt-prod15.7%
add-sqr-sqrt30.2%
sqrt-div30.2%
metadata-eval30.2%
unpow230.2%
sqrt-prod15.7%
add-sqr-sqrt16.1%
Applied egg-rr16.1%
add-sqr-sqrt16.1%
sqrt-unprod28.7%
pow228.7%
pow228.7%
pow-prod-up28.7%
metadata-eval28.7%
Applied egg-rr28.7%
if 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 100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification74.5%
(FPCore (re im)
:precision binary64
(if (<= im 760.0)
(sin re)
(if (<= im 1.95e+164)
(sqrt (/ 0.0625 (pow re 4.0)))
(* (* 0.5 re) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 760.0) {
tmp = sin(re);
} else if (im <= 1.95e+164) {
tmp = sqrt((0.0625 / pow(re, 4.0)));
} else {
tmp = (0.5 * re) * 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 <= 760.0d0) then
tmp = sin(re)
else if (im <= 1.95d+164) then
tmp = sqrt((0.0625d0 / (re ** 4.0d0)))
else
tmp = (0.5d0 * re) * (im ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 760.0) {
tmp = Math.sin(re);
} else if (im <= 1.95e+164) {
tmp = Math.sqrt((0.0625 / Math.pow(re, 4.0)));
} else {
tmp = (0.5 * re) * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 760.0: tmp = math.sin(re) elif im <= 1.95e+164: tmp = math.sqrt((0.0625 / math.pow(re, 4.0))) else: tmp = (0.5 * re) * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 760.0) tmp = sin(re); elseif (im <= 1.95e+164) tmp = sqrt(Float64(0.0625 / (re ^ 4.0))); else tmp = Float64(Float64(0.5 * re) * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 760.0) tmp = sin(re); elseif (im <= 1.95e+164) tmp = sqrt((0.0625 / (re ^ 4.0))); else tmp = (0.5 * re) * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 760.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.95e+164], N[Sqrt[N[(0.0625 / N[Power[re, 4.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 760:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.95 \cdot 10^{+164}:\\
\;\;\;\;\sqrt{\frac{0.0625}{{re}^{4}}}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 760Initial 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 62.8%
if 760 < im < 1.94999999999999993e164Initial program 97.4%
distribute-rgt-in97.4%
cancel-sign-sub97.4%
distribute-rgt-out--97.4%
sub-neg97.4%
neg-sub097.4%
remove-double-neg97.4%
Simplified97.4%
Applied egg-rr15.9%
Taylor expanded in re around 0 15.7%
add-sqr-sqrt15.7%
sqrt-unprod28.0%
frac-times28.0%
metadata-eval28.0%
pow-prod-up28.0%
metadata-eval28.0%
Applied egg-rr28.0%
if 1.94999999999999993e164 < 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 79.2%
Simplified79.2%
Taylor expanded in im around 0 79.2%
+-commutative79.2%
unpow279.2%
fma-def79.2%
Simplified79.2%
Taylor expanded in im around inf 79.2%
associate-*r*79.2%
*-commutative79.2%
associate-*r*79.2%
*-commutative79.2%
*-commutative79.2%
Simplified79.2%
Final simplification59.3%
(FPCore (re im)
:precision binary64
(if (<= im 760.0)
(sin re)
(if (<= im 1.95e+164)
(sqrt (pow (/ 0.5 re) 4.0))
(* (* 0.5 re) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 760.0) {
tmp = sin(re);
} else if (im <= 1.95e+164) {
tmp = sqrt(pow((0.5 / re), 4.0));
} else {
tmp = (0.5 * re) * 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 <= 760.0d0) then
tmp = sin(re)
else if (im <= 1.95d+164) then
tmp = sqrt(((0.5d0 / re) ** 4.0d0))
else
tmp = (0.5d0 * re) * (im ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 760.0) {
tmp = Math.sin(re);
} else if (im <= 1.95e+164) {
tmp = Math.sqrt(Math.pow((0.5 / re), 4.0));
} else {
tmp = (0.5 * re) * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 760.0: tmp = math.sin(re) elif im <= 1.95e+164: tmp = math.sqrt(math.pow((0.5 / re), 4.0)) else: tmp = (0.5 * re) * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 760.0) tmp = sin(re); elseif (im <= 1.95e+164) tmp = sqrt((Float64(0.5 / re) ^ 4.0)); else tmp = Float64(Float64(0.5 * re) * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 760.0) tmp = sin(re); elseif (im <= 1.95e+164) tmp = sqrt(((0.5 / re) ^ 4.0)); else tmp = (0.5 * re) * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 760.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.95e+164], N[Sqrt[N[Power[N[(0.5 / re), $MachinePrecision], 4.0], $MachinePrecision]], $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 760:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.95 \cdot 10^{+164}:\\
\;\;\;\;\sqrt{{\left(\frac{0.5}{re}\right)}^{4}}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 760Initial 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 62.8%
if 760 < im < 1.94999999999999993e164Initial program 97.4%
distribute-rgt-in97.4%
cancel-sign-sub97.4%
distribute-rgt-out--97.4%
sub-neg97.4%
neg-sub097.4%
remove-double-neg97.4%
Simplified97.4%
Applied egg-rr15.9%
Taylor expanded in re around 0 15.7%
add-sqr-sqrt15.7%
sqrt-div15.7%
metadata-eval15.7%
unpow215.7%
sqrt-prod15.3%
add-sqr-sqrt29.4%
sqrt-div29.4%
metadata-eval29.4%
unpow229.4%
sqrt-prod15.3%
add-sqr-sqrt15.7%
Applied egg-rr15.7%
add-sqr-sqrt15.7%
sqrt-unprod28.0%
pow228.0%
pow228.0%
pow-prod-up28.0%
metadata-eval28.0%
Applied egg-rr28.0%
if 1.94999999999999993e164 < 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 79.2%
Simplified79.2%
Taylor expanded in im around 0 79.2%
+-commutative79.2%
unpow279.2%
fma-def79.2%
Simplified79.2%
Taylor expanded in im around inf 79.2%
associate-*r*79.2%
*-commutative79.2%
associate-*r*79.2%
*-commutative79.2%
*-commutative79.2%
Simplified79.2%
Final simplification59.3%
(FPCore (re im) :precision binary64 (if (<= im 750.0) (sin re) (if (<= im 6.5e+153) (/ (/ 0.25 re) re) (* (* 0.5 re) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 750.0) {
tmp = sin(re);
} else if (im <= 6.5e+153) {
tmp = (0.25 / re) / re;
} else {
tmp = (0.5 * re) * 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 <= 750.0d0) then
tmp = sin(re)
else if (im <= 6.5d+153) then
tmp = (0.25d0 / re) / re
else
tmp = (0.5d0 * re) * (im ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 750.0) {
tmp = Math.sin(re);
} else if (im <= 6.5e+153) {
tmp = (0.25 / re) / re;
} else {
tmp = (0.5 * re) * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 750.0: tmp = math.sin(re) elif im <= 6.5e+153: tmp = (0.25 / re) / re else: tmp = (0.5 * re) * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 750.0) tmp = sin(re); elseif (im <= 6.5e+153) tmp = Float64(Float64(0.25 / re) / re); else tmp = Float64(Float64(0.5 * re) * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 750.0) tmp = sin(re); elseif (im <= 6.5e+153) tmp = (0.25 / re) / re; else tmp = (0.5 * re) * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 750.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 6.5e+153], N[(N[(0.25 / re), $MachinePrecision] / re), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 750:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 6.5 \cdot 10^{+153}:\\
\;\;\;\;\frac{\frac{0.25}{re}}{re}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 750Initial 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 62.8%
if 750 < im < 6.49999999999999972e153Initial program 97.3%
distribute-rgt-in97.3%
cancel-sign-sub97.3%
distribute-rgt-out--97.3%
sub-neg97.3%
neg-sub097.3%
remove-double-neg97.3%
Simplified97.3%
Applied egg-rr16.3%
Taylor expanded in re around 0 16.1%
add-sqr-sqrt16.1%
sqrt-div16.1%
metadata-eval16.1%
unpow216.1%
sqrt-prod15.7%
add-sqr-sqrt30.2%
sqrt-div30.2%
metadata-eval30.2%
unpow230.2%
sqrt-prod15.7%
add-sqr-sqrt16.1%
Applied egg-rr16.1%
associate-*l/16.1%
associate-*r/16.1%
metadata-eval16.1%
Applied egg-rr16.1%
if 6.49999999999999972e153 < 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 76.0%
Simplified76.0%
Taylor expanded in im around 0 76.0%
+-commutative76.0%
unpow276.0%
fma-def76.0%
Simplified76.0%
Taylor expanded in im around inf 76.0%
associate-*r*76.0%
*-commutative76.0%
associate-*r*76.0%
*-commutative76.0%
*-commutative76.0%
Simplified76.0%
Final simplification57.5%
(FPCore (re im) :precision binary64 (if (<= im 680.0) (sin re) (* 0.25 (pow re -2.0))))
double code(double re, double im) {
double tmp;
if (im <= 680.0) {
tmp = sin(re);
} else {
tmp = 0.25 * 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 <= 680.0d0) then
tmp = sin(re)
else
tmp = 0.25d0 * (re ** (-2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 680.0) {
tmp = Math.sin(re);
} else {
tmp = 0.25 * Math.pow(re, -2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 680.0: tmp = math.sin(re) else: tmp = 0.25 * math.pow(re, -2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 680.0) tmp = sin(re); else tmp = Float64(0.25 * (re ^ -2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 680.0) tmp = sin(re); else tmp = 0.25 * (re ^ -2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 680.0], N[Sin[re], $MachinePrecision], N[(0.25 * N[Power[re, -2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 680:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;0.25 \cdot {re}^{-2}\\
\end{array}
\end{array}
if im < 680Initial 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 62.8%
if 680 < im Initial program 98.4%
distribute-rgt-in98.4%
cancel-sign-sub98.4%
distribute-rgt-out--98.4%
sub-neg98.4%
neg-sub098.4%
remove-double-neg98.4%
Simplified98.4%
Applied egg-rr14.0%
Taylor expanded in re around 0 13.9%
clear-num13.9%
associate-/r/15.2%
pow-flip15.2%
metadata-eval15.2%
Applied egg-rr15.2%
Final simplification51.5%
(FPCore (re im) :precision binary64 (if (<= im 550.0) (sin re) (/ (/ 0.25 re) re)))
double code(double re, double im) {
double tmp;
if (im <= 550.0) {
tmp = sin(re);
} else {
tmp = (0.25 / 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 <= 550.0d0) then
tmp = sin(re)
else
tmp = (0.25d0 / re) / re
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 550.0) {
tmp = Math.sin(re);
} else {
tmp = (0.25 / re) / re;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 550.0: tmp = math.sin(re) else: tmp = (0.25 / re) / re return tmp
function code(re, im) tmp = 0.0 if (im <= 550.0) tmp = sin(re); else tmp = Float64(Float64(0.25 / re) / re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 550.0) tmp = sin(re); else tmp = (0.25 / re) / re; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 550.0], N[Sin[re], $MachinePrecision], N[(N[(0.25 / re), $MachinePrecision] / re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 550:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.25}{re}}{re}\\
\end{array}
\end{array}
if im < 550Initial 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 62.8%
if 550 < im Initial program 98.4%
distribute-rgt-in98.4%
cancel-sign-sub98.4%
distribute-rgt-out--98.4%
sub-neg98.4%
neg-sub098.4%
remove-double-neg98.4%
Simplified98.4%
Applied egg-rr14.0%
Taylor expanded in re around 0 13.9%
add-sqr-sqrt13.9%
sqrt-div13.9%
metadata-eval13.9%
unpow213.9%
sqrt-prod13.5%
add-sqr-sqrt30.8%
sqrt-div30.8%
metadata-eval30.8%
unpow230.8%
sqrt-prod13.5%
add-sqr-sqrt13.9%
Applied egg-rr13.9%
associate-*l/13.9%
associate-*r/13.9%
metadata-eval13.9%
Applied egg-rr13.9%
Final simplification51.1%
(FPCore (re im) :precision binary64 (if (<= im 700.0) re (/ (/ 0.25 re) re)))
double code(double re, double im) {
double tmp;
if (im <= 700.0) {
tmp = re;
} else {
tmp = (0.25 / 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 <= 700.0d0) then
tmp = re
else
tmp = (0.25d0 / re) / re
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 700.0) {
tmp = re;
} else {
tmp = (0.25 / re) / re;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 700.0: tmp = re else: tmp = (0.25 / re) / re return tmp
function code(re, im) tmp = 0.0 if (im <= 700.0) tmp = re; else tmp = Float64(Float64(0.25 / re) / re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 700.0) tmp = re; else tmp = (0.25 / re) / re; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 700.0], re, N[(N[(0.25 / re), $MachinePrecision] / re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 700:\\
\;\;\;\;re\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.25}{re}}{re}\\
\end{array}
\end{array}
if im < 700Initial 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 58.8%
Simplified58.8%
Taylor expanded in im around 0 29.8%
if 700 < im Initial program 98.4%
distribute-rgt-in98.4%
cancel-sign-sub98.4%
distribute-rgt-out--98.4%
sub-neg98.4%
neg-sub098.4%
remove-double-neg98.4%
Simplified98.4%
Applied egg-rr14.0%
Taylor expanded in re around 0 13.9%
add-sqr-sqrt13.9%
sqrt-div13.9%
metadata-eval13.9%
unpow213.9%
sqrt-prod13.5%
add-sqr-sqrt30.8%
sqrt-div30.8%
metadata-eval30.8%
unpow230.8%
sqrt-prod13.5%
add-sqr-sqrt13.9%
Applied egg-rr13.9%
associate-*l/13.9%
associate-*r/13.9%
metadata-eval13.9%
Applied egg-rr13.9%
Final simplification26.0%
(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 99.6%
distribute-rgt-in99.6%
cancel-sign-sub99.6%
distribute-rgt-out--99.6%
sub-neg99.6%
neg-sub099.6%
remove-double-neg99.6%
Simplified99.6%
Taylor expanded in re around 0 60.8%
Simplified60.8%
Taylor expanded in im around 0 23.2%
Final simplification23.2%
herbie shell --seed 2024021
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))