Development.Shake.Progress:decay from shake-0.15.5

Percentage Accurate: 66.6% → 66.6%
Time: 2.1s
Alternatives: 6
Speedup: 1.0×

Specification

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

\\
\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - 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 6 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: 66.6% accurate, 1.0× speedup?

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

\\
\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}
\end{array}

Alternative 1: 66.6% accurate, 1.0× speedup?

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

\\
\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}
\end{array}
Derivation
  1. Initial program 69.6%

    \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 47.6% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_1 := y + z \cdot \left(b - y\right)\\
t_2 := \frac{x \cdot y}{t\_1}\\
\mathbf{if}\;y \leq -1.05 \cdot 10^{-14}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;y \leq 1.7 \cdot 10^{+39}:\\
\;\;\;\;\frac{z \cdot \left(t - a\right)}{t\_1}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.0499999999999999e-14 or 1.6999999999999999e39 < y

    1. Initial program 51.9%

      \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \frac{\color{blue}{z \cdot \left(t - a\right)}}{y + z \cdot \left(b - y\right)} \]
    4. Applied rewrites35.6%

      \[\leadsto \frac{\color{blue}{x \cdot y}}{y + z \cdot \left(b - y\right)} \]

    if -1.0499999999999999e-14 < y < 1.6999999999999999e39

    1. Initial program 82.6%

      \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \frac{\color{blue}{x \cdot y + z \cdot \left(t - a\right)}}{y + z \cdot \left(b - y\right)} \]
    4. Applied rewrites67.8%

      \[\leadsto \frac{\color{blue}{z \cdot \left(t - a\right)}}{y + z \cdot \left(b - y\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 29.2% accurate, 1.4× speedup?

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

\\
\frac{x \cdot y}{y + z \cdot \left(b - y\right)}
\end{array}
Derivation
  1. Initial program 69.6%

    \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \frac{\color{blue}{z \cdot \left(t - a\right)}}{y + z \cdot \left(b - y\right)} \]
  4. Applied rewrites27.9%

    \[\leadsto \frac{\color{blue}{x \cdot y}}{y + z \cdot \left(b - y\right)} \]
  5. Add Preprocessing

Alternative 4: 4.5% accurate, 4.3× speedup?

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

\\
z \cdot \left(t - a\right)
\end{array}
Derivation
  1. Initial program 69.6%

    \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{x \cdot y}{y + z \cdot \left(b - y\right)} + \frac{z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}} \]
  4. Applied rewrites5.0%

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

    \[\leadsto x \cdot y + \color{blue}{z \cdot \left(t - a\right)} \]
  6. Applied rewrites5.1%

    \[\leadsto z \cdot \color{blue}{\left(t - a\right)} \]
  7. Add Preprocessing

Alternative 5: 3.7% accurate, 6.5× speedup?

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

\\
x \cdot y
\end{array}
Derivation
  1. Initial program 69.6%

    \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{x \cdot y}{y + z \cdot \left(b - y\right)} + \frac{z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}} \]
  4. Applied rewrites5.0%

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

    \[\leadsto z \cdot \color{blue}{\left(t - a\right)} \]
  6. Applied rewrites4.0%

    \[\leadsto x \cdot \color{blue}{y} \]
  7. Add Preprocessing

Alternative 6: 3.5% accurate, 9.8× speedup?

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

\\
t - a
\end{array}
Derivation
  1. Initial program 69.6%

    \[\frac{x \cdot y + z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{x \cdot y}{y + z \cdot \left(b - y\right)} + \frac{z \cdot \left(t - a\right)}{y + z \cdot \left(b - y\right)}} \]
  4. Applied rewrites5.0%

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

    \[\leadsto -1 \cdot \color{blue}{\left(x \cdot \left(-1 \cdot y + -1 \cdot \frac{z \cdot \left(t - a\right)}{x}\right)\right)} \]
  6. Applied rewrites3.3%

    \[\leadsto t - \color{blue}{a} \]
  7. Add Preprocessing

Developer Target 1: 74.2% accurate, 0.6× speedup?

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

\\
\frac{z \cdot t + y \cdot x}{y + z \cdot \left(b - y\right)} - \frac{a}{\left(b - y\right) + \frac{y}{z}}
\end{array}

Reproduce

?
herbie shell --seed 2024321 
(FPCore (x y z t a b)
  :name "Development.Shake.Progress:decay from shake-0.15.5"
  :precision binary64
  :pre (TRUE)

  :alt
  (! :herbie-platform default (- (/ (+ (* z t) (* y x)) (+ y (* z (- b y)))) (/ a (+ (- b y) (/ y z)))))

  (/ (+ (* x y) (* z (- t a))) (+ y (* z (- b y)))))