
(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 7 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%
sub0-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (if (or (<= im 0.06) (not (<= im 1.35e+154))) (+ (sin re) (* (* 0.5 (sin re)) (* im im))) (* (* 0.5 re) (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if ((im <= 0.06) || !(im <= 1.35e+154)) {
tmp = sin(re) + ((0.5 * sin(re)) * (im * im));
} else {
tmp = (0.5 * re) * (exp(-im) + exp(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.06d0) .or. (.not. (im <= 1.35d+154))) then
tmp = sin(re) + ((0.5d0 * sin(re)) * (im * im))
else
tmp = (0.5d0 * re) * (exp(-im) + exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 0.06) || !(im <= 1.35e+154)) {
tmp = Math.sin(re) + ((0.5 * Math.sin(re)) * (im * im));
} else {
tmp = (0.5 * re) * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 0.06) or not (im <= 1.35e+154): tmp = math.sin(re) + ((0.5 * math.sin(re)) * (im * im)) else: tmp = (0.5 * re) * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if ((im <= 0.06) || !(im <= 1.35e+154)) tmp = Float64(sin(re) + Float64(Float64(0.5 * sin(re)) * Float64(im * im))); else tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 0.06) || ~((im <= 1.35e+154))) tmp = sin(re) + ((0.5 * sin(re)) * (im * im)); else tmp = (0.5 * re) * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 0.06], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(N[Sin[re], $MachinePrecision] + N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(im * im), $MachinePrecision]), $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.06 \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\sin re + \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 0.059999999999999998 or 1.35000000000000003e154 < im Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 85.5%
Simplified85.5%
if 0.059999999999999998 < im < 1.35000000000000003e154Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 86.5%
Simplified86.5%
Final simplification85.6%
(FPCore (re im) :precision binary64 (if (<= im 0.00019) (sin re) (* (* 0.5 re) (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (im <= 0.00019) {
tmp = sin(re);
} else {
tmp = (0.5 * re) * (exp(-im) + exp(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.00019d0) then
tmp = sin(re)
else
tmp = (0.5d0 * re) * (exp(-im) + exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.00019) {
tmp = Math.sin(re);
} else {
tmp = (0.5 * re) * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.00019: tmp = math.sin(re) else: tmp = (0.5 * re) * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.00019) tmp = sin(re); else tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.00019) tmp = sin(re); else tmp = (0.5 * re) * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.00019], N[Sin[re], $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.00019:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 1.9000000000000001e-4Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 66.0%
if 1.9000000000000001e-4 < im Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 83.7%
Simplified83.7%
Final simplification70.6%
(FPCore (re im) :precision binary64 (if (<= im 4600000000.0) (sin re) (if (<= im 1.45e+71) (pow re -512.0) (+ re (* 0.5 (* re (* im im)))))))
double code(double re, double im) {
double tmp;
if (im <= 4600000000.0) {
tmp = sin(re);
} else if (im <= 1.45e+71) {
tmp = pow(re, -512.0);
} 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 <= 4600000000.0d0) then
tmp = sin(re)
else if (im <= 1.45d+71) then
tmp = re ** (-512.0d0)
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 <= 4600000000.0) {
tmp = Math.sin(re);
} else if (im <= 1.45e+71) {
tmp = Math.pow(re, -512.0);
} else {
tmp = re + (0.5 * (re * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4600000000.0: tmp = math.sin(re) elif im <= 1.45e+71: tmp = math.pow(re, -512.0) else: tmp = re + (0.5 * (re * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 4600000000.0) tmp = sin(re); elseif (im <= 1.45e+71) tmp = re ^ -512.0; 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 <= 4600000000.0) tmp = sin(re); elseif (im <= 1.45e+71) tmp = re ^ -512.0; else tmp = re + (0.5 * (re * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4600000000.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.45e+71], N[Power[re, -512.0], $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 4600000000:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.45 \cdot 10^{+71}:\\
\;\;\;\;{re}^{-512}\\
\mathbf{else}:\\
\;\;\;\;re + 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 4.6e9Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 65.7%
if 4.6e9 < im < 1.45000000000000004e71Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 75.0%
Simplified75.0%
Applied egg-rr31.9%
if 1.45000000000000004e71 < im Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 87.8%
Simplified87.8%
Taylor expanded in im around 0 70.2%
add-log-exp83.7%
*-un-lft-identity83.7%
log-prod83.7%
metadata-eval83.7%
add-log-exp70.2%
pow270.2%
*-commutative70.2%
associate-*l*54.7%
Applied egg-rr54.7%
+-lft-identity54.7%
associate-*r*70.2%
*-commutative70.2%
Simplified70.2%
Final simplification64.5%
(FPCore (re im) :precision binary64 (if (<= im 0.031) (sin re) (+ re (* 0.5 (* re (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 0.031) {
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 <= 0.031d0) 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 <= 0.031) {
tmp = Math.sin(re);
} else {
tmp = re + (0.5 * (re * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.031: tmp = math.sin(re) else: tmp = re + (0.5 * (re * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.031) 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 <= 0.031) tmp = sin(re); else tmp = re + (0.5 * (re * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.031], 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 0.031:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;re + 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 0.031Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 65.7%
if 0.031 < im Initial program 100.0%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 84.6%
Simplified84.6%
Taylor expanded in im around 0 53.5%
add-log-exp72.5%
*-un-lft-identity72.5%
log-prod72.5%
metadata-eval72.5%
add-log-exp53.5%
pow253.5%
*-commutative53.5%
associate-*l*41.8%
Applied egg-rr41.8%
+-lft-identity41.8%
associate-*r*53.5%
*-commutative53.5%
Simplified53.5%
Final simplification62.6%
(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%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 67.5%
Simplified67.5%
Taylor expanded in im around 0 52.5%
add-log-exp60.4%
*-un-lft-identity60.4%
log-prod60.4%
metadata-eval60.4%
add-log-exp52.5%
pow252.5%
*-commutative52.5%
associate-*l*46.2%
Applied egg-rr46.2%
+-lft-identity46.2%
associate-*r*52.5%
*-commutative52.5%
Simplified52.5%
Final simplification52.5%
(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%
sub0-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 67.5%
Simplified67.5%
Taylor expanded in im around 0 28.5%
Final simplification28.5%
herbie shell --seed 2023200
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))