| Alternative 1 | |
|---|---|
| Error | 11.6 |
| Cost | 26776 |
(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 6.1e-145)
(/ (log (- re)) (log base))
(if (<= im 4.1e+126)
(/ (log (sqrt (+ (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 <= 6.1e-145) {
tmp = log(-re) / log(base);
} else if (im <= 4.1e+126) {
tmp = log(sqrt((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 <= 6.1d-145) then
tmp = log(-re) / log(base)
else if (im <= 4.1d+126) then
tmp = log(sqrt(((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 <= 6.1e-145) {
tmp = Math.log(-re) / Math.log(base);
} else if (im <= 4.1e+126) {
tmp = Math.log(Math.sqrt((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 <= 6.1e-145: tmp = math.log(-re) / math.log(base) elif im <= 4.1e+126: tmp = math.log(math.sqrt((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 <= 6.1e-145) tmp = Float64(log(Float64(-re)) / log(base)); elseif (im <= 4.1e+126) tmp = Float64(log(sqrt(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 <= 6.1e-145) tmp = log(-re) / log(base); elseif (im <= 4.1e+126) tmp = log(sqrt(((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, 6.1e-145], N[(N[Log[(-re)], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4.1e+126], N[(N[Log[N[Sqrt[N[(N[Power[re, 2.0], $MachinePrecision] + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[base], $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 6.1 \cdot 10^{-145}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\
\mathbf{elif}\;im \leq 4.1 \cdot 10^{+126}:\\
\;\;\;\;\frac{\log \left(\sqrt{{re}^{2} + {im}^{2}}\right)}{\log base}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base}\\
\end{array}
Results
if im < 6.1e-145Initial program 32.4
Simplified32.4
[Start]32.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_best_oopsla_all_46_json_45_simplify-38 [=>]32.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_best_oopsla_all_46_json_45_simplify-85 [=>]32.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 [=>]32.4 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational_best_oopsla_all_46_json_45_simplify-85 [=>]32.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 base around 0 32.4
Taylor expanded in re around -inf 6.0
Simplified6.0
[Start]6.0 | \[ \frac{\log \left(-1 \cdot re\right)}{\log base}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]6.0 | \[ \frac{\log \color{blue}{\left(re \cdot -1\right)}}{\log base}
\] |
rational_best_oopsla_all_46_json_45_simplify-92 [=>]6.0 | \[ \frac{\log \color{blue}{\left(-re\right)}}{\log base}
\] |
if 6.1e-145 < im < 4.1000000000000001e126Initial program 11.8
Simplified11.8
[Start]11.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_best_oopsla_all_46_json_45_simplify-38 [=>]11.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_best_oopsla_all_46_json_45_simplify-85 [=>]11.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}
\] |
metadata-eval [=>]11.8 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}}
\] |
rational_best_oopsla_all_46_json_45_simplify-85 [=>]11.8 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}}
\] |
Taylor expanded in base around 0 11.7
if 4.1000000000000001e126 < im Initial program 56.3
Simplified56.3
[Start]56.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_oopsla_all_46_json_45_simplify-38 [=>]56.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_oopsla_all_46_json_45_simplify-85 [=>]56.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 [=>]56.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_oopsla_all_46_json_45_simplify-85 [=>]56.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
Final simplification7.4
| Alternative 1 | |
|---|---|
| Error | 11.6 |
| Cost | 26776 |
| Alternative 2 | |
|---|---|
| Error | 11.6 |
| Cost | 20764 |
| Alternative 3 | |
|---|---|
| Error | 11.6 |
| Cost | 13980 |
| Alternative 4 | |
|---|---|
| Error | 31.0 |
| Cost | 12992 |
herbie shell --seed 2023090
(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))))