
(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 4 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 -2.3e+163)
1.0
(if (<= y -1.5e+146)
-1.0
(if (<= y -1.08e+43) 1.0 (if (<= y 1.9e+65) (/ x (- 2.0 x)) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2.3e+163) {
tmp = 1.0;
} else if (y <= -1.5e+146) {
tmp = -1.0;
} else if (y <= -1.08e+43) {
tmp = 1.0;
} else if (y <= 1.9e+65) {
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.3d+163)) then
tmp = 1.0d0
else if (y <= (-1.5d+146)) then
tmp = -1.0d0
else if (y <= (-1.08d+43)) then
tmp = 1.0d0
else if (y <= 1.9d+65) 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.3e+163) {
tmp = 1.0;
} else if (y <= -1.5e+146) {
tmp = -1.0;
} else if (y <= -1.08e+43) {
tmp = 1.0;
} else if (y <= 1.9e+65) {
tmp = x / (2.0 - x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.3e+163: tmp = 1.0 elif y <= -1.5e+146: tmp = -1.0 elif y <= -1.08e+43: tmp = 1.0 elif y <= 1.9e+65: tmp = x / (2.0 - x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.3e+163) tmp = 1.0; elseif (y <= -1.5e+146) tmp = -1.0; elseif (y <= -1.08e+43) tmp = 1.0; elseif (y <= 1.9e+65) 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.3e+163) tmp = 1.0; elseif (y <= -1.5e+146) tmp = -1.0; elseif (y <= -1.08e+43) tmp = 1.0; elseif (y <= 1.9e+65) tmp = x / (2.0 - x); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.3e+163], 1.0, If[LessEqual[y, -1.5e+146], -1.0, If[LessEqual[y, -1.08e+43], 1.0, If[LessEqual[y, 1.9e+65], N[(x / N[(2.0 - x), $MachinePrecision]), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+163}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.5 \cdot 10^{+146}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq -1.08 \cdot 10^{+43}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+65}:\\
\;\;\;\;\frac{x}{2 - x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.30000000000000002e163 or -1.50000000000000001e146 < y < -1.08e43 or 1.90000000000000006e65 < y Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 89.6%
if -2.30000000000000002e163 < y < -1.50000000000000001e146Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -1.08e43 < y < 1.90000000000000006e65Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around 0 72.6%
Final simplification79.8%
(FPCore (x y)
:precision binary64
(if (<= y -2.3e+163)
1.0
(if (<= y -1.5e+146)
-1.0
(if (<= y -2e+44) 1.0 (if (<= y 8.5e+57) -1.0 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2.3e+163) {
tmp = 1.0;
} else if (y <= -1.5e+146) {
tmp = -1.0;
} else if (y <= -2e+44) {
tmp = 1.0;
} else if (y <= 8.5e+57) {
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 <= (-2.3d+163)) then
tmp = 1.0d0
else if (y <= (-1.5d+146)) then
tmp = -1.0d0
else if (y <= (-2d+44)) then
tmp = 1.0d0
else if (y <= 8.5d+57) 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 <= -2.3e+163) {
tmp = 1.0;
} else if (y <= -1.5e+146) {
tmp = -1.0;
} else if (y <= -2e+44) {
tmp = 1.0;
} else if (y <= 8.5e+57) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.3e+163: tmp = 1.0 elif y <= -1.5e+146: tmp = -1.0 elif y <= -2e+44: tmp = 1.0 elif y <= 8.5e+57: tmp = -1.0 else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.3e+163) tmp = 1.0; elseif (y <= -1.5e+146) tmp = -1.0; elseif (y <= -2e+44) tmp = 1.0; elseif (y <= 8.5e+57) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.3e+163) tmp = 1.0; elseif (y <= -1.5e+146) tmp = -1.0; elseif (y <= -2e+44) tmp = 1.0; elseif (y <= 8.5e+57) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.3e+163], 1.0, If[LessEqual[y, -1.5e+146], -1.0, If[LessEqual[y, -2e+44], 1.0, If[LessEqual[y, 8.5e+57], -1.0, 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+163}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.5 \cdot 10^{+146}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq -2 \cdot 10^{+44}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+57}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.30000000000000002e163 or -1.50000000000000001e146 < y < -2.0000000000000002e44 or 8.5000000000000001e57 < y Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in y around inf 88.9%
if -2.30000000000000002e163 < y < -1.50000000000000001e146 or -2.0000000000000002e44 < y < 8.5000000000000001e57Initial program 100.0%
associate--r+100.0%
Simplified100.0%
Taylor expanded in x around inf 55.4%
Final simplification68.8%
(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 37.6%
Final simplification37.6%
(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 2023271
(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))))