
(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 5 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 53.0%
accelerator-lowering-hypot.f64100.0%
Applied egg-rr100.0%
(FPCore (re im) :precision binary64 (log (+ im (/ (* re (+ (/ (* re -0.125) (* im (/ im re))) 0.5)) (/ im re)))))
double code(double re, double im) {
return log((im + ((re * (((re * -0.125) / (im * (im / re))) + 0.5)) / (im / re))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log((im + ((re * (((re * (-0.125d0)) / (im * (im / re))) + 0.5d0)) / (im / re))))
end function
public static double code(double re, double im) {
return Math.log((im + ((re * (((re * -0.125) / (im * (im / re))) + 0.5)) / (im / re))));
}
def code(re, im): return math.log((im + ((re * (((re * -0.125) / (im * (im / re))) + 0.5)) / (im / re))))
function code(re, im) return log(Float64(im + Float64(Float64(re * Float64(Float64(Float64(re * -0.125) / Float64(im * Float64(im / re))) + 0.5)) / Float64(im / re)))) end
function tmp = code(re, im) tmp = log((im + ((re * (((re * -0.125) / (im * (im / re))) + 0.5)) / (im / re)))); end
code[re_, im_] := N[Log[N[(im + N[(N[(re * N[(N[(N[(re * -0.125), $MachinePrecision] / N[(im * N[(im / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] / N[(im / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(im + \frac{re \cdot \left(\frac{re \cdot -0.125}{im \cdot \frac{im}{re}} + 0.5\right)}{\frac{im}{re}}\right)
\end{array}
Initial program 53.0%
Taylor expanded in re around 0
+-lowering-+.f64N/A
distribute-lft-inN/A
associate-*r/N/A
associate-*r/N/A
cube-multN/A
unpow2N/A
times-fracN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
associate-*l/N/A
distribute-lft-outN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
Simplified21.3%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6421.3%
Applied egg-rr21.3%
associate-*l*N/A
clear-numN/A
associate-*l/N/A
*-lft-identityN/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
+-lowering-+.f64N/A
times-fracN/A
clear-numN/A
frac-timesN/A
*-lft-identityN/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f6424.4%
Applied egg-rr24.4%
Final simplification24.4%
(FPCore (re im) :precision binary64 (log (+ im (* re (* 0.5 (/ re im))))))
double code(double re, double im) {
return log((im + (re * (0.5 * (re / im)))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log((im + (re * (0.5d0 * (re / im)))))
end function
public static double code(double re, double im) {
return Math.log((im + (re * (0.5 * (re / im)))));
}
def code(re, im): return math.log((im + (re * (0.5 * (re / im)))))
function code(re, im) return log(Float64(im + Float64(re * Float64(0.5 * Float64(re / im))))) end
function tmp = code(re, im) tmp = log((im + (re * (0.5 * (re / im))))); end
code[re_, im_] := N[Log[N[(im + N[(re * N[(0.5 * N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(im + re \cdot \left(0.5 \cdot \frac{re}{im}\right)\right)
\end{array}
Initial program 53.0%
Taylor expanded in re around 0
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
*-lft-identityN/A
*-inversesN/A
associate-*r/N/A
metadata-evalN/A
associate-*l/N/A
times-fracN/A
unpow2N/A
associate-*r/N/A
associate-*r/N/A
+-lowering-+.f64N/A
associate-*r/N/A
associate-*r/N/A
unpow2N/A
times-fracN/A
*-inversesN/A
associate-*l/N/A
Simplified23.9%
+-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
/-lowering-/.f6425.2%
Applied egg-rr25.2%
Final simplification25.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 53.0%
Taylor expanded in re around 0
Simplified25.6%
(FPCore (re im) :precision binary64 (* 0.5 (/ 0.0 0.0)))
double code(double re, double im) {
return 0.5 * (0.0 / 0.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (0.0d0 / 0.0d0)
end function
public static double code(double re, double im) {
return 0.5 * (0.0 / 0.0);
}
def code(re, im): return 0.5 * (0.0 / 0.0)
function code(re, im) return Float64(0.5 * Float64(0.0 / 0.0)) end
function tmp = code(re, im) tmp = 0.5 * (0.0 / 0.0); end
code[re_, im_] := N[(0.5 * N[(0.0 / 0.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{0}{0}
\end{array}
Initial program 53.0%
pow1/2N/A
pow-to-expN/A
rem-log-expN/A
*-lowering-*.f64N/A
log-lowering-log.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6453.0%
Applied egg-rr53.0%
Taylor expanded in re around 0
log-lowering-log.f64N/A
unpow2N/A
*-lowering-*.f6430.7%
Simplified30.7%
*-lowering-*.f64N/A
log-prodN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
/-lowering-/.f640.0%
Applied egg-rr0.0%
Final simplification0.0%
herbie shell --seed 2024194
(FPCore (re im)
:name "math.log/1 on complex, real part"
:precision binary64
(log (sqrt (+ (* re re) (* im im)))))