Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D

Percentage Accurate: 92.9% → 97.8%
Time: 7.6s
Alternatives: 8
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ x + \frac{y \cdot \left(z - x\right)}{t} \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / 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 - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
def code(x, y, z, t):
	return x + ((y * (z - x)) / t)
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * Float64(z - x)) / t))
end
function tmp = code(x, y, z, t)
	tmp = x + ((y * (z - x)) / t);
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \frac{y \cdot \left(z - x\right)}{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 8 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.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \frac{y \cdot \left(z - x\right)}{t} \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / 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 - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
def code(x, y, z, t):
	return x + ((y * (z - x)) / t)
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * Float64(z - x)) / t))
end
function tmp = code(x, y, z, t)
	tmp = x + ((y * (z - x)) / t);
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 97.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{y}{t}, z - x, x\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (fma (/ y t) (- z x) x))
double code(double x, double y, double z, double t) {
	return fma((y / t), (z - x), x);
}
function code(x, y, z, t)
	return fma(Float64(y / t), Float64(z - x), x)
end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)
\end{array}
Derivation
  1. Initial program 95.2%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)} \]
    9. lower-/.f6496.8

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)} \]
  5. Add Preprocessing

Alternative 2: 84.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{if}\;t \leq -3.4 \cdot 10^{-107}:\\
\;\;\;\;t\_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -3.39999999999999994e-107 or 1.55000000000000006e-113 < t

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{z - x}{t} \cdot y} + x \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
      8. lower-/.f6497.1

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    6. Step-by-step derivation
      1. lower-/.f6486.0

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    7. Applied rewrites86.0%

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

    if -3.39999999999999994e-107 < t < 1.55000000000000006e-113

    1. Initial program 97.1%

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

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

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

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

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

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

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

Alternative 3: 83.0% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{if}\;t \leq -4.3 \cdot 10^{-135}:\\
\;\;\;\;t\_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -4.29999999999999999e-135 or 1.55000000000000006e-113 < t

    1. Initial program 94.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{z - x}{t} \cdot y} + x \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
      8. lower-/.f6496.7

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    6. Step-by-step derivation
      1. lower-/.f6484.9

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
    7. Applied rewrites84.9%

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

    if -4.29999999999999999e-135 < t < 1.55000000000000006e-113

    1. Initial program 96.9%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\left(z - x\right) \cdot y}{t}} \]
    6. Step-by-step derivation
      1. Applied rewrites90.8%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -4.3 \cdot 10^{-135}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \mathbf{elif}\;t \leq 1.55 \cdot 10^{-113}:\\ \;\;\;\;\left(z - x\right) \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\ \end{array} \]
    9. Add Preprocessing

    Alternative 4: 47.6% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_1 := z \cdot \frac{y}{t}\\ \mathbf{if}\;z \leq -1.05 \cdot 10^{-169}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+54}:\\ \;\;\;\;\frac{x \cdot t}{t}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
    (FPCore (x y z t)
     :precision binary64
     (let* ((t_1 (* z (/ y t))))
       (if (<= z -1.05e-169) t_1 (if (<= z 1.8e+54) (/ (* x t) t) t_1))))
    double code(double x, double y, double z, double t) {
    	double t_1 = z * (y / t);
    	double tmp;
    	if (z <= -1.05e-169) {
    		tmp = t_1;
    	} else if (z <= 1.8e+54) {
    		tmp = (x * t) / t;
    	} 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 = z * (y / t)
        if (z <= (-1.05d-169)) then
            tmp = t_1
        else if (z <= 1.8d+54) then
            tmp = (x * t) / t
        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 = z * (y / t);
    	double tmp;
    	if (z <= -1.05e-169) {
    		tmp = t_1;
    	} else if (z <= 1.8e+54) {
    		tmp = (x * t) / t;
    	} else {
    		tmp = t_1;
    	}
    	return tmp;
    }
    
    def code(x, y, z, t):
    	t_1 = z * (y / t)
    	tmp = 0
    	if z <= -1.05e-169:
    		tmp = t_1
    	elif z <= 1.8e+54:
    		tmp = (x * t) / t
    	else:
    		tmp = t_1
    	return tmp
    
    function code(x, y, z, t)
    	t_1 = Float64(z * Float64(y / t))
    	tmp = 0.0
    	if (z <= -1.05e-169)
    		tmp = t_1;
    	elseif (z <= 1.8e+54)
    		tmp = Float64(Float64(x * t) / t);
    	else
    		tmp = t_1;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y, z, t)
    	t_1 = z * (y / t);
    	tmp = 0.0;
    	if (z <= -1.05e-169)
    		tmp = t_1;
    	elseif (z <= 1.8e+54)
    		tmp = (x * t) / t;
    	else
    		tmp = t_1;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.05e-169], t$95$1, If[LessEqual[z, 1.8e+54], N[(N[(x * t), $MachinePrecision] / t), $MachinePrecision], t$95$1]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_1 := z \cdot \frac{y}{t}\\
    \mathbf{if}\;z \leq -1.05 \cdot 10^{-169}:\\
    \;\;\;\;t\_1\\
    
    \mathbf{elif}\;z \leq 1.8 \cdot 10^{+54}:\\
    \;\;\;\;\frac{x \cdot t}{t}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if z < -1.05e-169 or 1.8000000000000001e54 < z

      1. Initial program 95.6%

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{z - x}{t} \cdot y} + x \]
        7. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
        8. lower-/.f6490.1

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

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

        \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
      6. Step-by-step derivation
        1. associate-*l/N/A

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

          \[\leadsto \color{blue}{\frac{y}{t} \cdot z} \]
        3. lower-/.f6457.8

          \[\leadsto \color{blue}{\frac{y}{t}} \cdot z \]
      7. Applied rewrites57.8%

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

      if -1.05e-169 < z < 1.8000000000000001e54

      1. Initial program 94.8%

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{z - x}{t} \cdot y} + x \]
        7. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
        8. lower-/.f6496.7

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

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

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

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

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

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

          \[\leadsto \frac{t \cdot x + \left(y \cdot z + \color{blue}{-1 \cdot \left(x \cdot y\right)}\right)}{t} \]
        5. associate-+r+N/A

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

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

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

          \[\leadsto \frac{-1 \cdot \left(x \cdot y\right) + \color{blue}{\left(y \cdot z + t \cdot x\right)}}{t} \]
        9. associate-+r+N/A

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{\mathsf{fma}\left(z - x, y, \color{blue}{x \cdot t}\right)}{t} \]
        19. lower-*.f6483.4

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

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

        \[\leadsto \frac{t \cdot x}{t} \]
      9. Step-by-step derivation
        1. Applied rewrites42.0%

          \[\leadsto \frac{t \cdot x}{t} \]
      10. Recombined 2 regimes into one program.
      11. Final simplification50.2%

        \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.05 \cdot 10^{-169}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+54}:\\ \;\;\;\;\frac{x \cdot t}{t}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{t}\\ \end{array} \]
      12. Add Preprocessing

      Alternative 5: 72.4% accurate, 1.3× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(\frac{z}{t}, y, x\right) \end{array} \]
      (FPCore (x y z t) :precision binary64 (fma (/ z t) y x))
      double code(double x, double y, double z, double t) {
      	return fma((z / t), y, x);
      }
      
      function code(x, y, z, t)
      	return fma(Float64(z / t), y, x)
      end
      
      code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(\frac{z}{t}, y, x\right)
      \end{array}
      
      Derivation
      1. Initial program 95.2%

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{z - x}{t} \cdot y} + x \]
        7. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
        8. lower-/.f6493.2

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
      6. Step-by-step derivation
        1. lower-/.f6475.9

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
      7. Applied rewrites75.9%

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{z}{t}}, y, x\right) \]
      8. Add Preprocessing

      Alternative 6: 40.4% accurate, 1.4× speedup?

      \[\begin{array}{l} \\ z \cdot \frac{y}{t} \end{array} \]
      (FPCore (x y z t) :precision binary64 (* z (/ y t)))
      double code(double x, double y, double z, double t) {
      	return 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 = z * (y / t)
      end function
      
      public static double code(double x, double y, double z, double t) {
      	return z * (y / t);
      }
      
      def code(x, y, z, t):
      	return z * (y / t)
      
      function code(x, y, z, t)
      	return Float64(z * Float64(y / t))
      end
      
      function tmp = code(x, y, z, t)
      	tmp = z * (y / t);
      end
      
      code[x_, y_, z_, t_] := N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      z \cdot \frac{y}{t}
      \end{array}
      
      Derivation
      1. Initial program 95.2%

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{z - x}{t} \cdot y} + x \]
        7. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)} \]
        8. lower-/.f6493.2

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

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

        \[\leadsto \color{blue}{\frac{y \cdot z}{t}} \]
      6. Step-by-step derivation
        1. associate-*l/N/A

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

          \[\leadsto \color{blue}{\frac{y}{t} \cdot z} \]
        3. lower-/.f6439.7

          \[\leadsto \color{blue}{\frac{y}{t}} \cdot z \]
      7. Applied rewrites39.7%

        \[\leadsto \color{blue}{\frac{y}{t} \cdot z} \]
      8. Final simplification39.7%

        \[\leadsto z \cdot \frac{y}{t} \]
      9. Add Preprocessing

      Alternative 7: 37.1% accurate, 1.4× speedup?

      \[\begin{array}{l} \\ \frac{z \cdot y}{t} \end{array} \]
      (FPCore (x y z t) :precision binary64 (/ (* z y) t))
      double code(double x, double y, double z, double t) {
      	return (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 = (z * y) / t
      end function
      
      public static double code(double x, double y, double z, double t) {
      	return (z * y) / t;
      }
      
      def code(x, y, z, t):
      	return (z * y) / t
      
      function code(x, y, z, t)
      	return Float64(Float64(z * y) / t)
      end
      
      function tmp = code(x, y, z, t)
      	tmp = (z * y) / t;
      end
      
      code[x_, y_, z_, t_] := N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{z \cdot y}{t}
      \end{array}
      
      Derivation
      1. Initial program 95.2%

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

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

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

          \[\leadsto \frac{\color{blue}{z \cdot y}}{t} \]
        3. lower-*.f6437.8

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

        \[\leadsto \color{blue}{\frac{z \cdot y}{t}} \]
      6. Add Preprocessing

      Alternative 8: 37.0% accurate, 1.4× speedup?

      \[\begin{array}{l} \\ \frac{z}{t} \cdot y \end{array} \]
      (FPCore (x y z t) :precision binary64 (* (/ z t) y))
      double code(double x, double y, double z, double t) {
      	return (z / t) * 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 = (z / t) * y
      end function
      
      public static double code(double x, double y, double z, double t) {
      	return (z / t) * y;
      }
      
      def code(x, y, z, t):
      	return (z / t) * y
      
      function code(x, y, z, t)
      	return Float64(Float64(z / t) * y)
      end
      
      function tmp = code(x, y, z, t)
      	tmp = (z / t) * y;
      end
      
      code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{z}{t} \cdot y
      \end{array}
      
      Derivation
      1. Initial program 95.2%

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

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

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

          \[\leadsto \frac{\color{blue}{z \cdot y}}{t} \]
        3. lower-*.f6437.8

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

        \[\leadsto \color{blue}{\frac{z \cdot y}{t}} \]
      6. Step-by-step derivation
        1. Applied rewrites36.0%

          \[\leadsto y \cdot \color{blue}{\frac{z}{t}} \]
        2. Final simplification36.0%

          \[\leadsto \frac{z}{t} \cdot y \]
        3. Add Preprocessing

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

        \[\begin{array}{l} \\ x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \end{array} \]
        (FPCore (x y z t)
         :precision binary64
         (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
        double code(double x, double y, double z, double t) {
        	return x - ((x * (y / t)) + (-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 - ((x * (y / t)) + (-z * (y / t)))
        end function
        
        public static double code(double x, double y, double z, double t) {
        	return x - ((x * (y / t)) + (-z * (y / t)));
        }
        
        def code(x, y, z, t):
        	return x - ((x * (y / t)) + (-z * (y / t)))
        
        function code(x, y, z, t)
        	return Float64(x - Float64(Float64(x * Float64(y / t)) + Float64(Float64(-z) * Float64(y / t))))
        end
        
        function tmp = code(x, y, z, t)
        	tmp = x - ((x * (y / t)) + (-z * (y / t)));
        end
        
        code[x_, y_, z_, t_] := N[(x - N[(N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision] + N[((-z) * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)
        \end{array}
        

        Reproduce

        ?
        herbie shell --seed 2024276 
        (FPCore (x y z t)
          :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
          :precision binary64
        
          :alt
          (! :herbie-platform default (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
        
          (+ x (/ (* y (- z x)) t)))