| Alternative 1 | |
|---|---|
| Error | 10.3 |
| Cost | 13188 |
(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 (<= im 4e-133)
(/ (log (- re)) (log base))
(if (<= im 3.3e+83)
(* 0.5 (/ (log (+ (pow re 2.0) (pow im 2.0))) (log base)))
(/ (log 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 (im <= 4e-133) {
tmp = log(-re) / log(base);
} else if (im <= 3.3e+83) {
tmp = 0.5 * (log((pow(re, 2.0) + pow(im, 2.0))) / log(base));
} else {
tmp = log(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 (im <= 4d-133) then
tmp = log(-re) / log(base)
else if (im <= 3.3d+83) then
tmp = 0.5d0 * (log(((re ** 2.0d0) + (im ** 2.0d0))) / log(base))
else
tmp = log(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 (im <= 4e-133) {
tmp = Math.log(-re) / Math.log(base);
} else if (im <= 3.3e+83) {
tmp = 0.5 * (Math.log((Math.pow(re, 2.0) + Math.pow(im, 2.0))) / Math.log(base));
} else {
tmp = Math.log(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 im <= 4e-133: tmp = math.log(-re) / math.log(base) elif im <= 3.3e+83: tmp = 0.5 * (math.log((math.pow(re, 2.0) + math.pow(im, 2.0))) / math.log(base)) else: tmp = math.log(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 (im <= 4e-133) tmp = Float64(log(Float64(-re)) / log(base)); elseif (im <= 3.3e+83) tmp = Float64(0.5 * Float64(log(Float64((re ^ 2.0) + (im ^ 2.0))) / log(base))); else tmp = Float64(log(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 (im <= 4e-133) tmp = log(-re) / log(base); elseif (im <= 3.3e+83) tmp = 0.5 * (log(((re ^ 2.0) + (im ^ 2.0))) / log(base)); else tmp = log(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[im, 4e-133], N[(N[Log[(-re)], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 3.3e+83], N[(0.5 * N[(N[Log[N[(N[Power[re, 2.0], $MachinePrecision] + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[im], $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}\;im \leq 4 \cdot 10^{-133}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\
\mathbf{elif}\;im \leq 3.3 \cdot 10^{+83}:\\
\;\;\;\;0.5 \cdot \frac{\log \left({re}^{2} + {im}^{2}\right)}{\log base}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base}\\
\end{array}
Results
if im < 4.0000000000000003e-133Initial program 32.6
Simplified32.6
[Start]32.6 | \[ \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-15 [=>]32.6 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{\left(\tan^{-1}_* \frac{im}{re} - \tan^{-1}_* \frac{im}{re}\right)}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-3 [=>]32.6 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-4 [=>]32.6 | \[ \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 [=>]32.6 | \[ \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-4 [=>]32.6 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}}
\] |
Taylor expanded in re around -inf 6.3
Simplified6.3
[Start]6.3 | \[ \frac{\log \left(-1 \cdot re\right) \cdot \log base}{\log base \cdot \log base}
\] |
|---|---|
rational_best-simplify-2 [=>]6.3 | \[ \frac{\log \color{blue}{\left(re \cdot -1\right)} \cdot \log base}{\log base \cdot \log base}
\] |
rational_best-simplify-12 [=>]6.3 | \[ \frac{\log \color{blue}{\left(-re\right)} \cdot \log base}{\log base \cdot \log base}
\] |
Taylor expanded in base around 0 6.2
if 4.0000000000000003e-133 < im < 3.29999999999999985e83Initial program 11.3
Simplified11.3
[Start]11.3 | \[ \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-15 [=>]11.3 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{\left(\tan^{-1}_* \frac{im}{re} - \tan^{-1}_* \frac{im}{re}\right)}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-3 [=>]11.3 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-4 [=>]11.3 | \[ \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 [=>]11.3 | \[ \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-4 [=>]11.3 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}}
\] |
Applied egg-rr11.3
Taylor expanded in base around 0 11.2
if 3.29999999999999985e83 < im Initial program 49.0
Simplified49.0
[Start]49.0 | \[ \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-15 [=>]49.0 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{\left(\tan^{-1}_* \frac{im}{re} - \tan^{-1}_* \frac{im}{re}\right)}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-3 [=>]49.0 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational_best-simplify-4 [=>]49.0 | \[ \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 [=>]49.0 | \[ \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-4 [=>]49.0 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}}
\] |
Taylor expanded in re around 0 6.0
Final simplification7.4
| Alternative 1 | |
|---|---|
| Error | 10.3 |
| Cost | 13188 |
| Alternative 2 | |
|---|---|
| Error | 31.0 |
| Cost | 12992 |
herbie shell --seed 2023092
(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))))