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

Percentage Accurate: 97.9% → 100.0%
Time: 4.9s
Alternatives: 7
Speedup: 1.3×

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 7 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: 97.9% 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.3× speedup?

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

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

    \[x \cdot y + z \cdot \left(1 - y\right) \]
  2. Step-by-step derivation
    1. distribute-lft-out--97.2%

      \[\leadsto x \cdot y + \color{blue}{\left(z \cdot 1 - z \cdot y\right)} \]
    2. *-rgt-identity97.2%

      \[\leadsto x \cdot y + \left(\color{blue}{z} - z \cdot y\right) \]
    3. cancel-sign-sub-inv97.2%

      \[\leadsto x \cdot y + \color{blue}{\left(z + \left(-z\right) \cdot y\right)} \]
    4. +-commutative97.2%

      \[\leadsto x \cdot y + \color{blue}{\left(\left(-z\right) \cdot y + z\right)} \]
    5. associate-+r+97.2%

      \[\leadsto \color{blue}{\left(x \cdot y + \left(-z\right) \cdot y\right) + z} \]
    6. +-commutative97.2%

      \[\leadsto \color{blue}{\left(\left(-z\right) \cdot y + x \cdot y\right)} + z \]
    7. distribute-rgt-out100.0%

      \[\leadsto \color{blue}{y \cdot \left(\left(-z\right) + x\right)} + z \]
    8. fma-def100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \left(-z\right) + x, z\right)} \]
    9. +-commutative100.0%

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{x + \left(-z\right)}, z\right) \]
    10. unsub-neg100.0%

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{x - z}, z\right) \]
  3. Simplified100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(x - z\right) + z} \]
  5. Applied egg-rr100.0%

    \[\leadsto \color{blue}{y \cdot \left(x - z\right) + z} \]
  6. Final simplification100.0%

    \[\leadsto z + y \cdot \left(x - z\right) \]

Alternative 2: 61.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -9.5 \cdot 10^{+242}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -6.3 \cdot 10^{+215}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{+150}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -9.8 \cdot 10^{+42}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-13} \lor \neg \left(y \leq -1.8 \cdot 10^{-100}\right) \land \left(y \leq -1.7 \cdot 10^{-116} \lor \neg \left(y \leq 6 \cdot 10^{-34}\right)\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (- z))))
   (if (<= y -9.5e+242)
     t_0
     (if (<= y -6.3e+215)
       (* y x)
       (if (<= y -1.9e+150)
         t_0
         (if (<= y -9.8e+42)
           (* y x)
           (if (<= y -5.2e+14)
             t_0
             (if (or (<= y -1.45e-13)
                     (and (not (<= y -1.8e-100))
                          (or (<= y -1.7e-116) (not (<= y 6e-34)))))
               (* y x)
               z))))))))
double code(double x, double y, double z) {
	double t_0 = y * -z;
	double tmp;
	if (y <= -9.5e+242) {
		tmp = t_0;
	} else if (y <= -6.3e+215) {
		tmp = y * x;
	} else if (y <= -1.9e+150) {
		tmp = t_0;
	} else if (y <= -9.8e+42) {
		tmp = y * x;
	} else if (y <= -5.2e+14) {
		tmp = t_0;
	} else if ((y <= -1.45e-13) || (!(y <= -1.8e-100) && ((y <= -1.7e-116) || !(y <= 6e-34)))) {
		tmp = y * x;
	} else {
		tmp = z;
	}
	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 = y * -z
    if (y <= (-9.5d+242)) then
        tmp = t_0
    else if (y <= (-6.3d+215)) then
        tmp = y * x
    else if (y <= (-1.9d+150)) then
        tmp = t_0
    else if (y <= (-9.8d+42)) then
        tmp = y * x
    else if (y <= (-5.2d+14)) then
        tmp = t_0
    else if ((y <= (-1.45d-13)) .or. (.not. (y <= (-1.8d-100))) .and. (y <= (-1.7d-116)) .or. (.not. (y <= 6d-34))) then
        tmp = y * x
    else
        tmp = z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * -z;
	double tmp;
	if (y <= -9.5e+242) {
		tmp = t_0;
	} else if (y <= -6.3e+215) {
		tmp = y * x;
	} else if (y <= -1.9e+150) {
		tmp = t_0;
	} else if (y <= -9.8e+42) {
		tmp = y * x;
	} else if (y <= -5.2e+14) {
		tmp = t_0;
	} else if ((y <= -1.45e-13) || (!(y <= -1.8e-100) && ((y <= -1.7e-116) || !(y <= 6e-34)))) {
		tmp = y * x;
	} else {
		tmp = z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * -z
	tmp = 0
	if y <= -9.5e+242:
		tmp = t_0
	elif y <= -6.3e+215:
		tmp = y * x
	elif y <= -1.9e+150:
		tmp = t_0
	elif y <= -9.8e+42:
		tmp = y * x
	elif y <= -5.2e+14:
		tmp = t_0
	elif (y <= -1.45e-13) or (not (y <= -1.8e-100) and ((y <= -1.7e-116) or not (y <= 6e-34))):
		tmp = y * x
	else:
		tmp = z
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(-z))
	tmp = 0.0
	if (y <= -9.5e+242)
		tmp = t_0;
	elseif (y <= -6.3e+215)
		tmp = Float64(y * x);
	elseif (y <= -1.9e+150)
		tmp = t_0;
	elseif (y <= -9.8e+42)
		tmp = Float64(y * x);
	elseif (y <= -5.2e+14)
		tmp = t_0;
	elseif ((y <= -1.45e-13) || (!(y <= -1.8e-100) && ((y <= -1.7e-116) || !(y <= 6e-34))))
		tmp = Float64(y * x);
	else
		tmp = z;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * -z;
	tmp = 0.0;
	if (y <= -9.5e+242)
		tmp = t_0;
	elseif (y <= -6.3e+215)
		tmp = y * x;
	elseif (y <= -1.9e+150)
		tmp = t_0;
	elseif (y <= -9.8e+42)
		tmp = y * x;
	elseif (y <= -5.2e+14)
		tmp = t_0;
	elseif ((y <= -1.45e-13) || (~((y <= -1.8e-100)) && ((y <= -1.7e-116) || ~((y <= 6e-34)))))
		tmp = y * x;
	else
		tmp = z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[y, -9.5e+242], t$95$0, If[LessEqual[y, -6.3e+215], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.9e+150], t$95$0, If[LessEqual[y, -9.8e+42], N[(y * x), $MachinePrecision], If[LessEqual[y, -5.2e+14], t$95$0, If[Or[LessEqual[y, -1.45e-13], And[N[Not[LessEqual[y, -1.8e-100]], $MachinePrecision], Or[LessEqual[y, -1.7e-116], N[Not[LessEqual[y, 6e-34]], $MachinePrecision]]]], N[(y * x), $MachinePrecision], z]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -6.3 \cdot 10^{+215}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq -1.9 \cdot 10^{+150}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -9.8 \cdot 10^{+42}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq -5.2 \cdot 10^{+14}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -1.45 \cdot 10^{-13} \lor \neg \left(y \leq -1.8 \cdot 10^{-100}\right) \land \left(y \leq -1.7 \cdot 10^{-116} \lor \neg \left(y \leq 6 \cdot 10^{-34}\right)\right):\\
\;\;\;\;y \cdot x\\

\mathbf{else}:\\
\;\;\;\;z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -9.49999999999999995e242 or -6.2999999999999997e215 < y < -1.89999999999999995e150 or -9.8000000000000004e42 < y < -5.2e14

    1. Initial program 86.1%

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

      \[\leadsto \color{blue}{z \cdot \left(1 - y\right)} \]
    3. Taylor expanded in y around inf 82.1%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot z\right)} \]
    4. Step-by-step derivation
      1. mul-1-neg82.1%

        \[\leadsto \color{blue}{-y \cdot z} \]
      2. distribute-lft-neg-out82.1%

        \[\leadsto \color{blue}{\left(-y\right) \cdot z} \]
      3. *-commutative82.1%

        \[\leadsto \color{blue}{z \cdot \left(-y\right)} \]
    5. Simplified82.1%

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

    if -9.49999999999999995e242 < y < -6.2999999999999997e215 or -1.89999999999999995e150 < y < -9.8000000000000004e42 or -5.2e14 < y < -1.4499999999999999e-13 or -1.7999999999999999e-100 < y < -1.69999999999999996e-116 or 6e-34 < y

    1. Initial program 97.2%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    3. Step-by-step derivation
      1. *-commutative68.1%

        \[\leadsto \color{blue}{y \cdot x} \]
    4. Simplified68.1%

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

    if -1.4499999999999999e-13 < y < -1.7999999999999999e-100 or -1.69999999999999996e-116 < y < 6e-34

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification74.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.5 \cdot 10^{+242}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq -6.3 \cdot 10^{+215}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{+150}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq -9.8 \cdot 10^{+42}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -5.2 \cdot 10^{+14}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-13} \lor \neg \left(y \leq -1.8 \cdot 10^{-100}\right) \land \left(y \leq -1.7 \cdot 10^{-116} \lor \neg \left(y \leq 6 \cdot 10^{-34}\right)\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Alternative 3: 84.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -6.4 \cdot 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-100}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-116}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.18 \cdot 10^{-23}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (- x z))))
   (if (<= y -6.4e-18)
     t_0
     (if (<= y -1.6e-100)
       z
       (if (<= y -2.8e-116) (* y x) (if (<= y 1.18e-23) z t_0))))))
double code(double x, double y, double z) {
	double t_0 = y * (x - z);
	double tmp;
	if (y <= -6.4e-18) {
		tmp = t_0;
	} else if (y <= -1.6e-100) {
		tmp = z;
	} else if (y <= -2.8e-116) {
		tmp = y * x;
	} else if (y <= 1.18e-23) {
		tmp = z;
	} 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 = y * (x - z)
    if (y <= (-6.4d-18)) then
        tmp = t_0
    else if (y <= (-1.6d-100)) then
        tmp = z
    else if (y <= (-2.8d-116)) then
        tmp = y * x
    else if (y <= 1.18d-23) then
        tmp = z
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * (x - z);
	double tmp;
	if (y <= -6.4e-18) {
		tmp = t_0;
	} else if (y <= -1.6e-100) {
		tmp = z;
	} else if (y <= -2.8e-116) {
		tmp = y * x;
	} else if (y <= 1.18e-23) {
		tmp = z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (x - z)
	tmp = 0
	if y <= -6.4e-18:
		tmp = t_0
	elif y <= -1.6e-100:
		tmp = z
	elif y <= -2.8e-116:
		tmp = y * x
	elif y <= 1.18e-23:
		tmp = z
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(x - z))
	tmp = 0.0
	if (y <= -6.4e-18)
		tmp = t_0;
	elseif (y <= -1.6e-100)
		tmp = z;
	elseif (y <= -2.8e-116)
		tmp = Float64(y * x);
	elseif (y <= 1.18e-23)
		tmp = z;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (x - z);
	tmp = 0.0;
	if (y <= -6.4e-18)
		tmp = t_0;
	elseif (y <= -1.6e-100)
		tmp = z;
	elseif (y <= -2.8e-116)
		tmp = y * x;
	elseif (y <= 1.18e-23)
		tmp = z;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.4e-18], t$95$0, If[LessEqual[y, -1.6e-100], z, If[LessEqual[y, -2.8e-116], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.18e-23], z, t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
\mathbf{if}\;y \leq -6.4 \cdot 10^{-18}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -1.6 \cdot 10^{-100}:\\
\;\;\;\;z\\

\mathbf{elif}\;y \leq -2.8 \cdot 10^{-116}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 1.18 \cdot 10^{-23}:\\
\;\;\;\;z\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -6.3999999999999998e-18 or 1.18e-23 < y

    1. Initial program 94.6%

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

      \[\leadsto \color{blue}{y \cdot \left(x + -1 \cdot z\right)} \]
    3. Step-by-step derivation
      1. neg-mul-194.8%

        \[\leadsto y \cdot \left(x + \color{blue}{\left(-z\right)}\right) \]
      2. sub-neg94.8%

        \[\leadsto y \cdot \color{blue}{\left(x - z\right)} \]
    4. Simplified94.8%

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

    if -6.3999999999999998e-18 < y < -1.60000000000000008e-100 or -2.7999999999999999e-116 < y < 1.18e-23

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{z} \]

    if -1.60000000000000008e-100 < y < -2.7999999999999999e-116

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    3. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{y \cdot x} \]
    4. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.4 \cdot 10^{-18}:\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{-100}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-116}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.18 \cdot 10^{-23}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x - z\right)\\ \end{array} \]

Alternative 4: 84.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ t_1 := z \cdot \left(1 - y\right)\\ \mathbf{if}\;y \leq -0.000112:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -7.3 \cdot 10^{-100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-116}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (- x z))) (t_1 (* z (- 1.0 y))))
   (if (<= y -0.000112)
     t_0
     (if (<= y -7.3e-100)
       t_1
       (if (<= y -2.8e-116) (* y x) (if (<= y 2.2e-11) t_1 t_0))))))
double code(double x, double y, double z) {
	double t_0 = y * (x - z);
	double t_1 = z * (1.0 - y);
	double tmp;
	if (y <= -0.000112) {
		tmp = t_0;
	} else if (y <= -7.3e-100) {
		tmp = t_1;
	} else if (y <= -2.8e-116) {
		tmp = y * x;
	} else if (y <= 2.2e-11) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = y * (x - z)
    t_1 = z * (1.0d0 - y)
    if (y <= (-0.000112d0)) then
        tmp = t_0
    else if (y <= (-7.3d-100)) then
        tmp = t_1
    else if (y <= (-2.8d-116)) then
        tmp = y * x
    else if (y <= 2.2d-11) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y * (x - z);
	double t_1 = z * (1.0 - y);
	double tmp;
	if (y <= -0.000112) {
		tmp = t_0;
	} else if (y <= -7.3e-100) {
		tmp = t_1;
	} else if (y <= -2.8e-116) {
		tmp = y * x;
	} else if (y <= 2.2e-11) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (x - z)
	t_1 = z * (1.0 - y)
	tmp = 0
	if y <= -0.000112:
		tmp = t_0
	elif y <= -7.3e-100:
		tmp = t_1
	elif y <= -2.8e-116:
		tmp = y * x
	elif y <= 2.2e-11:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(x - z))
	t_1 = Float64(z * Float64(1.0 - y))
	tmp = 0.0
	if (y <= -0.000112)
		tmp = t_0;
	elseif (y <= -7.3e-100)
		tmp = t_1;
	elseif (y <= -2.8e-116)
		tmp = Float64(y * x);
	elseif (y <= 2.2e-11)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (x - z);
	t_1 = z * (1.0 - y);
	tmp = 0.0;
	if (y <= -0.000112)
		tmp = t_0;
	elseif (y <= -7.3e-100)
		tmp = t_1;
	elseif (y <= -2.8e-116)
		tmp = y * x;
	elseif (y <= 2.2e-11)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.000112], t$95$0, If[LessEqual[y, -7.3e-100], t$95$1, If[LessEqual[y, -2.8e-116], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.2e-11], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \left(x - z\right)\\
t_1 := z \cdot \left(1 - y\right)\\
\mathbf{if}\;y \leq -0.000112:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -7.3 \cdot 10^{-100}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -2.8 \cdot 10^{-116}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;y \leq 2.2 \cdot 10^{-11}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.11999999999999998e-4 or 2.2000000000000002e-11 < y

    1. Initial program 94.2%

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

      \[\leadsto \color{blue}{y \cdot \left(x + -1 \cdot z\right)} \]
    3. Step-by-step derivation
      1. neg-mul-198.2%

        \[\leadsto y \cdot \left(x + \color{blue}{\left(-z\right)}\right) \]
      2. sub-neg98.2%

        \[\leadsto y \cdot \color{blue}{\left(x - z\right)} \]
    4. Simplified98.2%

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

    if -1.11999999999999998e-4 < y < -7.2999999999999995e-100 or -2.7999999999999999e-116 < y < 2.2000000000000002e-11

    1. Initial program 100.0%

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

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

    if -7.2999999999999995e-100 < y < -2.7999999999999999e-116

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    3. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{y \cdot x} \]
    4. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.000112:\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{elif}\;y \leq -7.3 \cdot 10^{-100}:\\ \;\;\;\;z \cdot \left(1 - y\right)\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-116}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-11}:\\ \;\;\;\;z \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x - z\right)\\ \end{array} \]

Alternative 5: 61.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{-13} \lor \neg \left(y \leq -1.6 \cdot 10^{-100} \lor \neg \left(y \leq -2.35 \cdot 10^{-116}\right) \land y \leq 1.5 \cdot 10^{-33}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.65e-13)
         (not
          (or (<= y -1.6e-100) (and (not (<= y -2.35e-116)) (<= y 1.5e-33)))))
   (* y x)
   z))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.65e-13) || !((y <= -1.6e-100) || (!(y <= -2.35e-116) && (y <= 1.5e-33)))) {
		tmp = y * x;
	} else {
		tmp = z;
	}
	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 ((y <= (-1.65d-13)) .or. (.not. (y <= (-1.6d-100)) .or. (.not. (y <= (-2.35d-116))) .and. (y <= 1.5d-33))) then
        tmp = y * x
    else
        tmp = z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.65e-13) || !((y <= -1.6e-100) || (!(y <= -2.35e-116) && (y <= 1.5e-33)))) {
		tmp = y * x;
	} else {
		tmp = z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -1.65e-13) or not ((y <= -1.6e-100) or (not (y <= -2.35e-116) and (y <= 1.5e-33))):
		tmp = y * x
	else:
		tmp = z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.65e-13) || !((y <= -1.6e-100) || (!(y <= -2.35e-116) && (y <= 1.5e-33))))
		tmp = Float64(y * x);
	else
		tmp = z;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -1.65e-13) || ~(((y <= -1.6e-100) || (~((y <= -2.35e-116)) && (y <= 1.5e-33)))))
		tmp = y * x;
	else
		tmp = z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.65e-13], N[Not[Or[LessEqual[y, -1.6e-100], And[N[Not[LessEqual[y, -2.35e-116]], $MachinePrecision], LessEqual[y, 1.5e-33]]]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-13} \lor \neg \left(y \leq -1.6 \cdot 10^{-100} \lor \neg \left(y \leq -2.35 \cdot 10^{-116}\right) \land y \leq 1.5 \cdot 10^{-33}\right):\\
\;\;\;\;y \cdot x\\

\mathbf{else}:\\
\;\;\;\;z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.65e-13 or -1.60000000000000008e-100 < y < -2.34999999999999997e-116 or 1.5000000000000001e-33 < y

    1. Initial program 94.8%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    3. Step-by-step derivation
      1. *-commutative58.9%

        \[\leadsto \color{blue}{y \cdot x} \]
    4. Simplified58.9%

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

    if -1.65e-13 < y < -1.60000000000000008e-100 or -2.34999999999999997e-116 < y < 1.5000000000000001e-33

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification68.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{-13} \lor \neg \left(y \leq -1.6 \cdot 10^{-100} \lor \neg \left(y \leq -2.35 \cdot 10^{-116}\right) \land y \leq 1.5 \cdot 10^{-33}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Alternative 6: 98.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 5 \cdot 10^{-9}\right):\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.0) (not (<= y 5e-9))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.0) || !(y <= 5e-9)) {
		tmp = y * (x - z);
	} else {
		tmp = z + (y * 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 ((y <= (-1.0d0)) .or. (.not. (y <= 5d-9))) then
        tmp = y * (x - z)
    else
        tmp = z + (y * x)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.0) || !(y <= 5e-9)) {
		tmp = y * (x - z);
	} else {
		tmp = z + (y * x);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -1.0) or not (y <= 5e-9):
		tmp = y * (x - z)
	else:
		tmp = z + (y * x)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.0) || !(y <= 5e-9))
		tmp = Float64(y * Float64(x - z));
	else
		tmp = Float64(z + Float64(y * x));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -1.0) || ~((y <= 5e-9)))
		tmp = y * (x - z);
	else
		tmp = z + (y * x);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 5e-9]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 5 \cdot 10^{-9}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1 or 5.0000000000000001e-9 < y

    1. Initial program 94.1%

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

      \[\leadsto \color{blue}{y \cdot \left(x + -1 \cdot z\right)} \]
    3. Step-by-step derivation
      1. neg-mul-198.1%

        \[\leadsto y \cdot \left(x + \color{blue}{\left(-z\right)}\right) \]
      2. sub-neg98.1%

        \[\leadsto y \cdot \color{blue}{\left(x - z\right)} \]
    4. Simplified98.1%

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

    if -1 < y < 5.0000000000000001e-9

    1. Initial program 100.0%

      \[x \cdot y + z \cdot \left(1 - y\right) \]
    2. Step-by-step derivation
      1. distribute-lft-out--100.0%

        \[\leadsto x \cdot y + \color{blue}{\left(z \cdot 1 - z \cdot y\right)} \]
      2. *-rgt-identity100.0%

        \[\leadsto x \cdot y + \left(\color{blue}{z} - z \cdot y\right) \]
      3. cancel-sign-sub-inv100.0%

        \[\leadsto x \cdot y + \color{blue}{\left(z + \left(-z\right) \cdot y\right)} \]
      4. +-commutative100.0%

        \[\leadsto x \cdot y + \color{blue}{\left(\left(-z\right) \cdot y + z\right)} \]
      5. associate-+r+100.0%

        \[\leadsto \color{blue}{\left(x \cdot y + \left(-z\right) \cdot y\right) + z} \]
      6. +-commutative100.0%

        \[\leadsto \color{blue}{\left(\left(-z\right) \cdot y + x \cdot y\right)} + z \]
      7. distribute-rgt-out100.0%

        \[\leadsto \color{blue}{y \cdot \left(\left(-z\right) + x\right)} + z \]
      8. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, \left(-z\right) + x, z\right)} \]
      9. +-commutative100.0%

        \[\leadsto \mathsf{fma}\left(y, \color{blue}{x + \left(-z\right)}, z\right) \]
      10. unsub-neg100.0%

        \[\leadsto \mathsf{fma}\left(y, \color{blue}{x - z}, z\right) \]
    3. Simplified100.0%

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

        \[\leadsto \color{blue}{y \cdot \left(x - z\right) + z} \]
    5. Applied egg-rr100.0%

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

      \[\leadsto \color{blue}{x \cdot y} + z \]
    7. Step-by-step derivation
      1. *-commutative98.9%

        \[\leadsto \color{blue}{y \cdot x} + z \]
    8. Simplified98.9%

      \[\leadsto \color{blue}{y \cdot x} + z \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 5 \cdot 10^{-9}\right):\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]

Alternative 7: 36.6% accurate, 9.0× speedup?

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

\\
z
\end{array}
Derivation
  1. Initial program 97.2%

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

    \[\leadsto \color{blue}{z} \]
  3. Final simplification39.9%

    \[\leadsto z \]

Developer target: 100.0% accurate, 1.3× 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 2024024 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (- z (* (- z x) y))

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