dl*log(m/l)

Percentage Accurate: 77.2% → 99.0%
Time: 3.4s
Alternatives: 3
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ dl \cdot \log \left(\frac{m}{\ell}\right) \end{array} \]
(FPCore (dl m l) :precision binary64 (* dl (log (/ m l))))
double code(double dl, double m, double l) {
	return dl * log((m / l));
}
real(8) function code(dl, m, l)
    real(8), intent (in) :: dl
    real(8), intent (in) :: m
    real(8), intent (in) :: l
    code = dl * log((m / l))
end function
public static double code(double dl, double m, double l) {
	return dl * Math.log((m / l));
}
def code(dl, m, l):
	return dl * math.log((m / l))
function code(dl, m, l)
	return Float64(dl * log(Float64(m / l)))
end
function tmp = code(dl, m, l)
	tmp = dl * log((m / l));
end
code[dl_, m_, l_] := N[(dl * N[Log[N[(m / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
dl \cdot \log \left(\frac{m}{\ell}\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 3 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 77.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ dl \cdot \log \left(\frac{m}{\ell}\right) \end{array} \]
(FPCore (dl m l) :precision binary64 (* dl (log (/ m l))))
double code(double dl, double m, double l) {
	return dl * log((m / l));
}
real(8) function code(dl, m, l)
    real(8), intent (in) :: dl
    real(8), intent (in) :: m
    real(8), intent (in) :: l
    code = dl * log((m / l))
end function
public static double code(double dl, double m, double l) {
	return dl * Math.log((m / l));
}
def code(dl, m, l):
	return dl * math.log((m / l))
function code(dl, m, l)
	return Float64(dl * log(Float64(m / l)))
end
function tmp = code(dl, m, l)
	tmp = dl * log((m / l));
end
code[dl_, m_, l_] := N[(dl * N[Log[N[(m / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
dl \cdot \log \left(\frac{m}{\ell}\right)
\end{array}

Alternative 1: 99.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -2 \cdot 10^{-310}:\\ \;\;\;\;dl \cdot \left(\log \left(-m\right) - \log \left(-\ell\right)\right)\\ \mathbf{else}:\\ \;\;\;\;dl \cdot \left(\log m - \log \ell\right)\\ \end{array} \end{array} \]
(FPCore (dl m l)
 :precision binary64
 (if (<= l -2e-310)
   (* dl (- (log (- m)) (log (- l))))
   (* dl (- (log m) (log l)))))
double code(double dl, double m, double l) {
	double tmp;
	if (l <= -2e-310) {
		tmp = dl * (log(-m) - log(-l));
	} else {
		tmp = dl * (log(m) - log(l));
	}
	return tmp;
}
real(8) function code(dl, m, l)
    real(8), intent (in) :: dl
    real(8), intent (in) :: m
    real(8), intent (in) :: l
    real(8) :: tmp
    if (l <= (-2d-310)) then
        tmp = dl * (log(-m) - log(-l))
    else
        tmp = dl * (log(m) - log(l))
    end if
    code = tmp
end function
public static double code(double dl, double m, double l) {
	double tmp;
	if (l <= -2e-310) {
		tmp = dl * (Math.log(-m) - Math.log(-l));
	} else {
		tmp = dl * (Math.log(m) - Math.log(l));
	}
	return tmp;
}
def code(dl, m, l):
	tmp = 0
	if l <= -2e-310:
		tmp = dl * (math.log(-m) - math.log(-l))
	else:
		tmp = dl * (math.log(m) - math.log(l))
	return tmp
function code(dl, m, l)
	tmp = 0.0
	if (l <= -2e-310)
		tmp = Float64(dl * Float64(log(Float64(-m)) - log(Float64(-l))));
	else
		tmp = Float64(dl * Float64(log(m) - log(l)));
	end
	return tmp
end
function tmp_2 = code(dl, m, l)
	tmp = 0.0;
	if (l <= -2e-310)
		tmp = dl * (log(-m) - log(-l));
	else
		tmp = dl * (log(m) - log(l));
	end
	tmp_2 = tmp;
end
code[dl_, m_, l_] := If[LessEqual[l, -2e-310], N[(dl * N[(N[Log[(-m)], $MachinePrecision] - N[Log[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(dl * N[(N[Log[m], $MachinePrecision] - N[Log[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;dl \cdot \left(\log \left(-m\right) - \log \left(-\ell\right)\right)\\

\mathbf{else}:\\
\;\;\;\;dl \cdot \left(\log m - \log \ell\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.999999999999994e-310

    1. Initial program 74.5%

      \[dl \cdot \log \left(\frac{m}{\ell}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto dl \cdot \log \color{blue}{\left(\frac{1}{\frac{\ell}{m}}\right)} \]
      2. log-recN/A

        \[\leadsto dl \cdot \color{blue}{\left(\mathsf{neg}\left(\log \left(\frac{\ell}{m}\right)\right)\right)} \]
      3. distribute-rgt-neg-outN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(dl \cdot \log \left(\frac{\ell}{m}\right)\right)} \]
      4. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{\ell}{m}\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{\ell}{m}\right)} \]
      6. neg-lowering-neg.f64N/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(dl\right)\right)} \cdot \log \left(\frac{\ell}{m}\right) \]
      7. clear-numN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \color{blue}{\left(\frac{1}{\frac{m}{\ell}}\right)} \]
      8. frac-2negN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{1}{\color{blue}{\frac{\mathsf{neg}\left(m\right)}{\mathsf{neg}\left(\ell\right)}}}\right) \]
      9. div-invN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{1}{\color{blue}{\left(\mathsf{neg}\left(m\right)\right) \cdot \frac{1}{\mathsf{neg}\left(\ell\right)}}}\right) \]
      10. associate-/r*N/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \color{blue}{\left(\frac{\frac{1}{\mathsf{neg}\left(m\right)}}{\frac{1}{\mathsf{neg}\left(\ell\right)}}\right)} \]
      11. inv-powN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{\frac{1}{\mathsf{neg}\left(m\right)}}{\color{blue}{{\left(\mathsf{neg}\left(\ell\right)\right)}^{-1}}}\right) \]
      12. sqr-powN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{\frac{1}{\mathsf{neg}\left(m\right)}}{\color{blue}{{\left(\mathsf{neg}\left(\ell\right)\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\mathsf{neg}\left(\ell\right)\right)}^{\left(\frac{-1}{2}\right)}}}\right) \]
      13. unpow-prod-downN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{\frac{1}{\mathsf{neg}\left(m\right)}}{\color{blue}{{\left(\left(\mathsf{neg}\left(\ell\right)\right) \cdot \left(\mathsf{neg}\left(\ell\right)\right)\right)}^{\left(\frac{-1}{2}\right)}}}\right) \]
      14. sqr-negN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{\frac{1}{\mathsf{neg}\left(m\right)}}{{\color{blue}{\left(\ell \cdot \ell\right)}}^{\left(\frac{-1}{2}\right)}}\right) \]
      15. pow-prod-downN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{\frac{1}{\mathsf{neg}\left(m\right)}}{\color{blue}{{\ell}^{\left(\frac{-1}{2}\right)} \cdot {\ell}^{\left(\frac{-1}{2}\right)}}}\right) \]
      16. sqr-powN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{\frac{1}{\mathsf{neg}\left(m\right)}}{\color{blue}{{\ell}^{-1}}}\right) \]
      17. inv-powN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{\frac{1}{\mathsf{neg}\left(m\right)}}{\color{blue}{\frac{1}{\ell}}}\right) \]
      18. associate-/r*N/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \color{blue}{\left(\frac{1}{\left(\mathsf{neg}\left(m\right)\right) \cdot \frac{1}{\ell}}\right)} \]
      19. div-invN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \left(\frac{1}{\color{blue}{\frac{\mathsf{neg}\left(m\right)}{\ell}}}\right) \]
      20. clear-numN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \color{blue}{\left(\frac{\ell}{\mathsf{neg}\left(m\right)}\right)} \]
      21. distribute-neg-frac2N/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \color{blue}{\left(\mathsf{neg}\left(\frac{\ell}{m}\right)\right)} \]
      22. log-lowering-log.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \color{blue}{\log \left(\mathsf{neg}\left(\frac{\ell}{m}\right)\right)} \]
      23. distribute-neg-fracN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \color{blue}{\left(\frac{\mathsf{neg}\left(\ell\right)}{m}\right)} \]
      24. clear-numN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \color{blue}{\left(\frac{1}{\frac{m}{\mathsf{neg}\left(\ell\right)}}\right)} \]
    4. Applied egg-rr73.3%

      \[\leadsto \color{blue}{\left(-dl\right) \cdot \log \left(\frac{\ell}{m}\right)} \]
    5. Step-by-step derivation
      1. frac-2negN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \log \color{blue}{\left(\frac{\mathsf{neg}\left(\ell\right)}{\mathsf{neg}\left(m\right)}\right)} \]
      2. log-divN/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \color{blue}{\left(\log \left(\mathsf{neg}\left(\ell\right)\right) - \log \left(\mathsf{neg}\left(m\right)\right)\right)} \]
      3. --lowering--.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \color{blue}{\left(\log \left(\mathsf{neg}\left(\ell\right)\right) - \log \left(\mathsf{neg}\left(m\right)\right)\right)} \]
      4. log-lowering-log.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \left(\color{blue}{\log \left(\mathsf{neg}\left(\ell\right)\right)} - \log \left(\mathsf{neg}\left(m\right)\right)\right) \]
      5. neg-lowering-neg.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \left(\log \color{blue}{\left(\mathsf{neg}\left(\ell\right)\right)} - \log \left(\mathsf{neg}\left(m\right)\right)\right) \]
      6. log-lowering-log.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(dl\right)\right) \cdot \left(\log \left(\mathsf{neg}\left(\ell\right)\right) - \color{blue}{\log \left(\mathsf{neg}\left(m\right)\right)}\right) \]
      7. neg-lowering-neg.f6499.0

        \[\leadsto \left(-dl\right) \cdot \left(\log \left(-\ell\right) - \log \color{blue}{\left(-m\right)}\right) \]
    6. Applied egg-rr99.0%

      \[\leadsto \left(-dl\right) \cdot \color{blue}{\left(\log \left(-\ell\right) - \log \left(-m\right)\right)} \]

    if -1.999999999999994e-310 < l

    1. Initial program 71.9%

      \[dl \cdot \log \left(\frac{m}{\ell}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log-divN/A

        \[\leadsto dl \cdot \color{blue}{\left(\log m - \log \ell\right)} \]
      2. --lowering--.f64N/A

        \[\leadsto dl \cdot \color{blue}{\left(\log m - \log \ell\right)} \]
      3. log-lowering-log.f64N/A

        \[\leadsto dl \cdot \left(\color{blue}{\log m} - \log \ell\right) \]
      4. log-lowering-log.f6499.2

        \[\leadsto dl \cdot \left(\log m - \color{blue}{\log \ell}\right) \]
    4. Applied egg-rr99.2%

      \[\leadsto dl \cdot \color{blue}{\left(\log m - \log \ell\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2 \cdot 10^{-310}:\\ \;\;\;\;dl \cdot \left(\log \left(-m\right) - \log \left(-\ell\right)\right)\\ \mathbf{else}:\\ \;\;\;\;dl \cdot \left(\log m - \log \ell\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 87.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 3.25 \cdot 10^{-302}:\\ \;\;\;\;dl \cdot \log \left(\frac{m}{\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;dl \cdot \left(\log m - \log \ell\right)\\ \end{array} \end{array} \]
(FPCore (dl m l)
 :precision binary64
 (if (<= l 3.25e-302) (* dl (log (/ m l))) (* dl (- (log m) (log l)))))
double code(double dl, double m, double l) {
	double tmp;
	if (l <= 3.25e-302) {
		tmp = dl * log((m / l));
	} else {
		tmp = dl * (log(m) - log(l));
	}
	return tmp;
}
real(8) function code(dl, m, l)
    real(8), intent (in) :: dl
    real(8), intent (in) :: m
    real(8), intent (in) :: l
    real(8) :: tmp
    if (l <= 3.25d-302) then
        tmp = dl * log((m / l))
    else
        tmp = dl * (log(m) - log(l))
    end if
    code = tmp
end function
public static double code(double dl, double m, double l) {
	double tmp;
	if (l <= 3.25e-302) {
		tmp = dl * Math.log((m / l));
	} else {
		tmp = dl * (Math.log(m) - Math.log(l));
	}
	return tmp;
}
def code(dl, m, l):
	tmp = 0
	if l <= 3.25e-302:
		tmp = dl * math.log((m / l))
	else:
		tmp = dl * (math.log(m) - math.log(l))
	return tmp
function code(dl, m, l)
	tmp = 0.0
	if (l <= 3.25e-302)
		tmp = Float64(dl * log(Float64(m / l)));
	else
		tmp = Float64(dl * Float64(log(m) - log(l)));
	end
	return tmp
end
function tmp_2 = code(dl, m, l)
	tmp = 0.0;
	if (l <= 3.25e-302)
		tmp = dl * log((m / l));
	else
		tmp = dl * (log(m) - log(l));
	end
	tmp_2 = tmp;
end
code[dl_, m_, l_] := If[LessEqual[l, 3.25e-302], N[(dl * N[Log[N[(m / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(dl * N[(N[Log[m], $MachinePrecision] - N[Log[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 3.25 \cdot 10^{-302}:\\
\;\;\;\;dl \cdot \log \left(\frac{m}{\ell}\right)\\

\mathbf{else}:\\
\;\;\;\;dl \cdot \left(\log m - \log \ell\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 3.2499999999999997e-302

    1. Initial program 74.7%

      \[dl \cdot \log \left(\frac{m}{\ell}\right) \]
    2. Add Preprocessing

    if 3.2499999999999997e-302 < l

    1. Initial program 71.7%

      \[dl \cdot \log \left(\frac{m}{\ell}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. log-divN/A

        \[\leadsto dl \cdot \color{blue}{\left(\log m - \log \ell\right)} \]
      2. --lowering--.f64N/A

        \[\leadsto dl \cdot \color{blue}{\left(\log m - \log \ell\right)} \]
      3. log-lowering-log.f64N/A

        \[\leadsto dl \cdot \left(\color{blue}{\log m} - \log \ell\right) \]
      4. log-lowering-log.f6499.2

        \[\leadsto dl \cdot \left(\log m - \color{blue}{\log \ell}\right) \]
    4. Applied egg-rr99.2%

      \[\leadsto dl \cdot \color{blue}{\left(\log m - \log \ell\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 77.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ dl \cdot \log \left(\frac{m}{\ell}\right) \end{array} \]
(FPCore (dl m l) :precision binary64 (* dl (log (/ m l))))
double code(double dl, double m, double l) {
	return dl * log((m / l));
}
real(8) function code(dl, m, l)
    real(8), intent (in) :: dl
    real(8), intent (in) :: m
    real(8), intent (in) :: l
    code = dl * log((m / l))
end function
public static double code(double dl, double m, double l) {
	return dl * Math.log((m / l));
}
def code(dl, m, l):
	return dl * math.log((m / l))
function code(dl, m, l)
	return Float64(dl * log(Float64(m / l)))
end
function tmp = code(dl, m, l)
	tmp = dl * log((m / l));
end
code[dl_, m_, l_] := N[(dl * N[Log[N[(m / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
dl \cdot \log \left(\frac{m}{\ell}\right)
\end{array}
Derivation
  1. Initial program 73.3%

    \[dl \cdot \log \left(\frac{m}{\ell}\right) \]
  2. Add Preprocessing
  3. Add Preprocessing

Reproduce

?
herbie shell --seed 5 
(FPCore (dl m l)
  :name "dl*log(m/l)"
  :precision binary64
  (* dl (log (/ m l))))