| Alternative 1 | |
|---|---|
| Error | 6.9 |
| Cost | 13768 |
(FPCore (re im base) :precision binary64 (/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))
(FPCore (re im base)
:precision binary64
(if (<= re -1.22e+148)
(/ (log (- re)) (log base))
(if (<= re -1.95e-136)
(* (/ (log (+ (* re re) (* im im))) (log base)) 0.5)
(- (/ (log (/ 1.0 im)) (log base))))))double code(double re, double im, double base) {
return ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
double code(double re, double im, double base) {
double tmp;
if (re <= -1.22e+148) {
tmp = log(-re) / log(base);
} else if (re <= -1.95e-136) {
tmp = (log(((re * re) + (im * im))) / log(base)) * 0.5;
} else {
tmp = -(log((1.0 / im)) / log(base));
}
return tmp;
}
real(8) function code(re, im, base)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
real(8) function code(re, im, base)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
real(8) :: tmp
if (re <= (-1.22d+148)) then
tmp = log(-re) / log(base)
else if (re <= (-1.95d-136)) then
tmp = (log(((re * re) + (im * im))) / log(base)) * 0.5d0
else
tmp = -(log((1.0d0 / im)) / log(base))
end if
code = tmp
end function
public static double code(double re, double im, double base) {
return ((Math.log(Math.sqrt(((re * re) + (im * im)))) * Math.log(base)) + (Math.atan2(im, re) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
public static double code(double re, double im, double base) {
double tmp;
if (re <= -1.22e+148) {
tmp = Math.log(-re) / Math.log(base);
} else if (re <= -1.95e-136) {
tmp = (Math.log(((re * re) + (im * im))) / Math.log(base)) * 0.5;
} else {
tmp = -(Math.log((1.0 / im)) / Math.log(base));
}
return tmp;
}
def code(re, im, base): return ((math.log(math.sqrt(((re * re) + (im * im)))) * math.log(base)) + (math.atan2(im, re) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
def code(re, im, base): tmp = 0 if re <= -1.22e+148: tmp = math.log(-re) / math.log(base) elif re <= -1.95e-136: tmp = (math.log(((re * re) + (im * im))) / math.log(base)) * 0.5 else: tmp = -(math.log((1.0 / im)) / math.log(base)) return tmp
function code(re, im, base) return Float64(Float64(Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * log(base)) + Float64(atan(im, re) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0))) end
function code(re, im, base) tmp = 0.0 if (re <= -1.22e+148) tmp = Float64(log(Float64(-re)) / log(base)); elseif (re <= -1.95e-136) tmp = Float64(Float64(log(Float64(Float64(re * re) + Float64(im * im))) / log(base)) * 0.5); else tmp = Float64(-Float64(log(Float64(1.0 / im)) / log(base))); end return tmp end
function tmp = code(re, im, base) tmp = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0)); end
function tmp_2 = code(re, im, base) tmp = 0.0; if (re <= -1.22e+148) tmp = log(-re) / log(base); elseif (re <= -1.95e-136) tmp = (log(((re * re) + (im * im))) / log(base)) * 0.5; else tmp = -(log((1.0 / im)) / log(base)); end tmp_2 = tmp; end
code[re_, im_, base_] := N[(N[(N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(N[ArcTan[im / re], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(0.0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[re_, im_, base_] := If[LessEqual[re, -1.22e+148], N[(N[Log[(-re)], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.95e-136], N[(N[(N[Log[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], (-N[(N[Log[N[(1.0 / im), $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision])]]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\begin{array}{l}
\mathbf{if}\;re \leq -1.22 \cdot 10^{+148}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\
\mathbf{elif}\;re \leq -1.95 \cdot 10^{-136}:\\
\;\;\;\;\frac{\log \left(re \cdot re + im \cdot im\right)}{\log base} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\log base}\\
\end{array}
Results
if re < -1.22000000000000007e148Initial program 61.9
Simplified61.9
[Start]61.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\] |
|---|---|
rational_best-simplify-65 [=>]61.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + 0 \cdot 0} + \frac{\tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}}
\] |
rational_best-simplify-17 [=>]61.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + 0 \cdot 0} + \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} - \tan^{-1}_* \frac{im}{re}}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-5 [=>]61.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + 0 \cdot 0} + \frac{\color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-64 [=>]61.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + 0}{\log base \cdot \log base + 0 \cdot 0}}
\] |
trig-simplify-13 [=>]61.9 | \[ \frac{\color{blue}{0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-6 [=>]61.9 | \[ \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0}
\] |
metadata-eval [=>]61.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational_best-simplify-3 [=>]61.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{0 + \log base \cdot \log base}}
\] |
rational_best-simplify-6 [=>]61.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}}
\] |
rational_best-simplify-90 [=>]61.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} + \frac{0}{\log base}}
\] |
rational_best-simplify-64 [=>]61.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) + 0}{\log base}}
\] |
rational_best-simplify-3 [=>]61.9 | \[ \frac{\color{blue}{0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right)}}{\log base}
\] |
Taylor expanded in re around -inf 3.7
Simplified3.7
[Start]3.7 | \[ \frac{\log \left(-1 \cdot re\right)}{\log base}
\] |
|---|---|
rational_best-simplify-1 [=>]3.7 | \[ \frac{\log \color{blue}{\left(re \cdot -1\right)}}{\log base}
\] |
rational_best-simplify-11 [<=]3.7 | \[ \frac{\log \color{blue}{\left(-re\right)}}{\log base}
\] |
if -1.22000000000000007e148 < re < -1.94999999999999988e-136Initial program 10.9
Simplified10.8
[Start]10.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\] |
|---|---|
rational_best-simplify-65 [=>]10.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + 0 \cdot 0} + \frac{\tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}}
\] |
rational_best-simplify-17 [=>]10.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + 0 \cdot 0} + \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} - \tan^{-1}_* \frac{im}{re}}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-5 [=>]10.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + 0 \cdot 0} + \frac{\color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-64 [=>]10.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + 0}{\log base \cdot \log base + 0 \cdot 0}}
\] |
trig-simplify-13 [=>]10.9 | \[ \frac{\color{blue}{0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-6 [=>]10.9 | \[ \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0}
\] |
metadata-eval [=>]10.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational_best-simplify-3 [=>]10.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{0 + \log base \cdot \log base}}
\] |
rational_best-simplify-6 [=>]10.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}}
\] |
rational_best-simplify-90 [=>]10.8 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} + \frac{0}{\log base}}
\] |
rational_best-simplify-64 [=>]10.8 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) + 0}{\log base}}
\] |
rational_best-simplify-3 [=>]10.8 | \[ \frac{\color{blue}{0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right)}}{\log base}
\] |
Applied egg-rr10.8
if -1.94999999999999988e-136 < re Initial program 30.9
Simplified30.9
[Start]30.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\] |
|---|---|
rational_best-simplify-65 [=>]30.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + 0 \cdot 0} + \frac{\tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}}
\] |
rational_best-simplify-17 [=>]30.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + 0 \cdot 0} + \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} - \tan^{-1}_* \frac{im}{re}}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-5 [=>]30.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + 0 \cdot 0} + \frac{\color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-64 [=>]30.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + 0}{\log base \cdot \log base + 0 \cdot 0}}
\] |
trig-simplify-13 [=>]30.9 | \[ \frac{\color{blue}{0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-6 [=>]30.9 | \[ \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0}
\] |
metadata-eval [=>]30.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational_best-simplify-3 [=>]30.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{0 + \log base \cdot \log base}}
\] |
rational_best-simplify-6 [=>]30.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}}
\] |
rational_best-simplify-90 [=>]30.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} + \frac{0}{\log base}}
\] |
rational_best-simplify-64 [=>]30.9 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) + 0}{\log base}}
\] |
rational_best-simplify-3 [=>]30.9 | \[ \frac{\color{blue}{0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right)}}{\log base}
\] |
Taylor expanded in im around inf 5.9
Simplified5.9
[Start]5.9 | \[ -1 \cdot \frac{\log \left(\frac{1}{im}\right)}{\log base}
\] |
|---|---|
rational_best-simplify-1 [=>]5.9 | \[ \color{blue}{\frac{\log \left(\frac{1}{im}\right)}{\log base} \cdot -1}
\] |
rational_best-simplify-10 [=>]5.9 | \[ \color{blue}{-\frac{\log \left(\frac{1}{im}\right)}{\log base}}
\] |
Final simplification7.0
| Alternative 1 | |
|---|---|
| Error | 6.9 |
| Cost | 13768 |
| Alternative 2 | |
|---|---|
| Error | 9.8 |
| Cost | 13316 |
| Alternative 3 | |
|---|---|
| Error | 9.8 |
| Cost | 13188 |
| Alternative 4 | |
|---|---|
| Error | 31.2 |
| Cost | 12992 |
herbie shell --seed 2023099
(FPCore (re im base)
:name "math.log/2 on complex, real part"
:precision binary64
(/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))