
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
double code(double re, double im) {
return exp(re) * sin(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * sin(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
def code(re, im): return math.exp(re) * math.sin(im)
function code(re, im) return Float64(exp(re) * sin(im)) end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \sin im
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
double code(double re, double im) {
return exp(re) * sin(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * sin(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
def code(re, im): return math.exp(re) * math.sin(im)
function code(re, im) return Float64(exp(re) * sin(im)) end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \sin im
\end{array}
(FPCore (re im) :precision binary64 (* (* (sin im) (sqrt (exp re))) (exp (* re 0.5))))
double code(double re, double im) {
return (sin(im) * sqrt(exp(re))) * exp((re * 0.5));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (sin(im) * sqrt(exp(re))) * exp((re * 0.5d0))
end function
public static double code(double re, double im) {
return (Math.sin(im) * Math.sqrt(Math.exp(re))) * Math.exp((re * 0.5));
}
def code(re, im): return (math.sin(im) * math.sqrt(math.exp(re))) * math.exp((re * 0.5))
function code(re, im) return Float64(Float64(sin(im) * sqrt(exp(re))) * exp(Float64(re * 0.5))) end
function tmp = code(re, im) tmp = (sin(im) * sqrt(exp(re))) * exp((re * 0.5)); end
code[re_, im_] := N[(N[(N[Sin[im], $MachinePrecision] * N[Sqrt[N[Exp[re], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(re * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\sin im \cdot \sqrt{e^{re}}\right) \cdot e^{re \cdot 0.5}
\end{array}
Initial program 100.0%
log1p-expm1-u99.6%
Applied egg-rr99.6%
log1p-expm1-u100.0%
*-commutative100.0%
add-sqr-sqrt100.0%
associate-*r*100.0%
Applied egg-rr100.0%
pow1/2100.0%
pow-exp100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (if (<= (exp re) 0.0) (exp re) (if (<= (exp re) 1.000002) (* (sin im) (+ re 1.0)) (* im (exp re)))))
double code(double re, double im) {
double tmp;
if (exp(re) <= 0.0) {
tmp = exp(re);
} else if (exp(re) <= 1.000002) {
tmp = sin(im) * (re + 1.0);
} else {
tmp = im * exp(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (exp(re) <= 0.0d0) then
tmp = exp(re)
else if (exp(re) <= 1.000002d0) then
tmp = sin(im) * (re + 1.0d0)
else
tmp = im * exp(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.exp(re) <= 0.0) {
tmp = Math.exp(re);
} else if (Math.exp(re) <= 1.000002) {
tmp = Math.sin(im) * (re + 1.0);
} else {
tmp = im * Math.exp(re);
}
return tmp;
}
def code(re, im): tmp = 0 if math.exp(re) <= 0.0: tmp = math.exp(re) elif math.exp(re) <= 1.000002: tmp = math.sin(im) * (re + 1.0) else: tmp = im * math.exp(re) return tmp
function code(re, im) tmp = 0.0 if (exp(re) <= 0.0) tmp = exp(re); elseif (exp(re) <= 1.000002) tmp = Float64(sin(im) * Float64(re + 1.0)); else tmp = Float64(im * exp(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (exp(re) <= 0.0) tmp = exp(re); elseif (exp(re) <= 1.000002) tmp = sin(im) * (re + 1.0); else tmp = im * exp(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Exp[re], $MachinePrecision], 0.0], N[Exp[re], $MachinePrecision], If[LessEqual[N[Exp[re], $MachinePrecision], 1.000002], N[(N[Sin[im], $MachinePrecision] * N[(re + 1.0), $MachinePrecision]), $MachinePrecision], N[(im * N[Exp[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;e^{re} \leq 1.000002:\\
\;\;\;\;\sin im \cdot \left(re + 1\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot e^{re}\\
\end{array}
\end{array}
if (exp.f64 re) < 0.0Initial program 100.0%
add-exp-log50.7%
prod-exp50.7%
Applied egg-rr50.7%
Taylor expanded in re around inf 100.0%
if 0.0 < (exp.f64 re) < 1.00000200000000006Initial program 100.0%
Taylor expanded in re around 0 99.9%
distribute-rgt1-in99.9%
Simplified99.9%
if 1.00000200000000006 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 75.8%
Final simplification93.7%
(FPCore (re im) :precision binary64 (if (<= (exp re) 0.0) (exp re) (if (<= (exp re) 1.000002) (sin im) (* im (exp re)))))
double code(double re, double im) {
double tmp;
if (exp(re) <= 0.0) {
tmp = exp(re);
} else if (exp(re) <= 1.000002) {
tmp = sin(im);
} else {
tmp = im * exp(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (exp(re) <= 0.0d0) then
tmp = exp(re)
else if (exp(re) <= 1.000002d0) then
tmp = sin(im)
else
tmp = im * exp(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.exp(re) <= 0.0) {
tmp = Math.exp(re);
} else if (Math.exp(re) <= 1.000002) {
tmp = Math.sin(im);
} else {
tmp = im * Math.exp(re);
}
return tmp;
}
def code(re, im): tmp = 0 if math.exp(re) <= 0.0: tmp = math.exp(re) elif math.exp(re) <= 1.000002: tmp = math.sin(im) else: tmp = im * math.exp(re) return tmp
function code(re, im) tmp = 0.0 if (exp(re) <= 0.0) tmp = exp(re); elseif (exp(re) <= 1.000002) tmp = sin(im); else tmp = Float64(im * exp(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (exp(re) <= 0.0) tmp = exp(re); elseif (exp(re) <= 1.000002) tmp = sin(im); else tmp = im * exp(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Exp[re], $MachinePrecision], 0.0], N[Exp[re], $MachinePrecision], If[LessEqual[N[Exp[re], $MachinePrecision], 1.000002], N[Sin[im], $MachinePrecision], N[(im * N[Exp[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;e^{re} \leq 1.000002:\\
\;\;\;\;\sin im\\
\mathbf{else}:\\
\;\;\;\;im \cdot e^{re}\\
\end{array}
\end{array}
if (exp.f64 re) < 0.0Initial program 100.0%
add-exp-log50.7%
prod-exp50.7%
Applied egg-rr50.7%
Taylor expanded in re around inf 100.0%
if 0.0 < (exp.f64 re) < 1.00000200000000006Initial program 100.0%
Taylor expanded in re around 0 98.8%
if 1.00000200000000006 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 75.8%
Final simplification93.2%
(FPCore (re im) :precision binary64 (let* ((t_0 (exp (* re 0.5)))) (* t_0 (* (sin im) t_0))))
double code(double re, double im) {
double t_0 = exp((re * 0.5));
return t_0 * (sin(im) * t_0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
t_0 = exp((re * 0.5d0))
code = t_0 * (sin(im) * t_0)
end function
public static double code(double re, double im) {
double t_0 = Math.exp((re * 0.5));
return t_0 * (Math.sin(im) * t_0);
}
def code(re, im): t_0 = math.exp((re * 0.5)) return t_0 * (math.sin(im) * t_0)
function code(re, im) t_0 = exp(Float64(re * 0.5)) return Float64(t_0 * Float64(sin(im) * t_0)) end
function tmp = code(re, im) t_0 = exp((re * 0.5)); tmp = t_0 * (sin(im) * t_0); end
code[re_, im_] := Block[{t$95$0 = N[Exp[N[(re * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 * N[(N[Sin[im], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{re \cdot 0.5}\\
t\_0 \cdot \left(\sin im \cdot t\_0\right)
\end{array}
\end{array}
Initial program 100.0%
log1p-expm1-u99.6%
Applied egg-rr99.6%
log1p-expm1-u100.0%
*-commutative100.0%
add-sqr-sqrt100.0%
associate-*r*100.0%
Applied egg-rr100.0%
pow1/2100.0%
pow-exp100.0%
Applied egg-rr100.0%
pow1/2100.0%
pow-exp100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (* (sin im) (exp re)))
double code(double re, double im) {
return sin(im) * exp(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sin(im) * exp(re)
end function
public static double code(double re, double im) {
return Math.sin(im) * Math.exp(re);
}
def code(re, im): return math.sin(im) * math.exp(re)
function code(re, im) return Float64(sin(im) * exp(re)) end
function tmp = code(re, im) tmp = sin(im) * exp(re); end
code[re_, im_] := N[(N[Sin[im], $MachinePrecision] * N[Exp[re], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin im \cdot e^{re}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (if (or (<= re -5e-7) (not (<= re 250000.0))) (exp re) (+ im (* im re))))
double code(double re, double im) {
double tmp;
if ((re <= -5e-7) || !(re <= 250000.0)) {
tmp = exp(re);
} else {
tmp = im + (im * re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-5d-7)) .or. (.not. (re <= 250000.0d0))) then
tmp = exp(re)
else
tmp = im + (im * re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -5e-7) || !(re <= 250000.0)) {
tmp = Math.exp(re);
} else {
tmp = im + (im * re);
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -5e-7) or not (re <= 250000.0): tmp = math.exp(re) else: tmp = im + (im * re) return tmp
function code(re, im) tmp = 0.0 if ((re <= -5e-7) || !(re <= 250000.0)) tmp = exp(re); else tmp = Float64(im + Float64(im * re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -5e-7) || ~((re <= 250000.0))) tmp = exp(re); else tmp = im + (im * re); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -5e-7], N[Not[LessEqual[re, 250000.0]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[(im + N[(im * re), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5 \cdot 10^{-7} \lor \neg \left(re \leq 250000\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;im + im \cdot re\\
\end{array}
\end{array}
if re < -4.99999999999999977e-7 or 2.5e5 < re Initial program 100.0%
add-exp-log55.5%
prod-exp55.5%
Applied egg-rr55.5%
Taylor expanded in re around inf 81.7%
if -4.99999999999999977e-7 < re < 2.5e5Initial program 100.0%
Taylor expanded in im around 0 52.8%
Taylor expanded in re around 0 51.8%
Final simplification67.6%
(FPCore (re im) :precision binary64 (if (or (<= re -55.0) (not (<= re 250000.0))) (exp re) (sin im)))
double code(double re, double im) {
double tmp;
if ((re <= -55.0) || !(re <= 250000.0)) {
tmp = exp(re);
} else {
tmp = sin(im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-55.0d0)) .or. (.not. (re <= 250000.0d0))) then
tmp = exp(re)
else
tmp = sin(im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -55.0) || !(re <= 250000.0)) {
tmp = Math.exp(re);
} else {
tmp = Math.sin(im);
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -55.0) or not (re <= 250000.0): tmp = math.exp(re) else: tmp = math.sin(im) return tmp
function code(re, im) tmp = 0.0 if ((re <= -55.0) || !(re <= 250000.0)) tmp = exp(re); else tmp = sin(im); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -55.0) || ~((re <= 250000.0))) tmp = exp(re); else tmp = sin(im); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -55.0], N[Not[LessEqual[re, 250000.0]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[Sin[im], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -55 \lor \neg \left(re \leq 250000\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\sin im\\
\end{array}
\end{array}
if re < -55 or 2.5e5 < re Initial program 100.0%
add-exp-log55.2%
prod-exp55.2%
Applied egg-rr55.2%
Taylor expanded in re around inf 82.1%
if -55 < re < 2.5e5Initial program 100.0%
Taylor expanded in re around 0 95.2%
Final simplification88.4%
(FPCore (re im) :precision binary64 (if (<= re 1.0) im (* im re)))
double code(double re, double im) {
double tmp;
if (re <= 1.0) {
tmp = im;
} else {
tmp = im * re;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 1.0d0) then
tmp = im
else
tmp = im * re
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 1.0) {
tmp = im;
} else {
tmp = im * re;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.0: tmp = im else: tmp = im * re return tmp
function code(re, im) tmp = 0.0 if (re <= 1.0) tmp = im; else tmp = Float64(im * re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.0) tmp = im; else tmp = im * re; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.0], im, N[(im * re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1:\\
\;\;\;\;im\\
\mathbf{else}:\\
\;\;\;\;im \cdot re\\
\end{array}
\end{array}
if re < 1Initial program 100.0%
Taylor expanded in im around 0 71.2%
Taylor expanded in re around 0 33.8%
if 1 < re Initial program 100.0%
Taylor expanded in im around 0 75.4%
Taylor expanded in re around 0 14.9%
Taylor expanded in re around inf 14.9%
Final simplification29.0%
(FPCore (re im) :precision binary64 (+ im (* im re)))
double code(double re, double im) {
return im + (im * re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im + (im * re)
end function
public static double code(double re, double im) {
return im + (im * re);
}
def code(re, im): return im + (im * re)
function code(re, im) return Float64(im + Float64(im * re)) end
function tmp = code(re, im) tmp = im + (im * re); end
code[re_, im_] := N[(im + N[(im * re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
im + im \cdot re
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 72.2%
Taylor expanded in re around 0 29.0%
Final simplification29.0%
(FPCore (re im) :precision binary64 im)
double code(double re, double im) {
return im;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im
end function
public static double code(double re, double im) {
return im;
}
def code(re, im): return im
function code(re, im) return im end
function tmp = code(re, im) tmp = im; end
code[re_, im_] := im
\begin{array}{l}
\\
im
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 72.2%
Taylor expanded in re around 0 25.9%
Final simplification25.9%
herbie shell --seed 2024030
(FPCore (re im)
:name "math.exp on complex, imaginary part"
:precision binary64
(* (exp re) (sin im)))