| Alternative 1 | |
|---|---|
| Error | 17.6 |
| Cost | 33096 |
(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
(let* ((t_0 (log (sqrt (+ (pow re 2.0) (pow im 2.0))))))
(if (<= im -1.4e+92)
(/ (log (- im)) (log base))
(if (<= im 2.5e-291)
(/ 0.5 (* (* (log base) 0.5) (/ 1.0 t_0)))
(if (<= im 1e-224)
(*
(/ (/ 1.0 (log base)) (log base))
(+ (* (log (/ -1.0 re)) (- (log base))) (* (atan2 im re) 0.0)))
(if (<= im 4.8e+55) (/ t_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 t_0 = log(sqrt((pow(re, 2.0) + pow(im, 2.0))));
double tmp;
if (im <= -1.4e+92) {
tmp = log(-im) / log(base);
} else if (im <= 2.5e-291) {
tmp = 0.5 / ((log(base) * 0.5) * (1.0 / t_0));
} else if (im <= 1e-224) {
tmp = ((1.0 / log(base)) / log(base)) * ((log((-1.0 / re)) * -log(base)) + (atan2(im, re) * 0.0));
} else if (im <= 4.8e+55) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = log(sqrt(((re ** 2.0d0) + (im ** 2.0d0))))
if (im <= (-1.4d+92)) then
tmp = log(-im) / log(base)
else if (im <= 2.5d-291) then
tmp = 0.5d0 / ((log(base) * 0.5d0) * (1.0d0 / t_0))
else if (im <= 1d-224) then
tmp = ((1.0d0 / log(base)) / log(base)) * ((log(((-1.0d0) / re)) * -log(base)) + (atan2(im, re) * 0.0d0))
else if (im <= 4.8d+55) then
tmp = t_0 / 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 t_0 = Math.log(Math.sqrt((Math.pow(re, 2.0) + Math.pow(im, 2.0))));
double tmp;
if (im <= -1.4e+92) {
tmp = Math.log(-im) / Math.log(base);
} else if (im <= 2.5e-291) {
tmp = 0.5 / ((Math.log(base) * 0.5) * (1.0 / t_0));
} else if (im <= 1e-224) {
tmp = ((1.0 / Math.log(base)) / Math.log(base)) * ((Math.log((-1.0 / re)) * -Math.log(base)) + (Math.atan2(im, re) * 0.0));
} else if (im <= 4.8e+55) {
tmp = t_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): t_0 = math.log(math.sqrt((math.pow(re, 2.0) + math.pow(im, 2.0)))) tmp = 0 if im <= -1.4e+92: tmp = math.log(-im) / math.log(base) elif im <= 2.5e-291: tmp = 0.5 / ((math.log(base) * 0.5) * (1.0 / t_0)) elif im <= 1e-224: tmp = ((1.0 / math.log(base)) / math.log(base)) * ((math.log((-1.0 / re)) * -math.log(base)) + (math.atan2(im, re) * 0.0)) elif im <= 4.8e+55: tmp = t_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) t_0 = log(sqrt(Float64((re ^ 2.0) + (im ^ 2.0)))) tmp = 0.0 if (im <= -1.4e+92) tmp = Float64(log(Float64(-im)) / log(base)); elseif (im <= 2.5e-291) tmp = Float64(0.5 / Float64(Float64(log(base) * 0.5) * Float64(1.0 / t_0))); elseif (im <= 1e-224) tmp = Float64(Float64(Float64(1.0 / log(base)) / log(base)) * Float64(Float64(log(Float64(-1.0 / re)) * Float64(-log(base))) + Float64(atan(im, re) * 0.0))); elseif (im <= 4.8e+55) tmp = Float64(t_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) t_0 = log(sqrt(((re ^ 2.0) + (im ^ 2.0)))); tmp = 0.0; if (im <= -1.4e+92) tmp = log(-im) / log(base); elseif (im <= 2.5e-291) tmp = 0.5 / ((log(base) * 0.5) * (1.0 / t_0)); elseif (im <= 1e-224) tmp = ((1.0 / log(base)) / log(base)) * ((log((-1.0 / re)) * -log(base)) + (atan2(im, re) * 0.0)); elseif (im <= 4.8e+55) tmp = t_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_] := Block[{t$95$0 = N[Log[N[Sqrt[N[(N[Power[re, 2.0], $MachinePrecision] + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[im, -1.4e+92], N[(N[Log[(-im)], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.5e-291], N[(0.5 / N[(N[(N[Log[base], $MachinePrecision] * 0.5), $MachinePrecision] * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1e-224], N[(N[(N[(1.0 / N[Log[base], $MachinePrecision]), $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Log[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision] * (-N[Log[base], $MachinePrecision])), $MachinePrecision] + N[(N[ArcTan[im / re], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4.8e+55], N[(t$95$0 / 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}
t_0 := \log \left(\sqrt{{re}^{2} + {im}^{2}}\right)\\
\mathbf{if}\;im \leq -1.4 \cdot 10^{+92}:\\
\;\;\;\;\frac{\log \left(-im\right)}{\log base}\\
\mathbf{elif}\;im \leq 2.5 \cdot 10^{-291}:\\
\;\;\;\;\frac{0.5}{\left(\log base \cdot 0.5\right) \cdot \frac{1}{t_0}}\\
\mathbf{elif}\;im \leq 10^{-224}:\\
\;\;\;\;\frac{\frac{1}{\log base}}{\log base} \cdot \left(\log \left(\frac{-1}{re}\right) \cdot \left(-\log base\right) + \tan^{-1}_* \frac{im}{re} \cdot 0\right)\\
\mathbf{elif}\;im \leq 4.8 \cdot 10^{+55}:\\
\;\;\;\;\frac{t_0}{\log base}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base}\\
\end{array}
Results
if im < -1.4e92Initial program 50.2
Simplified50.2
[Start]50.2 | \[ \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}
\] |
|---|---|
metadata-eval [=>]50.2 | \[ \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 + \color{blue}{0}}
\] |
rational.json-simplify-65 [=>]50.2 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\color{blue}{\log base \cdot \log base}}
\] |
rational.json-simplify-41 [=>]50.2 | \[ \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot 0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base}
\] |
Taylor expanded in base around 0 50.2
Taylor expanded in im around -inf 8.7
Simplified8.7
[Start]8.7 | \[ \frac{\log \left(-1 \cdot im\right)}{\log base}
\] |
|---|---|
rational.json-simplify-39 [=>]8.7 | \[ \frac{\log \color{blue}{\left(im \cdot -1\right)}}{\log base}
\] |
rational.json-simplify-72 [=>]8.7 | \[ \frac{\log \color{blue}{\left(-im\right)}}{\log base}
\] |
if -1.4e92 < im < 2.5000000000000002e-291Initial program 21.9
Simplified21.9
[Start]21.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}
\] |
|---|---|
metadata-eval [=>]21.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 + \color{blue}{0}}
\] |
rational.json-simplify-65 [=>]21.9 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\color{blue}{\log base \cdot \log base}}
\] |
rational.json-simplify-41 [=>]21.9 | \[ \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot 0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base}
\] |
Taylor expanded in base around 0 21.9
Applied egg-rr21.9
Applied egg-rr22.0
if 2.5000000000000002e-291 < im < 1e-224Initial program 30.6
Simplified30.6
[Start]30.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}
\] |
|---|---|
metadata-eval [=>]30.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 + \color{blue}{0}}
\] |
rational.json-simplify-65 [=>]30.6 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\color{blue}{\log base \cdot \log base}}
\] |
rational.json-simplify-41 [=>]30.6 | \[ \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot 0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base}
\] |
Applied egg-rr30.7
Taylor expanded in re around -inf 34.5
Simplified34.5
[Start]34.5 | \[ \frac{\tan^{-1}_* \frac{im}{re} \cdot 0 + \frac{1}{\frac{-1}{\log base \cdot \log \left(\frac{-1}{re}\right)}}}{\log base \cdot \log base}
\] |
|---|---|
rational.json-simplify-15 [=>]34.6 | \[ \frac{\tan^{-1}_* \frac{im}{re} \cdot 0 + \frac{1}{\color{blue}{\frac{\frac{-1}{\log base}}{\log \left(\frac{-1}{re}\right)}}}}{\log base \cdot \log base}
\] |
rational.json-simplify-7 [=>]34.5 | \[ \frac{\tan^{-1}_* \frac{im}{re} \cdot 0 + \frac{1}{\color{blue}{\frac{\frac{-1}{\log \left(\frac{-1}{re}\right)}}{\log base}}}}{\log base \cdot \log base}
\] |
Applied egg-rr34.5
if 1e-224 < im < 4.7999999999999998e55Initial program 20.1
Simplified20.1
[Start]20.1 | \[ \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}
\] |
|---|---|
metadata-eval [=>]20.1 | \[ \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 + \color{blue}{0}}
\] |
rational.json-simplify-65 [=>]20.1 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\color{blue}{\log base \cdot \log base}}
\] |
rational.json-simplify-41 [=>]20.1 | \[ \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot 0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base}
\] |
Taylor expanded in base around 0 20.1
if 4.7999999999999998e55 < im Initial program 45.3
Simplified45.3
[Start]45.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}
\] |
|---|---|
metadata-eval [=>]45.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 + \color{blue}{0}}
\] |
rational.json-simplify-65 [=>]45.3 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\color{blue}{\log base \cdot \log base}}
\] |
rational.json-simplify-41 [=>]45.3 | \[ \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot 0 + \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base}
\] |
Taylor expanded in re around 0 11.0
Final simplification17.6
| Alternative 1 | |
|---|---|
| Error | 17.6 |
| Cost | 33096 |
| Alternative 2 | |
|---|---|
| Error | 17.5 |
| Cost | 32976 |
| Alternative 3 | |
|---|---|
| Error | 17.6 |
| Cost | 32976 |
| Alternative 4 | |
|---|---|
| Error | 26.1 |
| Cost | 13580 |
| Alternative 5 | |
|---|---|
| Error | 26.1 |
| Cost | 13520 |
| Alternative 6 | |
|---|---|
| Error | 26.0 |
| Cost | 13520 |
| Alternative 7 | |
|---|---|
| Error | 26.0 |
| Cost | 13256 |
| Alternative 8 | |
|---|---|
| Error | 36.2 |
| Cost | 13124 |
| Alternative 9 | |
|---|---|
| Error | 46.7 |
| Cost | 12992 |
herbie shell --seed 2023066
(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))))