
(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 3 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}
(FPCore (re im) :precision binary64 (log (hypot re im)))
double code(double re, double im) {
return log(hypot(re, im));
}
public static double code(double re, double im) {
return Math.log(Math.hypot(re, im));
}
def code(re, im): return math.log(math.hypot(re, im))
function code(re, im) return log(hypot(re, im)) end
function tmp = code(re, im) tmp = log(hypot(re, im)); end
code[re_, im_] := 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 50.8%
log-lowering-log.f64N/A
accelerator-lowering-hypot.f64100.0%
Simplified100.0%
(FPCore (re im) :precision binary64 (log (+ im (* (/ re im) (* re 0.5)))))
double code(double re, double im) {
return log((im + ((re / im) * (re * 0.5))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log((im + ((re / im) * (re * 0.5d0))))
end function
public static double code(double re, double im) {
return Math.log((im + ((re / im) * (re * 0.5))));
}
def code(re, im): return math.log((im + ((re / im) * (re * 0.5))))
function code(re, im) return log(Float64(im + Float64(Float64(re / im) * Float64(re * 0.5)))) end
function tmp = code(re, im) tmp = log((im + ((re / im) * (re * 0.5)))); end
code[re_, im_] := N[Log[N[(im + N[(N[(re / im), $MachinePrecision] * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(im + \frac{re}{im} \cdot \left(re \cdot 0.5\right)\right)
\end{array}
Initial program 50.8%
log-lowering-log.f64N/A
accelerator-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around 0
associate-*r/N/A
associate-*l/N/A
metadata-evalN/A
associate-*r/N/A
*-rgt-identityN/A
associate-*r/N/A
metadata-evalN/A
associate-*l/N/A
*-inversesN/A
times-fracN/A
unpow2N/A
associate-*l/N/A
associate-*r/N/A
+-lowering-+.f64N/A
associate-*r/N/A
associate-*l/N/A
unpow2N/A
times-fracN/A
Simplified24.0%
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6426.2%
Applied egg-rr26.2%
Final simplification26.2%
(FPCore (re im) :precision binary64 (log im))
double code(double re, double im) {
return log(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(im)
end function
public static double code(double re, double im) {
return Math.log(im);
}
def code(re, im): return math.log(im)
function code(re, im) return log(im) end
function tmp = code(re, im) tmp = log(im); end
code[re_, im_] := N[Log[im], $MachinePrecision]
\begin{array}{l}
\\
\log im
\end{array}
Initial program 50.8%
log-lowering-log.f64N/A
accelerator-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around 0
log-lowering-log.f6426.5%
Simplified26.5%
herbie shell --seed 2024130
(FPCore (re im)
:name "math.log/1 on complex, real part"
:precision binary64
(log (sqrt (+ (* re re) (* im im)))))