
(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 (let* ((t_0 (+ (* re re) (* im im)))) (if (<= t_0 2e+302) (/ (log (sqrt t_0)) (log 10.0)) (log 10.0))))
double code(double re, double im) {
double t_0 = (re * re) + (im * im);
double tmp;
if (t_0 <= 2e+302) {
tmp = log(sqrt(t_0)) / log(10.0);
} else {
tmp = log(10.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = (re * re) + (im * im)
if (t_0 <= 2d+302) then
tmp = log(sqrt(t_0)) / log(10.0d0)
else
tmp = log(10.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (re * re) + (im * im);
double tmp;
if (t_0 <= 2e+302) {
tmp = Math.log(Math.sqrt(t_0)) / Math.log(10.0);
} else {
tmp = Math.log(10.0);
}
return tmp;
}
def code(re, im): t_0 = (re * re) + (im * im) tmp = 0 if t_0 <= 2e+302: tmp = math.log(math.sqrt(t_0)) / math.log(10.0) else: tmp = math.log(10.0) return tmp
function code(re, im) t_0 = Float64(Float64(re * re) + Float64(im * im)) tmp = 0.0 if (t_0 <= 2e+302) tmp = Float64(log(sqrt(t_0)) / log(10.0)); else tmp = log(10.0); end return tmp end
function tmp_2 = code(re, im) t_0 = (re * re) + (im * im); tmp = 0.0; if (t_0 <= 2e+302) tmp = log(sqrt(t_0)) / log(10.0); else tmp = log(10.0); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e+302], N[(N[Log[N[Sqrt[t$95$0], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision], N[Log[10.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := re \cdot re + im \cdot im\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+302}:\\
\;\;\;\;\frac{\log \left(\sqrt{t\_0}\right)}{\log 10}\\
\mathbf{else}:\\
\;\;\;\;\log 10\\
\end{array}
\end{array}
if (+.f64 (*.f64 re re) (*.f64 im im)) < 2.0000000000000002e302Initial program 91.8%
if 2.0000000000000002e302 < (+.f64 (*.f64 re re) (*.f64 im im)) Initial program 3.1%
Taylor expanded in re around 0
Applied rewrites3.1%
Taylor expanded in re around 0
Applied rewrites14.5%
(FPCore (re im) :precision binary64 (let* ((t_0 (+ (* re re) (* im im)))) (if (<= t_0 2e+302) (log (sqrt t_0)) (log 10.0))))
double code(double re, double im) {
double t_0 = (re * re) + (im * im);
double tmp;
if (t_0 <= 2e+302) {
tmp = log(sqrt(t_0));
} else {
tmp = log(10.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = (re * re) + (im * im)
if (t_0 <= 2d+302) then
tmp = log(sqrt(t_0))
else
tmp = log(10.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (re * re) + (im * im);
double tmp;
if (t_0 <= 2e+302) {
tmp = Math.log(Math.sqrt(t_0));
} else {
tmp = Math.log(10.0);
}
return tmp;
}
def code(re, im): t_0 = (re * re) + (im * im) tmp = 0 if t_0 <= 2e+302: tmp = math.log(math.sqrt(t_0)) else: tmp = math.log(10.0) return tmp
function code(re, im) t_0 = Float64(Float64(re * re) + Float64(im * im)) tmp = 0.0 if (t_0 <= 2e+302) tmp = log(sqrt(t_0)); else tmp = log(10.0); end return tmp end
function tmp_2 = code(re, im) t_0 = (re * re) + (im * im); tmp = 0.0; if (t_0 <= 2e+302) tmp = log(sqrt(t_0)); else tmp = log(10.0); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e+302], N[Log[N[Sqrt[t$95$0], $MachinePrecision]], $MachinePrecision], N[Log[10.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := re \cdot re + im \cdot im\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+302}:\\
\;\;\;\;\log \left(\sqrt{t\_0}\right)\\
\mathbf{else}:\\
\;\;\;\;\log 10\\
\end{array}
\end{array}
if (+.f64 (*.f64 re re) (*.f64 im im)) < 2.0000000000000002e302Initial program 91.8%
Taylor expanded in re around 0
Applied rewrites17.3%
if 2.0000000000000002e302 < (+.f64 (*.f64 re re) (*.f64 im im)) Initial program 3.1%
Taylor expanded in re around 0
Applied rewrites3.1%
Taylor expanded in re around 0
Applied rewrites14.5%
(FPCore (re im) :precision binary64 (log 10.0))
double code(double re, double im) {
return log(10.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(10.0d0)
end function
public static double code(double re, double im) {
return Math.log(10.0);
}
def code(re, im): return math.log(10.0)
function code(re, im) return log(10.0) end
function tmp = code(re, im) tmp = log(10.0); end
code[re_, im_] := N[Log[10.0], $MachinePrecision]
\begin{array}{l}
\\
\log 10
\end{array}
Initial program 56.5%
Taylor expanded in re around 0
Applied rewrites4.2%
Taylor expanded in re around 0
Applied rewrites11.5%
(FPCore (re im) :precision binary64 (sqrt (+ (* re re) (* im im))))
double code(double re, double im) {
return sqrt(((re * re) + (im * im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt(((re * re) + (im * im)))
end function
public static double code(double re, double im) {
return Math.sqrt(((re * re) + (im * im)));
}
def code(re, im): return math.sqrt(((re * re) + (im * im)))
function code(re, im) return sqrt(Float64(Float64(re * re) + Float64(im * im))) end
function tmp = code(re, im) tmp = sqrt(((re * re) + (im * im))); end
code[re_, im_] := N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{re \cdot re + im \cdot im}
\end{array}
Initial program 56.5%
Taylor expanded in re around 0
Applied rewrites4.2%
(FPCore (re im) :precision binary64 (* re re))
double code(double re, double im) {
return re * re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re * re
end function
public static double code(double re, double im) {
return re * re;
}
def code(re, im): return re * re
function code(re, im) return Float64(re * re) end
function tmp = code(re, im) tmp = re * re; end
code[re_, im_] := N[(re * re), $MachinePrecision]
\begin{array}{l}
\\
re \cdot re
\end{array}
Initial program 56.5%
Taylor expanded in re around 0
Applied rewrites11.6%
Taylor expanded in re around 0
Applied rewrites4.0%
(FPCore (re im) :precision binary64 (* im im))
double code(double re, double im) {
return im * im;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im * im
end function
public static double code(double re, double im) {
return im * im;
}
def code(re, im): return im * im
function code(re, im) return Float64(im * im) end
function tmp = code(re, im) tmp = im * im; end
code[re_, im_] := N[(im * im), $MachinePrecision]
\begin{array}{l}
\\
im \cdot im
\end{array}
Initial program 56.5%
Taylor expanded in re around 0
Applied rewrites11.6%
Taylor expanded in re around 0
Applied rewrites3.8%
herbie shell --seed 2024313
(FPCore (re im)
:name "math.log10 on complex, real part"
:precision binary64
(/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))