Diagrams.Solve.Tridiagonal:solveCyclicTriDiagonal from diagrams-solve-0.1, A

Percentage Accurate: 92.3% → 99.7%
Time: 2.2s
Alternatives: 3
Speedup: 1.0×

Specification

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

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

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

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

Alternative 1: 99.7% accurate, 0.6× speedup?

\[\begin{array}{l} z\_m = \left|z\right| \\ z\_s = \mathsf{copysign}\left(1, z\right) \\ y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\ \\ x\_s \cdot \left(y\_s \cdot \left(z\_s \cdot \begin{array}{l} \mathbf{if}\;z\_m \leq 6.1 \cdot 10^{-15}:\\ \;\;\;\;\frac{y\_m}{\frac{z\_m}{x\_m}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y\_m}{z\_m} \cdot x\_m\\ \end{array}\right)\right) \end{array} \]
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (x_s y_s z_s x_m y_m z_m)
 :precision binary64
 (*
  x_s
  (*
   y_s
   (* z_s (if (<= z_m 6.1e-15) (/ y_m (/ z_m x_m)) (* (/ y_m z_m) x_m))))))
z\_m = fabs(z);
z\_s = copysign(1.0, z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y_m && y_m < z_m);
double code(double x_s, double y_s, double z_s, double x_m, double y_m, double z_m) {
	double tmp;
	if (z_m <= 6.1e-15) {
		tmp = y_m / (z_m / x_m);
	} else {
		tmp = (y_m / z_m) * x_m;
	}
	return x_s * (y_s * (z_s * tmp));
}
z\_m = abs(z)
z\_s = copysign(1.0d0, z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
real(8) function code(x_s, y_s, z_s, x_m, y_m, z_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: y_s
    real(8), intent (in) :: z_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z_m
    real(8) :: tmp
    if (z_m <= 6.1d-15) then
        tmp = y_m / (z_m / x_m)
    else
        tmp = (y_m / z_m) * x_m
    end if
    code = x_s * (y_s * (z_s * tmp))
end function
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y_m && y_m < z_m;
public static double code(double x_s, double y_s, double z_s, double x_m, double y_m, double z_m) {
	double tmp;
	if (z_m <= 6.1e-15) {
		tmp = y_m / (z_m / x_m);
	} else {
		tmp = (y_m / z_m) * x_m;
	}
	return x_s * (y_s * (z_s * tmp));
}
z\_m = math.fabs(z)
z\_s = math.copysign(1.0, z)
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
[x_m, y_m, z_m] = sort([x_m, y_m, z_m])
def code(x_s, y_s, z_s, x_m, y_m, z_m):
	tmp = 0
	if z_m <= 6.1e-15:
		tmp = y_m / (z_m / x_m)
	else:
		tmp = (y_m / z_m) * x_m
	return x_s * (y_s * (z_s * tmp))
z\_m = abs(z)
z\_s = copysign(1.0, z)
y\_m = abs(y)
y\_s = copysign(1.0, y)
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y_m, z_m = sort([x_m, y_m, z_m])
function code(x_s, y_s, z_s, x_m, y_m, z_m)
	tmp = 0.0
	if (z_m <= 6.1e-15)
		tmp = Float64(y_m / Float64(z_m / x_m));
	else
		tmp = Float64(Float64(y_m / z_m) * x_m);
	end
	return Float64(x_s * Float64(y_s * Float64(z_s * tmp)))
end
z\_m = abs(z);
z\_s = sign(z) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y_m, z_m = num2cell(sort([x_m, y_m, z_m])){:}
function tmp_2 = code(x_s, y_s, z_s, x_m, y_m, z_m)
	tmp = 0.0;
	if (z_m <= 6.1e-15)
		tmp = y_m / (z_m / x_m);
	else
		tmp = (y_m / z_m) * x_m;
	end
	tmp_2 = x_s * (y_s * (z_s * tmp));
end
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[x$95$s_, y$95$s_, z$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(x$95$s * N[(y$95$s * N[(z$95$s * If[LessEqual[z$95$m, 6.1e-15], N[(y$95$m / N[(z$95$m / x$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(y$95$m / z$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
x\_s \cdot \left(y\_s \cdot \left(z\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 6.1 \cdot 10^{-15}:\\
\;\;\;\;\frac{y\_m}{\frac{z\_m}{x\_m}}\\

\mathbf{else}:\\
\;\;\;\;\frac{y\_m}{z\_m} \cdot x\_m\\


\end{array}\right)\right)
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 6.09999999999999972e-15

    1. Initial program 94.6%

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

        \[\leadsto \color{blue}{\frac{x \cdot y}{z}} \]
      2. clear-numN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{z}{x \cdot y}}} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{1}{\frac{z}{\color{blue}{x \cdot y}}} \]
      4. associate-/r*N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{z}{x}}{y}}} \]
      5. clear-numN/A

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
      7. lower-/.f6490.9

        \[\leadsto \frac{y}{\color{blue}{\frac{z}{x}}} \]
    4. Applied rewrites90.9%

      \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]

    if 6.09999999999999972e-15 < z

    1. Initial program 96.9%

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

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

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

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

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
      6. lower-/.f6494.0

        \[\leadsto \color{blue}{\frac{y}{z}} \cdot x \]
    4. Applied rewrites94.0%

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} z\_m = \left|z\right| \\ z\_s = \mathsf{copysign}\left(1, z\right) \\ y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\ \\ x\_s \cdot \left(y\_s \cdot \left(z\_s \cdot \begin{array}{l} \mathbf{if}\;\frac{x\_m \cdot y\_m}{z\_m} \leq 2 \cdot 10^{+25}:\\ \;\;\;\;\frac{y\_m}{z\_m} \cdot x\_m\\ \mathbf{else}:\\ \;\;\;\;\frac{x\_m}{z\_m} \cdot y\_m\\ \end{array}\right)\right) \end{array} \]
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (x_s y_s z_s x_m y_m z_m)
 :precision binary64
 (*
  x_s
  (*
   y_s
   (*
    z_s
    (if (<= (/ (* x_m y_m) z_m) 2e+25)
      (* (/ y_m z_m) x_m)
      (* (/ x_m z_m) y_m))))))
z\_m = fabs(z);
z\_s = copysign(1.0, z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y_m && y_m < z_m);
double code(double x_s, double y_s, double z_s, double x_m, double y_m, double z_m) {
	double tmp;
	if (((x_m * y_m) / z_m) <= 2e+25) {
		tmp = (y_m / z_m) * x_m;
	} else {
		tmp = (x_m / z_m) * y_m;
	}
	return x_s * (y_s * (z_s * tmp));
}
z\_m = abs(z)
z\_s = copysign(1.0d0, z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
real(8) function code(x_s, y_s, z_s, x_m, y_m, z_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: y_s
    real(8), intent (in) :: z_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z_m
    real(8) :: tmp
    if (((x_m * y_m) / z_m) <= 2d+25) then
        tmp = (y_m / z_m) * x_m
    else
        tmp = (x_m / z_m) * y_m
    end if
    code = x_s * (y_s * (z_s * tmp))
end function
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y_m && y_m < z_m;
public static double code(double x_s, double y_s, double z_s, double x_m, double y_m, double z_m) {
	double tmp;
	if (((x_m * y_m) / z_m) <= 2e+25) {
		tmp = (y_m / z_m) * x_m;
	} else {
		tmp = (x_m / z_m) * y_m;
	}
	return x_s * (y_s * (z_s * tmp));
}
z\_m = math.fabs(z)
z\_s = math.copysign(1.0, z)
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
[x_m, y_m, z_m] = sort([x_m, y_m, z_m])
def code(x_s, y_s, z_s, x_m, y_m, z_m):
	tmp = 0
	if ((x_m * y_m) / z_m) <= 2e+25:
		tmp = (y_m / z_m) * x_m
	else:
		tmp = (x_m / z_m) * y_m
	return x_s * (y_s * (z_s * tmp))
z\_m = abs(z)
z\_s = copysign(1.0, z)
y\_m = abs(y)
y\_s = copysign(1.0, y)
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y_m, z_m = sort([x_m, y_m, z_m])
function code(x_s, y_s, z_s, x_m, y_m, z_m)
	tmp = 0.0
	if (Float64(Float64(x_m * y_m) / z_m) <= 2e+25)
		tmp = Float64(Float64(y_m / z_m) * x_m);
	else
		tmp = Float64(Float64(x_m / z_m) * y_m);
	end
	return Float64(x_s * Float64(y_s * Float64(z_s * tmp)))
end
z\_m = abs(z);
z\_s = sign(z) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y_m, z_m = num2cell(sort([x_m, y_m, z_m])){:}
function tmp_2 = code(x_s, y_s, z_s, x_m, y_m, z_m)
	tmp = 0.0;
	if (((x_m * y_m) / z_m) <= 2e+25)
		tmp = (y_m / z_m) * x_m;
	else
		tmp = (x_m / z_m) * y_m;
	end
	tmp_2 = x_s * (y_s * (z_s * tmp));
end
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[x$95$s_, y$95$s_, z$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(x$95$s * N[(y$95$s * N[(z$95$s * If[LessEqual[N[(N[(x$95$m * y$95$m), $MachinePrecision] / z$95$m), $MachinePrecision], 2e+25], N[(N[(y$95$m / z$95$m), $MachinePrecision] * x$95$m), $MachinePrecision], N[(N[(x$95$m / z$95$m), $MachinePrecision] * y$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
x\_s \cdot \left(y\_s \cdot \left(z\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{x\_m \cdot y\_m}{z\_m} \leq 2 \cdot 10^{+25}:\\
\;\;\;\;\frac{y\_m}{z\_m} \cdot x\_m\\

\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{z\_m} \cdot y\_m\\


\end{array}\right)\right)
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x y) z) < 2.00000000000000018e25

    1. Initial program 94.3%

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

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

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

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

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
      6. lower-/.f6491.6

        \[\leadsto \color{blue}{\frac{y}{z}} \cdot x \]
    4. Applied rewrites91.6%

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

    if 2.00000000000000018e25 < (/.f64 (*.f64 x y) z)

    1. Initial program 98.2%

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

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

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

        \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
      5. lower-/.f6493.6

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 92.5% accurate, 1.0× speedup?

\[\begin{array}{l} z\_m = \left|z\right| \\ z\_s = \mathsf{copysign}\left(1, z\right) \\ y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\ \\ x\_s \cdot \left(y\_s \cdot \left(z\_s \cdot \left(\frac{x\_m}{z\_m} \cdot y\_m\right)\right)\right) \end{array} \]
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (x_s y_s z_s x_m y_m z_m)
 :precision binary64
 (* x_s (* y_s (* z_s (* (/ x_m z_m) y_m)))))
z\_m = fabs(z);
z\_s = copysign(1.0, z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y_m && y_m < z_m);
double code(double x_s, double y_s, double z_s, double x_m, double y_m, double z_m) {
	return x_s * (y_s * (z_s * ((x_m / z_m) * y_m)));
}
z\_m = abs(z)
z\_s = copysign(1.0d0, z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
real(8) function code(x_s, y_s, z_s, x_m, y_m, z_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: y_s
    real(8), intent (in) :: z_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    real(8), intent (in) :: z_m
    code = x_s * (y_s * (z_s * ((x_m / z_m) * y_m)))
end function
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y_m && y_m < z_m;
public static double code(double x_s, double y_s, double z_s, double x_m, double y_m, double z_m) {
	return x_s * (y_s * (z_s * ((x_m / z_m) * y_m)));
}
z\_m = math.fabs(z)
z\_s = math.copysign(1.0, z)
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
[x_m, y_m, z_m] = sort([x_m, y_m, z_m])
def code(x_s, y_s, z_s, x_m, y_m, z_m):
	return x_s * (y_s * (z_s * ((x_m / z_m) * y_m)))
z\_m = abs(z)
z\_s = copysign(1.0, z)
y\_m = abs(y)
y\_s = copysign(1.0, y)
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y_m, z_m = sort([x_m, y_m, z_m])
function code(x_s, y_s, z_s, x_m, y_m, z_m)
	return Float64(x_s * Float64(y_s * Float64(z_s * Float64(Float64(x_m / z_m) * y_m))))
end
z\_m = abs(z);
z\_s = sign(z) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y_m, z_m = num2cell(sort([x_m, y_m, z_m])){:}
function tmp = code(x_s, y_s, z_s, x_m, y_m, z_m)
	tmp = x_s * (y_s * (z_s * ((x_m / z_m) * y_m)));
end
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[x$95$s_, y$95$s_, z$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(x$95$s * N[(y$95$s * N[(z$95$s * N[(N[(x$95$m / z$95$m), $MachinePrecision] * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
x\_s \cdot \left(y\_s \cdot \left(z\_s \cdot \left(\frac{x\_m}{z\_m} \cdot y\_m\right)\right)\right)
\end{array}
Derivation
  1. Initial program 95.2%

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

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

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
    4. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
    5. lower-/.f6492.4

      \[\leadsto \color{blue}{\frac{x}{z}} \cdot y \]
  4. Applied rewrites92.4%

    \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
  5. Add Preprocessing

Developer Target 1: 87.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z < -4.262230790519429 \cdot 10^{-138}:\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{elif}\;z < 1.7042130660650472 \cdot 10^{-164}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (< z -4.262230790519429e-138)
   (/ (* x y) z)
   (if (< z 1.7042130660650472e-164) (/ x (/ z y)) (* (/ x z) y))))
double code(double x, double y, double z) {
	double tmp;
	if (z < -4.262230790519429e-138) {
		tmp = (x * y) / z;
	} else if (z < 1.7042130660650472e-164) {
		tmp = x / (z / y);
	} else {
		tmp = (x / z) * y;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z < (-4.262230790519429d-138)) then
        tmp = (x * y) / z
    else if (z < 1.7042130660650472d-164) then
        tmp = x / (z / y)
    else
        tmp = (x / z) * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z < -4.262230790519429e-138) {
		tmp = (x * y) / z;
	} else if (z < 1.7042130660650472e-164) {
		tmp = x / (z / y);
	} else {
		tmp = (x / z) * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z < -4.262230790519429e-138:
		tmp = (x * y) / z
	elif z < 1.7042130660650472e-164:
		tmp = x / (z / y)
	else:
		tmp = (x / z) * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z < -4.262230790519429e-138)
		tmp = Float64(Float64(x * y) / z);
	elseif (z < 1.7042130660650472e-164)
		tmp = Float64(x / Float64(z / y));
	else
		tmp = Float64(Float64(x / z) * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z < -4.262230790519429e-138)
		tmp = (x * y) / z;
	elseif (z < 1.7042130660650472e-164)
		tmp = x / (z / y);
	else
		tmp = (x / z) * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Less[z, -4.262230790519429e-138], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[Less[z, 1.7042130660650472e-164], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z < -4.262230790519429 \cdot 10^{-138}:\\
\;\;\;\;\frac{x \cdot y}{z}\\

\mathbf{elif}\;z < 1.7042130660650472 \cdot 10^{-164}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot y\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024327 
(FPCore (x y z)
  :name "Diagrams.Solve.Tridiagonal:solveCyclicTriDiagonal from diagrams-solve-0.1, A"
  :precision binary64

  :alt
  (! :herbie-platform default (if (< z -4262230790519429/1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ (* x y) z) (if (< z 2130266332581309/125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ x (/ z y)) (* (/ x z) y))))

  (/ (* x y) z))