
(FPCore (re im) :precision binary64 (log (sqrt (+ (* re re) (* im im)))))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im))))
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im))));
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im))))
function code(re, im) return log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))); end
code[re_, im_] := N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\sqrt{re \cdot re + im \cdot im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (log (sqrt (+ (* re re) (* im im)))))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im))))
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im))));
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im))))
function code(re, im) return log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))); end
code[re_, im_] := N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\sqrt{re \cdot re + im \cdot im}\right)
\end{array}
NOTE: re should be positive before calling this function NOTE: im should be positive before calling this function NOTE: re and im should be sorted in increasing order before calling this function. (FPCore (re im) :precision binary64 (+ (log im) (* (/ (* 0.5 re) im) (/ re im))))
re = abs(re);
im = abs(im);
assert(re < im);
double code(double re, double im) {
return log(im) + (((0.5 * re) / im) * (re / im));
}
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(im) + (((0.5d0 * re) / im) * (re / im))
end function
re = Math.abs(re);
im = Math.abs(im);
assert re < im;
public static double code(double re, double im) {
return Math.log(im) + (((0.5 * re) / im) * (re / im));
}
re = abs(re) im = abs(im) [re, im] = sort([re, im]) def code(re, im): return math.log(im) + (((0.5 * re) / im) * (re / im))
re = abs(re) im = abs(im) re, im = sort([re, im]) function code(re, im) return Float64(log(im) + Float64(Float64(Float64(0.5 * re) / im) * Float64(re / im))) end
re = abs(re)
im = abs(im)
re, im = num2cell(sort([re, im])){:}
function tmp = code(re, im)
tmp = log(im) + (((0.5 * re) / im) * (re / im));
end
NOTE: re should be positive before calling this function NOTE: im should be positive before calling this function NOTE: re and im should be sorted in increasing order before calling this function. code[re_, im_] := N[(N[Log[im], $MachinePrecision] + N[(N[(N[(0.5 * re), $MachinePrecision] / im), $MachinePrecision] * N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re = |re|\\
im = |im|\\
[re, im] = \mathsf{sort}([re, im])\\
\\
\log im + \frac{0.5 \cdot re}{im} \cdot \frac{re}{im}
\end{array}
Initial program 59.0%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around 0 19.2%
associate-*r/19.2%
unpow219.2%
unpow219.2%
Simplified19.2%
associate-*r*19.2%
times-frac22.0%
Applied egg-rr22.0%
Final simplification22.0%
NOTE: re should be positive before calling this function NOTE: im should be positive before calling this function NOTE: re and im should be sorted in increasing order before calling this function. (FPCore (re im) :precision binary64 (log im))
re = abs(re);
im = abs(im);
assert(re < im);
double code(double re, double im) {
return log(im);
}
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(im)
end function
re = Math.abs(re);
im = Math.abs(im);
assert re < im;
public static double code(double re, double im) {
return Math.log(im);
}
re = abs(re) im = abs(im) [re, im] = sort([re, im]) def code(re, im): return math.log(im)
re = abs(re) im = abs(im) re, im = sort([re, im]) function code(re, im) return log(im) end
re = abs(re)
im = abs(im)
re, im = num2cell(sort([re, im])){:}
function tmp = code(re, im)
tmp = log(im);
end
NOTE: re should be positive before calling this function NOTE: im should be positive before calling this function NOTE: re and im should be sorted in increasing order before calling this function. code[re_, im_] := N[Log[im], $MachinePrecision]
\begin{array}{l}
re = |re|\\
im = |im|\\
[re, im] = \mathsf{sort}([re, im])\\
\\
\log im
\end{array}
Initial program 59.0%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around 0 23.8%
Final simplification23.8%
herbie shell --seed 2023199
(FPCore (re im)
:name "math.log/1 on complex, real part"
:precision binary64
(log (sqrt (+ (* re re) (* im im)))))