
(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))))
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));
}
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
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));
}
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))
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 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
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]
\begin{array}{l}
\\
\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}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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))))
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));
}
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
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));
}
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))
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 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
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]
\begin{array}{l}
\\
\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}
\end{array}
(FPCore (re im base) :precision binary64 (/ (log (hypot re im)) (log base)))
double code(double re, double im, double base) {
return log(hypot(re, im)) / log(base);
}
public static double code(double re, double im, double base) {
return Math.log(Math.hypot(re, im)) / Math.log(base);
}
def code(re, im, base): return math.log(math.hypot(re, im)) / math.log(base)
function code(re, im, base) return Float64(log(hypot(re, im)) / log(base)) end
function tmp = code(re, im, base) tmp = log(hypot(re, im)) / log(base); end
code[re_, im_, base_] := N[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log base}
\end{array}
Initial program 49.7%
mul0-rgt49.7%
+-rgt-identity49.7%
metadata-eval49.7%
+-rgt-identity49.7%
times-frac49.8%
*-inverses49.8%
*-rgt-identity49.8%
hypot-def99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (re im base) :precision binary64 (if (<= (log base) -2e-310) (* (log base) (log im)) (log (hypot re im))))
double code(double re, double im, double base) {
double tmp;
if (log(base) <= -2e-310) {
tmp = log(base) * log(im);
} else {
tmp = log(hypot(re, im));
}
return tmp;
}
public static double code(double re, double im, double base) {
double tmp;
if (Math.log(base) <= -2e-310) {
tmp = Math.log(base) * Math.log(im);
} else {
tmp = Math.log(Math.hypot(re, im));
}
return tmp;
}
def code(re, im, base): tmp = 0 if math.log(base) <= -2e-310: tmp = math.log(base) * math.log(im) else: tmp = math.log(math.hypot(re, im)) return tmp
function code(re, im, base) tmp = 0.0 if (log(base) <= -2e-310) tmp = Float64(log(base) * log(im)); else tmp = log(hypot(re, im)); end return tmp end
function tmp_2 = code(re, im, base) tmp = 0.0; if (log(base) <= -2e-310) tmp = log(base) * log(im); else tmp = log(hypot(re, im)); end tmp_2 = tmp; end
code[re_, im_, base_] := If[LessEqual[N[Log[base], $MachinePrecision], -2e-310], N[(N[Log[base], $MachinePrecision] * N[Log[im], $MachinePrecision]), $MachinePrecision], N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\log base \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\log base \cdot \log im\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{hypot}\left(re, im\right)\right)\\
\end{array}
\end{array}
if (log.f64 base) < -1.999999999999994e-310Initial program 49.7%
mul0-rgt49.7%
+-rgt-identity49.7%
metadata-eval49.7%
+-rgt-identity49.7%
times-frac49.8%
*-inverses49.8%
*-rgt-identity49.8%
hypot-def99.6%
Simplified99.6%
Taylor expanded in re around 0 23.3%
frac-2neg23.3%
div-inv23.2%
add-sqr-sqrt23.1%
sqrt-unprod23.2%
sqr-neg23.2%
sqrt-prod0.0%
add-sqr-sqrt2.7%
Applied egg-rr2.7%
log-rec2.7%
associate-*r/2.7%
*-rgt-identity2.7%
log-rec2.7%
Simplified2.7%
div-inv2.7%
add-sqr-sqrt2.3%
sqrt-unprod22.4%
sqr-neg22.4%
sqrt-unprod20.0%
add-sqr-sqrt23.2%
add-exp-log0.0%
exp-neg0.0%
add-sqr-sqrt0.0%
sqrt-unprod0.0%
sqr-neg0.0%
sqrt-unprod0.0%
add-sqr-sqrt0.0%
add-exp-log4.2%
Applied egg-rr4.2%
if -1.999999999999994e-310 < (log.f64 base) Initial program 49.7%
mul0-rgt49.7%
+-rgt-identity49.7%
metadata-eval49.7%
+-rgt-identity49.7%
times-frac49.8%
*-inverses49.8%
*-rgt-identity49.8%
hypot-def99.5%
Simplified99.5%
clear-num99.4%
associate-/r/99.4%
Applied egg-rr99.4%
associate-/r/99.4%
Applied egg-rr99.4%
associate-/l*99.5%
add-sqr-sqrt99.1%
times-frac99.0%
metadata-eval99.0%
sqrt-div99.1%
add-exp-log98.6%
exp-neg98.7%
add-sqr-sqrt0.0%
sqrt-unprod14.2%
sqr-neg14.2%
sqrt-unprod14.2%
add-sqr-sqrt14.2%
add-exp-log14.2%
Applied egg-rr14.2%
associate-*r/14.2%
*-commutative14.2%
associate-/l*14.2%
*-inverses14.2%
/-rgt-identity14.2%
Simplified14.2%
Final simplification9.2%
(FPCore (re im base) :precision binary64 (if (<= im 8.5e-57) (/ (log (- re)) (log base)) (/ (log im) (log base))))
double code(double re, double im, double base) {
double tmp;
if (im <= 8.5e-57) {
tmp = log(-re) / 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
real(8) :: tmp
if (im <= 8.5d-57) then
tmp = log(-re) / log(base)
else
tmp = log(im) / log(base)
end if
code = tmp
end function
public static double code(double re, double im, double base) {
double tmp;
if (im <= 8.5e-57) {
tmp = Math.log(-re) / Math.log(base);
} else {
tmp = Math.log(im) / Math.log(base);
}
return tmp;
}
def code(re, im, base): tmp = 0 if im <= 8.5e-57: tmp = math.log(-re) / math.log(base) else: tmp = math.log(im) / math.log(base) return tmp
function code(re, im, base) tmp = 0.0 if (im <= 8.5e-57) tmp = Float64(log(Float64(-re)) / log(base)); else tmp = Float64(log(im) / log(base)); end return tmp end
function tmp_2 = code(re, im, base) tmp = 0.0; if (im <= 8.5e-57) tmp = log(-re) / log(base); else tmp = log(im) / log(base); end tmp_2 = tmp; end
code[re_, im_, base_] := If[LessEqual[im, 8.5e-57], N[(N[Log[(-re)], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision], N[(N[Log[im], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8.5 \cdot 10^{-57}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base}\\
\end{array}
\end{array}
if im < 8.49999999999999955e-57Initial program 53.7%
mul0-rgt53.7%
+-rgt-identity53.7%
metadata-eval53.7%
+-rgt-identity53.7%
times-frac53.8%
*-inverses53.8%
*-rgt-identity53.8%
hypot-def99.5%
Simplified99.5%
Taylor expanded in re around -inf 30.9%
associate-*r/30.9%
mul-1-neg30.9%
Simplified30.9%
expm1-log1p-u20.8%
expm1-udef20.7%
neg-log20.7%
frac-2neg20.7%
metadata-eval20.7%
remove-double-div20.7%
Applied egg-rr20.7%
expm1-def20.8%
expm1-log1p30.9%
Simplified30.9%
if 8.49999999999999955e-57 < im Initial program 41.0%
mul0-rgt41.0%
+-rgt-identity41.0%
metadata-eval41.0%
+-rgt-identity41.0%
times-frac40.9%
*-inverses40.9%
*-rgt-identity40.9%
hypot-def99.6%
Simplified99.6%
Taylor expanded in re around 0 77.6%
Final simplification45.3%
(FPCore (re im base) :precision binary64 (if (<= im -2e-310) (log (hypot re im)) (/ (log im) (log base))))
double code(double re, double im, double base) {
double tmp;
if (im <= -2e-310) {
tmp = log(hypot(re, im));
} else {
tmp = log(im) / log(base);
}
return tmp;
}
public static double code(double re, double im, double base) {
double tmp;
if (im <= -2e-310) {
tmp = Math.log(Math.hypot(re, im));
} else {
tmp = Math.log(im) / Math.log(base);
}
return tmp;
}
def code(re, im, base): tmp = 0 if im <= -2e-310: tmp = math.log(math.hypot(re, im)) else: tmp = math.log(im) / math.log(base) return tmp
function code(re, im, base) tmp = 0.0 if (im <= -2e-310) tmp = log(hypot(re, im)); else tmp = Float64(log(im) / log(base)); end return tmp end
function tmp_2 = code(re, im, base) tmp = 0.0; if (im <= -2e-310) tmp = log(hypot(re, im)); else tmp = log(im) / log(base); end tmp_2 = tmp; end
code[re_, im_, base_] := If[LessEqual[im, -2e-310], N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision], N[(N[Log[im], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\log \left(\mathsf{hypot}\left(re, im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base}\\
\end{array}
\end{array}
if im < -1.999999999999994e-310Initial program 53.4%
mul0-rgt53.4%
+-rgt-identity53.4%
metadata-eval53.4%
+-rgt-identity53.4%
times-frac53.5%
*-inverses53.5%
*-rgt-identity53.5%
hypot-def99.5%
Simplified99.5%
clear-num99.4%
associate-/r/99.4%
Applied egg-rr99.4%
associate-/r/99.4%
Applied egg-rr99.4%
associate-/l*99.5%
add-sqr-sqrt45.8%
times-frac45.8%
metadata-eval45.8%
sqrt-div45.8%
add-exp-log45.6%
exp-neg45.6%
add-sqr-sqrt0.0%
sqrt-unprod6.6%
sqr-neg6.6%
sqrt-unprod6.6%
add-sqr-sqrt6.6%
add-exp-log6.6%
Applied egg-rr6.6%
associate-*r/6.6%
*-commutative6.6%
associate-/l*6.6%
*-inverses7.5%
/-rgt-identity7.5%
Simplified7.5%
if -1.999999999999994e-310 < im Initial program 45.7%
mul0-rgt45.7%
+-rgt-identity45.7%
metadata-eval45.7%
+-rgt-identity45.7%
times-frac45.7%
*-inverses45.7%
*-rgt-identity45.7%
hypot-def99.6%
Simplified99.6%
Taylor expanded in re around 0 53.7%
Final simplification29.5%
(FPCore (re im base) :precision binary64 (log (hypot re im)))
double code(double re, double im, double base) {
return log(hypot(re, im));
}
public static double code(double re, double im, double base) {
return Math.log(Math.hypot(re, im));
}
def code(re, im, base): return math.log(math.hypot(re, im))
function code(re, im, base) return log(hypot(re, im)) end
function tmp = code(re, im, base) tmp = log(hypot(re, im)); end
code[re_, im_, base_] := N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\mathsf{hypot}\left(re, im\right)\right)
\end{array}
Initial program 49.7%
mul0-rgt49.7%
+-rgt-identity49.7%
metadata-eval49.7%
+-rgt-identity49.7%
times-frac49.8%
*-inverses49.8%
*-rgt-identity49.8%
hypot-def99.6%
Simplified99.6%
clear-num99.4%
associate-/r/99.4%
Applied egg-rr99.4%
associate-/r/99.4%
Applied egg-rr99.4%
associate-/l*99.6%
add-sqr-sqrt49.5%
times-frac49.5%
metadata-eval49.5%
sqrt-div49.6%
add-exp-log49.3%
exp-neg49.3%
add-sqr-sqrt0.0%
sqrt-unprod7.1%
sqr-neg7.1%
sqrt-unprod7.1%
add-sqr-sqrt7.1%
add-exp-log7.1%
Applied egg-rr7.1%
associate-*r/7.1%
*-commutative7.1%
associate-/l*7.1%
*-inverses7.9%
/-rgt-identity7.9%
Simplified7.9%
Final simplification7.9%
(FPCore (re im base) :precision binary64 (log im))
double code(double re, double im, double base) {
return log(im);
}
real(8) function code(re, im, base)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = log(im)
end function
public static double code(double re, double im, double base) {
return Math.log(im);
}
def code(re, im, base): return math.log(im)
function code(re, im, base) return log(im) end
function tmp = code(re, im, base) tmp = log(im); end
code[re_, im_, base_] := N[Log[im], $MachinePrecision]
\begin{array}{l}
\\
\log im
\end{array}
Initial program 49.7%
mul0-rgt49.7%
+-rgt-identity49.7%
metadata-eval49.7%
+-rgt-identity49.7%
times-frac49.8%
*-inverses49.8%
*-rgt-identity49.8%
hypot-def99.6%
Simplified99.6%
Taylor expanded in re around 0 25.6%
frac-2neg25.6%
div-inv25.6%
add-sqr-sqrt11.5%
sqrt-unprod13.4%
sqr-neg13.4%
sqrt-prod1.8%
add-sqr-sqrt3.1%
Applied egg-rr3.1%
log-rec3.1%
associate-*r/3.1%
*-rgt-identity3.1%
log-rec3.1%
Simplified3.1%
add-sqr-sqrt2.7%
add-sqr-sqrt1.6%
sqrt-unprod13.4%
sqr-neg13.4%
sqrt-unprod11.8%
add-sqr-sqrt13.9%
*-un-lft-identity13.9%
times-frac13.9%
Applied egg-rr2.6%
associate-*r/2.6%
*-commutative2.6%
associate-/l*2.6%
*-inverses3.7%
/-rgt-identity3.7%
Simplified3.7%
Final simplification3.7%
herbie shell --seed 2023195
(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))))