Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3

Percentage Accurate: 98.1% → 100.0%
Time: 6.6s
Alternatives: 6
Speedup: 1.7×

Specification

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

\\
x \cdot y + z \cdot \left(1 - 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: 98.1% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

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

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

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

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

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

      \[\leadsto x \cdot y + \color{blue}{\left(1 \cdot z + \left(\mathsf{neg}\left(y \cdot z\right)\right)\right)} \]
    3. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \mathsf{neg}\left(\left(z + -1 \cdot x\right)\right), z\right)} \]
  5. Applied rewrites100.0%

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

Alternative 2: 60.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -3.3 \cdot 10^{+156}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-98}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(z, y, z\right)\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+96}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (- y))))
   (if (<= y -3.3e+156)
     t_0
     (if (<= y -8e-98)
       (* y x)
       (if (<= y 4.3e-7) (fma z y z) (if (<= y 8.5e+96) (* y x) t_0))))))
double code(double x, double y, double z) {
	double t_0 = z * -y;
	double tmp;
	if (y <= -3.3e+156) {
		tmp = t_0;
	} else if (y <= -8e-98) {
		tmp = y * x;
	} else if (y <= 4.3e-7) {
		tmp = fma(z, y, z);
	} else if (y <= 8.5e+96) {
		tmp = y * x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(z * Float64(-y))
	tmp = 0.0
	if (y <= -3.3e+156)
		tmp = t_0;
	elseif (y <= -8e-98)
		tmp = Float64(y * x);
	elseif (y <= 4.3e-7)
		tmp = fma(z, y, z);
	elseif (y <= 8.5e+96)
		tmp = Float64(y * x);
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-y)), $MachinePrecision]}, If[LessEqual[y, -3.3e+156], t$95$0, If[LessEqual[y, -8e-98], N[(y * x), $MachinePrecision], If[LessEqual[y, 4.3e-7], N[(z * y + z), $MachinePrecision], If[LessEqual[y, 8.5e+96], N[(y * x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -3.3 \cdot 10^{+156}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -8 \cdot 10^{-98}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 4.3 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(z, y, z\right)\\

\mathbf{elif}\;y \leq 8.5 \cdot 10^{+96}:\\
\;\;\;\;y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.2999999999999999e156 or 8.50000000000000025e96 < y

    1. Initial program 92.9%

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

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

        \[\leadsto \color{blue}{1 \cdot z - y \cdot z} \]
      2. *-lft-identityN/A

        \[\leadsto \color{blue}{z} - y \cdot z \]
      3. lower--.f64N/A

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

        \[\leadsto z - \color{blue}{z \cdot y} \]
      5. lower-*.f6467.3

        \[\leadsto z - \color{blue}{z \cdot y} \]
    5. Applied rewrites67.3%

      \[\leadsto \color{blue}{z - z \cdot y} \]
    6. Taylor expanded in y around inf

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    7. Step-by-step derivation
      1. mul-1-negN/A

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

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

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

        \[\leadsto \color{blue}{y \cdot \left(-1 \cdot z\right)} \]
      5. mul-1-negN/A

        \[\leadsto y \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \]
      6. lower-neg.f6467.3

        \[\leadsto y \cdot \color{blue}{\left(-z\right)} \]
    8. Applied rewrites67.3%

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

    if -3.2999999999999999e156 < y < -7.99999999999999951e-98 or 4.3000000000000001e-7 < y < 8.50000000000000025e96

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6471.0

        \[\leadsto \color{blue}{y \cdot x} \]
    5. Applied rewrites71.0%

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

    if -7.99999999999999951e-98 < y < 4.3000000000000001e-7

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{1 \cdot z - y \cdot z} \]
      2. *-lft-identityN/A

        \[\leadsto \color{blue}{z} - y \cdot z \]
      3. lower--.f64N/A

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

        \[\leadsto z - \color{blue}{z \cdot y} \]
      5. lower-*.f6474.2

        \[\leadsto z - \color{blue}{z \cdot y} \]
    5. Applied rewrites74.2%

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

        \[\leadsto z - \color{blue}{z \cdot y} \]
      2. sub-negN/A

        \[\leadsto \color{blue}{z + \left(\mathsf{neg}\left(z \cdot y\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{z \cdot y}\right)\right) + z \]
      5. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot y} + z \]
      6. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(z\right), y, z\right)} \]
      7. lower-neg.f6474.2

        \[\leadsto \mathsf{fma}\left(\color{blue}{-z}, y, z\right) \]
    7. Applied rewrites74.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-z, y, z\right)} \]
    8. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{0 - z}, y, z\right) \]
      2. flip3--N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{{0}^{3} - {z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}}, y, z\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{0} - {z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      4. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\mathsf{neg}\left({z}^{3}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      5. cube-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{\left(\mathsf{neg}\left(z\right)\right)}^{3}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      6. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{{\color{blue}{\left(\mathsf{neg}\left(z\right)\right)}}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      7. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{\left(\mathsf{neg}\left(z\right)\right)}^{\left(\frac{3}{2}\right)} \cdot {\left(\mathsf{neg}\left(z\right)\right)}^{\left(\frac{3}{2}\right)}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      8. unpow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(z\right)\right)\right)}^{\left(\frac{3}{2}\right)}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      9. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{{\left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot \left(\mathsf{neg}\left(z\right)\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      10. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{{\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)}\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      11. sqr-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{{\color{blue}{\left(z \cdot z\right)}}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      12. pow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{z}^{\left(\frac{3}{2}\right)} \cdot {z}^{\left(\frac{3}{2}\right)}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      13. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{z}^{3}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{\color{blue}{0} + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      15. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{\color{blue}{z \cdot z + 0 \cdot z}}, y, z\right) \]
      16. distribute-rgt-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{\color{blue}{z \cdot \left(z + 0\right)}}, y, z\right) \]
      17. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{z \cdot \color{blue}{\left(0 + z\right)}}, y, z\right) \]
      18. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{z \cdot \color{blue}{z}}, y, z\right) \]
      19. pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{\color{blue}{{z}^{2}}}, y, z\right) \]
      20. pow-divN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{{z}^{\left(3 - 2\right)}}, y, z\right) \]
      21. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left({z}^{\color{blue}{1}}, y, z\right) \]
      22. unpow173.8

        \[\leadsto \mathsf{fma}\left(\color{blue}{z}, y, z\right) \]
    9. Applied rewrites73.8%

      \[\leadsto \mathsf{fma}\left(\color{blue}{z}, y, z\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification71.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.3 \cdot 10^{+156}:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-98}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(z, y, z\right)\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+96}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-y\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.9 \cdot 10^{-133}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, z\right)\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-65}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z - y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -2.9e-133)
   (fma (- z) y z)
   (if (<= z 6.5e-65) (* y x) (- z (* y z)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.9e-133) {
		tmp = fma(-z, y, z);
	} else if (z <= 6.5e-65) {
		tmp = y * x;
	} else {
		tmp = z - (y * z);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (z <= -2.9e-133)
		tmp = fma(Float64(-z), y, z);
	elseif (z <= 6.5e-65)
		tmp = Float64(y * x);
	else
		tmp = Float64(z - Float64(y * z));
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[z, -2.9e-133], N[((-z) * y + z), $MachinePrecision], If[LessEqual[z, 6.5e-65], N[(y * x), $MachinePrecision], N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{-133}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, z\right)\\

\mathbf{elif}\;z \leq 6.5 \cdot 10^{-65}:\\
\;\;\;\;y \cdot x\\

\mathbf{else}:\\
\;\;\;\;z - y \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -2.8999999999999998e-133

    1. Initial program 96.2%

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

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

        \[\leadsto \color{blue}{1 \cdot z - y \cdot z} \]
      2. *-lft-identityN/A

        \[\leadsto \color{blue}{z} - y \cdot z \]
      3. lower--.f64N/A

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

        \[\leadsto z - \color{blue}{z \cdot y} \]
      5. lower-*.f6482.2

        \[\leadsto z - \color{blue}{z \cdot y} \]
    5. Applied rewrites82.2%

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

        \[\leadsto z - \color{blue}{z \cdot y} \]
      2. sub-negN/A

        \[\leadsto \color{blue}{z + \left(\mathsf{neg}\left(z \cdot y\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{z \cdot y}\right)\right) + z \]
      5. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot y} + z \]
      6. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(z\right), y, z\right)} \]
      7. lower-neg.f6482.2

        \[\leadsto \mathsf{fma}\left(\color{blue}{-z}, y, z\right) \]
    7. Applied rewrites82.2%

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

    if -2.8999999999999998e-133 < z < 6.5e-65

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6480.5

        \[\leadsto \color{blue}{y \cdot x} \]
    5. Applied rewrites80.5%

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

    if 6.5e-65 < z

    1. Initial program 96.6%

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

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

        \[\leadsto \color{blue}{1 \cdot z - y \cdot z} \]
      2. *-lft-identityN/A

        \[\leadsto \color{blue}{z} - y \cdot z \]
      3. lower--.f64N/A

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

        \[\leadsto z - \color{blue}{z \cdot y} \]
      5. lower-*.f6485.5

        \[\leadsto z - \color{blue}{z \cdot y} \]
    5. Applied rewrites85.5%

      \[\leadsto \color{blue}{z - z \cdot y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification82.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.9 \cdot 10^{-133}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, z\right)\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-65}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z - y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 75.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z - y \cdot z\\ \mathbf{if}\;z \leq -2.9 \cdot 10^{-133}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-65}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- z (* y z))))
   (if (<= z -2.9e-133) t_0 (if (<= z 6.5e-65) (* y x) t_0))))
double code(double x, double y, double z) {
	double t_0 = z - (y * z);
	double tmp;
	if (z <= -2.9e-133) {
		tmp = t_0;
	} else if (z <= 6.5e-65) {
		tmp = y * x;
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = z - (y * z)
    if (z <= (-2.9d-133)) then
        tmp = t_0
    else if (z <= 6.5d-65) then
        tmp = y * x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = z - (y * z);
	double tmp;
	if (z <= -2.9e-133) {
		tmp = t_0;
	} else if (z <= 6.5e-65) {
		tmp = y * x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z - (y * z)
	tmp = 0
	if z <= -2.9e-133:
		tmp = t_0
	elif z <= 6.5e-65:
		tmp = y * x
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(z - Float64(y * z))
	tmp = 0.0
	if (z <= -2.9e-133)
		tmp = t_0;
	elseif (z <= 6.5e-65)
		tmp = Float64(y * x);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z - (y * z);
	tmp = 0.0;
	if (z <= -2.9e-133)
		tmp = t_0;
	elseif (z <= 6.5e-65)
		tmp = y * x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.9e-133], t$95$0, If[LessEqual[z, 6.5e-65], N[(y * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z - y \cdot z\\
\mathbf{if}\;z \leq -2.9 \cdot 10^{-133}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 6.5 \cdot 10^{-65}:\\
\;\;\;\;y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.8999999999999998e-133 or 6.5e-65 < z

    1. Initial program 96.4%

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

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

        \[\leadsto \color{blue}{1 \cdot z - y \cdot z} \]
      2. *-lft-identityN/A

        \[\leadsto \color{blue}{z} - y \cdot z \]
      3. lower--.f64N/A

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

        \[\leadsto z - \color{blue}{z \cdot y} \]
      5. lower-*.f6483.9

        \[\leadsto z - \color{blue}{z \cdot y} \]
    5. Applied rewrites83.9%

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

    if -2.8999999999999998e-133 < z < 6.5e-65

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6480.5

        \[\leadsto \color{blue}{y \cdot x} \]
    5. Applied rewrites80.5%

      \[\leadsto \color{blue}{y \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification82.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.9 \cdot 10^{-133}:\\ \;\;\;\;z - y \cdot z\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-65}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z - y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 60.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{-98}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(z, y, z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -8e-98) (* y x) (if (<= y 4.3e-7) (fma z y z) (* y x))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -8e-98) {
		tmp = y * x;
	} else if (y <= 4.3e-7) {
		tmp = fma(z, y, z);
	} else {
		tmp = y * x;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= -8e-98)
		tmp = Float64(y * x);
	elseif (y <= 4.3e-7)
		tmp = fma(z, y, z);
	else
		tmp = Float64(y * x);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, -8e-98], N[(y * x), $MachinePrecision], If[LessEqual[y, 4.3e-7], N[(z * y + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{-98}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 4.3 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(z, y, z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.99999999999999951e-98 or 4.3000000000000001e-7 < y

    1. Initial program 95.8%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6455.3

        \[\leadsto \color{blue}{y \cdot x} \]
    5. Applied rewrites55.3%

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

    if -7.99999999999999951e-98 < y < 4.3000000000000001e-7

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{1 \cdot z - y \cdot z} \]
      2. *-lft-identityN/A

        \[\leadsto \color{blue}{z} - y \cdot z \]
      3. lower--.f64N/A

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

        \[\leadsto z - \color{blue}{z \cdot y} \]
      5. lower-*.f6474.2

        \[\leadsto z - \color{blue}{z \cdot y} \]
    5. Applied rewrites74.2%

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

        \[\leadsto z - \color{blue}{z \cdot y} \]
      2. sub-negN/A

        \[\leadsto \color{blue}{z + \left(\mathsf{neg}\left(z \cdot y\right)\right)} \]
      3. +-commutativeN/A

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{z \cdot y}\right)\right) + z \]
      5. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot y} + z \]
      6. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(z\right), y, z\right)} \]
      7. lower-neg.f6474.2

        \[\leadsto \mathsf{fma}\left(\color{blue}{-z}, y, z\right) \]
    7. Applied rewrites74.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-z, y, z\right)} \]
    8. Step-by-step derivation
      1. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{0 - z}, y, z\right) \]
      2. flip3--N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{{0}^{3} - {z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}}, y, z\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{0} - {z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      4. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\mathsf{neg}\left({z}^{3}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      5. cube-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{\left(\mathsf{neg}\left(z\right)\right)}^{3}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      6. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{{\color{blue}{\left(\mathsf{neg}\left(z\right)\right)}}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      7. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{\left(\mathsf{neg}\left(z\right)\right)}^{\left(\frac{3}{2}\right)} \cdot {\left(\mathsf{neg}\left(z\right)\right)}^{\left(\frac{3}{2}\right)}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      8. unpow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(z\right)\right)\right)}^{\left(\frac{3}{2}\right)}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      9. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{{\left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot \left(\mathsf{neg}\left(z\right)\right)\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      10. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{{\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)}\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      11. sqr-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{{\color{blue}{\left(z \cdot z\right)}}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      12. pow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{z}^{\left(\frac{3}{2}\right)} \cdot {z}^{\left(\frac{3}{2}\right)}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      13. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{{z}^{3}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      14. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{\color{blue}{0} + \left(z \cdot z + 0 \cdot z\right)}, y, z\right) \]
      15. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{\color{blue}{z \cdot z + 0 \cdot z}}, y, z\right) \]
      16. distribute-rgt-outN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{\color{blue}{z \cdot \left(z + 0\right)}}, y, z\right) \]
      17. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{z \cdot \color{blue}{\left(0 + z\right)}}, y, z\right) \]
      18. +-lft-identityN/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{z \cdot \color{blue}{z}}, y, z\right) \]
      19. pow2N/A

        \[\leadsto \mathsf{fma}\left(\frac{{z}^{3}}{\color{blue}{{z}^{2}}}, y, z\right) \]
      20. pow-divN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{{z}^{\left(3 - 2\right)}}, y, z\right) \]
      21. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left({z}^{\color{blue}{1}}, y, z\right) \]
      22. unpow173.8

        \[\leadsto \mathsf{fma}\left(\color{blue}{z}, y, z\right) \]
    9. Applied rewrites73.8%

      \[\leadsto \mathsf{fma}\left(\color{blue}{z}, y, z\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 42.0% accurate, 2.8× speedup?

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

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

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

    \[\leadsto \color{blue}{x \cdot y} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{y \cdot x} \]
    2. lower-*.f6442.6

      \[\leadsto \color{blue}{y \cdot x} \]
  5. Applied rewrites42.6%

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

Developer Target 1: 100.0% accurate, 1.4× speedup?

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

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

Reproduce

?
herbie shell --seed 2024219 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
  :precision binary64

  :alt
  (! :herbie-platform default (- z (* (- z x) y)))

  (+ (* x y) (* z (- 1.0 y))))