
(FPCore (re im base) :precision binary64 (/ (- (* (atan2 im re) (log base)) (* (log (sqrt (+ (* re re) (* im im)))) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
return ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
real(8) function code(re, im, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
return ((Math.atan2(im, re) * Math.log(base)) - (Math.log(Math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base): return ((math.atan2(im, re) * math.log(base)) - (math.log(math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base) return Float64(Float64(Float64(atan(im, re) * log(base)) - Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0))) end
function tmp = code(re, im, base) tmp = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0)); end
code[re_, im_, base_] := N[(N[(N[(N[ArcTan[im / re], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] - N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(0.0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\tan^{-1}_* \frac{im}{re} \cdot \log base - \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im base) :precision binary64 (/ (- (* (atan2 im re) (log base)) (* (log (sqrt (+ (* re re) (* im im)))) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
return ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
real(8) function code(re, im, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
return ((Math.atan2(im, re) * Math.log(base)) - (Math.log(Math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base): return ((math.atan2(im, re) * math.log(base)) - (math.log(math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base) return Float64(Float64(Float64(atan(im, re) * log(base)) - Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0))) end
function tmp = code(re, im, base) tmp = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0)); end
code[re_, im_, base_] := N[(N[(N[(N[ArcTan[im / re], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] - N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(0.0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\tan^{-1}_* \frac{im}{re} \cdot \log base - \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
(FPCore (re im base)
:precision binary64
(let* ((t_0 (/ (atan2 im re) (log (sqrt (* base base))))))
(if (<= base -7.6e+146)
t_0
(if (<= base -1.56e-162)
(/ (atan2 0.0 re) (log (fabs base)))
(if (<= base 1.6e-299) t_0 (/ (atan2 im re) (log base)))))))double code(double re, double im, double base) {
double t_0 = atan2(im, re) / log(sqrt((base * base)));
double tmp;
if (base <= -7.6e+146) {
tmp = t_0;
} else if (base <= -1.56e-162) {
tmp = atan2(0.0, re) / log(fabs(base));
} else if (base <= 1.6e-299) {
tmp = t_0;
} else {
tmp = atan2(im, re) / log(base);
}
return tmp;
}
real(8) function code(re, im, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
real(8) :: t_0
real(8) :: tmp
t_0 = atan2(im, re) / log(sqrt((base * base)))
if (base <= (-7.6d+146)) then
tmp = t_0
else if (base <= (-1.56d-162)) then
tmp = atan2(0.0d0, re) / log(abs(base))
else if (base <= 1.6d-299) then
tmp = t_0
else
tmp = atan2(im, re) / log(base)
end if
code = tmp
end function
public static double code(double re, double im, double base) {
double t_0 = Math.atan2(im, re) / Math.log(Math.sqrt((base * base)));
double tmp;
if (base <= -7.6e+146) {
tmp = t_0;
} else if (base <= -1.56e-162) {
tmp = Math.atan2(0.0, re) / Math.log(Math.abs(base));
} else if (base <= 1.6e-299) {
tmp = t_0;
} else {
tmp = Math.atan2(im, re) / Math.log(base);
}
return tmp;
}
def code(re, im, base): t_0 = math.atan2(im, re) / math.log(math.sqrt((base * base))) tmp = 0 if base <= -7.6e+146: tmp = t_0 elif base <= -1.56e-162: tmp = math.atan2(0.0, re) / math.log(math.fabs(base)) elif base <= 1.6e-299: tmp = t_0 else: tmp = math.atan2(im, re) / math.log(base) return tmp
function code(re, im, base) t_0 = Float64(atan(im, re) / log(sqrt(Float64(base * base)))) tmp = 0.0 if (base <= -7.6e+146) tmp = t_0; elseif (base <= -1.56e-162) tmp = Float64(atan(0.0, re) / log(abs(base))); elseif (base <= 1.6e-299) tmp = t_0; else tmp = Float64(atan(im, re) / log(base)); end return tmp end
function tmp_2 = code(re, im, base) t_0 = atan2(im, re) / log(sqrt((base * base))); tmp = 0.0; if (base <= -7.6e+146) tmp = t_0; elseif (base <= -1.56e-162) tmp = atan2(0.0, re) / log(abs(base)); elseif (base <= 1.6e-299) tmp = t_0; else tmp = atan2(im, re) / log(base); end tmp_2 = tmp; end
code[re_, im_, base_] := Block[{t$95$0 = N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[N[Sqrt[N[(base * base), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[base, -7.6e+146], t$95$0, If[LessEqual[base, -1.56e-162], N[(N[ArcTan[0.0 / re], $MachinePrecision] / N[Log[N[Abs[base], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[base, 1.6e-299], t$95$0, N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := \frac{\tan^{-1}_* \frac{im}{re}}{\log \left(\sqrt{base \cdot base}\right)}\\
\mathbf{if}\;base \leq -7.6 \cdot 10^{+146}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;base \leq -1.56 \cdot 10^{-162}:\\
\;\;\;\;\frac{\tan^{-1}_* \frac{0}{re}}{\log \left(\left|base\right|\right)}\\
\mathbf{elif}\;base \leq 1.6 \cdot 10^{-299}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1}_* \frac{im}{re}}{\log base}\\
\end{array}
if base < -7.5999999999999996e146 or -1.5600000000000001e-162 < base < 1.6e-299Initial program 24.8%
lift-/.f64N/A
mult-flipN/A
lift--.f64N/A
lift-*.f64N/A
mul0-rgtN/A
--rgt-identityN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6449.8%
lift-+.f64N/A
lift-*.f64N/A
metadata-evalN/A
+-rgt-identity49.8%
lift-*.f64N/A
*-commutativeN/A
Applied rewrites49.8%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
pow2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
lower-*.f64N/A
lower-/.f6449.9%
Applied rewrites49.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
rgt-mult-inverseN/A
mult-flip-revN/A
associate-/l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-/l/N/A
lift-*.f64N/A
lift-*.f64N/A
lift-log.f64N/A
log-pow-revN/A
log-powN/A
associate-/r*N/A
Applied rewrites54.7%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
lower-sqrt.f64N/A
lower-*.f6455.5%
Applied rewrites55.5%
if -7.5999999999999996e146 < base < -1.5600000000000001e-162Initial program 24.8%
lift-/.f64N/A
mult-flipN/A
lift--.f64N/A
lift-*.f64N/A
mul0-rgtN/A
--rgt-identityN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6449.8%
lift-+.f64N/A
lift-*.f64N/A
metadata-evalN/A
+-rgt-identity49.8%
lift-*.f64N/A
*-commutativeN/A
Applied rewrites49.8%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
pow2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
lower-*.f64N/A
lower-/.f6449.9%
Applied rewrites49.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
rgt-mult-inverseN/A
mult-flip-revN/A
associate-/l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-/l/N/A
lift-*.f64N/A
lift-*.f64N/A
lift-log.f64N/A
log-pow-revN/A
log-powN/A
associate-/r*N/A
Applied rewrites54.7%
Taylor expanded in undef-var around zero
Applied rewrites37.2%
if 1.6e-299 < base Initial program 24.8%
Taylor expanded in re around 0
lower-/.f64N/A
lower-atan2.f64N/A
lower-log.f6450.0%
Applied rewrites50.0%
(FPCore (re im base) :precision binary64 (if (<= base 1e-300) (/ (atan2 0.0 re) (log (fabs base))) (/ (atan2 im re) (log base))))
double code(double re, double im, double base) {
double tmp;
if (base <= 1e-300) {
tmp = atan2(0.0, re) / log(fabs(base));
} else {
tmp = atan2(im, re) / log(base);
}
return tmp;
}
real(8) function code(re, im, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
real(8) :: tmp
if (base <= 1d-300) then
tmp = atan2(0.0d0, re) / log(abs(base))
else
tmp = atan2(im, re) / log(base)
end if
code = tmp
end function
public static double code(double re, double im, double base) {
double tmp;
if (base <= 1e-300) {
tmp = Math.atan2(0.0, re) / Math.log(Math.abs(base));
} else {
tmp = Math.atan2(im, re) / Math.log(base);
}
return tmp;
}
def code(re, im, base): tmp = 0 if base <= 1e-300: tmp = math.atan2(0.0, re) / math.log(math.fabs(base)) else: tmp = math.atan2(im, re) / math.log(base) return tmp
function code(re, im, base) tmp = 0.0 if (base <= 1e-300) tmp = Float64(atan(0.0, re) / log(abs(base))); else tmp = Float64(atan(im, re) / log(base)); end return tmp end
function tmp_2 = code(re, im, base) tmp = 0.0; if (base <= 1e-300) tmp = atan2(0.0, re) / log(abs(base)); else tmp = atan2(im, re) / log(base); end tmp_2 = tmp; end
code[re_, im_, base_] := If[LessEqual[base, 1e-300], N[(N[ArcTan[0.0 / re], $MachinePrecision] / N[Log[N[Abs[base], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;base \leq 10^{-300}:\\
\;\;\;\;\frac{\tan^{-1}_* \frac{0}{re}}{\log \left(\left|base\right|\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\tan^{-1}_* \frac{im}{re}}{\log base}\\
\end{array}
if base < 1e-300Initial program 24.8%
lift-/.f64N/A
mult-flipN/A
lift--.f64N/A
lift-*.f64N/A
mul0-rgtN/A
--rgt-identityN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6449.8%
lift-+.f64N/A
lift-*.f64N/A
metadata-evalN/A
+-rgt-identity49.8%
lift-*.f64N/A
*-commutativeN/A
Applied rewrites49.8%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
pow2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
lower-*.f64N/A
lower-/.f6449.9%
Applied rewrites49.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
rgt-mult-inverseN/A
mult-flip-revN/A
associate-/l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-/l/N/A
lift-*.f64N/A
lift-*.f64N/A
lift-log.f64N/A
log-pow-revN/A
log-powN/A
associate-/r*N/A
Applied rewrites54.7%
Taylor expanded in undef-var around zero
Applied rewrites37.2%
if 1e-300 < base Initial program 24.8%
Taylor expanded in re around 0
lower-/.f64N/A
lower-atan2.f64N/A
lower-log.f6450.0%
Applied rewrites50.0%
(FPCore (re im base) :precision binary64 (/ (atan2 im re) (log (fabs base))))
double code(double re, double im, double base) {
return atan2(im, re) / log(fabs(base));
}
real(8) function code(re, im, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = atan2(im, re) / log(abs(base))
end function
public static double code(double re, double im, double base) {
return Math.atan2(im, re) / Math.log(Math.abs(base));
}
def code(re, im, base): return math.atan2(im, re) / math.log(math.fabs(base))
function code(re, im, base) return Float64(atan(im, re) / log(abs(base))) end
function tmp = code(re, im, base) tmp = atan2(im, re) / log(abs(base)); end
code[re_, im_, base_] := N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[N[Abs[base], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\frac{\tan^{-1}_* \frac{im}{re}}{\log \left(\left|base\right|\right)}
Initial program 24.8%
lift-/.f64N/A
mult-flipN/A
lift--.f64N/A
lift-*.f64N/A
mul0-rgtN/A
--rgt-identityN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6449.8%
lift-+.f64N/A
lift-*.f64N/A
metadata-evalN/A
+-rgt-identity49.8%
lift-*.f64N/A
*-commutativeN/A
Applied rewrites49.8%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
pow2N/A
pow-flipN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
lower-*.f64N/A
lower-/.f6449.9%
Applied rewrites49.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
rgt-mult-inverseN/A
mult-flip-revN/A
associate-/l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-/l/N/A
lift-*.f64N/A
lift-*.f64N/A
lift-log.f64N/A
log-pow-revN/A
log-powN/A
associate-/r*N/A
Applied rewrites54.7%
(FPCore (re im base) :precision binary64 (/ (atan2 im re) (log base)))
double code(double re, double im, double base) {
return atan2(im, re) / log(base);
}
real(8) function code(re, im, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = atan2(im, re) / log(base)
end function
public static double code(double re, double im, double base) {
return Math.atan2(im, re) / Math.log(base);
}
def code(re, im, base): return math.atan2(im, re) / math.log(base)
function code(re, im, base) return Float64(atan(im, re) / log(base)) end
function tmp = code(re, im, base) tmp = atan2(im, re) / log(base); end
code[re_, im_, base_] := N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\frac{\tan^{-1}_* \frac{im}{re}}{\log base}
Initial program 24.8%
Taylor expanded in re around 0
lower-/.f64N/A
lower-atan2.f64N/A
lower-log.f6450.0%
Applied rewrites50.0%
herbie shell --seed 2025313 -o setup:search
(FPCore (re im base)
:name "math.log/2 on complex, imaginary part"
:precision binary64
(/ (- (* (atan2 im re) (log base)) (* (log (sqrt (+ (* re re) (* im im)))) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))