Logarithmic Transform

Percentage Accurate: 41.7% → 88.8%
Time: 21.4s
Alternatives: 9
Speedup: 5.0×

Specification

?
\[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
(FPCore (c x y)
  :precision binary64
  (* c (log (+ 1.0 (* (- (pow E x) 1.0) y)))))
double code(double c, double x, double y) {
	return c * log((1.0 + ((pow(((double) M_E), x) - 1.0) * y)));
}
public static double code(double c, double x, double y) {
	return c * Math.log((1.0 + ((Math.pow(Math.E, x) - 1.0) * y)));
}
def code(c, x, y):
	return c * math.log((1.0 + ((math.pow(math.e, x) - 1.0) * y)))
function code(c, x, y)
	return Float64(c * log(Float64(1.0 + Float64(Float64((exp(1) ^ x) - 1.0) * y))))
end
function tmp = code(c, x, y)
	tmp = c * log((1.0 + (((2.71828182845904523536 ^ x) - 1.0) * y)));
end
code[c_, x_, y_] := N[(c * N[Log[N[(1.0 + N[(N[(N[Power[E, x], $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)

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 9 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: 41.7% accurate, 1.0× speedup?

\[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
(FPCore (c x y)
  :precision binary64
  (* c (log (+ 1.0 (* (- (pow E x) 1.0) y)))))
double code(double c, double x, double y) {
	return c * log((1.0 + ((pow(((double) M_E), x) - 1.0) * y)));
}
public static double code(double c, double x, double y) {
	return c * Math.log((1.0 + ((Math.pow(Math.E, x) - 1.0) * y)));
}
def code(c, x, y):
	return c * math.log((1.0 + ((math.pow(math.e, x) - 1.0) * y)))
function code(c, x, y)
	return Float64(c * log(Float64(1.0 + Float64(Float64((exp(1) ^ x) - 1.0) * y))))
end
function tmp = code(c, x, y)
	tmp = c * log((1.0 + (((2.71828182845904523536 ^ x) - 1.0) * y)));
end
code[c_, x_, y_] := N[(c * N[Log[N[(1.0 + N[(N[(N[Power[E, x], $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)

Alternative 1: 88.8% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{+46}:\\ \;\;\;\;\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(x\right), 1\right)\right) \cdot c\\ \mathbf{elif}\;y \leq 0.03:\\ \;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{+228}:\\ \;\;\;\;c \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{fma}\left(y, x \cdot \left(1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot x\right)\right)\right), 1\right)\right) \cdot c\\ \end{array} \]
(FPCore (c x y)
  :precision binary64
  (if (<= y -8.2e+46)
  (* (log (fma y (expm1 x) 1.0)) c)
  (if (<= y 0.03)
    (* (* (expm1 x) c) y)
    (if (<= y 2.7e+228)
      (* c (* x y))
      (*
       (log
        (fma
         y
         (*
          x
          (+
           1.0
           (*
            x
            (+
             0.5
             (*
              x
              (+ 0.16666666666666666 (* 0.041666666666666664 x)))))))
         1.0))
       c)))))
double code(double c, double x, double y) {
	double tmp;
	if (y <= -8.2e+46) {
		tmp = log(fma(y, expm1(x), 1.0)) * c;
	} else if (y <= 0.03) {
		tmp = (expm1(x) * c) * y;
	} else if (y <= 2.7e+228) {
		tmp = c * (x * y);
	} else {
		tmp = log(fma(y, (x * (1.0 + (x * (0.5 + (x * (0.16666666666666666 + (0.041666666666666664 * x))))))), 1.0)) * c;
	}
	return tmp;
}
function code(c, x, y)
	tmp = 0.0
	if (y <= -8.2e+46)
		tmp = Float64(log(fma(y, expm1(x), 1.0)) * c);
	elseif (y <= 0.03)
		tmp = Float64(Float64(expm1(x) * c) * y);
	elseif (y <= 2.7e+228)
		tmp = Float64(c * Float64(x * y));
	else
		tmp = Float64(log(fma(y, Float64(x * Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * Float64(0.16666666666666666 + Float64(0.041666666666666664 * x))))))), 1.0)) * c);
	end
	return tmp
end
code[c_, x_, y_] := If[LessEqual[y, -8.2e+46], N[(N[Log[N[(y * N[(Exp[x] - 1), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision], If[LessEqual[y, 0.03], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 2.7e+228], N[(c * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[(y * N[(x * N[(1.0 + N[(x * N[(0.5 + N[(x * N[(0.16666666666666666 + N[(0.041666666666666664 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]]]]
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{+46}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(x\right), 1\right)\right) \cdot c\\

\mathbf{elif}\;y \leq 0.03:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\

\mathbf{elif}\;y \leq 2.7 \cdot 10^{+228}:\\
\;\;\;\;c \cdot \left(x \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(y, x \cdot \left(1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot x\right)\right)\right), 1\right)\right) \cdot c\\


\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -8.2e46

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \cdot c} \]
      3. lower-*.f6441.7%

        \[\leadsto \color{blue}{\log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \cdot c} \]
    3. Applied rewrites51.7%

      \[\leadsto \color{blue}{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(x\right), 1\right)\right) \cdot c} \]

    if -8.2e46 < y < 0.029999999999999999

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \left(e^{x} - 1\right)\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \left(e^{x} - 1\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\left(e^{x} - 1\right)}\right) \]
      3. lower-expm1.f6473.7%

        \[\leadsto c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right) \]
    4. Applied rewrites73.7%

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]
      2. lift-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\mathsf{expm1}\left(x\right)}\right) \]
      3. *-commutativeN/A

        \[\leadsto c \cdot \left(\mathsf{expm1}\left(x\right) \cdot \color{blue}{y}\right) \]
      4. associate-*r*N/A

        \[\leadsto \left(c \cdot \mathsf{expm1}\left(x\right)\right) \cdot \color{blue}{y} \]
      5. lower-*.f64N/A

        \[\leadsto \left(c \cdot \mathsf{expm1}\left(x\right)\right) \cdot \color{blue}{y} \]
      6. *-commutativeN/A

        \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y \]
      7. lower-*.f6476.7%

        \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y \]
    6. Applied rewrites76.7%

      \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot \color{blue}{y} \]

    if 0.029999999999999999 < y < 2.7000000000000002e228

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lower-*.f6456.0%

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
    4. Applied rewrites56.0%

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]

    if 2.7000000000000002e228 < y

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \cdot c} \]
      3. lower-*.f6441.7%

        \[\leadsto \color{blue}{\log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \cdot c} \]
    3. Applied rewrites51.7%

      \[\leadsto \color{blue}{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(x\right), 1\right)\right) \cdot c} \]
    4. Taylor expanded in x around 0

      \[\leadsto \log \left(\mathsf{fma}\left(y, \color{blue}{x \cdot \left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}, 1\right)\right) \cdot c \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \log \left(\mathsf{fma}\left(y, x \cdot \color{blue}{\left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}, 1\right)\right) \cdot c \]
      2. lower-+.f64N/A

        \[\leadsto \log \left(\mathsf{fma}\left(y, x \cdot \left(1 + \color{blue}{x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right), 1\right)\right) \cdot c \]
      3. lower-*.f64N/A

        \[\leadsto \log \left(\mathsf{fma}\left(y, x \cdot \left(1 + x \cdot \color{blue}{\left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right), 1\right)\right) \cdot c \]
      4. lower-+.f64N/A

        \[\leadsto \log \left(\mathsf{fma}\left(y, x \cdot \left(1 + x \cdot \left(\frac{1}{2} + \color{blue}{x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)}\right)\right), 1\right)\right) \cdot c \]
      5. lower-*.f64N/A

        \[\leadsto \log \left(\mathsf{fma}\left(y, x \cdot \left(1 + x \cdot \left(\frac{1}{2} + x \cdot \color{blue}{\left(\frac{1}{6} + \frac{1}{24} \cdot x\right)}\right)\right), 1\right)\right) \cdot c \]
      6. lower-+.f64N/A

        \[\leadsto \log \left(\mathsf{fma}\left(y, x \cdot \left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \color{blue}{\frac{1}{24} \cdot x}\right)\right)\right), 1\right)\right) \cdot c \]
      7. lower-*.f6436.7%

        \[\leadsto \log \left(\mathsf{fma}\left(y, x \cdot \left(1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot \color{blue}{x}\right)\right)\right), 1\right)\right) \cdot c \]
    6. Applied rewrites36.7%

      \[\leadsto \log \left(\mathsf{fma}\left(y, \color{blue}{x \cdot \left(1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + 0.041666666666666664 \cdot x\right)\right)\right)}, 1\right)\right) \cdot c \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 2: 88.8% accurate, 1.0× speedup?

\[\begin{array}{l} t_0 := \log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(x\right), 1\right)\right) \cdot c\\ \mathbf{if}\;y \leq -8.2 \cdot 10^{+46}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 0.03:\\ \;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+228}:\\ \;\;\;\;c \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
(FPCore (c x y)
  :precision binary64
  (let* ((t_0 (* (log (fma y (expm1 x) 1.0)) c)))
  (if (<= y -8.2e+46)
    t_0
    (if (<= y 0.03)
      (* (* (expm1 x) c) y)
      (if (<= y 3e+228) (* c (* x y)) t_0)))))
double code(double c, double x, double y) {
	double t_0 = log(fma(y, expm1(x), 1.0)) * c;
	double tmp;
	if (y <= -8.2e+46) {
		tmp = t_0;
	} else if (y <= 0.03) {
		tmp = (expm1(x) * c) * y;
	} else if (y <= 3e+228) {
		tmp = c * (x * y);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(c, x, y)
	t_0 = Float64(log(fma(y, expm1(x), 1.0)) * c)
	tmp = 0.0
	if (y <= -8.2e+46)
		tmp = t_0;
	elseif (y <= 0.03)
		tmp = Float64(Float64(expm1(x) * c) * y);
	elseif (y <= 3e+228)
		tmp = Float64(c * Float64(x * y));
	else
		tmp = t_0;
	end
	return tmp
end
code[c_, x_, y_] := Block[{t$95$0 = N[(N[Log[N[(y * N[(Exp[x] - 1), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]}, If[LessEqual[y, -8.2e+46], t$95$0, If[LessEqual[y, 0.03], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 3e+228], N[(c * N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
t_0 := \log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(x\right), 1\right)\right) \cdot c\\
\mathbf{if}\;y \leq -8.2 \cdot 10^{+46}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 0.03:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\

\mathbf{elif}\;y \leq 3 \cdot 10^{+228}:\\
\;\;\;\;c \cdot \left(x \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -8.2e46 or 3.0000000000000001e228 < y

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \cdot c} \]
      3. lower-*.f6441.7%

        \[\leadsto \color{blue}{\log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \cdot c} \]
    3. Applied rewrites51.7%

      \[\leadsto \color{blue}{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(x\right), 1\right)\right) \cdot c} \]

    if -8.2e46 < y < 0.029999999999999999

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \left(e^{x} - 1\right)\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \left(e^{x} - 1\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\left(e^{x} - 1\right)}\right) \]
      3. lower-expm1.f6473.7%

        \[\leadsto c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right) \]
    4. Applied rewrites73.7%

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]
      2. lift-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\mathsf{expm1}\left(x\right)}\right) \]
      3. *-commutativeN/A

        \[\leadsto c \cdot \left(\mathsf{expm1}\left(x\right) \cdot \color{blue}{y}\right) \]
      4. associate-*r*N/A

        \[\leadsto \left(c \cdot \mathsf{expm1}\left(x\right)\right) \cdot \color{blue}{y} \]
      5. lower-*.f64N/A

        \[\leadsto \left(c \cdot \mathsf{expm1}\left(x\right)\right) \cdot \color{blue}{y} \]
      6. *-commutativeN/A

        \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y \]
      7. lower-*.f6476.7%

        \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y \]
    6. Applied rewrites76.7%

      \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot \color{blue}{y} \]

    if 0.029999999999999999 < y < 3.0000000000000001e228

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lower-*.f6456.0%

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
    4. Applied rewrites56.0%

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 82.6% accurate, 1.3× speedup?

\[\begin{array}{l} t_0 := \log \left(\mathsf{fma}\left(y, x, 1\right)\right) \cdot c\\ \mathbf{if}\;y \leq -4.8 \cdot 10^{+131}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 0.03:\\ \;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+228}:\\ \;\;\;\;c \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
(FPCore (c x y)
  :precision binary64
  (let* ((t_0 (* (log (fma y x 1.0)) c)))
  (if (<= y -4.8e+131)
    t_0
    (if (<= y 0.03)
      (* (* (expm1 x) c) y)
      (if (<= y 3e+228) (* c (* x y)) t_0)))))
double code(double c, double x, double y) {
	double t_0 = log(fma(y, x, 1.0)) * c;
	double tmp;
	if (y <= -4.8e+131) {
		tmp = t_0;
	} else if (y <= 0.03) {
		tmp = (expm1(x) * c) * y;
	} else if (y <= 3e+228) {
		tmp = c * (x * y);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(c, x, y)
	t_0 = Float64(log(fma(y, x, 1.0)) * c)
	tmp = 0.0
	if (y <= -4.8e+131)
		tmp = t_0;
	elseif (y <= 0.03)
		tmp = Float64(Float64(expm1(x) * c) * y);
	elseif (y <= 3e+228)
		tmp = Float64(c * Float64(x * y));
	else
		tmp = t_0;
	end
	return tmp
end
code[c_, x_, y_] := Block[{t$95$0 = N[(N[Log[N[(y * x + 1.0), $MachinePrecision]], $MachinePrecision] * c), $MachinePrecision]}, If[LessEqual[y, -4.8e+131], t$95$0, If[LessEqual[y, 0.03], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * c), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 3e+228], N[(c * N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
t_0 := \log \left(\mathsf{fma}\left(y, x, 1\right)\right) \cdot c\\
\mathbf{if}\;y \leq -4.8 \cdot 10^{+131}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 0.03:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y\\

\mathbf{elif}\;y \leq 3 \cdot 10^{+228}:\\
\;\;\;\;c \cdot \left(x \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.7999999999999999e131 or 3.0000000000000001e228 < y

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right)} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \cdot c} \]
      3. lower-*.f6441.7%

        \[\leadsto \color{blue}{\log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \cdot c} \]
    3. Applied rewrites51.7%

      \[\leadsto \color{blue}{\log \left(\mathsf{fma}\left(y, \mathsf{expm1}\left(x\right), 1\right)\right) \cdot c} \]
    4. Taylor expanded in x around 0

      \[\leadsto \log \color{blue}{\left(1 + x \cdot y\right)} \cdot c \]
    5. Step-by-step derivation
      1. lower-+.f64N/A

        \[\leadsto \log \left(1 + \color{blue}{x \cdot y}\right) \cdot c \]
      2. lower-*.f6440.2%

        \[\leadsto \log \left(1 + x \cdot \color{blue}{y}\right) \cdot c \]
    6. Applied rewrites40.2%

      \[\leadsto \log \color{blue}{\left(1 + x \cdot y\right)} \cdot c \]
    7. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \log \left(1 + \color{blue}{x \cdot y}\right) \cdot c \]
      2. +-commutativeN/A

        \[\leadsto \log \left(x \cdot y + \color{blue}{1}\right) \cdot c \]
      3. remove-double-negN/A

        \[\leadsto \log \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot y\right)\right)\right)\right) + 1\right) \cdot c \]
      4. mul-1-negN/A

        \[\leadsto \log \left(-1 \cdot \left(\mathsf{neg}\left(x \cdot y\right)\right) + 1\right) \cdot c \]
      5. metadata-evalN/A

        \[\leadsto \log \left(\left(\mathsf{neg}\left(1\right)\right) \cdot \left(\mathsf{neg}\left(x \cdot y\right)\right) + 1\right) \cdot c \]
      6. metadata-evalN/A

        \[\leadsto \log \left(-1 \cdot \left(\mathsf{neg}\left(x \cdot y\right)\right) + 1\right) \cdot c \]
      7. mul-1-negN/A

        \[\leadsto \log \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x \cdot y\right)\right)\right)\right) + 1\right) \cdot c \]
      8. remove-double-negN/A

        \[\leadsto \log \left(x \cdot y + 1\right) \cdot c \]
      9. lift-*.f64N/A

        \[\leadsto \log \left(x \cdot y + 1\right) \cdot c \]
      10. *-commutativeN/A

        \[\leadsto \log \left(y \cdot x + 1\right) \cdot c \]
      11. lower-fma.f6440.2%

        \[\leadsto \log \left(\mathsf{fma}\left(y, \color{blue}{x}, 1\right)\right) \cdot c \]
    8. Applied rewrites40.2%

      \[\leadsto \log \left(\mathsf{fma}\left(y, \color{blue}{x}, 1\right)\right) \cdot c \]

    if -4.7999999999999999e131 < y < 0.029999999999999999

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \left(e^{x} - 1\right)\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \left(e^{x} - 1\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\left(e^{x} - 1\right)}\right) \]
      3. lower-expm1.f6473.7%

        \[\leadsto c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right) \]
    4. Applied rewrites73.7%

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]
      2. lift-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\mathsf{expm1}\left(x\right)}\right) \]
      3. *-commutativeN/A

        \[\leadsto c \cdot \left(\mathsf{expm1}\left(x\right) \cdot \color{blue}{y}\right) \]
      4. associate-*r*N/A

        \[\leadsto \left(c \cdot \mathsf{expm1}\left(x\right)\right) \cdot \color{blue}{y} \]
      5. lower-*.f64N/A

        \[\leadsto \left(c \cdot \mathsf{expm1}\left(x\right)\right) \cdot \color{blue}{y} \]
      6. *-commutativeN/A

        \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y \]
      7. lower-*.f6476.7%

        \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y \]
    6. Applied rewrites76.7%

      \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot \color{blue}{y} \]

    if 0.029999999999999999 < y < 3.0000000000000001e228

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lower-*.f6456.0%

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
    4. Applied rewrites56.0%

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 79.6% accurate, 1.4× speedup?

\[\mathsf{copysign}\left(1, c\right) \cdot \begin{array}{l} \mathbf{if}\;\left|c\right| \leq 200000000000:\\ \;\;\;\;\left|c\right| \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot \left|c\right|\right) \cdot y\\ \end{array} \]
(FPCore (c x y)
  :precision binary64
  (*
 (copysign 1.0 c)
 (if (<= (fabs c) 200000000000.0)
   (* (fabs c) (* y (expm1 x)))
   (* (* (expm1 x) (fabs c)) y))))
double code(double c, double x, double y) {
	double tmp;
	if (fabs(c) <= 200000000000.0) {
		tmp = fabs(c) * (y * expm1(x));
	} else {
		tmp = (expm1(x) * fabs(c)) * y;
	}
	return copysign(1.0, c) * tmp;
}
public static double code(double c, double x, double y) {
	double tmp;
	if (Math.abs(c) <= 200000000000.0) {
		tmp = Math.abs(c) * (y * Math.expm1(x));
	} else {
		tmp = (Math.expm1(x) * Math.abs(c)) * y;
	}
	return Math.copySign(1.0, c) * tmp;
}
def code(c, x, y):
	tmp = 0
	if math.fabs(c) <= 200000000000.0:
		tmp = math.fabs(c) * (y * math.expm1(x))
	else:
		tmp = (math.expm1(x) * math.fabs(c)) * y
	return math.copysign(1.0, c) * tmp
function code(c, x, y)
	tmp = 0.0
	if (abs(c) <= 200000000000.0)
		tmp = Float64(abs(c) * Float64(y * expm1(x)));
	else
		tmp = Float64(Float64(expm1(x) * abs(c)) * y);
	end
	return Float64(copysign(1.0, c) * tmp)
end
code[c_, x_, y_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[c], $MachinePrecision], 200000000000.0], N[(N[Abs[c], $MachinePrecision] * N[(y * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(Exp[x] - 1), $MachinePrecision] * N[Abs[c], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, c\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|c\right| \leq 200000000000:\\
\;\;\;\;\left|c\right| \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\mathsf{expm1}\left(x\right) \cdot \left|c\right|\right) \cdot y\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < 2e11

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \left(e^{x} - 1\right)\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \left(e^{x} - 1\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\left(e^{x} - 1\right)}\right) \]
      3. lower-expm1.f6473.7%

        \[\leadsto c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right) \]
    4. Applied rewrites73.7%

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]

    if 2e11 < c

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \left(e^{x} - 1\right)\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \left(e^{x} - 1\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\left(e^{x} - 1\right)}\right) \]
      3. lower-expm1.f6473.7%

        \[\leadsto c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right) \]
    4. Applied rewrites73.7%

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]
      2. lift-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\mathsf{expm1}\left(x\right)}\right) \]
      3. *-commutativeN/A

        \[\leadsto c \cdot \left(\mathsf{expm1}\left(x\right) \cdot \color{blue}{y}\right) \]
      4. associate-*r*N/A

        \[\leadsto \left(c \cdot \mathsf{expm1}\left(x\right)\right) \cdot \color{blue}{y} \]
      5. lower-*.f64N/A

        \[\leadsto \left(c \cdot \mathsf{expm1}\left(x\right)\right) \cdot \color{blue}{y} \]
      6. *-commutativeN/A

        \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y \]
      7. lower-*.f6476.7%

        \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot y \]
    6. Applied rewrites76.7%

      \[\leadsto \left(\mathsf{expm1}\left(x\right) \cdot c\right) \cdot \color{blue}{y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 76.3% accurate, 2.0× speedup?

\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-27}:\\ \;\;\;\;c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot c\right) \cdot y\\ \end{array} \]
(FPCore (c x y)
  :precision binary64
  (if (<= x -2e-27) (* c (* y (expm1 x))) (* (* x c) y)))
double code(double c, double x, double y) {
	double tmp;
	if (x <= -2e-27) {
		tmp = c * (y * expm1(x));
	} else {
		tmp = (x * c) * y;
	}
	return tmp;
}
public static double code(double c, double x, double y) {
	double tmp;
	if (x <= -2e-27) {
		tmp = c * (y * Math.expm1(x));
	} else {
		tmp = (x * c) * y;
	}
	return tmp;
}
def code(c, x, y):
	tmp = 0
	if x <= -2e-27:
		tmp = c * (y * math.expm1(x))
	else:
		tmp = (x * c) * y
	return tmp
function code(c, x, y)
	tmp = 0.0
	if (x <= -2e-27)
		tmp = Float64(c * Float64(y * expm1(x)));
	else
		tmp = Float64(Float64(x * c) * y);
	end
	return tmp
end
code[c_, x_, y_] := If[LessEqual[x, -2e-27], N[(c * N[(y * N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * c), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-27}:\\
\;\;\;\;c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot c\right) \cdot y\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2.0000000000000001e-27

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \left(e^{x} - 1\right)\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(y \cdot \left(e^{x} - 1\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{\left(e^{x} - 1\right)}\right) \]
      3. lower-expm1.f6473.7%

        \[\leadsto c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right) \]
    4. Applied rewrites73.7%

      \[\leadsto \color{blue}{c \cdot \left(y \cdot \mathsf{expm1}\left(x\right)\right)} \]

    if -2.0000000000000001e-27 < x

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lower-*.f6456.0%

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
    4. Applied rewrites56.0%

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lift-*.f64N/A

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(c \cdot x\right) \cdot \color{blue}{y} \]
      4. lower-*.f64N/A

        \[\leadsto \left(c \cdot x\right) \cdot \color{blue}{y} \]
      5. *-commutativeN/A

        \[\leadsto \left(x \cdot c\right) \cdot y \]
      6. lower-*.f6459.0%

        \[\leadsto \left(x \cdot c\right) \cdot y \]
    6. Applied rewrites59.0%

      \[\leadsto \left(x \cdot c\right) \cdot \color{blue}{y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 64.6% accurate, 1.9× speedup?

\[\mathsf{copysign}\left(1, c\right) \cdot \begin{array}{l} \mathbf{if}\;\left|c\right| \leq 10^{-18}:\\ \;\;\;\;\left(y \cdot \left|c\right|\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \left|c\right|\right) \cdot y\\ \end{array} \]
(FPCore (c x y)
  :precision binary64
  (*
 (copysign 1.0 c)
 (if (<= (fabs c) 1e-18) (* (* y (fabs c)) x) (* (* x (fabs c)) y))))
double code(double c, double x, double y) {
	double tmp;
	if (fabs(c) <= 1e-18) {
		tmp = (y * fabs(c)) * x;
	} else {
		tmp = (x * fabs(c)) * y;
	}
	return copysign(1.0, c) * tmp;
}
public static double code(double c, double x, double y) {
	double tmp;
	if (Math.abs(c) <= 1e-18) {
		tmp = (y * Math.abs(c)) * x;
	} else {
		tmp = (x * Math.abs(c)) * y;
	}
	return Math.copySign(1.0, c) * tmp;
}
def code(c, x, y):
	tmp = 0
	if math.fabs(c) <= 1e-18:
		tmp = (y * math.fabs(c)) * x
	else:
		tmp = (x * math.fabs(c)) * y
	return math.copysign(1.0, c) * tmp
function code(c, x, y)
	tmp = 0.0
	if (abs(c) <= 1e-18)
		tmp = Float64(Float64(y * abs(c)) * x);
	else
		tmp = Float64(Float64(x * abs(c)) * y);
	end
	return Float64(copysign(1.0, c) * tmp)
end
function tmp_2 = code(c, x, y)
	tmp = 0.0;
	if (abs(c) <= 1e-18)
		tmp = (y * abs(c)) * x;
	else
		tmp = (x * abs(c)) * y;
	end
	tmp_2 = (sign(c) * abs(1.0)) * tmp;
end
code[c_, x_, y_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[c], $MachinePrecision], 1e-18], N[(N[(y * N[Abs[c], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(N[(x * N[Abs[c], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, c\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|c\right| \leq 10^{-18}:\\
\;\;\;\;\left(y \cdot \left|c\right|\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot \left|c\right|\right) \cdot y\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < 1.0000000000000001e-18

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lower-*.f6456.0%

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
    4. Applied rewrites56.0%

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lift-*.f64N/A

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
      3. *-commutativeN/A

        \[\leadsto c \cdot \left(y \cdot \color{blue}{x}\right) \]
      4. associate-*r*N/A

        \[\leadsto \left(c \cdot y\right) \cdot \color{blue}{x} \]
      5. lower-*.f64N/A

        \[\leadsto \left(c \cdot y\right) \cdot \color{blue}{x} \]
      6. *-commutativeN/A

        \[\leadsto \left(y \cdot c\right) \cdot x \]
      7. lower-*.f6461.6%

        \[\leadsto \left(y \cdot c\right) \cdot x \]
    6. Applied rewrites61.6%

      \[\leadsto \left(y \cdot c\right) \cdot \color{blue}{x} \]

    if 1.0000000000000001e-18 < c

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lower-*.f6456.0%

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
    4. Applied rewrites56.0%

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lift-*.f64N/A

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
      3. associate-*r*N/A

        \[\leadsto \left(c \cdot x\right) \cdot \color{blue}{y} \]
      4. lower-*.f64N/A

        \[\leadsto \left(c \cdot x\right) \cdot \color{blue}{y} \]
      5. *-commutativeN/A

        \[\leadsto \left(x \cdot c\right) \cdot y \]
      6. lower-*.f6459.0%

        \[\leadsto \left(x \cdot c\right) \cdot y \]
    6. Applied rewrites59.0%

      \[\leadsto \left(x \cdot c\right) \cdot \color{blue}{y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 61.5% accurate, 3.3× speedup?

\[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{+71}:\\ \;\;\;\;0 \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot c\right) \cdot y\\ \end{array} \]
(FPCore (c x y)
  :precision binary64
  (if (<= x -7e+71) (* 0.0 (* x y)) (* (* x c) y)))
double code(double c, double x, double y) {
	double tmp;
	if (x <= -7e+71) {
		tmp = 0.0 * (x * y);
	} else {
		tmp = (x * c) * y;
	}
	return tmp;
}
real(8) function code(c, x, y)
use fmin_fmax_functions
    real(8), intent (in) :: c
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-7d+71)) then
        tmp = 0.0d0 * (x * y)
    else
        tmp = (x * c) * y
    end if
    code = tmp
end function
public static double code(double c, double x, double y) {
	double tmp;
	if (x <= -7e+71) {
		tmp = 0.0 * (x * y);
	} else {
		tmp = (x * c) * y;
	}
	return tmp;
}
def code(c, x, y):
	tmp = 0
	if x <= -7e+71:
		tmp = 0.0 * (x * y)
	else:
		tmp = (x * c) * y
	return tmp
function code(c, x, y)
	tmp = 0.0
	if (x <= -7e+71)
		tmp = Float64(0.0 * Float64(x * y));
	else
		tmp = Float64(Float64(x * c) * y);
	end
	return tmp
end
function tmp_2 = code(c, x, y)
	tmp = 0.0;
	if (x <= -7e+71)
		tmp = 0.0 * (x * y);
	else
		tmp = (x * c) * y;
	end
	tmp_2 = tmp;
end
code[c_, x_, y_] := If[LessEqual[x, -7e+71], N[(0.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(x * c), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+71}:\\
\;\;\;\;0 \cdot \left(x \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot c\right) \cdot y\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -6.9999999999999998e71

    1. Initial program 41.7%

      \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
      2. lower-*.f6456.0%

        \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
    4. Applied rewrites56.0%

      \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
    5. Taylor expanded in undef-var around zero

      \[\leadsto 0 \cdot \left(\color{blue}{x} \cdot y\right) \]
    6. Step-by-step derivation
      1. Applied rewrites30.6%

        \[\leadsto 0 \cdot \left(\color{blue}{x} \cdot y\right) \]

      if -6.9999999999999998e71 < x

      1. Initial program 41.7%

        \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
      2. Taylor expanded in x around 0

        \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
        2. lower-*.f6456.0%

          \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
      4. Applied rewrites56.0%

        \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
        2. lift-*.f64N/A

          \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
        3. associate-*r*N/A

          \[\leadsto \left(c \cdot x\right) \cdot \color{blue}{y} \]
        4. lower-*.f64N/A

          \[\leadsto \left(c \cdot x\right) \cdot \color{blue}{y} \]
        5. *-commutativeN/A

          \[\leadsto \left(x \cdot c\right) \cdot y \]
        6. lower-*.f6459.0%

          \[\leadsto \left(x \cdot c\right) \cdot y \]
      6. Applied rewrites59.0%

        \[\leadsto \left(x \cdot c\right) \cdot \color{blue}{y} \]
    7. Recombined 2 regimes into one program.
    8. Add Preprocessing

    Alternative 8: 58.5% accurate, 3.3× speedup?

    \[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{+71}:\\ \;\;\;\;0 \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;c \cdot \left(x \cdot y\right)\\ \end{array} \]
    (FPCore (c x y)
      :precision binary64
      (if (<= x -7e+71) (* 0.0 (* x y)) (* c (* x y))))
    double code(double c, double x, double y) {
    	double tmp;
    	if (x <= -7e+71) {
    		tmp = 0.0 * (x * y);
    	} else {
    		tmp = c * (x * y);
    	}
    	return tmp;
    }
    
    real(8) function code(c, x, y)
    use fmin_fmax_functions
        real(8), intent (in) :: c
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8) :: tmp
        if (x <= (-7d+71)) then
            tmp = 0.0d0 * (x * y)
        else
            tmp = c * (x * y)
        end if
        code = tmp
    end function
    
    public static double code(double c, double x, double y) {
    	double tmp;
    	if (x <= -7e+71) {
    		tmp = 0.0 * (x * y);
    	} else {
    		tmp = c * (x * y);
    	}
    	return tmp;
    }
    
    def code(c, x, y):
    	tmp = 0
    	if x <= -7e+71:
    		tmp = 0.0 * (x * y)
    	else:
    		tmp = c * (x * y)
    	return tmp
    
    function code(c, x, y)
    	tmp = 0.0
    	if (x <= -7e+71)
    		tmp = Float64(0.0 * Float64(x * y));
    	else
    		tmp = Float64(c * Float64(x * y));
    	end
    	return tmp
    end
    
    function tmp_2 = code(c, x, y)
    	tmp = 0.0;
    	if (x <= -7e+71)
    		tmp = 0.0 * (x * y);
    	else
    		tmp = c * (x * y);
    	end
    	tmp_2 = tmp;
    end
    
    code[c_, x_, y_] := If[LessEqual[x, -7e+71], N[(0.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(c * N[(x * y), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    \mathbf{if}\;x \leq -7 \cdot 10^{+71}:\\
    \;\;\;\;0 \cdot \left(x \cdot y\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;c \cdot \left(x \cdot y\right)\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -6.9999999999999998e71

      1. Initial program 41.7%

        \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
      2. Taylor expanded in x around 0

        \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
        2. lower-*.f6456.0%

          \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
      4. Applied rewrites56.0%

        \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
      5. Taylor expanded in undef-var around zero

        \[\leadsto 0 \cdot \left(\color{blue}{x} \cdot y\right) \]
      6. Step-by-step derivation
        1. Applied rewrites30.6%

          \[\leadsto 0 \cdot \left(\color{blue}{x} \cdot y\right) \]

        if -6.9999999999999998e71 < x

        1. Initial program 41.7%

          \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
        2. Taylor expanded in x around 0

          \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
        3. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
          2. lower-*.f6456.0%

            \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
        4. Applied rewrites56.0%

          \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
      7. Recombined 2 regimes into one program.
      8. Add Preprocessing

      Alternative 9: 56.0% accurate, 5.0× speedup?

      \[c \cdot \left(x \cdot y\right) \]
      (FPCore (c x y)
        :precision binary64
        (* c (* x y)))
      double code(double c, double x, double y) {
      	return c * (x * y);
      }
      
      real(8) function code(c, x, y)
      use fmin_fmax_functions
          real(8), intent (in) :: c
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          code = c * (x * y)
      end function
      
      public static double code(double c, double x, double y) {
      	return c * (x * y);
      }
      
      def code(c, x, y):
      	return c * (x * y)
      
      function code(c, x, y)
      	return Float64(c * Float64(x * y))
      end
      
      function tmp = code(c, x, y)
      	tmp = c * (x * y);
      end
      
      code[c_, x_, y_] := N[(c * N[(x * y), $MachinePrecision]), $MachinePrecision]
      
      c \cdot \left(x \cdot y\right)
      
      Derivation
      1. Initial program 41.7%

        \[c \cdot \log \left(1 + \left({e}^{x} - 1\right) \cdot y\right) \]
      2. Taylor expanded in x around 0

        \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto c \cdot \color{blue}{\left(x \cdot y\right)} \]
        2. lower-*.f6456.0%

          \[\leadsto c \cdot \left(x \cdot \color{blue}{y}\right) \]
      4. Applied rewrites56.0%

        \[\leadsto \color{blue}{c \cdot \left(x \cdot y\right)} \]
      5. Add Preprocessing

      Developer Target 1: 93.4% accurate, 1.4× speedup?

      \[c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right) \]
      (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]
      
      c \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(x\right) \cdot y\right)
      

      Reproduce

      ?
      herbie shell --seed 2025322 
      (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)))))