| Alternative 1 | |
|---|---|
| Error | 7.3 |
| Cost | 20296 |
(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 3.9e-99)
(* (/ 1.0 (log base)) (log (- re)))
(if (<= im 4.2e+107)
(/ 1.0 (* (/ 1.0 (log (sqrt (+ (* re re) (* im im))))) (log base)))
(* (/ (log im) (* (log base) (log base))) (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 <= 3.9e-99) {
tmp = (1.0 / log(base)) * log(-re);
} else if (im <= 4.2e+107) {
tmp = 1.0 / ((1.0 / log(sqrt(((re * re) + (im * im))))) * log(base));
} else {
tmp = (log(im) / (log(base) * log(base))) * 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 <= 3.9d-99) then
tmp = (1.0d0 / log(base)) * log(-re)
else if (im <= 4.2d+107) then
tmp = 1.0d0 / ((1.0d0 / log(sqrt(((re * re) + (im * im))))) * log(base))
else
tmp = (log(im) / (log(base) * log(base))) * 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 <= 3.9e-99) {
tmp = (1.0 / Math.log(base)) * Math.log(-re);
} else if (im <= 4.2e+107) {
tmp = 1.0 / ((1.0 / Math.log(Math.sqrt(((re * re) + (im * im))))) * Math.log(base));
} else {
tmp = (Math.log(im) / (Math.log(base) * Math.log(base))) * 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 <= 3.9e-99: tmp = (1.0 / math.log(base)) * math.log(-re) elif im <= 4.2e+107: tmp = 1.0 / ((1.0 / math.log(math.sqrt(((re * re) + (im * im))))) * math.log(base)) else: tmp = (math.log(im) / (math.log(base) * math.log(base))) * 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 <= 3.9e-99) tmp = Float64(Float64(1.0 / log(base)) * log(Float64(-re))); elseif (im <= 4.2e+107) tmp = Float64(1.0 / Float64(Float64(1.0 / log(sqrt(Float64(Float64(re * re) + Float64(im * im))))) * log(base))); else tmp = Float64(Float64(log(im) / Float64(log(base) * log(base))) * 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 <= 3.9e-99) tmp = (1.0 / log(base)) * log(-re); elseif (im <= 4.2e+107) tmp = 1.0 / ((1.0 / log(sqrt(((re * re) + (im * im))))) * log(base)); else tmp = (log(im) / (log(base) * log(base))) * 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, 3.9e-99], N[(N[(1.0 / N[Log[base], $MachinePrecision]), $MachinePrecision] * N[Log[(-re)], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4.2e+107], N[(1.0 / N[(N[(1.0 / N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[im], $MachinePrecision] / N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $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}\;im \leq 3.9 \cdot 10^{-99}:\\
\;\;\;\;\frac{1}{\log base} \cdot \log \left(-re\right)\\
\mathbf{elif}\;im \leq 4.2 \cdot 10^{+107}:\\
\;\;\;\;\frac{1}{\frac{1}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \log base}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base \cdot \log base} \cdot \log base\\
\end{array}
Results
if im < 3.89999999999999987e-99Initial program 30.4
Simplified30.4
[Start]30.4 | \[ \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 [=>]30.4 | \[ \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 [=>]30.4 | \[ \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.4 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational.json-simplify-4 [=>]30.4 | \[ \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 7.9
Simplified7.9
[Start]7.9 | \[ \frac{\log \left(-1 \cdot re\right) \cdot \log base}{\log base \cdot \log base}
\] |
|---|---|
rational.json-simplify-2 [=>]7.9 | \[ \frac{\log \color{blue}{\left(re \cdot -1\right)} \cdot \log base}{\log base \cdot \log base}
\] |
rational.json-simplify-9 [=>]7.9 | \[ \frac{\log \color{blue}{\left(-re\right)} \cdot \log base}{\log base \cdot \log base}
\] |
Applied egg-rr7.9
if 3.89999999999999987e-99 < im < 4.1999999999999999e107Initial program 9.8
Simplified9.7
[Start]9.8 | \[ \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 [=>]9.8 | \[ \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 [=>]9.8 | \[ \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 [=>]9.8 | \[ \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 [=>]9.8 | \[ \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 [=>]9.8 | \[ \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 [=>]9.8 | \[ \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 [=>]9.7 | \[ \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \color{blue}{\frac{\frac{\log base}{\log base}}{\log base}}
\] |
Applied egg-rr9.7
Applied egg-rr9.8
if 4.1999999999999999e107 < im Initial program 52.3
Simplified52.3
[Start]52.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.json-simplify-14 [=>]52.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.json-simplify-4 [=>]52.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 [=>]52.3 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational.json-simplify-4 [=>]52.3 | \[ \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 4.6
Applied egg-rr4.6
Final simplification7.4
| Alternative 1 | |
|---|---|
| Error | 7.3 |
| Cost | 20296 |
| Alternative 2 | |
|---|---|
| Error | 7.3 |
| Cost | 20040 |
| Alternative 3 | |
|---|---|
| Error | 9.7 |
| Cost | 13188 |
| Alternative 4 | |
|---|---|
| Error | 30.4 |
| Cost | 12992 |
herbie shell --seed 2023064
(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))))