
(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) (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-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(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%
sub0-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (* (sin re) (+ 0.5 (* 0.5 (exp im)))))
double code(double re, double im) {
return sin(re) * (0.5 + (0.5 * exp(im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sin(re) * (0.5d0 + (0.5d0 * exp(im)))
end function
public static double code(double re, double im) {
return Math.sin(re) * (0.5 + (0.5 * Math.exp(im)));
}
def code(re, im): return math.sin(re) * (0.5 + (0.5 * math.exp(im)))
function code(re, im) return Float64(sin(re) * Float64(0.5 + Float64(0.5 * exp(im)))) end
function tmp = code(re, im) tmp = sin(re) * (0.5 + (0.5 * exp(im))); end
code[re_, im_] := N[(N[Sin[re], $MachinePrecision] * N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)
\end{array}
Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 77.5%
Taylor expanded in re around inf 77.5%
*-commutative77.5%
Simplified77.5%
Final simplification77.5%
(FPCore (re im) :precision binary64 (if (<= im 750.0) (sin re) (if (<= im 1.35e+154) (pow re -3.0) (* (sin re) (* 0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 750.0) {
tmp = sin(re);
} else if (im <= 1.35e+154) {
tmp = pow(re, -3.0);
} else {
tmp = sin(re) * (0.5 * (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 <= 750.0d0) then
tmp = sin(re)
else if (im <= 1.35d+154) then
tmp = re ** (-3.0d0)
else
tmp = sin(re) * (0.5d0 * (im * im))
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 <= 1.35e+154) {
tmp = Math.pow(re, -3.0);
} else {
tmp = Math.sin(re) * (0.5 * (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 750.0: tmp = math.sin(re) elif im <= 1.35e+154: tmp = math.pow(re, -3.0) else: tmp = math.sin(re) * (0.5 * (im * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 750.0) tmp = sin(re); elseif (im <= 1.35e+154) tmp = re ^ -3.0; else tmp = Float64(sin(re) * Float64(0.5 * Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 750.0) tmp = sin(re); elseif (im <= 1.35e+154) tmp = re ^ -3.0; else tmp = sin(re) * (0.5 * (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 750.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[Power[re, -3.0], $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 750:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;{re}^{-3}\\
\mathbf{else}:\\
\;\;\;\;\sin re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 750Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 71.7%
if 750 < im < 1.35000000000000003e154Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 82.4%
distribute-lft-out82.4%
+-commutative82.4%
rec-exp82.4%
Simplified82.4%
Applied egg-rr60.4%
if 1.35000000000000003e154 < im Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
unpow2100.0%
Simplified100.0%
Final simplification75.5%
(FPCore (re im)
:precision binary64
(if (<= im 4.4)
(sin re)
(if (<= im 1.35e+154)
(* re (+ 0.5 (* 0.5 (exp im))))
(* (sin re) (* 0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 4.4) {
tmp = sin(re);
} else if (im <= 1.35e+154) {
tmp = re * (0.5 + (0.5 * exp(im)));
} else {
tmp = sin(re) * (0.5 * (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 <= 4.4d0) then
tmp = sin(re)
else if (im <= 1.35d+154) then
tmp = re * (0.5d0 + (0.5d0 * exp(im)))
else
tmp = sin(re) * (0.5d0 * (im * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.4) {
tmp = Math.sin(re);
} else if (im <= 1.35e+154) {
tmp = re * (0.5 + (0.5 * Math.exp(im)));
} else {
tmp = Math.sin(re) * (0.5 * (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.4: tmp = math.sin(re) elif im <= 1.35e+154: tmp = re * (0.5 + (0.5 * math.exp(im))) else: tmp = math.sin(re) * (0.5 * (im * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.4) tmp = sin(re); elseif (im <= 1.35e+154) tmp = Float64(re * Float64(0.5 + Float64(0.5 * exp(im)))); else tmp = Float64(sin(re) * Float64(0.5 * Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.4) tmp = sin(re); elseif (im <= 1.35e+154) tmp = re * (0.5 + (0.5 * exp(im))); else tmp = sin(re) * (0.5 * (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.4], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(re * N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.4:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 4.4000000000000004Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 71.7%
if 4.4000000000000004 < im < 1.35000000000000003e154Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 82.4%
if 1.35000000000000003e154 < im Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
unpow2100.0%
Simplified100.0%
Final simplification76.9%
(FPCore (re im)
:precision binary64
(if (<= im 4.4)
(* (* (sin re) 0.5) (+ 2.0 (* im im)))
(if (<= im 1e+154)
(* re (+ 0.5 (* 0.5 (exp im))))
(* (sin re) (* 0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 4.4) {
tmp = (sin(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1e+154) {
tmp = re * (0.5 + (0.5 * exp(im)));
} else {
tmp = sin(re) * (0.5 * (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 <= 4.4d0) then
tmp = (sin(re) * 0.5d0) * (2.0d0 + (im * im))
else if (im <= 1d+154) then
tmp = re * (0.5d0 + (0.5d0 * exp(im)))
else
tmp = sin(re) * (0.5d0 * (im * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.4) {
tmp = (Math.sin(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1e+154) {
tmp = re * (0.5 + (0.5 * Math.exp(im)));
} else {
tmp = Math.sin(re) * (0.5 * (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.4: tmp = (math.sin(re) * 0.5) * (2.0 + (im * im)) elif im <= 1e+154: tmp = re * (0.5 + (0.5 * math.exp(im))) else: tmp = math.sin(re) * (0.5 * (im * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.4) tmp = Float64(Float64(sin(re) * 0.5) * Float64(2.0 + Float64(im * im))); elseif (im <= 1e+154) tmp = Float64(re * Float64(0.5 + Float64(0.5 * exp(im)))); else tmp = Float64(sin(re) * Float64(0.5 * Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.4) tmp = (sin(re) * 0.5) * (2.0 + (im * im)); elseif (im <= 1e+154) tmp = re * (0.5 + (0.5 * exp(im))); else tmp = sin(re) * (0.5 * (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.4], N[(N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1e+154], N[(re * N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.4:\\
\;\;\;\;\left(\sin re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 10^{+154}:\\
\;\;\;\;re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 4.4000000000000004Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 86.8%
unpow286.8%
Simplified86.8%
if 4.4000000000000004 < im < 1.00000000000000004e154Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 82.4%
if 1.00000000000000004e154 < im Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
unpow2100.0%
Simplified100.0%
Final simplification88.6%
(FPCore (re im) :precision binary64 (if (<= im 800.0) (sin re) (if (<= im 6.8e+153) (pow re -3.0) (* re (+ (* 0.5 (* im im)) 1.0)))))
double code(double re, double im) {
double tmp;
if (im <= 800.0) {
tmp = sin(re);
} else if (im <= 6.8e+153) {
tmp = pow(re, -3.0);
} else {
tmp = re * ((0.5 * (im * im)) + 1.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 800.0d0) then
tmp = sin(re)
else if (im <= 6.8d+153) then
tmp = re ** (-3.0d0)
else
tmp = re * ((0.5d0 * (im * im)) + 1.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 800.0) {
tmp = Math.sin(re);
} else if (im <= 6.8e+153) {
tmp = Math.pow(re, -3.0);
} else {
tmp = re * ((0.5 * (im * im)) + 1.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 800.0: tmp = math.sin(re) elif im <= 6.8e+153: tmp = math.pow(re, -3.0) else: tmp = re * ((0.5 * (im * im)) + 1.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 800.0) tmp = sin(re); elseif (im <= 6.8e+153) tmp = re ^ -3.0; else tmp = Float64(re * Float64(Float64(0.5 * Float64(im * im)) + 1.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 800.0) tmp = sin(re); elseif (im <= 6.8e+153) tmp = re ^ -3.0; else tmp = re * ((0.5 * (im * im)) + 1.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 800.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 6.8e+153], N[Power[re, -3.0], $MachinePrecision], N[(re * N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 800:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 6.8 \cdot 10^{+153}:\\
\;\;\;\;{re}^{-3}\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)\\
\end{array}
\end{array}
if im < 800Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 71.7%
if 800 < im < 6.7999999999999995e153Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 82.4%
distribute-lft-out82.4%
+-commutative82.4%
rec-exp82.4%
Simplified82.4%
Applied egg-rr60.4%
if 6.7999999999999995e153 < im Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 63.4%
Taylor expanded in im around 0 63.4%
unpow263.4%
Simplified63.4%
Final simplification69.6%
(FPCore (re im) :precision binary64 (if (<= im 0.00095) (sin re) (* re (+ (* 0.5 (* im im)) 1.0))))
double code(double re, double im) {
double tmp;
if (im <= 0.00095) {
tmp = sin(re);
} else {
tmp = re * ((0.5 * (im * im)) + 1.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.00095d0) then
tmp = sin(re)
else
tmp = re * ((0.5d0 * (im * im)) + 1.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.00095) {
tmp = Math.sin(re);
} else {
tmp = re * ((0.5 * (im * im)) + 1.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.00095: tmp = math.sin(re) else: tmp = re * ((0.5 * (im * im)) + 1.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.00095) tmp = sin(re); else tmp = Float64(re * Float64(Float64(0.5 * Float64(im * im)) + 1.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.00095) tmp = sin(re); else tmp = re * ((0.5 * (im * im)) + 1.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.00095], N[Sin[re], $MachinePrecision], N[(re * N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.00095:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)\\
\end{array}
\end{array}
if im < 9.49999999999999998e-4Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 71.9%
if 9.49999999999999998e-4 < im Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 69.5%
Taylor expanded in im around 0 47.6%
unpow247.6%
Simplified47.6%
Final simplification66.3%
(FPCore (re im) :precision binary64 (* re (+ (* 0.5 (* im im)) 1.0)))
double code(double re, double im) {
return re * ((0.5 * (im * im)) + 1.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re * ((0.5d0 * (im * im)) + 1.0d0)
end function
public static double code(double re, double im) {
return re * ((0.5 * (im * im)) + 1.0);
}
def code(re, im): return re * ((0.5 * (im * im)) + 1.0)
function code(re, im) return Float64(re * Float64(Float64(0.5 * Float64(im * im)) + 1.0)) end
function tmp = code(re, im) tmp = re * ((0.5 * (im * im)) + 1.0); end
code[re_, im_] := N[(re * N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)
\end{array}
Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 61.0%
Taylor expanded in im around 0 49.1%
unpow249.1%
Simplified49.1%
Final simplification49.1%
(FPCore (re im) :precision binary64 (+ re (* 0.5 (* re im))))
double code(double re, double im) {
return re + (0.5 * (re * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re + (0.5d0 * (re * im))
end function
public static double code(double re, double im) {
return re + (0.5 * (re * im));
}
def code(re, im): return re + (0.5 * (re * im))
function code(re, im) return Float64(re + Float64(0.5 * Float64(re * im))) end
function tmp = code(re, im) tmp = re + (0.5 * (re * im)); end
code[re_, im_] := N[(re + N[(0.5 * N[(re * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re + 0.5 \cdot \left(re \cdot im\right)
\end{array}
Initial program 100.0%
distribute-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 77.5%
Taylor expanded in re around 0 44.5%
Taylor expanded in im around 0 35.9%
Final simplification35.9%
(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-lft-in100.0%
+-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-in100.0%
fma-def100.0%
exp-diff100.0%
associate-*l/100.0%
exp-0100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 61.0%
distribute-lft-out61.0%
+-commutative61.0%
rec-exp61.0%
Simplified61.0%
Taylor expanded in im around 0 29.7%
Final simplification29.7%
herbie shell --seed 2023238
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))