
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
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
public static double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
def code(x, y): return (x - y) / (2.0 - (x + y))
function code(x, y) return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) end
function tmp = code(x, y) tmp = (x - y) / (2.0 - (x + y)); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{2 - \left(x + y\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
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
public static double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
def code(x, y): return (x - y) / (2.0 - (x + y))
function code(x, y) return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) end
function tmp = code(x, y) tmp = (x - y) / (2.0 - (x + y)); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{2 - \left(x + y\right)}
\end{array}
(FPCore (x y) :precision binary64 (/ (- x y) (- 2.0 (+ x y))))
double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
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
public static double code(double x, double y) {
return (x - y) / (2.0 - (x + y));
}
def code(x, y): return (x - y) / (2.0 - (x + y))
function code(x, y) return Float64(Float64(x - y) / Float64(2.0 - Float64(x + y))) end
function tmp = code(x, y) tmp = (x - y) / (2.0 - (x + y)); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(2.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{2 - \left(x + y\right)}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.9e+22) 1.0 (if (<= y 3.2e-19) (/ x (- 2.0 x)) (/ (- y) (- 2.0 y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.9e+22) {
tmp = 1.0;
} else if (y <= 3.2e-19) {
tmp = x / (2.0 - x);
} else {
tmp = -y / (2.0 - 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.9d+22)) then
tmp = 1.0d0
else if (y <= 3.2d-19) then
tmp = x / (2.0d0 - x)
else
tmp = -y / (2.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.9e+22) {
tmp = 1.0;
} else if (y <= 3.2e-19) {
tmp = x / (2.0 - x);
} else {
tmp = -y / (2.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.9e+22: tmp = 1.0 elif y <= 3.2e-19: tmp = x / (2.0 - x) else: tmp = -y / (2.0 - y) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.9e+22) tmp = 1.0; elseif (y <= 3.2e-19) tmp = Float64(x / Float64(2.0 - x)); else tmp = Float64(Float64(-y) / Float64(2.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.9e+22) tmp = 1.0; elseif (y <= 3.2e-19) tmp = x / (2.0 - x); else tmp = -y / (2.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.9e+22], 1.0, If[LessEqual[y, 3.2e-19], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], N[((-y) / N[(2.0 - y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+22}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{-19}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-y}{2 - y}\\
\end{array}
\end{array}
if y < -1.9000000000000002e22Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 82.1%
if -1.9000000000000002e22 < y < 3.19999999999999982e-19Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 76.5%
if 3.19999999999999982e-19 < y Initial program 99.9%
associate--r+99.9%
Simplified99.9%
Taylor expanded in x around 0 78.8%
mul-1-neg78.8%
distribute-neg-frac78.8%
Simplified78.8%
Final simplification78.3%
(FPCore (x y) :precision binary64 (if (<= y -1.5e+23) (+ 1.0 (/ (* x -2.0) y)) (if (<= y 4.7e-23) (/ x (- 2.0 x)) (/ (- y) (- 2.0 y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.5e+23) {
tmp = 1.0 + ((x * -2.0) / y);
} else if (y <= 4.7e-23) {
tmp = x / (2.0 - x);
} else {
tmp = -y / (2.0 - 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.5d+23)) then
tmp = 1.0d0 + ((x * (-2.0d0)) / y)
else if (y <= 4.7d-23) then
tmp = x / (2.0d0 - x)
else
tmp = -y / (2.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.5e+23) {
tmp = 1.0 + ((x * -2.0) / y);
} else if (y <= 4.7e-23) {
tmp = x / (2.0 - x);
} else {
tmp = -y / (2.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.5e+23: tmp = 1.0 + ((x * -2.0) / y) elif y <= 4.7e-23: tmp = x / (2.0 - x) else: tmp = -y / (2.0 - y) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.5e+23) tmp = Float64(1.0 + Float64(Float64(x * -2.0) / y)); elseif (y <= 4.7e-23) tmp = Float64(x / Float64(2.0 - x)); else tmp = Float64(Float64(-y) / Float64(2.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.5e+23) tmp = 1.0 + ((x * -2.0) / y); elseif (y <= 4.7e-23) tmp = x / (2.0 - x); else tmp = -y / (2.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.5e+23], N[(1.0 + N[(N[(x * -2.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.7e-23], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], N[((-y) / N[(2.0 - y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+23}:\\
\;\;\;\;1 + \frac{x \cdot -2}{y}\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{-23}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-y}{2 - y}\\
\end{array}
\end{array}
if y < -1.5e23Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 82.5%
associate--l+82.5%
associate-*r/82.5%
associate-*r/82.5%
div-sub82.5%
cancel-sign-sub-inv82.5%
metadata-eval82.5%
*-lft-identity82.5%
+-commutative82.5%
mul-1-neg82.5%
unsub-neg82.5%
Simplified82.5%
Taylor expanded in x around inf 82.5%
*-commutative82.5%
Simplified82.5%
if -1.5e23 < y < 4.7000000000000001e-23Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 76.5%
if 4.7000000000000001e-23 < y Initial program 99.9%
associate--r+99.9%
Simplified99.9%
Taylor expanded in x around 0 78.8%
mul-1-neg78.8%
distribute-neg-frac78.8%
Simplified78.8%
Final simplification78.3%
(FPCore (x y) :precision binary64 (if (<= y -2.8e+23) 1.0 (if (<= y 7e+24) (/ x (- 2.0 x)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.8e+23) {
tmp = 1.0;
} else if (y <= 7e+24) {
tmp = x / (2.0 - x);
} 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 <= (-2.8d+23)) then
tmp = 1.0d0
else if (y <= 7d+24) then
tmp = x / (2.0d0 - x)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.8e+23) {
tmp = 1.0;
} else if (y <= 7e+24) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.8e+23: tmp = 1.0 elif y <= 7e+24: tmp = x / (2.0 - x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.8e+23) tmp = 1.0; elseif (y <= 7e+24) tmp = Float64(x / Float64(2.0 - x)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.8e+23) tmp = 1.0; elseif (y <= 7e+24) tmp = x / (2.0 - x); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.8e+23], 1.0, If[LessEqual[y, 7e+24], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+23}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+24}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.8e23 or 7.0000000000000004e24 < y Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 81.8%
if -2.8e23 < y < 7.0000000000000004e24Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 75.0%
Final simplification77.9%
(FPCore (x y) :precision binary64 (if (<= y -1e+17) 1.0 (if (<= y 7e+24) -1.0 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1e+17) {
tmp = 1.0;
} else if (y <= 7e+24) {
tmp = -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 <= (-1d+17)) then
tmp = 1.0d0
else if (y <= 7d+24) then
tmp = -1.0d0
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1e+17) {
tmp = 1.0;
} else if (y <= 7e+24) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1e+17: tmp = 1.0 elif y <= 7e+24: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1e+17) tmp = 1.0; elseif (y <= 7e+24) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1e+17) tmp = 1.0; elseif (y <= 7e+24) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1e+17], 1.0, If[LessEqual[y, 7e+24], -1.0, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+17}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+24}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1e17 or 7.0000000000000004e24 < y Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 81.8%
if -1e17 < y < 7.0000000000000004e24Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 57.6%
Final simplification67.9%
(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}
Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 40.9%
Final simplification40.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (- 2.0 (+ x y)))) (- (/ x t_0) (/ y t_0))))
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
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) {
double t_0 = 2.0 - (x + y);
return (x / t_0) - (y / t_0);
}
def code(x, y): t_0 = 2.0 - (x + y) return (x / t_0) - (y / t_0)
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) t_0 = 2.0 - (x + y); tmp = (x / t_0) - (y / t_0); end
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]]
\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}
herbie shell --seed 2023274
(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))))