| Alternative 1 | |
|---|---|
| Error | 7.0 |
| Cost | 19720 |
(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 9.5e-163)
(- (/ (log (/ -1.0 re)) (log base)))
(if (<= im 3e+103)
(/ (log (+ (* re re) (* im im))) (* (log base) 2.0))
(* (log (pow im (/ 0.5 (log base)))) 2.0))))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 <= 9.5e-163) {
tmp = -(log((-1.0 / re)) / log(base));
} else if (im <= 3e+103) {
tmp = log(((re * re) + (im * im))) / (log(base) * 2.0);
} else {
tmp = log(pow(im, (0.5 / log(base)))) * 2.0;
}
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 <= 9.5d-163) then
tmp = -(log(((-1.0d0) / re)) / log(base))
else if (im <= 3d+103) then
tmp = log(((re * re) + (im * im))) / (log(base) * 2.0d0)
else
tmp = log((im ** (0.5d0 / log(base)))) * 2.0d0
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 <= 9.5e-163) {
tmp = -(Math.log((-1.0 / re)) / Math.log(base));
} else if (im <= 3e+103) {
tmp = Math.log(((re * re) + (im * im))) / (Math.log(base) * 2.0);
} else {
tmp = Math.log(Math.pow(im, (0.5 / Math.log(base)))) * 2.0;
}
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 <= 9.5e-163: tmp = -(math.log((-1.0 / re)) / math.log(base)) elif im <= 3e+103: tmp = math.log(((re * re) + (im * im))) / (math.log(base) * 2.0) else: tmp = math.log(math.pow(im, (0.5 / math.log(base)))) * 2.0 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 <= 9.5e-163) tmp = Float64(-Float64(log(Float64(-1.0 / re)) / log(base))); elseif (im <= 3e+103) tmp = Float64(log(Float64(Float64(re * re) + Float64(im * im))) / Float64(log(base) * 2.0)); else tmp = Float64(log((im ^ Float64(0.5 / log(base)))) * 2.0); 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 <= 9.5e-163) tmp = -(log((-1.0 / re)) / log(base)); elseif (im <= 3e+103) tmp = log(((re * re) + (im * im))) / (log(base) * 2.0); else tmp = log((im ^ (0.5 / log(base)))) * 2.0; 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, 9.5e-163], (-N[(N[Log[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]), If[LessEqual[im, 3e+103], N[(N[Log[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[Log[base], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[Power[im, N[(0.5 / N[Log[base], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 2.0), $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 9.5 \cdot 10^{-163}:\\
\;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\
\mathbf{elif}\;im \leq 3 \cdot 10^{+103}:\\
\;\;\;\;\frac{\log \left(re \cdot re + im \cdot im\right)}{\log base \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\log \left({im}^{\left(\frac{0.5}{\log base}\right)}\right) \cdot 2\\
\end{array}
Results
if im < 9.50000000000000012e-163Initial program 32.7
Simplified32.7
[Start]32.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 [=>]32.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 [=>]32.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 [=>]32.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 [=>]32.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 [=>]32.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 [=>]32.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 [=>]32.7 | \[ \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \color{blue}{\frac{\frac{\log base}{\log base}}{\log base}}
\] |
Taylor expanded in re around -inf 4.8
Simplified4.8
[Start]4.8 | \[ -1 \cdot \frac{\log \left(\frac{-1}{re}\right)}{\log base}
\] |
|---|---|
rational.json-simplify-2 [=>]4.8 | \[ \color{blue}{\frac{\log \left(\frac{-1}{re}\right)}{\log base} \cdot -1}
\] |
rational.json-simplify-9 [=>]4.8 | \[ \color{blue}{-\frac{\log \left(\frac{-1}{re}\right)}{\log base}}
\] |
if 9.50000000000000012e-163 < im < 3e103Initial 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}
\] |
metadata-eval [=>]11.7 | \[ \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 [=>]11.7 | \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}}
\] |
Applied egg-rr12.1
Simplified12.1
[Start]12.1 | \[ \log \left({\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}^{\left(\frac{1}{\log base}\right)}\right)
\] |
|---|---|
exponential.json-simplify-32 [=>]12.1 | \[ \log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{\left(0.5 \cdot \frac{1}{\log base}\right)}\right)}
\] |
Applied egg-rr11.6
if 3e103 < im Initial program 52.0
Simplified52.0
[Start]52.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.json-simplify-14 [=>]52.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.json-simplify-4 [=>]52.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}
\] |
rational.json-simplify-2 [=>]52.0 | \[ \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 [=>]52.0 | \[ \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 [=>]52.0 | \[ \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 [=>]52.0 | \[ \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 [=>]52.0 | \[ \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \color{blue}{\frac{\frac{\log base}{\log base}}{\log base}}
\] |
Taylor expanded in re around 0 4.9
Applied egg-rr5.1
Final simplification7.0
| Alternative 1 | |
|---|---|
| Error | 7.0 |
| Cost | 19720 |
| Alternative 2 | |
|---|---|
| Error | 7.1 |
| Cost | 13768 |
| Alternative 3 | |
|---|---|
| Error | 7.0 |
| Cost | 13768 |
| Alternative 4 | |
|---|---|
| Error | 10.2 |
| Cost | 13580 |
| Alternative 5 | |
|---|---|
| Error | 10.2 |
| Cost | 13580 |
| Alternative 6 | |
|---|---|
| Error | 30.5 |
| Cost | 12992 |
herbie shell --seed 2023074
(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))))