
(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 8 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 52.0%
log-lowering-log.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
(FPCore (re im) :precision binary64 (log (- im (/ (* re -0.5) (/ im re)))))
double code(double re, double im) {
return log((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 * (-0.5d0)) / (im / re))))
end function
public static double code(double re, double im) {
return Math.log((im - ((re * -0.5) / (im / re))));
}
def code(re, im): return math.log((im - ((re * -0.5) / (im / re))))
function code(re, im) return log(Float64(im - Float64(Float64(re * -0.5) / Float64(im / re)))) end
function tmp = code(re, im) tmp = log((im - ((re * -0.5) / (im / re)))); end
code[re_, im_] := N[Log[N[(im - N[(N[(re * -0.5), $MachinePrecision] / N[(im / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(im - \frac{re \cdot -0.5}{\frac{im}{re}}\right)
\end{array}
Initial program 52.0%
log-lowering-log.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in im around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6424.2%
Simplified24.2%
+-commutativeN/A
distribute-rgt-inN/A
fma-defineN/A
associate-*r*N/A
div-invN/A
associate-*r*N/A
associate-*l*N/A
lft-mult-inverseN/A
*-rgt-identityN/A
remove-double-negN/A
distribute-rgt-neg-outN/A
fmm-defN/A
*-lft-identityN/A
--lowering--.f64N/A
distribute-rgt-neg-outN/A
clear-numN/A
un-div-invN/A
distribute-neg-fracN/A
/-lowering-/.f64N/A
Applied egg-rr24.8%
(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 52.0%
log-lowering-log.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around 0
log-lowering-log.f6425.1%
Simplified25.1%
(FPCore (re im) :precision binary64 (/ (/ 1.0 im) (* (/ im re) (/ 2.0 re))))
double code(double re, double im) {
return (1.0 / im) / ((im / re) * (2.0 / re));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (1.0d0 / im) / ((im / re) * (2.0d0 / re))
end function
public static double code(double re, double im) {
return (1.0 / im) / ((im / re) * (2.0 / re));
}
def code(re, im): return (1.0 / im) / ((im / re) * (2.0 / re))
function code(re, im) return Float64(Float64(1.0 / im) / Float64(Float64(im / re) * Float64(2.0 / re))) end
function tmp = code(re, im) tmp = (1.0 / im) / ((im / re) * (2.0 / re)); end
code[re_, im_] := N[(N[(1.0 / im), $MachinePrecision] / N[(N[(im / re), $MachinePrecision] * N[(2.0 / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{im}}{\frac{im}{re} \cdot \frac{2}{re}}
\end{array}
Initial program 52.0%
log-lowering-log.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around 0
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6423.1%
Simplified23.1%
Taylor expanded in im around 0
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.7%
Simplified2.7%
associate-*r*N/A
times-fracN/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*l/N/A
distribute-lft-neg-inN/A
clear-numN/A
div-invN/A
clear-numN/A
distribute-neg-frac2N/A
associate-/l/N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
distribute-rgt-neg-inN/A
metadata-evalN/A
*-lowering-*.f643.2%
Applied egg-rr3.2%
div-invN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
associate-/r*N/A
metadata-evalN/A
/-lowering-/.f643.2%
Applied egg-rr3.2%
(FPCore (re im) :precision binary64 (/ (/ re (/ im (* re 0.5))) im))
double code(double re, double im) {
return (re / (im / (re * 0.5))) / im;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (re / (im / (re * 0.5d0))) / im
end function
public static double code(double re, double im) {
return (re / (im / (re * 0.5))) / im;
}
def code(re, im): return (re / (im / (re * 0.5))) / im
function code(re, im) return Float64(Float64(re / Float64(im / Float64(re * 0.5))) / im) end
function tmp = code(re, im) tmp = (re / (im / (re * 0.5))) / im; end
code[re_, im_] := N[(N[(re / N[(im / N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / im), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{re}{\frac{im}{re \cdot 0.5}}}{im}
\end{array}
Initial program 52.0%
log-lowering-log.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around 0
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6423.1%
Simplified23.1%
Taylor expanded in im around 0
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.7%
Simplified2.7%
associate-*r*N/A
times-fracN/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*l/N/A
distribute-lft-neg-inN/A
clear-numN/A
div-invN/A
/-lowering-/.f64N/A
Applied egg-rr3.2%
(FPCore (re im) :precision binary64 (* (/ re (/ im re)) (/ 0.5 im)))
double code(double re, double im) {
return (re / (im / re)) * (0.5 / im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (re / (im / re)) * (0.5d0 / im)
end function
public static double code(double re, double im) {
return (re / (im / re)) * (0.5 / im);
}
def code(re, im): return (re / (im / re)) * (0.5 / im)
function code(re, im) return Float64(Float64(re / Float64(im / re)) * Float64(0.5 / im)) end
function tmp = code(re, im) tmp = (re / (im / re)) * (0.5 / im); end
code[re_, im_] := N[(N[(re / N[(im / re), $MachinePrecision]), $MachinePrecision] * N[(0.5 / im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{re}{\frac{im}{re}} \cdot \frac{0.5}{im}
\end{array}
Initial program 52.0%
log-lowering-log.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around 0
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6423.1%
Simplified23.1%
Taylor expanded in im around 0
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.7%
Simplified2.7%
*-commutativeN/A
times-fracN/A
*-lowering-*.f64N/A
associate-/l*N/A
clear-numN/A
div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f643.2%
Applied egg-rr3.2%
(FPCore (re im) :precision binary64 (* (/ re (/ im 0.5)) (/ re im)))
double code(double re, double im) {
return (re / (im / 0.5)) * (re / im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (re / (im / 0.5d0)) * (re / im)
end function
public static double code(double re, double im) {
return (re / (im / 0.5)) * (re / im);
}
def code(re, im): return (re / (im / 0.5)) * (re / im)
function code(re, im) return Float64(Float64(re / Float64(im / 0.5)) * Float64(re / im)) end
function tmp = code(re, im) tmp = (re / (im / 0.5)) * (re / im); end
code[re_, im_] := N[(N[(re / N[(im / 0.5), $MachinePrecision]), $MachinePrecision] * N[(re / im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{re}{\frac{im}{0.5}} \cdot \frac{re}{im}
\end{array}
Initial program 52.0%
log-lowering-log.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around 0
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6423.1%
Simplified23.1%
Taylor expanded in im around 0
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.7%
Simplified2.7%
associate-/l*N/A
times-fracN/A
associate-*r*N/A
metadata-evalN/A
times-fracN/A
*-commutativeN/A
neg-mul-1N/A
*-lowering-*.f64N/A
associate-/l*N/A
metadata-evalN/A
frac-2negN/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f643.2%
Applied egg-rr3.2%
(FPCore (re im) :precision binary64 (* re (* re (/ 0.5 (* im im)))))
double code(double re, double im) {
return re * (re * (0.5 / (im * im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re * (re * (0.5d0 / (im * im)))
end function
public static double code(double re, double im) {
return re * (re * (0.5 / (im * im)));
}
def code(re, im): return re * (re * (0.5 / (im * im)))
function code(re, im) return Float64(re * Float64(re * Float64(0.5 / Float64(im * im)))) end
function tmp = code(re, im) tmp = re * (re * (0.5 / (im * im))); end
code[re_, im_] := N[(re * N[(re * N[(0.5 / N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot \left(re \cdot \frac{0.5}{im \cdot im}\right)
\end{array}
Initial program 52.0%
log-lowering-log.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f64100.0%
Simplified100.0%
Taylor expanded in re around 0
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-/r*N/A
/-lowering-/.f64N/A
/-lowering-/.f6423.1%
Simplified23.1%
Taylor expanded in im around 0
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f642.7%
Simplified2.7%
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
*-lowering-*.f64N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f643.0%
Applied egg-rr3.0%
associate-/r/N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f643.0%
Applied egg-rr3.0%
Final simplification3.0%
herbie shell --seed 2024164
(FPCore (re im)
:name "math.log/1 on complex, real part"
:precision binary64
(log (sqrt (+ (* re re) (* im im)))))