Data.Colour.RGB:hslsv from colour-2.3.3, C

?

Percentage Accurate: 100.0% → 100.0%
Time: 8.1s
Precision: binary64
Cost: 960

?

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

\\
\begin{array}{l}
t_0 := 2 - \left(x + y\right)\\
\frac{x}{t_0} - \frac{y}{t_0}
\end{array}
\end{array}

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.

Herbie found 10 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original100.0%
Target100.0%
Herbie100.0%
\[\frac{x}{2 - \left(x + y\right)} - \frac{y}{2 - \left(x + y\right)} \]

Derivation?

  1. Initial program 100.0%

    \[\frac{x - y}{2 - \left(x + y\right)} \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\frac{x - y}{\left(2 - x\right) - y}} \]
    Step-by-step derivation

    [Start]100.0%

    \[ \frac{x - y}{2 - \left(x + y\right)} \]

    associate--r+ [=>]100.0%

    \[ \frac{x - y}{\color{blue}{\left(2 - x\right) - y}} \]
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{x}{2 - \left(x + y\right)} - \frac{y}{2 - \left(x + y\right)}} \]
    Step-by-step derivation

    [Start]100.0%

    \[ \frac{x - y}{\left(2 - x\right) - y} \]

    div-sub [=>]100.0%

    \[ \color{blue}{\frac{x}{\left(2 - x\right) - y} - \frac{y}{\left(2 - x\right) - y}} \]

    associate--l- [=>]100.0%

    \[ \frac{x}{\color{blue}{2 - \left(x + y\right)}} - \frac{y}{\left(2 - x\right) - y} \]

    associate--l- [=>]100.0%

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

    \[\leadsto \frac{x}{2 - \left(x + y\right)} - \frac{y}{2 - \left(x + y\right)} \]

Alternatives

Alternative 1
Accuracy100.0%
Cost960
\[\begin{array}{l} t_0 := 2 - \left(x + y\right)\\ \frac{x}{t_0} - \frac{y}{t_0} \end{array} \]
Alternative 2
Accuracy59.7%
Cost988
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-121}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-187}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-166}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-100}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-12}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{+34}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 3
Accuracy59.5%
Cost988
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-125}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-187}:\\ \;\;\;\;1 + \frac{2}{y}\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-166}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-97}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-12}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+30}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 4
Accuracy71.5%
Cost976
\[\begin{array}{l} t_0 := \frac{x}{2 - x}\\ \mathbf{if}\;x \leq -4.8 \cdot 10^{-115}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-93}:\\ \;\;\;\;\frac{y}{y + -2}\\ \mathbf{elif}\;x \leq 18500000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.65 \cdot 10^{+33}:\\ \;\;\;\;1 + \frac{x \cdot -2}{y}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 5
Accuracy71.4%
Cost848
\[\begin{array}{l} t_0 := \frac{x}{2 - x}\\ \mathbf{if}\;y \leq -7.5 \cdot 10^{+127}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{-166}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.18 \cdot 10^{-136}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{elif}\;y \leq 9000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{2}{y}\\ \end{array} \]
Alternative 6
Accuracy60.2%
Cost724
\[\begin{array}{l} \mathbf{if}\;x \leq -2:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-121}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-96}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{-12}:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{elif}\;x \leq 4.15 \cdot 10^{+30}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 7
Accuracy71.7%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -4.1 \cdot 10^{-115} \lor \neg \left(x \leq 7.5 \cdot 10^{-93}\right):\\ \;\;\;\;\frac{x}{2 - x}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{y + -2}\\ \end{array} \]
Alternative 8
Accuracy100.0%
Cost576
\[\frac{x - y}{2 - \left(x + y\right)} \]
Alternative 9
Accuracy62.1%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+26}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 6 \cdot 10^{+31}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 10
Accuracy37.7%
Cost64
\[-1 \]

Reproduce?

herbie shell --seed 2023167 
(FPCore (x y)
  :name "Data.Colour.RGB:hslsv from colour-2.3.3, C"
  :precision binary64

  :herbie-target
  (- (/ x (- 2.0 (+ x y))) (/ y (- 2.0 (+ x y))))

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