| Alternative 1 | |
|---|---|
| Error | 11.1 |
| Cost | 13772 |
(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 1.65e-163)
(- (/ (log (- re)) (log (/ 1.0 base))))
(if (<= im 1.36e+137)
(/ (log (sqrt (+ (* re re) (* im im)))) (log base))
(/ 1.0 (/ (log base) (log im))))))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 <= 1.65e-163) {
tmp = -(log(-re) / log((1.0 / base)));
} else if (im <= 1.36e+137) {
tmp = log(sqrt(((re * re) + (im * im)))) / log(base);
} else {
tmp = 1.0 / (log(base) / log(im));
}
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 <= 1.65d-163) then
tmp = -(log(-re) / log((1.0d0 / base)))
else if (im <= 1.36d+137) then
tmp = log(sqrt(((re * re) + (im * im)))) / log(base)
else
tmp = 1.0d0 / (log(base) / log(im))
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 <= 1.65e-163) {
tmp = -(Math.log(-re) / Math.log((1.0 / base)));
} else if (im <= 1.36e+137) {
tmp = Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(base);
} else {
tmp = 1.0 / (Math.log(base) / Math.log(im));
}
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 <= 1.65e-163: tmp = -(math.log(-re) / math.log((1.0 / base))) elif im <= 1.36e+137: tmp = math.log(math.sqrt(((re * re) + (im * im)))) / math.log(base) else: tmp = 1.0 / (math.log(base) / math.log(im)) 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 <= 1.65e-163) tmp = Float64(-Float64(log(Float64(-re)) / log(Float64(1.0 / base)))); elseif (im <= 1.36e+137) tmp = Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(base)); else tmp = Float64(1.0 / Float64(log(base) / log(im))); 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 <= 1.65e-163) tmp = -(log(-re) / log((1.0 / base))); elseif (im <= 1.36e+137) tmp = log(sqrt(((re * re) + (im * im)))) / log(base); else tmp = 1.0 / (log(base) / log(im)); 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, 1.65e-163], (-N[(N[Log[(-re)], $MachinePrecision] / N[Log[N[(1.0 / base), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), If[LessEqual[im, 1.36e+137], N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Log[base], $MachinePrecision] / N[Log[im], $MachinePrecision]), $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 1.65 \cdot 10^{-163}:\\
\;\;\;\;-\frac{\log \left(-re\right)}{\log \left(\frac{1}{base}\right)}\\
\mathbf{elif}\;im \leq 1.36 \cdot 10^{+137}:\\
\;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\log base}{\log im}}\\
\end{array}
Results
if im < 1.65e-163Initial 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.json-simplify-14 [=>]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.json-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}
\] |
rational.json-simplify-2 [=>]32.6 | \[ \frac{\color{blue}{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}}{\log base \cdot \log base + 0 \cdot 0}
\] |
metadata-eval [=>]32.6 | \[ \frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational.json-simplify-4 [=>]32.6 | \[ \frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\color{blue}{\log base \cdot \log base}}
\] |
rational.json-simplify-49 [=>]32.6 | \[ \color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \frac{\log base}{\log base \cdot \log base}}
\] |
rational.json-simplify-46 [=>]32.6 | \[ \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \color{blue}{\frac{\frac{\log base}{\log base}}{\log base}}
\] |
Applied egg-rr32.6
Simplified32.6
[Start]32.6 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} + 0
\] |
|---|---|
rational.json-simplify-4 [=>]32.6 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}
\] |
Taylor expanded in re around -inf 5.0
Simplified5.0
[Start]5.0 | \[ \frac{\log \left(-1 \cdot re\right)}{\log base}
\] |
|---|---|
rational.json-simplify-2 [=>]5.0 | \[ \frac{\log \color{blue}{\left(re \cdot -1\right)}}{\log base}
\] |
rational.json-simplify-9 [=>]5.0 | \[ \frac{\log \color{blue}{\left(-re\right)}}{\log base}
\] |
Taylor expanded in base around inf 5.1
Simplified5.1
[Start]5.1 | \[ -1 \cdot \frac{\log \left(-re\right)}{\log \left(\frac{1}{base}\right)}
\] |
|---|---|
rational.json-simplify-2 [=>]5.1 | \[ \color{blue}{\frac{\log \left(-re\right)}{\log \left(\frac{1}{base}\right)} \cdot -1}
\] |
rational.json-simplify-9 [=>]5.1 | \[ \color{blue}{-\frac{\log \left(-re\right)}{\log \left(\frac{1}{base}\right)}}
\] |
if 1.65e-163 < im < 1.35999999999999999e137Initial program 11.7
Simplified11.7
[Start]11.7 | \[ \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.json-simplify-14 [=>]11.7 | \[ \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.json-simplify-4 [=>]11.7 | \[ \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0}
\] |
rational.json-simplify-2 [=>]11.7 | \[ \frac{\color{blue}{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}}{\log base \cdot \log base + 0 \cdot 0}
\] |
metadata-eval [=>]11.7 | \[ \frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational.json-simplify-4 [=>]11.7 | \[ \frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\color{blue}{\log base \cdot \log base}}
\] |
rational.json-simplify-49 [=>]11.7 | \[ \color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \frac{\log base}{\log base \cdot \log base}}
\] |
rational.json-simplify-46 [=>]11.7 | \[ \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \color{blue}{\frac{\frac{\log base}{\log base}}{\log base}}
\] |
Applied egg-rr11.6
Simplified11.6
[Start]11.6 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} + 0
\] |
|---|---|
rational.json-simplify-4 [=>]11.6 | \[ \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}}
\] |
if 1.35999999999999999e137 < im Initial program 59.6
Simplified59.6
[Start]59.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.json-simplify-14 [=>]59.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.json-simplify-4 [=>]59.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}
\] |
rational.json-simplify-2 [=>]59.6 | \[ \frac{\color{blue}{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}}{\log base \cdot \log base + 0 \cdot 0}
\] |
metadata-eval [=>]59.6 | \[ \frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational.json-simplify-4 [=>]59.6 | \[ \frac{\log base \cdot \log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\color{blue}{\log base \cdot \log base}}
\] |
rational.json-simplify-49 [=>]59.6 | \[ \color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \frac{\log base}{\log base \cdot \log base}}
\] |
rational.json-simplify-46 [=>]59.6 | \[ \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \color{blue}{\frac{\frac{\log base}{\log base}}{\log base}}
\] |
Applied egg-rr59.6
Taylor expanded in re around 0 4.1
Final simplification7.1
| Alternative 1 | |
|---|---|
| Error | 11.1 |
| Cost | 13772 |
| Alternative 2 | |
|---|---|
| Error | 11.1 |
| Cost | 13708 |
| Alternative 3 | |
|---|---|
| Error | 11.1 |
| Cost | 13516 |
| Alternative 4 | |
|---|---|
| Error | 11.1 |
| Cost | 13516 |
| Alternative 5 | |
|---|---|
| Error | 11.1 |
| Cost | 13452 |
| Alternative 6 | |
|---|---|
| Error | 30.9 |
| Cost | 12992 |
herbie shell --seed 2023063
(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))))