Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3

Percentage Accurate: 78.3% → 100.0%
Time: 3.8s
Alternatives: 5
Speedup: 1.3×

Specification

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

\\
x + \left(1 - x\right) \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 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: 78.3% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.3× speedup?

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

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

    \[x + \left(1 - x\right) \cdot \left(1 - y\right) \]
  2. Step-by-step derivation
    1. +-commutative75.9%

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

      \[\leadsto \left(1 - x\right) \cdot \color{blue}{\left(1 + \left(-y\right)\right)} + x \]
    3. distribute-lft-in75.9%

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

      \[\leadsto \color{blue}{\left(\left(1 - x\right) \cdot \left(-y\right) + \left(1 - x\right) \cdot 1\right)} + x \]
    5. *-rgt-identity75.9%

      \[\leadsto \left(\left(1 - x\right) \cdot \left(-y\right) + \color{blue}{\left(1 - x\right)}\right) + x \]
    6. associate-+r-75.9%

      \[\leadsto \color{blue}{\left(\left(\left(1 - x\right) \cdot \left(-y\right) + 1\right) - x\right)} + x \]
    7. associate-+l-100.0%

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

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

      \[\leadsto \color{blue}{\left(1 - x\right) \cdot \left(-y\right) + 1} \]
    10. sub-neg100.0%

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

      \[\leadsto \color{blue}{\left(\left(-x\right) + 1\right)} \cdot \left(-y\right) + 1 \]
    12. distribute-lft1-in100.0%

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

      \[\leadsto \left(\color{blue}{\left(-y\right) \cdot \left(-x\right)} + \left(-y\right)\right) + 1 \]
    14. unsub-neg100.0%

      \[\leadsto \color{blue}{\left(\left(-y\right) \cdot \left(-x\right) - y\right)} + 1 \]
    15. associate-+l-100.0%

      \[\leadsto \color{blue}{\left(-y\right) \cdot \left(-x\right) - \left(y - 1\right)} \]
    16. distribute-lft-neg-out100.0%

      \[\leadsto \color{blue}{\left(-y \cdot \left(-x\right)\right)} - \left(y - 1\right) \]
    17. *-commutative100.0%

      \[\leadsto \left(-\color{blue}{\left(-x\right) \cdot y}\right) - \left(y - 1\right) \]
    18. distribute-lft-neg-in100.0%

      \[\leadsto \color{blue}{\left(-\left(-x\right)\right) \cdot y} - \left(y - 1\right) \]
    19. remove-double-neg100.0%

      \[\leadsto \color{blue}{x} \cdot y - \left(y - 1\right) \]
    20. sub-neg100.0%

      \[\leadsto x \cdot y - \color{blue}{\left(y + \left(-1\right)\right)} \]
    21. metadata-eval100.0%

      \[\leadsto x \cdot y - \left(y + \color{blue}{-1}\right) \]
  3. Simplified100.0%

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

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

Alternative 2: 62.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4.3 \cdot 10^{+238}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -5.8 \cdot 10^{+125}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -2.75 \cdot 10^{+82}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-22}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 0.0105:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -4.3e+238)
   (- y)
   (if (<= y -5.8e+125)
     (* x y)
     (if (<= y -2.75e+82)
       (- y)
       (if (<= y -3.6e-22) (* x y) (if (<= y 0.0105) 1.0 (- y)))))))
double code(double x, double y) {
	double tmp;
	if (y <= -4.3e+238) {
		tmp = -y;
	} else if (y <= -5.8e+125) {
		tmp = x * y;
	} else if (y <= -2.75e+82) {
		tmp = -y;
	} else if (y <= -3.6e-22) {
		tmp = x * y;
	} else if (y <= 0.0105) {
		tmp = 1.0;
	} else {
		tmp = -y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-4.3d+238)) then
        tmp = -y
    else if (y <= (-5.8d+125)) then
        tmp = x * y
    else if (y <= (-2.75d+82)) then
        tmp = -y
    else if (y <= (-3.6d-22)) then
        tmp = x * y
    else if (y <= 0.0105d0) then
        tmp = 1.0d0
    else
        tmp = -y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -4.3e+238) {
		tmp = -y;
	} else if (y <= -5.8e+125) {
		tmp = x * y;
	} else if (y <= -2.75e+82) {
		tmp = -y;
	} else if (y <= -3.6e-22) {
		tmp = x * y;
	} else if (y <= 0.0105) {
		tmp = 1.0;
	} else {
		tmp = -y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -4.3e+238:
		tmp = -y
	elif y <= -5.8e+125:
		tmp = x * y
	elif y <= -2.75e+82:
		tmp = -y
	elif y <= -3.6e-22:
		tmp = x * y
	elif y <= 0.0105:
		tmp = 1.0
	else:
		tmp = -y
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -4.3e+238)
		tmp = Float64(-y);
	elseif (y <= -5.8e+125)
		tmp = Float64(x * y);
	elseif (y <= -2.75e+82)
		tmp = Float64(-y);
	elseif (y <= -3.6e-22)
		tmp = Float64(x * y);
	elseif (y <= 0.0105)
		tmp = 1.0;
	else
		tmp = Float64(-y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -4.3e+238)
		tmp = -y;
	elseif (y <= -5.8e+125)
		tmp = x * y;
	elseif (y <= -2.75e+82)
		tmp = -y;
	elseif (y <= -3.6e-22)
		tmp = x * y;
	elseif (y <= 0.0105)
		tmp = 1.0;
	else
		tmp = -y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -4.3e+238], (-y), If[LessEqual[y, -5.8e+125], N[(x * y), $MachinePrecision], If[LessEqual[y, -2.75e+82], (-y), If[LessEqual[y, -3.6e-22], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.0105], 1.0, (-y)]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{+238}:\\
\;\;\;\;-y\\

\mathbf{elif}\;y \leq -5.8 \cdot 10^{+125}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq -2.75 \cdot 10^{+82}:\\
\;\;\;\;-y\\

\mathbf{elif}\;y \leq -3.6 \cdot 10^{-22}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq 0.0105:\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.29999999999999983e238 or -5.79999999999999986e125 < y < -2.74999999999999998e82 or 0.0105000000000000007 < y

    1. Initial program 99.9%

      \[x + \left(1 - x\right) \cdot \left(1 - y\right) \]
    2. Step-by-step derivation
      1. +-commutative99.9%

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

        \[\leadsto \left(1 - x\right) \cdot \color{blue}{\left(1 + \left(-y\right)\right)} + x \]
      3. distribute-lft-in99.9%

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

        \[\leadsto \color{blue}{\left(\left(1 - x\right) \cdot \left(-y\right) + \left(1 - x\right) \cdot 1\right)} + x \]
      5. *-rgt-identity99.9%

        \[\leadsto \left(\left(1 - x\right) \cdot \left(-y\right) + \color{blue}{\left(1 - x\right)}\right) + x \]
      6. associate-+r-99.9%

        \[\leadsto \color{blue}{\left(\left(\left(1 - x\right) \cdot \left(-y\right) + 1\right) - x\right)} + x \]
      7. associate-+l-100.0%

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

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

        \[\leadsto \color{blue}{\left(1 - x\right) \cdot \left(-y\right) + 1} \]
      10. sub-neg100.0%

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

        \[\leadsto \color{blue}{\left(\left(-x\right) + 1\right)} \cdot \left(-y\right) + 1 \]
      12. distribute-lft1-in100.0%

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

        \[\leadsto \left(\color{blue}{\left(-y\right) \cdot \left(-x\right)} + \left(-y\right)\right) + 1 \]
      14. unsub-neg100.0%

        \[\leadsto \color{blue}{\left(\left(-y\right) \cdot \left(-x\right) - y\right)} + 1 \]
      15. associate-+l-100.0%

        \[\leadsto \color{blue}{\left(-y\right) \cdot \left(-x\right) - \left(y - 1\right)} \]
      16. distribute-lft-neg-out100.0%

        \[\leadsto \color{blue}{\left(-y \cdot \left(-x\right)\right)} - \left(y - 1\right) \]
      17. *-commutative100.0%

        \[\leadsto \left(-\color{blue}{\left(-x\right) \cdot y}\right) - \left(y - 1\right) \]
      18. distribute-lft-neg-in100.0%

        \[\leadsto \color{blue}{\left(-\left(-x\right)\right) \cdot y} - \left(y - 1\right) \]
      19. remove-double-neg100.0%

        \[\leadsto \color{blue}{x} \cdot y - \left(y - 1\right) \]
      20. sub-neg100.0%

        \[\leadsto x \cdot y - \color{blue}{\left(y + \left(-1\right)\right)} \]
      21. metadata-eval100.0%

        \[\leadsto x \cdot y - \left(y + \color{blue}{-1}\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(x - 1\right)} \]
    5. Taylor expanded in x around 0 69.2%

      \[\leadsto \color{blue}{-1 \cdot y} \]
    6. Step-by-step derivation
      1. mul-1-neg69.2%

        \[\leadsto \color{blue}{-y} \]
    7. Simplified69.2%

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

    if -4.29999999999999983e238 < y < -5.79999999999999986e125 or -2.74999999999999998e82 < y < -3.5999999999999998e-22

    1. Initial program 95.8%

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

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

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

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

    if -3.5999999999999998e-22 < y < 0.0105000000000000007

    1. Initial program 52.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.3 \cdot 10^{+238}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -5.8 \cdot 10^{+125}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -2.75 \cdot 10^{+82}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-22}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 0.0105:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]

Alternative 3: 86.2% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{+31}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+89}:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -5.8e+31) (* x y) (if (<= x 4.4e+89) (- 1.0 y) (* x y))))
double code(double x, double y) {
	double tmp;
	if (x <= -5.8e+31) {
		tmp = x * y;
	} else if (x <= 4.4e+89) {
		tmp = 1.0 - y;
	} else {
		tmp = x * y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-5.8d+31)) then
        tmp = x * y
    else if (x <= 4.4d+89) then
        tmp = 1.0d0 - y
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -5.8e+31) {
		tmp = x * y;
	} else if (x <= 4.4e+89) {
		tmp = 1.0 - y;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -5.8e+31:
		tmp = x * y
	elif x <= 4.4e+89:
		tmp = 1.0 - y
	else:
		tmp = x * y
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -5.8e+31)
		tmp = Float64(x * y);
	elseif (x <= 4.4e+89)
		tmp = Float64(1.0 - y);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -5.8e+31)
		tmp = x * y;
	elseif (x <= 4.4e+89)
		tmp = 1.0 - y;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -5.8e+31], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.4e+89], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{+31}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 4.4 \cdot 10^{+89}:\\
\;\;\;\;1 - y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.8000000000000001e31 or 4.4e89 < x

    1. Initial program 50.4%

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

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

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

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

    if -5.8000000000000001e31 < x < 4.4e89

    1. Initial program 92.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{+31}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+89}:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]

Alternative 4: 61.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 0.0105:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.0) (- y) (if (<= y 0.0105) 1.0 (- y))))
double code(double x, double y) {
	double tmp;
	if (y <= -1.0) {
		tmp = -y;
	} else if (y <= 0.0105) {
		tmp = 1.0;
	} else {
		tmp = -y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-1.0d0)) then
        tmp = -y
    else if (y <= 0.0105d0) then
        tmp = 1.0d0
    else
        tmp = -y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.0) {
		tmp = -y;
	} else if (y <= 0.0105) {
		tmp = 1.0;
	} else {
		tmp = -y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.0:
		tmp = -y
	elif y <= 0.0105:
		tmp = 1.0
	else:
		tmp = -y
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.0)
		tmp = Float64(-y);
	elseif (y <= 0.0105)
		tmp = 1.0;
	else
		tmp = Float64(-y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.0)
		tmp = -y;
	elseif (y <= 0.0105)
		tmp = 1.0;
	else
		tmp = -y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 0.0105], 1.0, (-y)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;-y\\

\mathbf{elif}\;y \leq 0.0105:\\
\;\;\;\;1\\

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


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

    1. Initial program 99.9%

      \[x + \left(1 - x\right) \cdot \left(1 - y\right) \]
    2. Step-by-step derivation
      1. +-commutative99.9%

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

        \[\leadsto \left(1 - x\right) \cdot \color{blue}{\left(1 + \left(-y\right)\right)} + x \]
      3. distribute-lft-in99.9%

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

        \[\leadsto \color{blue}{\left(\left(1 - x\right) \cdot \left(-y\right) + \left(1 - x\right) \cdot 1\right)} + x \]
      5. *-rgt-identity99.9%

        \[\leadsto \left(\left(1 - x\right) \cdot \left(-y\right) + \color{blue}{\left(1 - x\right)}\right) + x \]
      6. associate-+r-99.9%

        \[\leadsto \color{blue}{\left(\left(\left(1 - x\right) \cdot \left(-y\right) + 1\right) - x\right)} + x \]
      7. associate-+l-100.0%

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

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

        \[\leadsto \color{blue}{\left(1 - x\right) \cdot \left(-y\right) + 1} \]
      10. sub-neg100.0%

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

        \[\leadsto \color{blue}{\left(\left(-x\right) + 1\right)} \cdot \left(-y\right) + 1 \]
      12. distribute-lft1-in100.0%

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

        \[\leadsto \left(\color{blue}{\left(-y\right) \cdot \left(-x\right)} + \left(-y\right)\right) + 1 \]
      14. unsub-neg100.0%

        \[\leadsto \color{blue}{\left(\left(-y\right) \cdot \left(-x\right) - y\right)} + 1 \]
      15. associate-+l-100.0%

        \[\leadsto \color{blue}{\left(-y\right) \cdot \left(-x\right) - \left(y - 1\right)} \]
      16. distribute-lft-neg-out100.0%

        \[\leadsto \color{blue}{\left(-y \cdot \left(-x\right)\right)} - \left(y - 1\right) \]
      17. *-commutative100.0%

        \[\leadsto \left(-\color{blue}{\left(-x\right) \cdot y}\right) - \left(y - 1\right) \]
      18. distribute-lft-neg-in100.0%

        \[\leadsto \color{blue}{\left(-\left(-x\right)\right) \cdot y} - \left(y - 1\right) \]
      19. remove-double-neg100.0%

        \[\leadsto \color{blue}{x} \cdot y - \left(y - 1\right) \]
      20. sub-neg100.0%

        \[\leadsto x \cdot y - \color{blue}{\left(y + \left(-1\right)\right)} \]
      21. metadata-eval100.0%

        \[\leadsto x \cdot y - \left(y + \color{blue}{-1}\right) \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{y \cdot \left(x - 1\right)} \]
    5. Taylor expanded in x around 0 56.9%

      \[\leadsto \color{blue}{-1 \cdot y} \]
    6. Step-by-step derivation
      1. mul-1-neg56.9%

        \[\leadsto \color{blue}{-y} \]
    7. Simplified56.9%

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

    if -1 < y < 0.0105000000000000007

    1. Initial program 51.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 0.0105:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]

Alternative 5: 37.9% accurate, 9.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 75.9%

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

    \[\leadsto \color{blue}{1} \]
  3. Final simplification38.7%

    \[\leadsto 1 \]

Developer target: 100.0% accurate, 1.3× speedup?

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

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

Reproduce

?
herbie shell --seed 2023297 
(FPCore (x y)
  :name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
  :precision binary64

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

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