| Alternative 1 | |
|---|---|
| Accuracy | 94.9% |
| Cost | 58688 |
(FPCore (x.re x.im y.re y.im)
:precision binary64
(*
(exp
(-
(* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re)
(* (atan2 x.im x.re) y.im)))
(cos
(+
(* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.im)
(* (atan2 x.im x.re) y.re)))))(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (* (atan2 x.im x.re) y.im))
(t_1 (exp (- (* (log (hypot x.re x.im)) y.re) t_0))))
(if (<= y.re -2.6e-59)
(* t_1 (cos (* y.re (atan2 x.im x.re))))
(if (<= y.re 1e-44)
(/ (cos (* y.im (log (hypot x.im x.re)))) (exp t_0))
t_1))))double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return exp(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_im) + (atan2(x_46_im, x_46_re) * y_46_re)));
}
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = atan2(x_46_im, x_46_re) * y_46_im;
double t_1 = exp(((log(hypot(x_46_re, x_46_im)) * y_46_re) - t_0));
double tmp;
if (y_46_re <= -2.6e-59) {
tmp = t_1 * cos((y_46_re * atan2(x_46_im, x_46_re)));
} else if (y_46_re <= 1e-44) {
tmp = cos((y_46_im * log(hypot(x_46_im, x_46_re)))) / exp(t_0);
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return Math.exp(((Math.log(Math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (Math.atan2(x_46_im, x_46_re) * y_46_im))) * Math.cos(((Math.log(Math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_im) + (Math.atan2(x_46_im, x_46_re) * y_46_re)));
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = Math.atan2(x_46_im, x_46_re) * y_46_im;
double t_1 = Math.exp(((Math.log(Math.hypot(x_46_re, x_46_im)) * y_46_re) - t_0));
double tmp;
if (y_46_re <= -2.6e-59) {
tmp = t_1 * Math.cos((y_46_re * Math.atan2(x_46_im, x_46_re)));
} else if (y_46_re <= 1e-44) {
tmp = Math.cos((y_46_im * Math.log(Math.hypot(x_46_im, x_46_re)))) / Math.exp(t_0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return math.exp(((math.log(math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (math.atan2(x_46_im, x_46_re) * y_46_im))) * math.cos(((math.log(math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_im) + (math.atan2(x_46_im, x_46_re) * y_46_re)))
def code(x_46_re, x_46_im, y_46_re, y_46_im): t_0 = math.atan2(x_46_im, x_46_re) * y_46_im t_1 = math.exp(((math.log(math.hypot(x_46_re, x_46_im)) * y_46_re) - t_0)) tmp = 0 if y_46_re <= -2.6e-59: tmp = t_1 * math.cos((y_46_re * math.atan2(x_46_im, x_46_re))) elif y_46_re <= 1e-44: tmp = math.cos((y_46_im * math.log(math.hypot(x_46_im, x_46_re)))) / math.exp(t_0) else: tmp = t_1 return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(exp(Float64(Float64(log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im)))) * y_46_re) - Float64(atan(x_46_im, x_46_re) * y_46_im))) * cos(Float64(Float64(log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im)))) * y_46_im) + Float64(atan(x_46_im, x_46_re) * y_46_re)))) end
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(atan(x_46_im, x_46_re) * y_46_im) t_1 = exp(Float64(Float64(log(hypot(x_46_re, x_46_im)) * y_46_re) - t_0)) tmp = 0.0 if (y_46_re <= -2.6e-59) tmp = Float64(t_1 * cos(Float64(y_46_re * atan(x_46_im, x_46_re)))); elseif (y_46_re <= 1e-44) tmp = Float64(cos(Float64(y_46_im * log(hypot(x_46_im, x_46_re)))) / exp(t_0)); else tmp = t_1; end return tmp end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = exp(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_im) + (atan2(x_46_im, x_46_re) * y_46_re))); end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = atan2(x_46_im, x_46_re) * y_46_im; t_1 = exp(((log(hypot(x_46_re, x_46_im)) * y_46_re) - t_0)); tmp = 0.0; if (y_46_re <= -2.6e-59) tmp = t_1 * cos((y_46_re * atan2(x_46_im, x_46_re))); elseif (y_46_re <= 1e-44) tmp = cos((y_46_im * log(hypot(x_46_im, x_46_re)))) / exp(t_0); else tmp = t_1; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[Exp[N[(N[(N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * y$46$re), $MachinePrecision] - N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * y$46$im), $MachinePrecision] + N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(N[(N[Log[N[Sqrt[x$46$re ^ 2 + x$46$im ^ 2], $MachinePrecision]], $MachinePrecision] * y$46$re), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[y$46$re, -2.6e-59], N[(t$95$1 * N[Cos[N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1e-44], N[(N[Cos[N[(y$46$im * N[Log[N[Sqrt[x$46$im ^ 2 + x$46$re ^ 2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Exp[t$95$0], $MachinePrecision]), $MachinePrecision], t$95$1]]]]
e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\begin{array}{l}
t_0 := \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im\\
t_1 := e^{\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.re - t_0}\\
\mathbf{if}\;y.re \leq -2.6 \cdot 10^{-59}:\\
\;\;\;\;t_1 \cdot \cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)\\
\mathbf{elif}\;y.re \leq 10^{-44}:\\
\;\;\;\;\frac{\cos \left(y.im \cdot \log \left(\mathsf{hypot}\left(x.im, x.re\right)\right)\right)}{e^{t_0}}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
if y.re < -2.59999999999999998e-59Initial program 42.7%
Simplified98.1%
[Start]42.7 | \[ e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\] |
|---|---|
hypot-def [=>]42.7 | \[ e^{\log \color{blue}{\left(\mathsf{hypot}\left(x.re, x.im\right)\right)} \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\] |
fma-def [=>]42.7 | \[ e^{\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \color{blue}{\left(\mathsf{fma}\left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right), y.im, \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)\right)}
\] |
hypot-def [=>]98.1 | \[ e^{\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\mathsf{fma}\left(\log \color{blue}{\left(\mathsf{hypot}\left(x.re, x.im\right)\right)}, y.im, \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)\right)
\] |
*-commutative [=>]98.1 | \[ e^{\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\mathsf{fma}\left(\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right), y.im, \color{blue}{y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}}\right)\right)
\] |
Taylor expanded in y.im around 0 98.3%
if -2.59999999999999998e-59 < y.re < 9.99999999999999953e-45Initial program 47.6%
Simplified89.0%
[Start]47.6 | \[ e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\] |
|---|---|
exp-diff [=>]47.6 | \[ \color{blue}{\frac{e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re}}{e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot y.im}}} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\] |
associate-*l/ [=>]47.6 | \[ \color{blue}{\frac{e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)}{e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot y.im}}}
\] |
/-rgt-identity [<=]47.6 | \[ \frac{e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)}{\color{blue}{\frac{e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot y.im}}{1}}}
\] |
exp-0 [<=]47.6 | \[ \frac{e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)}{\frac{e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot y.im}}{\color{blue}{e^{0}}}}
\] |
*-commutative [=>]47.6 | \[ \frac{\color{blue}{\cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right) \cdot e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re}}}{\frac{e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot y.im}}{e^{0}}}
\] |
associate-/l* [=>]47.6 | \[ \color{blue}{\frac{\cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)}{\frac{\frac{e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot y.im}}{e^{0}}}{e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re}}}}
\] |
Taylor expanded in y.re around 0 92.1%
Taylor expanded in y.im around inf 47.6%
Simplified92.1%
[Start]47.6 | \[ \frac{\cos \left(y.im \cdot \log \left(\sqrt{{x.im}^{2} + {x.re}^{2}}\right)\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
|---|---|
+-commutative [=>]47.6 | \[ \frac{\cos \left(y.im \cdot \log \left(\sqrt{\color{blue}{{x.re}^{2} + {x.im}^{2}}}\right)\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
unpow2 [=>]47.6 | \[ \frac{\cos \left(y.im \cdot \log \left(\sqrt{\color{blue}{x.re \cdot x.re} + {x.im}^{2}}\right)\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
unpow2 [=>]47.6 | \[ \frac{\cos \left(y.im \cdot \log \left(\sqrt{x.re \cdot x.re + \color{blue}{x.im \cdot x.im}}\right)\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
hypot-def [=>]92.1 | \[ \frac{\cos \left(y.im \cdot \log \color{blue}{\left(\mathsf{hypot}\left(x.re, x.im\right)\right)}\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
hypot-def [<=]47.6 | \[ \frac{\cos \left(y.im \cdot \log \color{blue}{\left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right)}\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
unpow2 [<=]47.6 | \[ \frac{\cos \left(y.im \cdot \log \left(\sqrt{\color{blue}{{x.re}^{2}} + x.im \cdot x.im}\right)\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
unpow2 [<=]47.6 | \[ \frac{\cos \left(y.im \cdot \log \left(\sqrt{{x.re}^{2} + \color{blue}{{x.im}^{2}}}\right)\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
+-commutative [<=]47.6 | \[ \frac{\cos \left(y.im \cdot \log \left(\sqrt{\color{blue}{{x.im}^{2} + {x.re}^{2}}}\right)\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
unpow2 [=>]47.6 | \[ \frac{\cos \left(y.im \cdot \log \left(\sqrt{\color{blue}{x.im \cdot x.im} + {x.re}^{2}}\right)\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
unpow2 [=>]47.6 | \[ \frac{\cos \left(y.im \cdot \log \left(\sqrt{x.im \cdot x.im + \color{blue}{x.re \cdot x.re}}\right)\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
hypot-def [=>]92.1 | \[ \frac{\cos \left(y.im \cdot \log \color{blue}{\left(\mathsf{hypot}\left(x.im, x.re\right)\right)}\right)}{e^{y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}}}
\] |
if 9.99999999999999953e-45 < y.re Initial program 65.6%
Simplified97.5%
[Start]65.6 | \[ e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\] |
|---|---|
hypot-def [=>]65.6 | \[ e^{\log \color{blue}{\left(\mathsf{hypot}\left(x.re, x.im\right)\right)} \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\] |
fma-def [=>]65.6 | \[ e^{\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \color{blue}{\left(\mathsf{fma}\left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right), y.im, \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)\right)}
\] |
hypot-def [=>]97.5 | \[ e^{\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\mathsf{fma}\left(\log \color{blue}{\left(\mathsf{hypot}\left(x.re, x.im\right)\right)}, y.im, \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)\right)
\] |
*-commutative [=>]97.5 | \[ e^{\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\mathsf{fma}\left(\log \left(\mathsf{hypot}\left(x.re, x.im\right)\right), y.im, \color{blue}{y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}}\right)\right)
\] |
Taylor expanded in y.im around 0 97.7%
Taylor expanded in y.re around 0 96.8%
Final simplification94.9%
| Alternative 1 | |
|---|---|
| Accuracy | 94.9% |
| Cost | 58688 |
| Alternative 2 | |
|---|---|
| Accuracy | 94.6% |
| Cost | 45696 |
| Alternative 3 | |
|---|---|
| Accuracy | 94.7% |
| Cost | 32841 |
| Alternative 4 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 26308 |
| Alternative 5 | |
|---|---|
| Accuracy | 94.1% |
| Cost | 26176 |
| Alternative 6 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 20036 |
| Alternative 7 | |
|---|---|
| Accuracy | 67.7% |
| Cost | 13120 |
| Alternative 8 | |
|---|---|
| Accuracy | 42.7% |
| Cost | 13056 |
herbie shell --seed 2023130
(FPCore (x.re x.im y.re y.im)
:name "powComplex, real part"
:precision binary64
(* (exp (- (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re) (* (atan2 x.im x.re) y.im))) (cos (+ (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.im) (* (atan2 x.im x.re) y.re)))))