Graphics.Rendering.Chart.Axis.Types:hBufferRect from Chart-1.5.3

Percentage Accurate: 99.9% → 100.0%
Time: 7.7s
Alternatives: 5
Speedup: 1.0×

Specification

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

\\
x + \frac{x - y}{2}
\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: 99.9% accurate, 1.0× speedup?

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

\\
x + \frac{x - y}{2}
\end{array}

Alternative 1: 100.0% accurate, 0.1× speedup?

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

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

    \[x + \frac{x - y}{2} \]
  2. Step-by-step derivation
    1. div-subN/A

      \[\leadsto x + \left(\frac{x}{2} - \color{blue}{\frac{y}{2}}\right) \]
    2. sub-negN/A

      \[\leadsto x + \left(\frac{x}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)}\right) \]
    3. associate-+r+N/A

      \[\leadsto \left(x + \frac{x}{2}\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)} \]
    4. +-commutativeN/A

      \[\leadsto \left(\mathsf{neg}\left(\frac{y}{2}\right)\right) + \color{blue}{\left(x + \frac{x}{2}\right)} \]
    5. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\mathsf{neg}\left(\frac{y}{2}\right)\right), \color{blue}{\left(x + \frac{x}{2}\right)}\right) \]
    6. distribute-neg-frac2N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\frac{y}{\mathsf{neg}\left(2\right)}\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{x}{2}\right)\right) \]
    9. remove-double-negN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)}{2}\right)\right) \]
    10. neg-mul-1N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{-1 \cdot \left(\mathsf{neg}\left(x\right)\right)}{2}\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\left(\mathsf{neg}\left(x\right)\right) \cdot -1}{2}\right)\right) \]
    12. associate-/l*N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \color{blue}{x \cdot \frac{-1}{2}}\right)\right) \]
    14. *-commutativeN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \frac{-1}{2} \cdot \color{blue}{x}\right)\right) \]
    15. cancel-sign-sub-invN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \color{blue}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right) \cdot x}\right)\right) \]
    16. *-lft-identityN/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right) \cdot x\right)\right) \]
    18. distribute-rgt-outN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
    19. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
    20. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right)\right)\right)\right) \]
    21. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)\right)\right) \]
    22. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \frac{1}{2}\right)\right)\right) \]
    23. metadata-eval99.9%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \frac{3}{2}\right)\right) \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\frac{y}{-2} + x \cdot 1.5} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto x \cdot \frac{3}{2} + \color{blue}{\frac{y}{-2}} \]
    2. fma-defineN/A

      \[\leadsto \mathsf{fma}\left(x, \color{blue}{\frac{3}{2}}, \frac{y}{-2}\right) \]
    3. fma-lowering-fma.f64N/A

      \[\leadsto \mathsf{fma.f64}\left(x, \color{blue}{\frac{3}{2}}, \left(\frac{y}{-2}\right)\right) \]
    4. /-lowering-/.f64100.0%

      \[\leadsto \mathsf{fma.f64}\left(x, \frac{3}{2}, \mathsf{/.f64}\left(y, -2\right)\right) \]
  6. Applied egg-rr100.0%

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

Alternative 2: 73.6% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7 \cdot 10^{+55}:\\
\;\;\;\;x \cdot 1.5\\

\mathbf{elif}\;x \leq 1.25 \cdot 10^{+82}:\\
\;\;\;\;y \cdot -0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.7000000000000001e55 or 1.25000000000000004e82 < x

    1. Initial program 99.7%

      \[x + \frac{x - y}{2} \]
    2. Step-by-step derivation
      1. div-subN/A

        \[\leadsto x + \left(\frac{x}{2} - \color{blue}{\frac{y}{2}}\right) \]
      2. sub-negN/A

        \[\leadsto x + \left(\frac{x}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)}\right) \]
      3. associate-+r+N/A

        \[\leadsto \left(x + \frac{x}{2}\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)} \]
      4. +-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{y}{2}\right)\right) + \color{blue}{\left(x + \frac{x}{2}\right)} \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\mathsf{neg}\left(\frac{y}{2}\right)\right), \color{blue}{\left(x + \frac{x}{2}\right)}\right) \]
      6. distribute-neg-frac2N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{y}{\mathsf{neg}\left(2\right)}\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{x}{2}\right)\right) \]
      9. remove-double-negN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)}{2}\right)\right) \]
      10. neg-mul-1N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{-1 \cdot \left(\mathsf{neg}\left(x\right)\right)}{2}\right)\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\left(\mathsf{neg}\left(x\right)\right) \cdot -1}{2}\right)\right) \]
      12. associate-/l*N/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \color{blue}{x \cdot \frac{-1}{2}}\right)\right) \]
      14. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \frac{-1}{2} \cdot \color{blue}{x}\right)\right) \]
      15. cancel-sign-sub-invN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \color{blue}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right) \cdot x}\right)\right) \]
      16. *-lft-identityN/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right) \cdot x\right)\right) \]
      18. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
      19. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
      20. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right)\right)\right)\right) \]
      21. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)\right)\right) \]
      22. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \frac{1}{2}\right)\right)\right) \]
      23. metadata-eval99.7%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \frac{3}{2}\right)\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{y}{-2} + x \cdot 1.5} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0

      \[\leadsto \color{blue}{\frac{3}{2} \cdot x} \]
    6. Step-by-step derivation
      1. *-lowering-*.f6482.7%

        \[\leadsto \mathsf{*.f64}\left(\frac{3}{2}, \color{blue}{x}\right) \]
    7. Simplified82.7%

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

    if -4.7000000000000001e55 < x < 1.25000000000000004e82

    1. Initial program 99.9%

      \[x + \frac{x - y}{2} \]
    2. Step-by-step derivation
      1. div-subN/A

        \[\leadsto x + \left(\frac{x}{2} - \color{blue}{\frac{y}{2}}\right) \]
      2. sub-negN/A

        \[\leadsto x + \left(\frac{x}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)}\right) \]
      3. associate-+r+N/A

        \[\leadsto \left(x + \frac{x}{2}\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)} \]
      4. +-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{y}{2}\right)\right) + \color{blue}{\left(x + \frac{x}{2}\right)} \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\mathsf{neg}\left(\frac{y}{2}\right)\right), \color{blue}{\left(x + \frac{x}{2}\right)}\right) \]
      6. distribute-neg-frac2N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\frac{y}{\mathsf{neg}\left(2\right)}\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{x}{2}\right)\right) \]
      9. remove-double-negN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)}{2}\right)\right) \]
      10. neg-mul-1N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{-1 \cdot \left(\mathsf{neg}\left(x\right)\right)}{2}\right)\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\left(\mathsf{neg}\left(x\right)\right) \cdot -1}{2}\right)\right) \]
      12. associate-/l*N/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \color{blue}{x \cdot \frac{-1}{2}}\right)\right) \]
      14. *-commutativeN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \frac{-1}{2} \cdot \color{blue}{x}\right)\right) \]
      15. cancel-sign-sub-invN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \color{blue}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right) \cdot x}\right)\right) \]
      16. *-lft-identityN/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right) \cdot x\right)\right) \]
      18. distribute-rgt-outN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
      19. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
      20. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right)\right)\right)\right) \]
      21. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)\right)\right) \]
      22. metadata-evalN/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \frac{1}{2}\right)\right)\right) \]
      23. metadata-eval99.9%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \frac{3}{2}\right)\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\frac{y}{-2} + x \cdot 1.5} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot y} \]
    6. Step-by-step derivation
      1. *-lowering-*.f6476.2%

        \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{y}\right) \]
    7. Simplified76.2%

      \[\leadsto \color{blue}{-0.5 \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.7 \cdot 10^{+55}:\\ \;\;\;\;x \cdot 1.5\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{+82}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot 1.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.9% accurate, 1.0× speedup?

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

\\
\frac{y}{-2} + x \cdot 1.5
\end{array}
Derivation
  1. Initial program 99.9%

    \[x + \frac{x - y}{2} \]
  2. Step-by-step derivation
    1. div-subN/A

      \[\leadsto x + \left(\frac{x}{2} - \color{blue}{\frac{y}{2}}\right) \]
    2. sub-negN/A

      \[\leadsto x + \left(\frac{x}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)}\right) \]
    3. associate-+r+N/A

      \[\leadsto \left(x + \frac{x}{2}\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)} \]
    4. +-commutativeN/A

      \[\leadsto \left(\mathsf{neg}\left(\frac{y}{2}\right)\right) + \color{blue}{\left(x + \frac{x}{2}\right)} \]
    5. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\mathsf{neg}\left(\frac{y}{2}\right)\right), \color{blue}{\left(x + \frac{x}{2}\right)}\right) \]
    6. distribute-neg-frac2N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\frac{y}{\mathsf{neg}\left(2\right)}\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{x}{2}\right)\right) \]
    9. remove-double-negN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)}{2}\right)\right) \]
    10. neg-mul-1N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{-1 \cdot \left(\mathsf{neg}\left(x\right)\right)}{2}\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\left(\mathsf{neg}\left(x\right)\right) \cdot -1}{2}\right)\right) \]
    12. associate-/l*N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \color{blue}{x \cdot \frac{-1}{2}}\right)\right) \]
    14. *-commutativeN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \frac{-1}{2} \cdot \color{blue}{x}\right)\right) \]
    15. cancel-sign-sub-invN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \color{blue}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right) \cdot x}\right)\right) \]
    16. *-lft-identityN/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right) \cdot x\right)\right) \]
    18. distribute-rgt-outN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
    19. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
    20. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right)\right)\right)\right) \]
    21. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)\right)\right) \]
    22. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \frac{1}{2}\right)\right)\right) \]
    23. metadata-eval99.9%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \frac{3}{2}\right)\right) \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\frac{y}{-2} + x \cdot 1.5} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 4: 99.9% accurate, 1.0× speedup?

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

\\
x + \frac{x - y}{2}
\end{array}
Derivation
  1. Initial program 99.9%

    \[x + \frac{x - y}{2} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 5: 51.5% accurate, 2.3× speedup?

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

\\
y \cdot -0.5
\end{array}
Derivation
  1. Initial program 99.9%

    \[x + \frac{x - y}{2} \]
  2. Step-by-step derivation
    1. div-subN/A

      \[\leadsto x + \left(\frac{x}{2} - \color{blue}{\frac{y}{2}}\right) \]
    2. sub-negN/A

      \[\leadsto x + \left(\frac{x}{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)}\right) \]
    3. associate-+r+N/A

      \[\leadsto \left(x + \frac{x}{2}\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{y}{2}\right)\right)} \]
    4. +-commutativeN/A

      \[\leadsto \left(\mathsf{neg}\left(\frac{y}{2}\right)\right) + \color{blue}{\left(x + \frac{x}{2}\right)} \]
    5. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\mathsf{neg}\left(\frac{y}{2}\right)\right), \color{blue}{\left(x + \frac{x}{2}\right)}\right) \]
    6. distribute-neg-frac2N/A

      \[\leadsto \mathsf{+.f64}\left(\left(\frac{y}{\mathsf{neg}\left(2\right)}\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{x} + \frac{x}{2}\right)\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{x}{2}\right)\right) \]
    9. remove-double-negN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)}{2}\right)\right) \]
    10. neg-mul-1N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{-1 \cdot \left(\mathsf{neg}\left(x\right)\right)}{2}\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \frac{\left(\mathsf{neg}\left(x\right)\right) \cdot -1}{2}\right)\right) \]
    12. associate-/l*N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \color{blue}{x \cdot \frac{-1}{2}}\right)\right) \]
    14. *-commutativeN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x - \frac{-1}{2} \cdot \color{blue}{x}\right)\right) \]
    15. cancel-sign-sub-invN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x + \color{blue}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right) \cdot x}\right)\right) \]
    16. *-lft-identityN/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right) \cdot x\right)\right) \]
    18. distribute-rgt-outN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \left(x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
    19. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)}\right)\right) \]
    20. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\color{blue}{\frac{-1}{2}}\right)\right)\right)\right)\right) \]
    21. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)\right)\right) \]
    22. metadata-evalN/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \left(1 + \frac{1}{2}\right)\right)\right) \]
    23. metadata-eval99.9%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{/.f64}\left(y, -2\right), \mathsf{*.f64}\left(x, \frac{3}{2}\right)\right) \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{\frac{y}{-2} + x \cdot 1.5} \]
  4. Add Preprocessing
  5. Taylor expanded in y around inf

    \[\leadsto \color{blue}{\frac{-1}{2} \cdot y} \]
  6. Step-by-step derivation
    1. *-lowering-*.f6454.2%

      \[\leadsto \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{y}\right) \]
  7. Simplified54.2%

    \[\leadsto \color{blue}{-0.5 \cdot y} \]
  8. Final simplification54.2%

    \[\leadsto y \cdot -0.5 \]
  9. Add Preprocessing

Developer Target 1: 99.9% accurate, 1.0× speedup?

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

\\
1.5 \cdot x - 0.5 \cdot y
\end{array}

Reproduce

?
herbie shell --seed 2024158 
(FPCore (x y)
  :name "Graphics.Rendering.Chart.Axis.Types:hBufferRect from Chart-1.5.3"
  :precision binary64

  :alt
  (! :herbie-platform default (- (* 3/2 x) (* 1/2 y)))

  (+ x (/ (- x y) 2.0)))