Numeric.Signal.Multichannel:$cput from hsignal-0.2.7.1

Percentage Accurate: 96.7% → 96.6%
Time: 9.5s
Alternatives: 17
Speedup: N/A×

Specification

?
\[\begin{array}{l} \\ \frac{x - y}{z - y} \cdot t \end{array} \]
(FPCore (x y z t) :precision binary64 (* (/ (- x y) (- z y)) t))
double code(double x, double y, double z, double t) {
	return ((x - y) / (z - y)) * t;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = ((x - y) / (z - y)) * t
end function
public static double code(double x, double y, double z, double t) {
	return ((x - y) / (z - y)) * t;
}
def code(x, y, z, t):
	return ((x - y) / (z - y)) * t
function code(x, y, z, t)
	return Float64(Float64(Float64(x - y) / Float64(z - y)) * t)
end
function tmp = code(x, y, z, t)
	tmp = ((x - y) / (z - y)) * t;
end
code[x_, y_, z_, t_] := N[(N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}

\\
\frac{x - y}{z - y} \cdot t
\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 17 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: 96.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x - y}{z - y} \cdot t \end{array} \]
(FPCore (x y z t) :precision binary64 (* (/ (- x y) (- z y)) t))
double code(double x, double y, double z, double t) {
	return ((x - y) / (z - y)) * t;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = ((x - y) / (z - y)) * t
end function
public static double code(double x, double y, double z, double t) {
	return ((x - y) / (z - y)) * t;
}
def code(x, y, z, t):
	return ((x - y) / (z - y)) * t
function code(x, y, z, t)
	return Float64(Float64(Float64(x - y) / Float64(z - y)) * t)
end
function tmp = code(x, y, z, t)
	tmp = ((x - y) / (z - y)) * t;
end
code[x_, y_, z_, t_] := N[(N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}

\\
\frac{x - y}{z - y} \cdot t
\end{array}

Alternative 1: 96.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := t \cdot \frac{x - y}{z - y}\\ \mathbf{if}\;y \leq -7 \cdot 10^{-66}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{-18}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{t}{z - y}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* t (/ (- x y) (- z y)))))
   (if (<= y -7e-66) t_1 (if (<= y 4.1e-18) (* (- x y) (/ t (- z y))) t_1))))
double code(double x, double y, double z, double t) {
	double t_1 = t * ((x - y) / (z - y));
	double tmp;
	if (y <= -7e-66) {
		tmp = t_1;
	} else if (y <= 4.1e-18) {
		tmp = (x - y) * (t / (z - y));
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = t * ((x - y) / (z - y))
    if (y <= (-7d-66)) then
        tmp = t_1
    else if (y <= 4.1d-18) then
        tmp = (x - y) * (t / (z - y))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = t * ((x - y) / (z - y));
	double tmp;
	if (y <= -7e-66) {
		tmp = t_1;
	} else if (y <= 4.1e-18) {
		tmp = (x - y) * (t / (z - y));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = t * ((x - y) / (z - y))
	tmp = 0
	if y <= -7e-66:
		tmp = t_1
	elif y <= 4.1e-18:
		tmp = (x - y) * (t / (z - y))
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t)
	t_1 = Float64(t * Float64(Float64(x - y) / Float64(z - y)))
	tmp = 0.0
	if (y <= -7e-66)
		tmp = t_1;
	elseif (y <= 4.1e-18)
		tmp = Float64(Float64(x - y) * Float64(t / Float64(z - y)));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = t * ((x - y) / (z - y));
	tmp = 0.0;
	if (y <= -7e-66)
		tmp = t_1;
	elseif (y <= 4.1e-18)
		tmp = (x - y) * (t / (z - y));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t * N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7e-66], t$95$1, If[LessEqual[y, 4.1e-18], N[(N[(x - y), $MachinePrecision] * N[(t / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := t \cdot \frac{x - y}{z - y}\\
\mathbf{if}\;y \leq -7 \cdot 10^{-66}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 4.1 \cdot 10^{-18}:\\
\;\;\;\;\left(x - y\right) \cdot \frac{t}{z - y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.0000000000000001e-66 or 4.0999999999999998e-18 < y

    1. Initial program 99.8%

      \[\frac{x - y}{z - y} \cdot t \]
    2. Add Preprocessing

    if -7.0000000000000001e-66 < y < 4.0999999999999998e-18

    1. Initial program 86.7%

      \[\frac{x - y}{z - y} \cdot t \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\frac{x - y}{z - y} \cdot t} \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{x - y}{z - y}} \cdot t \]
      3. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot t}{z - y}} \]
      4. associate-/l*N/A

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

        \[\leadsto \color{blue}{\frac{t}{z - y} \cdot \left(x - y\right)} \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{t}{z - y} \cdot \left(x - y\right)} \]
      7. lower-/.f6497.1

        \[\leadsto \color{blue}{\frac{t}{z - y}} \cdot \left(x - y\right) \]
    4. Applied rewrites97.1%

      \[\leadsto \color{blue}{\frac{t}{z - y} \cdot \left(x - y\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7 \cdot 10^{-66}:\\ \;\;\;\;t \cdot \frac{x - y}{z - y}\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{-18}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{t}{z - y}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \frac{x - y}{z - y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 69.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{x - y}{z - y}\\ \mathbf{if}\;t\_1 \leq -1 \cdot 10^{-13}:\\ \;\;\;\;\frac{t \cdot x}{z}\\ \mathbf{elif}\;t\_1 \leq 10^{-270}:\\ \;\;\;\;-\frac{t \cdot y}{z}\\ \mathbf{elif}\;t\_1 \leq 0.8:\\ \;\;\;\;t \cdot \frac{x}{z}\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;\mathsf{fma}\left(t, \frac{z}{y}, t\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \frac{x}{-y}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ (- x y) (- z y))))
   (if (<= t_1 -1e-13)
     (/ (* t x) z)
     (if (<= t_1 1e-270)
       (- (/ (* t y) z))
       (if (<= t_1 0.8)
         (* t (/ x z))
         (if (<= t_1 2.0) (fma t (/ z y) t) (* t (/ x (- y)))))))))
double code(double x, double y, double z, double t) {
	double t_1 = (x - y) / (z - y);
	double tmp;
	if (t_1 <= -1e-13) {
		tmp = (t * x) / z;
	} else if (t_1 <= 1e-270) {
		tmp = -((t * y) / z);
	} else if (t_1 <= 0.8) {
		tmp = t * (x / z);
	} else if (t_1 <= 2.0) {
		tmp = fma(t, (z / y), t);
	} else {
		tmp = t * (x / -y);
	}
	return tmp;
}
function code(x, y, z, t)
	t_1 = Float64(Float64(x - y) / Float64(z - y))
	tmp = 0.0
	if (t_1 <= -1e-13)
		tmp = Float64(Float64(t * x) / z);
	elseif (t_1 <= 1e-270)
		tmp = Float64(-Float64(Float64(t * y) / z));
	elseif (t_1 <= 0.8)
		tmp = Float64(t * Float64(x / z));
	elseif (t_1 <= 2.0)
		tmp = fma(t, Float64(z / y), t);
	else
		tmp = Float64(t * Float64(x / Float64(-y)));
	end
	return tmp
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-13], N[(N[(t * x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[t$95$1, 1e-270], (-N[(N[(t * y), $MachinePrecision] / z), $MachinePrecision]), If[LessEqual[t$95$1, 0.8], N[(t * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[(t * N[(z / y), $MachinePrecision] + t), $MachinePrecision], N[(t * N[(x / (-y)), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{x - y}{z - y}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-13}:\\
\;\;\;\;\frac{t \cdot x}{z}\\

\mathbf{elif}\;t\_1 \leq 10^{-270}:\\
\;\;\;\;-\frac{t \cdot y}{z}\\

\mathbf{elif}\;t\_1 \leq 0.8:\\
\;\;\;\;t \cdot \frac{x}{z}\\

\mathbf{elif}\;t\_1 \leq 2:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{z}{y}, t\right)\\

\mathbf{else}:\\
\;\;\;\;t \cdot \frac{x}{-y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (/.f64 (-.f64 x y) (-.f64 z y)) < -1e-13

    1. Initial program 94.7%

      \[\frac{x - y}{z - y} \cdot t \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{\frac{t \cdot x}{z}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{t \cdot x}{z}} \]
      2. lower-*.f6450.8

        \[\leadsto \frac{\color{blue}{t \cdot x}}{z} \]
    5. Applied rewrites50.8%

      \[\leadsto \color{blue}{\frac{t \cdot x}{z}} \]

    if -1e-13 < (/.f64 (-.f64 x y) (-.f64 z y)) < 1e-270

    1. Initial program 91.5%

      \[\frac{x - y}{z - y} \cdot t \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{\frac{t \cdot \left(x - y\right)}{z}} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\left(x - y\right) \cdot t}}{z} \]
      2. associate-/l*N/A

        \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{t}{z}} \]
      3. lower-*.f64N/A

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

        \[\leadsto \color{blue}{\left(x - y\right)} \cdot \frac{t}{z} \]
      5. lower-/.f6492.6

        \[\leadsto \left(x - y\right) \cdot \color{blue}{\frac{t}{z}} \]
    5. Applied rewrites92.6%

      \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{t}{z}} \]
    6. Taylor expanded in x around 0

      \[\leadsto -1 \cdot \color{blue}{\frac{t \cdot y}{z}} \]
    7. Step-by-step derivation
      1. Applied rewrites61.9%

        \[\leadsto \frac{t \cdot y}{\color{blue}{-z}} \]

      if 1e-270 < (/.f64 (-.f64 x y) (-.f64 z y)) < 0.80000000000000004

      1. Initial program 99.7%

        \[\frac{x - y}{z - y} \cdot t \]
      2. Add Preprocessing
      3. Taylor expanded in y around 0

        \[\leadsto \color{blue}{\frac{x}{z}} \cdot t \]
      4. Step-by-step derivation
        1. lower-/.f6458.1

          \[\leadsto \color{blue}{\frac{x}{z}} \cdot t \]
      5. Applied rewrites58.1%

        \[\leadsto \color{blue}{\frac{x}{z}} \cdot t \]

      if 0.80000000000000004 < (/.f64 (-.f64 x y) (-.f64 z y)) < 2

      1. Initial program 99.9%

        \[\frac{x - y}{z - y} \cdot t \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{\frac{x - y}{z - y} \cdot t} \]
        2. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{x - y}{z - y}} \cdot t \]
        3. associate-*l/N/A

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

          \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot t}{z - y}} \]
        5. lower-*.f6473.3

          \[\leadsto \frac{\color{blue}{\left(x - y\right) \cdot t}}{z - y} \]
      4. Applied rewrites73.3%

        \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot t}{z - y}} \]
      5. Taylor expanded in y around inf

        \[\leadsto \color{blue}{\left(t + -1 \cdot \frac{t \cdot x}{y}\right) - -1 \cdot \frac{t \cdot z}{y}} \]
      6. Step-by-step derivation
        1. associate--l+N/A

          \[\leadsto \color{blue}{t + \left(-1 \cdot \frac{t \cdot x}{y} - -1 \cdot \frac{t \cdot z}{y}\right)} \]
        2. distribute-lft-out--N/A

          \[\leadsto t + \color{blue}{-1 \cdot \left(\frac{t \cdot x}{y} - \frac{t \cdot z}{y}\right)} \]
        3. div-subN/A

          \[\leadsto t + -1 \cdot \color{blue}{\frac{t \cdot x - t \cdot z}{y}} \]
        4. +-commutativeN/A

          \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot x - t \cdot z}{y} + t} \]
        5. mul-1-negN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{t \cdot x - t \cdot z}{y}\right)\right)} + t \]
        6. distribute-lft-out--N/A

          \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{t \cdot \left(x - z\right)}}{y}\right)\right) + t \]
        7. associate-/l*N/A

          \[\leadsto \left(\mathsf{neg}\left(\color{blue}{t \cdot \frac{x - z}{y}}\right)\right) + t \]
        8. distribute-rgt-neg-inN/A

          \[\leadsto \color{blue}{t \cdot \left(\mathsf{neg}\left(\frac{x - z}{y}\right)\right)} + t \]
        9. mul-1-negN/A

          \[\leadsto t \cdot \color{blue}{\left(-1 \cdot \frac{x - z}{y}\right)} + t \]
        10. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(t, -1 \cdot \frac{x - z}{y}, t\right)} \]
      7. Applied rewrites99.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(t, \frac{z - x}{y}, t\right)} \]
      8. Taylor expanded in z around inf

        \[\leadsto \mathsf{fma}\left(t, \frac{z}{\color{blue}{y}}, t\right) \]
      9. Step-by-step derivation
        1. Applied rewrites97.8%

          \[\leadsto \mathsf{fma}\left(t, \frac{z}{\color{blue}{y}}, t\right) \]

        if 2 < (/.f64 (-.f64 x y) (-.f64 z y))

        1. Initial program 95.3%

          \[\frac{x - y}{z - y} \cdot t \]
        2. Add Preprocessing
        3. Taylor expanded in x around inf

          \[\leadsto \color{blue}{\frac{x}{z - y}} \cdot t \]
        4. Step-by-step derivation
          1. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{x}{z - y}} \cdot t \]
          2. lower--.f6493.4

            \[\leadsto \frac{x}{\color{blue}{z - y}} \cdot t \]
        5. Applied rewrites93.4%

          \[\leadsto \color{blue}{\frac{x}{z - y}} \cdot t \]
        6. Taylor expanded in z around 0

          \[\leadsto \frac{x}{-1 \cdot \color{blue}{y}} \cdot t \]
        7. Step-by-step derivation
          1. Applied rewrites52.5%

            \[\leadsto \frac{x}{-y} \cdot t \]
        8. Recombined 5 regimes into one program.
        9. Final simplification69.7%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y}{z - y} \leq -1 \cdot 10^{-13}:\\ \;\;\;\;\frac{t \cdot x}{z}\\ \mathbf{elif}\;\frac{x - y}{z - y} \leq 10^{-270}:\\ \;\;\;\;-\frac{t \cdot y}{z}\\ \mathbf{elif}\;\frac{x - y}{z - y} \leq 0.8:\\ \;\;\;\;t \cdot \frac{x}{z}\\ \mathbf{elif}\;\frac{x - y}{z - y} \leq 2:\\ \;\;\;\;\mathsf{fma}\left(t, \frac{z}{y}, t\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \frac{x}{-y}\\ \end{array} \]
        10. Add Preprocessing

        Developer Target 1: 96.7% accurate, 0.8× speedup?

        \[\begin{array}{l} \\ \frac{t}{\frac{z - y}{x - y}} \end{array} \]
        (FPCore (x y z t) :precision binary64 (/ t (/ (- z y) (- x y))))
        double code(double x, double y, double z, double t) {
        	return t / ((z - y) / (x - y));
        }
        
        real(8) function code(x, y, z, t)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            real(8), intent (in) :: t
            code = t / ((z - y) / (x - y))
        end function
        
        public static double code(double x, double y, double z, double t) {
        	return t / ((z - y) / (x - y));
        }
        
        def code(x, y, z, t):
        	return t / ((z - y) / (x - y))
        
        function code(x, y, z, t)
        	return Float64(t / Float64(Float64(z - y) / Float64(x - y)))
        end
        
        function tmp = code(x, y, z, t)
        	tmp = t / ((z - y) / (x - y));
        end
        
        code[x_, y_, z_, t_] := N[(t / N[(N[(z - y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \frac{t}{\frac{z - y}{x - y}}
        \end{array}
        

        Reproduce

        ?
        herbie shell --seed 2024228 
        (FPCore (x y z t)
          :name "Numeric.Signal.Multichannel:$cput from hsignal-0.2.7.1"
          :precision binary64
        
          :alt
          (! :herbie-platform default (/ t (/ (- z y) (- x y))))
        
          (* (/ (- x y) (- z y)) t))