Numeric.SpecFunctions:choose from math-functions-0.1.5.2

Percentage Accurate: 84.9% → 96.0%
Time: 5.6s
Alternatives: 5
Speedup: 1.1×

Specification

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

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

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

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

Alternative 1: 96.0% accurate, 1.1× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{x \cdot y + x \cdot z}{z}} \]
  4. Step-by-step derivation
    1. distribute-lft-inN/A

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

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

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

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

      \[\leadsto x \cdot \frac{z + \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot y}{z} \]
    6. cancel-sign-sub-invN/A

      \[\leadsto x \cdot \frac{\color{blue}{z - -1 \cdot y}}{z} \]
    7. div-subN/A

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

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

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

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

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

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} + 1\right)} \]
    14. metadata-evalN/A

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

      \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} - -1\right)} \]
    16. sub-negN/A

      \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} + \left(\mathsf{neg}\left(-1\right)\right)\right)} \]
    17. metadata-evalN/A

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

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x \cdot 1} \]
    19. *-rgt-identityN/A

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{x}{z}}, y, x\right) \]
  5. Applied rewrites94.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)} \]
  6. Step-by-step derivation
    1. Applied rewrites98.4%

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

    Alternative 2: 49.4% accurate, 0.5× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\left(z + y\right) \cdot x}{z} \leq 0:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (<= (/ (* (+ z y) x) z) 0.0) (* (/ y z) x) (* 1.0 x)))
    double code(double x, double y, double z) {
    	double tmp;
    	if ((((z + y) * x) / z) <= 0.0) {
    		tmp = (y / z) * x;
    	} else {
    		tmp = 1.0 * x;
    	}
    	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 + y) * x) / z) <= 0.0d0) then
            tmp = (y / z) * x
        else
            tmp = 1.0d0 * x
        end if
        code = tmp
    end function
    
    public static double code(double x, double y, double z) {
    	double tmp;
    	if ((((z + y) * x) / z) <= 0.0) {
    		tmp = (y / z) * x;
    	} else {
    		tmp = 1.0 * x;
    	}
    	return tmp;
    }
    
    def code(x, y, z):
    	tmp = 0
    	if (((z + y) * x) / z) <= 0.0:
    		tmp = (y / z) * x
    	else:
    		tmp = 1.0 * x
    	return tmp
    
    function code(x, y, z)
    	tmp = 0.0
    	if (Float64(Float64(Float64(z + y) * x) / z) <= 0.0)
    		tmp = Float64(Float64(y / z) * x);
    	else
    		tmp = Float64(1.0 * x);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y, z)
    	tmp = 0.0;
    	if ((((z + y) * x) / z) <= 0.0)
    		tmp = (y / z) * x;
    	else
    		tmp = 1.0 * x;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_, z_] := If[LessEqual[N[(N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision] / z), $MachinePrecision], 0.0], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;\frac{\left(z + y\right) \cdot x}{z} \leq 0:\\
    \;\;\;\;\frac{y}{z} \cdot x\\
    
    \mathbf{else}:\\
    \;\;\;\;1 \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (/.f64 (*.f64 x (+.f64 y z)) z) < 0.0

      1. Initial program 78.3%

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

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

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

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

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

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

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

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

          \[\leadsto \frac{\color{blue}{z + y}}{z} \cdot x \]
        9. lower-+.f6498.5

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

        \[\leadsto \color{blue}{\frac{z + y}{z} \cdot x} \]
      5. Taylor expanded in z around 0

        \[\leadsto \color{blue}{\frac{y}{z}} \cdot x \]
      6. Step-by-step derivation
        1. lower-/.f6443.3

          \[\leadsto \color{blue}{\frac{y}{z}} \cdot x \]
      7. Applied rewrites43.3%

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

      if 0.0 < (/.f64 (*.f64 x (+.f64 y z)) z)

      1. Initial program 89.8%

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

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

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

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

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

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

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

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

          \[\leadsto \frac{\color{blue}{z + y}}{z} \cdot x \]
        9. lower-+.f6498.3

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

        \[\leadsto \color{blue}{\frac{z + y}{z} \cdot x} \]
      5. Taylor expanded in z around inf

        \[\leadsto \color{blue}{1} \cdot x \]
      6. Step-by-step derivation
        1. Applied rewrites48.7%

          \[\leadsto \color{blue}{1} \cdot x \]
      7. Recombined 2 regimes into one program.
      8. Final simplification45.8%

        \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(z + y\right) \cdot x}{z} \leq 0:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \]
      9. Add Preprocessing

      Alternative 3: 49.5% accurate, 0.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\left(z + y\right) \cdot x}{z} \leq 0:\\ \;\;\;\;\frac{x}{z} \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (<= (/ (* (+ z y) x) z) 0.0) (* (/ x z) y) (* 1.0 x)))
      double code(double x, double y, double z) {
      	double tmp;
      	if ((((z + y) * x) / z) <= 0.0) {
      		tmp = (x / z) * y;
      	} else {
      		tmp = 1.0 * x;
      	}
      	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 + y) * x) / z) <= 0.0d0) then
              tmp = (x / z) * y
          else
              tmp = 1.0d0 * x
          end if
          code = tmp
      end function
      
      public static double code(double x, double y, double z) {
      	double tmp;
      	if ((((z + y) * x) / z) <= 0.0) {
      		tmp = (x / z) * y;
      	} else {
      		tmp = 1.0 * x;
      	}
      	return tmp;
      }
      
      def code(x, y, z):
      	tmp = 0
      	if (((z + y) * x) / z) <= 0.0:
      		tmp = (x / z) * y
      	else:
      		tmp = 1.0 * x
      	return tmp
      
      function code(x, y, z)
      	tmp = 0.0
      	if (Float64(Float64(Float64(z + y) * x) / z) <= 0.0)
      		tmp = Float64(Float64(x / z) * y);
      	else
      		tmp = Float64(1.0 * x);
      	end
      	return tmp
      end
      
      function tmp_2 = code(x, y, z)
      	tmp = 0.0;
      	if ((((z + y) * x) / z) <= 0.0)
      		tmp = (x / z) * y;
      	else
      		tmp = 1.0 * x;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_, y_, z_] := If[LessEqual[N[(N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision] / z), $MachinePrecision], 0.0], N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\frac{\left(z + y\right) \cdot x}{z} \leq 0:\\
      \;\;\;\;\frac{x}{z} \cdot y\\
      
      \mathbf{else}:\\
      \;\;\;\;1 \cdot x\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (/.f64 (*.f64 x (+.f64 y z)) z) < 0.0

        1. Initial program 78.3%

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\color{blue}{z + y}}{z} \cdot x \]
          9. lower-+.f6498.5

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

          \[\leadsto \color{blue}{\frac{z + y}{z} \cdot x} \]
        5. Step-by-step derivation
          1. lift-*.f64N/A

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

            \[\leadsto \color{blue}{\frac{z + y}{z}} \cdot x \]
          3. div-invN/A

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

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

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

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

            \[\leadsto \color{blue}{\frac{z + y}{\frac{z}{x}}} \]
          8. lift-+.f64N/A

            \[\leadsto \frac{\color{blue}{z + y}}{\frac{z}{x}} \]
          9. +-commutativeN/A

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

            \[\leadsto \frac{\color{blue}{y + z}}{\frac{z}{x}} \]
          11. lower-/.f6483.0

            \[\leadsto \frac{y + z}{\color{blue}{\frac{z}{x}}} \]
        6. Applied rewrites83.0%

          \[\leadsto \color{blue}{\frac{y + z}{\frac{z}{x}}} \]
        7. Taylor expanded in z around 0

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

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

            \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
          3. lower-/.f6441.9

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

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

        if 0.0 < (/.f64 (*.f64 x (+.f64 y z)) z)

        1. Initial program 89.8%

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\color{blue}{z + y}}{z} \cdot x \]
          9. lower-+.f6498.3

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

          \[\leadsto \color{blue}{\frac{z + y}{z} \cdot x} \]
        5. Taylor expanded in z around inf

          \[\leadsto \color{blue}{1} \cdot x \]
        6. Step-by-step derivation
          1. Applied rewrites48.7%

            \[\leadsto \color{blue}{1} \cdot x \]
        7. Recombined 2 regimes into one program.
        8. Final simplification45.1%

          \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(z + y\right) \cdot x}{z} \leq 0:\\ \;\;\;\;\frac{x}{z} \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \]
        9. Add Preprocessing

        Alternative 4: 94.1% accurate, 1.1× speedup?

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

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

          \[\leadsto \color{blue}{\frac{x \cdot y + x \cdot z}{z}} \]
        4. Step-by-step derivation
          1. distribute-lft-inN/A

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

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

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

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

            \[\leadsto x \cdot \frac{z + \color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot y}{z} \]
          6. cancel-sign-sub-invN/A

            \[\leadsto x \cdot \frac{\color{blue}{z - -1 \cdot y}}{z} \]
          7. div-subN/A

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

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

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

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

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

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

            \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} + 1\right)} \]
          14. metadata-evalN/A

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

            \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} - -1\right)} \]
          16. sub-negN/A

            \[\leadsto x \cdot \color{blue}{\left(\frac{y}{z} + \left(\mathsf{neg}\left(-1\right)\right)\right)} \]
          17. metadata-evalN/A

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

            \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x \cdot 1} \]
          19. *-rgt-identityN/A

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{x}{z}}, y, x\right) \]
        5. Applied rewrites94.1%

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

        Alternative 5: 49.8% accurate, 3.3× speedup?

        \[\begin{array}{l} \\ 1 \cdot x \end{array} \]
        (FPCore (x y z) :precision binary64 (* 1.0 x))
        double code(double x, double y, double z) {
        	return 1.0 * x;
        }
        
        real(8) function code(x, y, z)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8), intent (in) :: z
            code = 1.0d0 * x
        end function
        
        public static double code(double x, double y, double z) {
        	return 1.0 * x;
        }
        
        def code(x, y, z):
        	return 1.0 * x
        
        function code(x, y, z)
        	return Float64(1.0 * x)
        end
        
        function tmp = code(x, y, z)
        	tmp = 1.0 * x;
        end
        
        code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        1 \cdot x
        \end{array}
        
        Derivation
        1. Initial program 83.6%

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\color{blue}{z + y}}{z} \cdot x \]
          9. lower-+.f6498.4

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

          \[\leadsto \color{blue}{\frac{z + y}{z} \cdot x} \]
        5. Taylor expanded in z around inf

          \[\leadsto \color{blue}{1} \cdot x \]
        6. Step-by-step derivation
          1. Applied rewrites53.4%

            \[\leadsto \color{blue}{1} \cdot x \]
          2. Add Preprocessing

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

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

          Reproduce

          ?
          herbie shell --seed 2024249 
          (FPCore (x y z)
            :name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
            :precision binary64
          
            :alt
            (! :herbie-platform default (/ x (/ z (+ y z))))
          
            (/ (* x (+ y z)) z))