Logarithmic Transform

Percentage Accurate: 29.2% → 29.2%
Time: 2.6s
Alternatives: 1
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ c \cdot \log \left(1 + \left({\mathsf{E}\left(\right)}^{x} - 1\right) \cdot y\right) \end{array} \]
(FPCore (c x y)
 :precision binary64
 (* c (log (+ 1.0 (* (- (pow (E) x) 1.0) y)))))
\begin{array}{l}

\\
c \cdot \log \left(1 + \left({\mathsf{E}\left(\right)}^{x} - 1\right) \cdot y\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 1 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: 29.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ c \cdot \log \left(1 + \left({\mathsf{E}\left(\right)}^{x} - 1\right) \cdot y\right) \end{array} \]
(FPCore (c x y)
 :precision binary64
 (* c (log (+ 1.0 (* (- (pow (E) x) 1.0) y)))))
\begin{array}{l}

\\
c \cdot \log \left(1 + \left({\mathsf{E}\left(\right)}^{x} - 1\right) \cdot y\right)
\end{array}

Alternative 1: 29.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \log \left(y \cdot \left({\mathsf{E}\left(\right)}^{x} - 1\right) + 1\right) \cdot c \end{array} \]
(FPCore (c x y)
 :precision binary64
 (* (log (+ (* y (- (pow (E) x) 1.0)) 1.0)) c))
\begin{array}{l}

\\
\log \left(y \cdot \left({\mathsf{E}\left(\right)}^{x} - 1\right) + 1\right) \cdot c
\end{array}
Derivation
  1. Initial program 39.7%

    \[c \cdot \log \left(1 + \left({\mathsf{E}\left(\right)}^{x} - 1\right) \cdot y\right) \]
  2. Add Preprocessing
  3. Final simplification39.7%

    \[\leadsto \log \left(y \cdot \left({\mathsf{E}\left(\right)}^{x} - 1\right) + 1\right) \cdot c \]
  4. Add Preprocessing

Developer Target 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right) \end{array} \]
(FPCore (c x y) :precision binary64 (* c (log1p (* (expm1 x) y))))
double code(double c, double x, double y) {
	return c * log1p((expm1(x) * y));
}
public static double code(double c, double x, double y) {
	return c * Math.log1p((Math.expm1(x) * y));
}
def code(c, x, y):
	return c * math.log1p((math.expm1(x) * y))
function code(c, x, y)
	return Float64(c * log1p(Float64(expm1(x) * y)))
end
code[c_, x_, y_] := N[(c * N[Log[1 + N[(N[(Exp[x] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right)
\end{array}

Reproduce

?
herbie shell --seed 2024346 
(FPCore (c x y)
  :name "Logarithmic Transform"
  :precision binary64

  :alt
  (* c (log1p (* (expm1 x) y)))

  (* c (log (+ 1.0 (* (- (pow (E) x) 1.0) y)))))