
(FPCore (re im) :precision binary64 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im)))) / log(10.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im)))) / log(10.0d0)
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(10.0);
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im)))) / math.log(10.0)
function code(re, im) return Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(10.0)) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))) / log(10.0); end
code[re_, im_] := N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im)))) / log(10.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im)))) / log(10.0d0)
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(10.0);
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im)))) / math.log(10.0)
function code(re, im) return Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(10.0)) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))) / log(10.0); end
code[re_, im_] := N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\end{array}
(FPCore (re im) :precision binary64 (log (pow (hypot re im) (pow (pow (log 10.0) -0.5) 2.0))))
double code(double re, double im) {
return log(pow(hypot(re, im), pow(pow(log(10.0), -0.5), 2.0)));
}
public static double code(double re, double im) {
return Math.log(Math.pow(Math.hypot(re, im), Math.pow(Math.pow(Math.log(10.0), -0.5), 2.0)));
}
def code(re, im): return math.log(math.pow(math.hypot(re, im), math.pow(math.pow(math.log(10.0), -0.5), 2.0)))
function code(re, im) return log((hypot(re, im) ^ ((log(10.0) ^ -0.5) ^ 2.0))) end
function tmp = code(re, im) tmp = log((hypot(re, im) ^ ((log(10.0) ^ -0.5) ^ 2.0))); end
code[re_, im_] := N[Log[N[Power[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision], N[Power[N[Power[N[Log[10.0], $MachinePrecision], -0.5], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left({\left({\log 10}^{-0.5}\right)}^{2}\right)}\right)
\end{array}
Initial program 49.9%
hypot-def99.1%
Simplified99.1%
add-log-exp99.1%
div-inv98.6%
exp-to-pow98.5%
frac-2neg98.5%
metadata-eval98.5%
neg-log99.0%
metadata-eval99.0%
Applied egg-rr99.0%
metadata-eval99.0%
metadata-eval99.0%
neg-log98.5%
frac-2neg98.5%
add-sqr-sqrt98.5%
associate-/r*99.7%
un-div-inv99.7%
pow299.7%
pow1/299.7%
pow-flip99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (re im) :precision binary64 (/ (log (hypot re im)) (log 10.0)))
double code(double re, double im) {
return log(hypot(re, im)) / log(10.0);
}
public static double code(double re, double im) {
return Math.log(Math.hypot(re, im)) / Math.log(10.0);
}
def code(re, im): return math.log(math.hypot(re, im)) / math.log(10.0)
function code(re, im) return Float64(log(hypot(re, im)) / log(10.0)) end
function tmp = code(re, im) tmp = log(hypot(re, im)) / log(10.0); end
code[re_, im_] := N[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}
\end{array}
Initial program 49.9%
hypot-def99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (re im) :precision binary64 (if (<= im 2.8e-142) (/ (log (- re)) (log 10.0)) (/ 1.0 (/ (log 10.0) (log im)))))
double code(double re, double im) {
double tmp;
if (im <= 2.8e-142) {
tmp = log(-re) / log(10.0);
} else {
tmp = 1.0 / (log(10.0) / log(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.8d-142) then
tmp = log(-re) / log(10.0d0)
else
tmp = 1.0d0 / (log(10.0d0) / log(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.8e-142) {
tmp = Math.log(-re) / Math.log(10.0);
} else {
tmp = 1.0 / (Math.log(10.0) / Math.log(im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.8e-142: tmp = math.log(-re) / math.log(10.0) else: tmp = 1.0 / (math.log(10.0) / math.log(im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 2.8e-142) tmp = Float64(log(Float64(-re)) / log(10.0)); else tmp = Float64(1.0 / Float64(log(10.0) / log(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.8e-142) tmp = log(-re) / log(10.0); else tmp = 1.0 / (log(10.0) / log(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.8e-142], N[(N[Log[(-re)], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Log[10.0], $MachinePrecision] / N[Log[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.8 \cdot 10^{-142}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\log 10}{\log im}}\\
\end{array}
\end{array}
if im < 2.80000000000000004e-142Initial program 46.5%
hypot-def99.1%
Simplified99.1%
Taylor expanded in re around -inf 33.6%
associate-*r/33.6%
mul-1-neg33.6%
Simplified33.6%
*-un-lft-identity33.6%
neg-log33.6%
frac-2neg33.6%
metadata-eval33.6%
remove-double-div33.6%
Applied egg-rr33.6%
*-lft-identity33.6%
Simplified33.6%
if 2.80000000000000004e-142 < im Initial program 55.8%
hypot-def99.1%
Simplified99.1%
Taylor expanded in re around 0 70.4%
clear-num70.4%
inv-pow70.4%
Applied egg-rr70.4%
unpow-170.4%
Simplified70.4%
Final simplification47.0%
(FPCore (re im) :precision binary64 (if (<= im 4.2e-142) (/ (log (- re)) (log 10.0)) (/ (log im) (log 10.0))))
double code(double re, double im) {
double tmp;
if (im <= 4.2e-142) {
tmp = log(-re) / log(10.0);
} else {
tmp = log(im) / log(10.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 4.2d-142) then
tmp = log(-re) / log(10.0d0)
else
tmp = log(im) / log(10.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.2e-142) {
tmp = Math.log(-re) / Math.log(10.0);
} else {
tmp = Math.log(im) / Math.log(10.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.2e-142: tmp = math.log(-re) / math.log(10.0) else: tmp = math.log(im) / math.log(10.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.2e-142) tmp = Float64(log(Float64(-re)) / log(10.0)); else tmp = Float64(log(im) / log(10.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.2e-142) tmp = log(-re) / log(10.0); else tmp = log(im) / log(10.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.2e-142], N[(N[Log[(-re)], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision], N[(N[Log[im], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.2 \cdot 10^{-142}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log 10}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log 10}\\
\end{array}
\end{array}
if im < 4.1999999999999999e-142Initial program 46.5%
hypot-def99.1%
Simplified99.1%
Taylor expanded in re around -inf 33.6%
associate-*r/33.6%
mul-1-neg33.6%
Simplified33.6%
*-un-lft-identity33.6%
neg-log33.6%
frac-2neg33.6%
metadata-eval33.6%
remove-double-div33.6%
Applied egg-rr33.6%
*-lft-identity33.6%
Simplified33.6%
if 4.1999999999999999e-142 < im Initial program 55.8%
hypot-def99.1%
Simplified99.1%
Taylor expanded in re around 0 70.4%
Final simplification47.0%
(FPCore (re im) :precision binary64 (/ (log im) (log 0.1)))
double code(double re, double im) {
return log(im) / log(0.1);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(im) / log(0.1d0)
end function
public static double code(double re, double im) {
return Math.log(im) / Math.log(0.1);
}
def code(re, im): return math.log(im) / math.log(0.1)
function code(re, im) return Float64(log(im) / log(0.1)) end
function tmp = code(re, im) tmp = log(im) / log(0.1); end
code[re_, im_] := N[(N[Log[im], $MachinePrecision] / N[Log[0.1], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log im}{\log 0.1}
\end{array}
Initial program 49.9%
hypot-def99.1%
Simplified99.1%
add-log-exp99.1%
div-inv98.6%
exp-to-pow98.5%
frac-2neg98.5%
metadata-eval98.5%
neg-log99.0%
metadata-eval99.0%
Applied egg-rr99.0%
Taylor expanded in re around 0 29.0%
neg-mul-129.0%
distribute-neg-frac29.0%
Simplified29.0%
add-sqr-sqrt9.2%
sqrt-unprod9.7%
sqr-neg9.7%
sqrt-unprod0.4%
add-sqr-sqrt2.9%
*-un-lft-identity2.9%
add-sqr-sqrt0.0%
times-frac0.0%
Applied egg-rr0.0%
times-frac0.0%
*-lft-identity0.0%
rem-square-sqrt2.9%
Simplified2.9%
Final simplification2.9%
(FPCore (re im) :precision binary64 (/ (log im) (log 10.0)))
double code(double re, double im) {
return log(im) / log(10.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(im) / log(10.0d0)
end function
public static double code(double re, double im) {
return Math.log(im) / Math.log(10.0);
}
def code(re, im): return math.log(im) / math.log(10.0)
function code(re, im) return Float64(log(im) / log(10.0)) end
function tmp = code(re, im) tmp = log(im) / log(10.0); end
code[re_, im_] := N[(N[Log[im], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log im}{\log 10}
\end{array}
Initial program 49.9%
hypot-def99.1%
Simplified99.1%
Taylor expanded in re around 0 29.0%
Final simplification29.0%
herbie shell --seed 2023192
(FPCore (re im)
:name "math.log10 on complex, real part"
:precision binary64
(/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))