
(FPCore (re im base) :precision binary64 (/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
return ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
real(8) function code(re, im, base)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
return ((Math.log(Math.sqrt(((re * re) + (im * im)))) * Math.log(base)) + (Math.atan2(im, re) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base): return ((math.log(math.sqrt(((re * re) + (im * im)))) * math.log(base)) + (math.atan2(im, re) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base) return Float64(Float64(Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * log(base)) + Float64(atan(im, re) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0))) end
function tmp = code(re, im, base) tmp = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0)); end
code[re_, im_, base_] := N[(N[(N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(N[ArcTan[im / re], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(0.0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im base) :precision binary64 (/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
return ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
real(8) function code(re, im, base)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
return ((Math.log(Math.sqrt(((re * re) + (im * im)))) * Math.log(base)) + (Math.atan2(im, re) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base): return ((math.log(math.sqrt(((re * re) + (im * im)))) * math.log(base)) + (math.atan2(im, re) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base) return Float64(Float64(Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * log(base)) + Float64(atan(im, re) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0))) end
function tmp = code(re, im, base) tmp = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0)); end
code[re_, im_, base_] := N[(N[(N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(N[ArcTan[im / re], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(0.0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\end{array}
im_m = (fabs.f64 im) (FPCore (re im_m base) :precision binary64 (/ (+ (* (log (hypot (exp (log im_m)) re)) (log base)) 0.0) (pow (log base) 2.0)))
im_m = fabs(im);
double code(double re, double im_m, double base) {
return ((log(hypot(exp(log(im_m)), re)) * log(base)) + 0.0) / pow(log(base), 2.0);
}
im_m = Math.abs(im);
public static double code(double re, double im_m, double base) {
return ((Math.log(Math.hypot(Math.exp(Math.log(im_m)), re)) * Math.log(base)) + 0.0) / Math.pow(Math.log(base), 2.0);
}
im_m = math.fabs(im) def code(re, im_m, base): return ((math.log(math.hypot(math.exp(math.log(im_m)), re)) * math.log(base)) + 0.0) / math.pow(math.log(base), 2.0)
im_m = abs(im) function code(re, im_m, base) return Float64(Float64(Float64(log(hypot(exp(log(im_m)), re)) * log(base)) + 0.0) / (log(base) ^ 2.0)) end
im_m = abs(im); function tmp = code(re, im_m, base) tmp = ((log(hypot(exp(log(im_m)), re)) * log(base)) + 0.0) / (log(base) ^ 2.0); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_, base_] := N[(N[(N[(N[Log[N[Sqrt[N[Exp[N[Log[im$95$m], $MachinePrecision]], $MachinePrecision] ^ 2 + re ^ 2], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision] / N[Power[N[Log[base], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\frac{\log \left(\mathsf{hypot}\left(e^{\log im\_m}, re\right)\right) \cdot \log base + 0}{{\log base}^{2}}
\end{array}
Initial program 54.6%
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
pow2N/A
pow-to-expN/A
exp-lft-sqrN/A
lift-*.f64N/A
lower-hypot.f64N/A
lower-exp.f64N/A
lower-log.f6448.1
Applied rewrites48.1%
Taylor expanded in im around 0
Applied rewrites48.1%
lift-*.f64N/A
metadata-eval48.1
Applied rewrites48.1%
lift-+.f64N/A
+-rgt-identity48.1
lift-*.f64N/A
pow2N/A
lower-pow.f6448.1
Applied rewrites48.1%
im_m = (fabs.f64 im) (FPCore (re im_m base) :precision binary64 (/ (+ 0.0 (* (log base) (log (hypot im_m re)))) (pow (log base) 2.0)))
im_m = fabs(im);
double code(double re, double im_m, double base) {
return (0.0 + (log(base) * log(hypot(im_m, re)))) / pow(log(base), 2.0);
}
im_m = Math.abs(im);
public static double code(double re, double im_m, double base) {
return (0.0 + (Math.log(base) * Math.log(Math.hypot(im_m, re)))) / Math.pow(Math.log(base), 2.0);
}
im_m = math.fabs(im) def code(re, im_m, base): return (0.0 + (math.log(base) * math.log(math.hypot(im_m, re)))) / math.pow(math.log(base), 2.0)
im_m = abs(im) function code(re, im_m, base) return Float64(Float64(0.0 + Float64(log(base) * log(hypot(im_m, re)))) / (log(base) ^ 2.0)) end
im_m = abs(im); function tmp = code(re, im_m, base) tmp = (0.0 + (log(base) * log(hypot(im_m, re)))) / (log(base) ^ 2.0); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_, base_] := N[(N[(0.0 + N[(N[Log[base], $MachinePrecision] * N[Log[N[Sqrt[im$95$m ^ 2 + re ^ 2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[N[Log[base], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\frac{0 + \log base \cdot \log \left(\mathsf{hypot}\left(im\_m, re\right)\right)}{{\log base}^{2}}
\end{array}
Initial program 54.6%
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
pow2N/A
pow-to-expN/A
exp-lft-sqrN/A
lift-*.f64N/A
lower-hypot.f64N/A
lower-exp.f64N/A
lower-log.f6448.1
Applied rewrites48.1%
Taylor expanded in im around 0
Applied rewrites48.1%
lift-exp.f64N/A
lift-log.f64N/A
rem-exp-log99.2
Applied rewrites99.2%
lift-+.f64N/A
lift-*.f64N/A
metadata-evalN/A
+-rgt-identity99.2
lift-*.f64N/A
pow2N/A
lower-pow.f6499.2
Applied rewrites99.2%
Final simplification99.2%
im_m = (fabs.f64 im) (FPCore (re im_m base) :precision binary64 (/ (log im_m) (log (/ 1.0 (/ 1.0 base)))))
im_m = fabs(im);
double code(double re, double im_m, double base) {
return log(im_m) / log((1.0 / (1.0 / base)));
}
im_m = abs(im)
real(8) function code(re, im_m, base)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8), intent (in) :: base
code = log(im_m) / log((1.0d0 / (1.0d0 / base)))
end function
im_m = Math.abs(im);
public static double code(double re, double im_m, double base) {
return Math.log(im_m) / Math.log((1.0 / (1.0 / base)));
}
im_m = math.fabs(im) def code(re, im_m, base): return math.log(im_m) / math.log((1.0 / (1.0 / base)))
im_m = abs(im) function code(re, im_m, base) return Float64(log(im_m) / log(Float64(1.0 / Float64(1.0 / base)))) end
im_m = abs(im); function tmp = code(re, im_m, base) tmp = log(im_m) / log((1.0 / (1.0 / base))); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_, base_] := N[(N[Log[im$95$m], $MachinePrecision] / N[Log[N[(1.0 / N[(1.0 / base), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\frac{\log im\_m}{\log \left(\frac{1}{\frac{1}{base}}\right)}
\end{array}
Initial program 54.6%
Taylor expanded in re around 0
lower-/.f64N/A
lower-log.f64N/A
lower-log.f6429.1
Applied rewrites29.1%
Applied rewrites29.1%
im_m = (fabs.f64 im) (FPCore (re im_m base) :precision binary64 (/ (log im_m) (log base)))
im_m = fabs(im);
double code(double re, double im_m, double base) {
return log(im_m) / log(base);
}
im_m = abs(im)
real(8) function code(re, im_m, base)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8), intent (in) :: base
code = log(im_m) / log(base)
end function
im_m = Math.abs(im);
public static double code(double re, double im_m, double base) {
return Math.log(im_m) / Math.log(base);
}
im_m = math.fabs(im) def code(re, im_m, base): return math.log(im_m) / math.log(base)
im_m = abs(im) function code(re, im_m, base) return Float64(log(im_m) / log(base)) end
im_m = abs(im); function tmp = code(re, im_m, base) tmp = log(im_m) / log(base); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_, base_] := N[(N[Log[im$95$m], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\frac{\log im\_m}{\log base}
\end{array}
Initial program 54.6%
Taylor expanded in re around 0
lower-/.f64N/A
lower-log.f64N/A
lower-log.f6429.1
Applied rewrites29.1%
im_m = (fabs.f64 im) (FPCore (re im_m base) :precision binary64 0.0)
im_m = fabs(im);
double code(double re, double im_m, double base) {
return 0.0;
}
im_m = abs(im)
real(8) function code(re, im_m, base)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8), intent (in) :: base
code = 0.0d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m, double base) {
return 0.0;
}
im_m = math.fabs(im) def code(re, im_m, base): return 0.0
im_m = abs(im) function code(re, im_m, base) return 0.0 end
im_m = abs(im); function tmp = code(re, im_m, base) tmp = 0.0; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_, base_] := 0.0
\begin{array}{l}
im_m = \left|im\right|
\\
0
\end{array}
Initial program 54.6%
Taylor expanded in re around 0
lower-/.f64N/A
lower-log.f64N/A
lower-log.f6429.1
Applied rewrites29.1%
Applied rewrites3.1%
herbie shell --seed 2024222
(FPCore (re im base)
:name "math.log/2 on complex, real part"
:precision binary64
(/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))