
(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 11 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) (/ 1.0 (cosh im))))
double code(double re, double im) {
return sin(re) / (1.0 / cosh(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sin(re) / (1.0d0 / cosh(im))
end function
public static double code(double re, double im) {
return Math.sin(re) / (1.0 / Math.cosh(im));
}
def code(re, im): return math.sin(re) / (1.0 / math.cosh(im))
function code(re, im) return Float64(sin(re) / Float64(1.0 / cosh(im))) end
function tmp = code(re, im) tmp = sin(re) / (1.0 / cosh(im)); end
code[re_, im_] := N[(N[Sin[re], $MachinePrecision] / N[(1.0 / N[Cosh[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin re}{\frac{1}{\cosh im}}
\end{array}
Initial program 100.0%
+-commutative100.0%
sub0-neg100.0%
cosh-undef100.0%
Applied egg-rr100.0%
add-log-exp77.5%
*-un-lft-identity77.5%
log-prod77.5%
metadata-eval77.5%
add-log-exp100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
cosh-def100.0%
cosh-undef100.0%
associate-*r/100.0%
*-commutative100.0%
Applied egg-rr100.0%
associate-/l*100.0%
*-commutative100.0%
associate-/r*100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (* (sin re) (cosh im)))
double code(double re, double im) {
return sin(re) * cosh(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sin(re) * cosh(im)
end function
public static double code(double re, double im) {
return Math.sin(re) * Math.cosh(im);
}
def code(re, im): return math.sin(re) * math.cosh(im)
function code(re, im) return Float64(sin(re) * cosh(im)) end
function tmp = code(re, im) tmp = sin(re) * cosh(im); end
code[re_, im_] := N[(N[Sin[re], $MachinePrecision] * N[Cosh[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin re \cdot \cosh im
\end{array}
Initial program 100.0%
+-commutative100.0%
sub0-neg100.0%
cosh-undef100.0%
Applied egg-rr100.0%
add-log-exp77.5%
*-un-lft-identity77.5%
log-prod77.5%
metadata-eval77.5%
add-log-exp100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (* im im) (* (sin re) 0.5))) (t_1 (* re (cosh im))))
(if (<= im -1.35e+154)
t_0
(if (<= im -18.0)
t_1
(if (<= im 6.9e-18) (sin re) (if (<= im 1.35e+154) t_1 t_0))))))
double code(double re, double im) {
double t_0 = (im * im) * (sin(re) * 0.5);
double t_1 = re * cosh(im);
double tmp;
if (im <= -1.35e+154) {
tmp = t_0;
} else if (im <= -18.0) {
tmp = t_1;
} else if (im <= 6.9e-18) {
tmp = sin(re);
} else if (im <= 1.35e+154) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (im * im) * (sin(re) * 0.5d0)
t_1 = re * cosh(im)
if (im <= (-1.35d+154)) then
tmp = t_0
else if (im <= (-18.0d0)) then
tmp = t_1
else if (im <= 6.9d-18) then
tmp = sin(re)
else if (im <= 1.35d+154) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (im * im) * (Math.sin(re) * 0.5);
double t_1 = re * Math.cosh(im);
double tmp;
if (im <= -1.35e+154) {
tmp = t_0;
} else if (im <= -18.0) {
tmp = t_1;
} else if (im <= 6.9e-18) {
tmp = Math.sin(re);
} else if (im <= 1.35e+154) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = (im * im) * (math.sin(re) * 0.5) t_1 = re * math.cosh(im) tmp = 0 if im <= -1.35e+154: tmp = t_0 elif im <= -18.0: tmp = t_1 elif im <= 6.9e-18: tmp = math.sin(re) elif im <= 1.35e+154: tmp = t_1 else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(Float64(im * im) * Float64(sin(re) * 0.5)) t_1 = Float64(re * cosh(im)) tmp = 0.0 if (im <= -1.35e+154) tmp = t_0; elseif (im <= -18.0) tmp = t_1; elseif (im <= 6.9e-18) tmp = sin(re); elseif (im <= 1.35e+154) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = (im * im) * (sin(re) * 0.5); t_1 = re * cosh(im); tmp = 0.0; if (im <= -1.35e+154) tmp = t_0; elseif (im <= -18.0) tmp = t_1; elseif (im <= 6.9e-18) tmp = sin(re); elseif (im <= 1.35e+154) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(im * im), $MachinePrecision] * N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(re * N[Cosh[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.35e+154], t$95$0, If[LessEqual[im, -18.0], t$95$1, If[LessEqual[im, 6.9e-18], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(im \cdot im\right) \cdot \left(\sin re \cdot 0.5\right)\\
t_1 := re \cdot \cosh im\\
\mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq -18:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq 6.9 \cdot 10^{-18}:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if im < -1.35000000000000003e154 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
if -1.35000000000000003e154 < im < -18 or 6.9000000000000003e-18 < im < 1.35000000000000003e154Initial program 99.9%
+-commutative99.9%
sub0-neg99.9%
cosh-undef99.9%
Applied egg-rr99.9%
Taylor expanded in re around 0 75.5%
expm1-log1p-u45.9%
expm1-udef41.3%
associate-*r*41.3%
*-commutative41.3%
associate-*r*41.3%
metadata-eval41.3%
*-un-lft-identity41.3%
Applied egg-rr41.3%
expm1-def45.9%
expm1-log1p75.5%
Simplified75.5%
if -18 < im < 6.9000000000000003e-18Initial program 100.0%
Taylor expanded in im around 0 98.6%
Final simplification93.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (sin re) 0.5)) (t_1 (* (* im im) t_0)) (t_2 (* re (cosh im))))
(if (<= im -1.35e+154)
t_1
(if (<= im -18.0)
t_2
(if (<= im 0.112)
(* t_0 (+ (* im im) 2.0))
(if (<= im 1.35e+154) t_2 t_1))))))
double code(double re, double im) {
double t_0 = sin(re) * 0.5;
double t_1 = (im * im) * t_0;
double t_2 = re * cosh(im);
double tmp;
if (im <= -1.35e+154) {
tmp = t_1;
} else if (im <= -18.0) {
tmp = t_2;
} else if (im <= 0.112) {
tmp = t_0 * ((im * im) + 2.0);
} else if (im <= 1.35e+154) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = sin(re) * 0.5d0
t_1 = (im * im) * t_0
t_2 = re * cosh(im)
if (im <= (-1.35d+154)) then
tmp = t_1
else if (im <= (-18.0d0)) then
tmp = t_2
else if (im <= 0.112d0) then
tmp = t_0 * ((im * im) + 2.0d0)
else if (im <= 1.35d+154) then
tmp = t_2
else
tmp = t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sin(re) * 0.5;
double t_1 = (im * im) * t_0;
double t_2 = re * Math.cosh(im);
double tmp;
if (im <= -1.35e+154) {
tmp = t_1;
} else if (im <= -18.0) {
tmp = t_2;
} else if (im <= 0.112) {
tmp = t_0 * ((im * im) + 2.0);
} else if (im <= 1.35e+154) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = math.sin(re) * 0.5 t_1 = (im * im) * t_0 t_2 = re * math.cosh(im) tmp = 0 if im <= -1.35e+154: tmp = t_1 elif im <= -18.0: tmp = t_2 elif im <= 0.112: tmp = t_0 * ((im * im) + 2.0) elif im <= 1.35e+154: tmp = t_2 else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(sin(re) * 0.5) t_1 = Float64(Float64(im * im) * t_0) t_2 = Float64(re * cosh(im)) tmp = 0.0 if (im <= -1.35e+154) tmp = t_1; elseif (im <= -18.0) tmp = t_2; elseif (im <= 0.112) tmp = Float64(t_0 * Float64(Float64(im * im) + 2.0)); elseif (im <= 1.35e+154) tmp = t_2; else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = sin(re) * 0.5; t_1 = (im * im) * t_0; t_2 = re * cosh(im); tmp = 0.0; if (im <= -1.35e+154) tmp = t_1; elseif (im <= -18.0) tmp = t_2; elseif (im <= 0.112) tmp = t_0 * ((im * im) + 2.0); elseif (im <= 1.35e+154) tmp = t_2; else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[(N[(im * im), $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(re * N[Cosh[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.35e+154], t$95$1, If[LessEqual[im, -18.0], t$95$2, If[LessEqual[im, 0.112], N[(t$95$0 * N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], t$95$2, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin re \cdot 0.5\\
t_1 := \left(im \cdot im\right) \cdot t_0\\
t_2 := re \cdot \cosh im\\
\mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq -18:\\
\;\;\;\;t_2\\
\mathbf{elif}\;im \leq 0.112:\\
\;\;\;\;t_0 \cdot \left(im \cdot im + 2\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < -1.35000000000000003e154 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
if -1.35000000000000003e154 < im < -18 or 0.112000000000000002 < im < 1.35000000000000003e154Initial program 100.0%
+-commutative100.0%
sub0-neg100.0%
cosh-undef100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 75.4%
expm1-log1p-u43.9%
expm1-udef43.9%
associate-*r*43.9%
*-commutative43.9%
associate-*r*43.9%
metadata-eval43.9%
*-un-lft-identity43.9%
Applied egg-rr43.9%
expm1-def43.9%
expm1-log1p75.4%
Simplified75.4%
if -18 < im < 0.112000000000000002Initial program 100.0%
Taylor expanded in im around 0 98.6%
Simplified98.6%
Final simplification93.8%
(FPCore (re im) :precision binary64 (if (or (<= im -18.0) (not (<= im 6.9e-18))) (* re (cosh im)) (sin re)))
double code(double re, double im) {
double tmp;
if ((im <= -18.0) || !(im <= 6.9e-18)) {
tmp = re * cosh(im);
} else {
tmp = sin(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= (-18.0d0)) .or. (.not. (im <= 6.9d-18))) then
tmp = re * cosh(im)
else
tmp = sin(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -18.0) || !(im <= 6.9e-18)) {
tmp = re * Math.cosh(im);
} else {
tmp = Math.sin(re);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -18.0) or not (im <= 6.9e-18): tmp = re * math.cosh(im) else: tmp = math.sin(re) return tmp
function code(re, im) tmp = 0.0 if ((im <= -18.0) || !(im <= 6.9e-18)) tmp = Float64(re * cosh(im)); else tmp = sin(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -18.0) || ~((im <= 6.9e-18))) tmp = re * cosh(im); else tmp = sin(re); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -18.0], N[Not[LessEqual[im, 6.9e-18]], $MachinePrecision]], N[(re * N[Cosh[im], $MachinePrecision]), $MachinePrecision], N[Sin[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -18 \lor \neg \left(im \leq 6.9 \cdot 10^{-18}\right):\\
\;\;\;\;re \cdot \cosh im\\
\mathbf{else}:\\
\;\;\;\;\sin re\\
\end{array}
\end{array}
if im < -18 or 6.9000000000000003e-18 < im Initial program 100.0%
+-commutative100.0%
sub0-neg100.0%
cosh-undef100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 73.0%
expm1-log1p-u34.1%
expm1-udef31.9%
associate-*r*31.9%
*-commutative31.9%
associate-*r*31.9%
metadata-eval31.9%
*-un-lft-identity31.9%
Applied egg-rr31.9%
expm1-def34.1%
expm1-log1p73.0%
Simplified73.0%
if -18 < im < 6.9000000000000003e-18Initial program 100.0%
Taylor expanded in im around 0 98.6%
Final simplification86.0%
(FPCore (re im) :precision binary64 (if (<= im -2.7e+16) (* (* im im) (* re 0.5)) (if (<= im 6.9e-18) (sin re) (+ re (* 0.5 (* re (* im im)))))))
double code(double re, double im) {
double tmp;
if (im <= -2.7e+16) {
tmp = (im * im) * (re * 0.5);
} else if (im <= 6.9e-18) {
tmp = sin(re);
} else {
tmp = re + (0.5 * (re * (im * im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= (-2.7d+16)) then
tmp = (im * im) * (re * 0.5d0)
else if (im <= 6.9d-18) then
tmp = sin(re)
else
tmp = re + (0.5d0 * (re * (im * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= -2.7e+16) {
tmp = (im * im) * (re * 0.5);
} else if (im <= 6.9e-18) {
tmp = Math.sin(re);
} else {
tmp = re + (0.5 * (re * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= -2.7e+16: tmp = (im * im) * (re * 0.5) elif im <= 6.9e-18: tmp = math.sin(re) else: tmp = re + (0.5 * (re * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (im <= -2.7e+16) tmp = Float64(Float64(im * im) * Float64(re * 0.5)); elseif (im <= 6.9e-18) tmp = sin(re); else tmp = Float64(re + Float64(0.5 * Float64(re * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= -2.7e+16) tmp = (im * im) * (re * 0.5); elseif (im <= 6.9e-18) tmp = sin(re); else tmp = re + (0.5 * (re * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, -2.7e+16], N[(N[(im * im), $MachinePrecision] * N[(re * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 6.9e-18], N[Sin[re], $MachinePrecision], N[(re + N[(0.5 * N[(re * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -2.7 \cdot 10^{+16}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(re \cdot 0.5\right)\\
\mathbf{elif}\;im \leq 6.9 \cdot 10^{-18}:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;re + 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < -2.7e16Initial program 100.0%
Taylor expanded in im around 0 55.6%
Simplified55.6%
Taylor expanded in im around inf 55.6%
unpow255.6%
associate-*r*55.6%
*-commutative55.6%
Simplified55.6%
Taylor expanded in re around 0 47.7%
associate-*r*47.7%
*-commutative47.7%
unpow247.7%
Simplified47.7%
if -2.7e16 < im < 6.9000000000000003e-18Initial program 100.0%
Taylor expanded in im around 0 97.2%
if 6.9000000000000003e-18 < im Initial program 99.9%
Taylor expanded in im around 0 59.6%
Simplified59.6%
Taylor expanded in re around 0 42.9%
unpow242.9%
Simplified42.9%
Taylor expanded in re around 0 42.9%
Final simplification72.2%
(FPCore (re im) :precision binary64 (if (or (<= im -3.4e-7) (not (<= im 0.0035))) (* 0.5 (* im (* re im))) re))
double code(double re, double im) {
double tmp;
if ((im <= -3.4e-7) || !(im <= 0.0035)) {
tmp = 0.5 * (im * (re * im));
} else {
tmp = re;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= (-3.4d-7)) .or. (.not. (im <= 0.0035d0))) then
tmp = 0.5d0 * (im * (re * im))
else
tmp = re
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -3.4e-7) || !(im <= 0.0035)) {
tmp = 0.5 * (im * (re * im));
} else {
tmp = re;
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -3.4e-7) or not (im <= 0.0035): tmp = 0.5 * (im * (re * im)) else: tmp = re return tmp
function code(re, im) tmp = 0.0 if ((im <= -3.4e-7) || !(im <= 0.0035)) tmp = Float64(0.5 * Float64(im * Float64(re * im))); else tmp = re; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -3.4e-7) || ~((im <= 0.0035))) tmp = 0.5 * (im * (re * im)); else tmp = re; end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -3.4e-7], N[Not[LessEqual[im, 0.0035]], $MachinePrecision]], N[(0.5 * N[(im * N[(re * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], re]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -3.4 \cdot 10^{-7} \lor \neg \left(im \leq 0.0035\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(re \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;re\\
\end{array}
\end{array}
if im < -3.39999999999999974e-7 or 0.00350000000000000007 < im Initial program 100.0%
Taylor expanded in im around 0 55.3%
Simplified55.3%
Taylor expanded in re around 0 42.6%
Taylor expanded in im around inf 42.6%
unpow242.6%
associate-*r*33.7%
*-commutative33.7%
Simplified33.7%
if -3.39999999999999974e-7 < im < 0.00350000000000000007Initial program 100.0%
Taylor expanded in im around 0 99.4%
Taylor expanded in re around 0 47.2%
Final simplification40.5%
(FPCore (re im) :precision binary64 (if (or (<= im -3.4e-7) (not (<= im 0.0035))) (* (* im im) (* re 0.5)) re))
double code(double re, double im) {
double tmp;
if ((im <= -3.4e-7) || !(im <= 0.0035)) {
tmp = (im * im) * (re * 0.5);
} else {
tmp = re;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= (-3.4d-7)) .or. (.not. (im <= 0.0035d0))) then
tmp = (im * im) * (re * 0.5d0)
else
tmp = re
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -3.4e-7) || !(im <= 0.0035)) {
tmp = (im * im) * (re * 0.5);
} else {
tmp = re;
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -3.4e-7) or not (im <= 0.0035): tmp = (im * im) * (re * 0.5) else: tmp = re return tmp
function code(re, im) tmp = 0.0 if ((im <= -3.4e-7) || !(im <= 0.0035)) tmp = Float64(Float64(im * im) * Float64(re * 0.5)); else tmp = re; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -3.4e-7) || ~((im <= 0.0035))) tmp = (im * im) * (re * 0.5); else tmp = re; end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -3.4e-7], N[Not[LessEqual[im, 0.0035]], $MachinePrecision]], N[(N[(im * im), $MachinePrecision] * N[(re * 0.5), $MachinePrecision]), $MachinePrecision], re]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -3.4 \cdot 10^{-7} \lor \neg \left(im \leq 0.0035\right):\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(re \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;re\\
\end{array}
\end{array}
if im < -3.39999999999999974e-7 or 0.00350000000000000007 < im Initial program 100.0%
Taylor expanded in im around 0 55.3%
Simplified55.3%
Taylor expanded in im around inf 54.0%
unpow254.0%
associate-*r*54.0%
*-commutative54.0%
Simplified54.0%
Taylor expanded in re around 0 42.6%
associate-*r*42.6%
*-commutative42.6%
unpow242.6%
Simplified42.6%
if -3.39999999999999974e-7 < im < 0.00350000000000000007Initial program 100.0%
Taylor expanded in im around 0 99.4%
Taylor expanded in re around 0 47.2%
Final simplification44.9%
(FPCore (re im) :precision binary64 (* (+ (* im im) 2.0) (* re 0.5)))
double code(double re, double im) {
return ((im * im) + 2.0) * (re * 0.5);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = ((im * im) + 2.0d0) * (re * 0.5d0)
end function
public static double code(double re, double im) {
return ((im * im) + 2.0) * (re * 0.5);
}
def code(re, im): return ((im * im) + 2.0) * (re * 0.5)
function code(re, im) return Float64(Float64(Float64(im * im) + 2.0) * Float64(re * 0.5)) end
function tmp = code(re, im) tmp = ((im * im) + 2.0) * (re * 0.5); end
code[re_, im_] := N[(N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision] * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(im \cdot im + 2\right) \cdot \left(re \cdot 0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 78.0%
Simplified78.0%
Taylor expanded in re around 0 45.2%
Final simplification45.2%
(FPCore (re im) :precision binary64 (+ re (* 0.5 (* re (* im im)))))
double code(double re, double im) {
return re + (0.5 * (re * (im * im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re + (0.5d0 * (re * (im * im)))
end function
public static double code(double re, double im) {
return re + (0.5 * (re * (im * im)));
}
def code(re, im): return re + (0.5 * (re * (im * im)))
function code(re, im) return Float64(re + Float64(0.5 * Float64(re * Float64(im * im)))) end
function tmp = code(re, im) tmp = re + (0.5 * (re * (im * im))); end
code[re_, im_] := N[(re + N[(0.5 * N[(re * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re + 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 78.0%
Simplified78.0%
Taylor expanded in re around 0 66.1%
unpow266.1%
Simplified66.1%
Taylor expanded in re around 0 45.2%
Final simplification45.2%
(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%
Taylor expanded in im around 0 52.4%
Taylor expanded in re around 0 25.2%
Final simplification25.2%
herbie shell --seed 2023187
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))