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

Percentage Accurate: 77.1% → 100.0%
Time: 4.4s
Alternatives: 8
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 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 77.1% 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, 0.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(1 + \color{blue}{\left(0 \cdot -1\right)} \cdot x\right) + \left(-y\right) \cdot \left(1 - x\right) \]
    12. associate-*r*100.0%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \mathsf{fma}\left(x, y, 1 - y\right) \]

Alternative 2: 63.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -7.8 \cdot 10^{+95}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{+54}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -1.15 \cdot 10^{-37}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 8.4 \cdot 10^{-23}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+119}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -7.8e+95)
   (* x y)
   (if (<= y -1.9e+54)
     (- y)
     (if (<= y -1.15e-37)
       (* x y)
       (if (<= y 8.4e-23) 1.0 (if (<= y 2.2e+119) (* x y) (- y)))))))
double code(double x, double y) {
	double tmp;
	if (y <= -7.8e+95) {
		tmp = x * y;
	} else if (y <= -1.9e+54) {
		tmp = -y;
	} else if (y <= -1.15e-37) {
		tmp = x * y;
	} else if (y <= 8.4e-23) {
		tmp = 1.0;
	} else if (y <= 2.2e+119) {
		tmp = x * y;
	} 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 <= (-7.8d+95)) then
        tmp = x * y
    else if (y <= (-1.9d+54)) then
        tmp = -y
    else if (y <= (-1.15d-37)) then
        tmp = x * y
    else if (y <= 8.4d-23) then
        tmp = 1.0d0
    else if (y <= 2.2d+119) then
        tmp = x * y
    else
        tmp = -y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -7.8e+95) {
		tmp = x * y;
	} else if (y <= -1.9e+54) {
		tmp = -y;
	} else if (y <= -1.15e-37) {
		tmp = x * y;
	} else if (y <= 8.4e-23) {
		tmp = 1.0;
	} else if (y <= 2.2e+119) {
		tmp = x * y;
	} else {
		tmp = -y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -7.8e+95:
		tmp = x * y
	elif y <= -1.9e+54:
		tmp = -y
	elif y <= -1.15e-37:
		tmp = x * y
	elif y <= 8.4e-23:
		tmp = 1.0
	elif y <= 2.2e+119:
		tmp = x * y
	else:
		tmp = -y
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -7.8e+95)
		tmp = Float64(x * y);
	elseif (y <= -1.9e+54)
		tmp = Float64(-y);
	elseif (y <= -1.15e-37)
		tmp = Float64(x * y);
	elseif (y <= 8.4e-23)
		tmp = 1.0;
	elseif (y <= 2.2e+119)
		tmp = Float64(x * y);
	else
		tmp = Float64(-y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -7.8e+95)
		tmp = x * y;
	elseif (y <= -1.9e+54)
		tmp = -y;
	elseif (y <= -1.15e-37)
		tmp = x * y;
	elseif (y <= 8.4e-23)
		tmp = 1.0;
	elseif (y <= 2.2e+119)
		tmp = x * y;
	else
		tmp = -y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -7.8e+95], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.9e+54], (-y), If[LessEqual[y, -1.15e-37], N[(x * y), $MachinePrecision], If[LessEqual[y, 8.4e-23], 1.0, If[LessEqual[y, 2.2e+119], N[(x * y), $MachinePrecision], (-y)]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;y \leq -1.15 \cdot 10^{-37}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq 8.4 \cdot 10^{-23}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 2.2 \cdot 10^{+119}:\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -7.7999999999999994e95 or -1.9000000000000001e54 < y < -1.15e-37 or 8.4000000000000003e-23 < y < 2.2000000000000001e119

    1. Initial program 90.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(1 - 1\right) - \left(-y\right)\right)} \cdot x \]
      5. metadata-eval60.8%

        \[\leadsto \left(\color{blue}{0} - \left(-y\right)\right) \cdot x \]
      6. neg-sub060.8%

        \[\leadsto \color{blue}{\left(-\left(-y\right)\right)} \cdot x \]
      7. remove-double-neg60.8%

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

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

    if -7.7999999999999994e95 < y < -1.9000000000000001e54 or 2.2000000000000001e119 < y

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.15e-37 < y < 8.4000000000000003e-23

    1. Initial program 64.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.8 \cdot 10^{+95}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{+54}:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq -1.15 \cdot 10^{-37}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 8.4 \cdot 10^{-23}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+119}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]

Alternative 3: 86.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{-38} \lor \neg \left(y \leq 4 \cdot 10^{-22}\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -8.80000000000000029e-38 or 4.0000000000000002e-22 < y

    1. Initial program 93.9%

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

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

        \[\leadsto \color{blue}{-y \cdot \left(1 - x\right)} \]
      2. distribute-rgt-neg-in96.6%

        \[\leadsto \color{blue}{y \cdot \left(-\left(1 - x\right)\right)} \]
      3. sub-neg96.6%

        \[\leadsto y \cdot \left(-\color{blue}{\left(1 + \left(-x\right)\right)}\right) \]
      4. distribute-neg-in96.6%

        \[\leadsto y \cdot \color{blue}{\left(\left(-1\right) + \left(-\left(-x\right)\right)\right)} \]
      5. metadata-eval96.6%

        \[\leadsto y \cdot \left(\color{blue}{-1} + \left(-\left(-x\right)\right)\right) \]
      6. remove-double-neg96.6%

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

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

    if -8.80000000000000029e-38 < y < 4.0000000000000002e-22

    1. Initial program 64.4%

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

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

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

Alternative 4: 86.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4.3 \cdot 10^{-38}:\\ \;\;\;\;x \cdot y - y\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{-24}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + -1\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -4.3e-38) (- (* x y) y) (if (<= y 9.5e-24) 1.0 (* y (+ x -1.0)))))
double code(double x, double y) {
	double tmp;
	if (y <= -4.3e-38) {
		tmp = (x * y) - y;
	} else if (y <= 9.5e-24) {
		tmp = 1.0;
	} else {
		tmp = y * (x + -1.0);
	}
	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-38)) then
        tmp = (x * y) - y
    else if (y <= 9.5d-24) then
        tmp = 1.0d0
    else
        tmp = y * (x + (-1.0d0))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -4.3e-38) {
		tmp = (x * y) - y;
	} else if (y <= 9.5e-24) {
		tmp = 1.0;
	} else {
		tmp = y * (x + -1.0);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -4.3e-38:
		tmp = (x * y) - y
	elif y <= 9.5e-24:
		tmp = 1.0
	else:
		tmp = y * (x + -1.0)
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -4.3e-38)
		tmp = Float64(Float64(x * y) - y);
	elseif (y <= 9.5e-24)
		tmp = 1.0;
	else
		tmp = Float64(y * Float64(x + -1.0));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -4.3e-38)
		tmp = (x * y) - y;
	elseif (y <= 9.5e-24)
		tmp = 1.0;
	else
		tmp = y * (x + -1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -4.3e-38], N[(N[(x * y), $MachinePrecision] - y), $MachinePrecision], If[LessEqual[y, 9.5e-24], 1.0, N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 9.5 \cdot 10^{-24}:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + -1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.3000000000000002e-38

    1. Initial program 92.3%

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

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

        \[\leadsto \color{blue}{-y \cdot \left(1 - x\right)} \]
      2. distribute-rgt-neg-in94.7%

        \[\leadsto \color{blue}{y \cdot \left(-\left(1 - x\right)\right)} \]
      3. sub-neg94.7%

        \[\leadsto y \cdot \left(-\color{blue}{\left(1 + \left(-x\right)\right)}\right) \]
      4. distribute-neg-in94.7%

        \[\leadsto y \cdot \color{blue}{\left(\left(-1\right) + \left(-\left(-x\right)\right)\right)} \]
      5. metadata-eval94.7%

        \[\leadsto y \cdot \left(\color{blue}{-1} + \left(-\left(-x\right)\right)\right) \]
      6. remove-double-neg94.7%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 + x\right)} \]
    5. Step-by-step derivation
      1. +-commutative94.7%

        \[\leadsto y \cdot \color{blue}{\left(x + -1\right)} \]
      2. distribute-rgt-in94.7%

        \[\leadsto \color{blue}{x \cdot y + -1 \cdot y} \]
      3. *-commutative94.7%

        \[\leadsto \color{blue}{y \cdot x} + -1 \cdot y \]
      4. neg-mul-194.7%

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

        \[\leadsto \color{blue}{y \cdot x - y} \]
    6. Applied egg-rr94.7%

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

    if -4.3000000000000002e-38 < y < 9.50000000000000029e-24

    1. Initial program 64.4%

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

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

    if 9.50000000000000029e-24 < y

    1. Initial program 95.6%

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

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

        \[\leadsto \color{blue}{-y \cdot \left(1 - x\right)} \]
      2. distribute-rgt-neg-in98.5%

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

        \[\leadsto y \cdot \left(-\color{blue}{\left(1 + \left(-x\right)\right)}\right) \]
      4. distribute-neg-in98.5%

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

        \[\leadsto y \cdot \left(\color{blue}{-1} + \left(-\left(-x\right)\right)\right) \]
      6. remove-double-neg98.5%

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

      \[\leadsto \color{blue}{y \cdot \left(-1 + x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification91.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.3 \cdot 10^{-38}:\\ \;\;\;\;x \cdot y - y\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{-24}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + -1\right)\\ \end{array} \]

Alternative 5: 84.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{+137}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+26}:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -5e+137) (* x y) (if (<= x 1.6e+26) (- 1.0 y) (* x y))))
double code(double x, double y) {
	double tmp;
	if (x <= -5e+137) {
		tmp = x * y;
	} else if (x <= 1.6e+26) {
		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 <= (-5d+137)) then
        tmp = x * y
    else if (x <= 1.6d+26) 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 <= -5e+137) {
		tmp = x * y;
	} else if (x <= 1.6e+26) {
		tmp = 1.0 - y;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -5e+137:
		tmp = x * y
	elif x <= 1.6e+26:
		tmp = 1.0 - y
	else:
		tmp = x * y
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -5e+137)
		tmp = Float64(x * y);
	elseif (x <= 1.6e+26)
		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 <= -5e+137)
		tmp = x * y;
	elseif (x <= 1.6e+26)
		tmp = 1.0 - y;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -5e+137], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.6e+26], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.0000000000000002e137 or 1.60000000000000014e26 < x

    1. Initial program 57.5%

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

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

        \[\leadsto \left(1 + \color{blue}{\left(-\left(1 - y\right)\right)}\right) \cdot x \]
      2. unsub-neg57.5%

        \[\leadsto \color{blue}{\left(1 - \left(1 - y\right)\right)} \cdot x \]
      3. sub-neg57.5%

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

        \[\leadsto \color{blue}{\left(\left(1 - 1\right) - \left(-y\right)\right)} \cdot x \]
      5. metadata-eval82.2%

        \[\leadsto \left(\color{blue}{0} - \left(-y\right)\right) \cdot x \]
      6. neg-sub082.2%

        \[\leadsto \color{blue}{\left(-\left(-y\right)\right)} \cdot x \]
      7. remove-double-neg82.2%

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

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

    if -5.0000000000000002e137 < x < 1.60000000000000014e26

    1. Initial program 91.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{+137}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{+26}:\\ \;\;\;\;1 - y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]

Alternative 6: 100.0% accurate, 1.3× speedup?

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

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

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

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

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

Alternative 7: 61.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+21}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.0) (- y) (if (<= y 2.1e+21) 1.0 (- y))))
double code(double x, double y) {
	double tmp;
	if (y <= -1.0) {
		tmp = -y;
	} else if (y <= 2.1e+21) {
		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 <= 2.1d+21) 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 <= 2.1e+21) {
		tmp = 1.0;
	} else {
		tmp = -y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.0:
		tmp = -y
	elif y <= 2.1e+21:
		tmp = 1.0
	else:
		tmp = -y
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.0)
		tmp = Float64(-y);
	elseif (y <= 2.1e+21)
		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 <= 2.1e+21)
		tmp = 1.0;
	else
		tmp = -y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 2.1e+21], 1.0, (-y)]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 2.1 \cdot 10^{+21}:\\
\;\;\;\;1\\

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


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

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{-y \cdot \left(1 - x\right)} \]
      2. distribute-rgt-neg-in99.2%

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

        \[\leadsto y \cdot \left(-\color{blue}{\left(1 + \left(-x\right)\right)}\right) \]
      4. distribute-neg-in99.2%

        \[\leadsto y \cdot \color{blue}{\left(\left(-1\right) + \left(-\left(-x\right)\right)\right)} \]
      5. metadata-eval99.2%

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

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

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

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

        \[\leadsto \color{blue}{-y} \]
    7. Simplified53.8%

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

    if -1 < y < 2.1e21

    1. Initial program 63.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;-y\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+21}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-y\\ \end{array} \]

Alternative 8: 38.5% 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 80.1%

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

    \[\leadsto \color{blue}{1} \]
  3. Final simplification43.2%

    \[\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 2023221 
(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))))