
(FPCore (x y) :precision binary64 (- (- 1.0 x) y))
double code(double x, double y) {
return (1.0 - x) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) - y
end function
public static double code(double x, double y) {
return (1.0 - x) - y;
}
def code(x, y): return (1.0 - x) - y
function code(x, y) return Float64(Float64(1.0 - x) - y) end
function tmp = code(x, y) tmp = (1.0 - x) - y; end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) - y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (- 1.0 x) y))
double code(double x, double y) {
return (1.0 - x) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) - y
end function
public static double code(double x, double y) {
return (1.0 - x) - y;
}
def code(x, y): return (1.0 - x) - y
function code(x, y) return Float64(Float64(1.0 - x) - y) end
function tmp = code(x, y) tmp = (1.0 - x) - y; end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) - y
\end{array}
(FPCore (x y) :precision binary64 (- (- 1.0 x) y))
double code(double x, double y) {
return (1.0 - x) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) - y
end function
public static double code(double x, double y) {
return (1.0 - x) - y;
}
def code(x, y): return (1.0 - x) - y
function code(x, y) return Float64(Float64(1.0 - x) - y) end
function tmp = code(x, y) tmp = (1.0 - x) - y; end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) - y
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -3e+15) (- y) (if (<= y 6.8e+41) (- 1.0 x) (- y))))
double code(double x, double y) {
double tmp;
if (y <= -3e+15) {
tmp = -y;
} else if (y <= 6.8e+41) {
tmp = 1.0 - x;
} 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 <= (-3d+15)) then
tmp = -y
else if (y <= 6.8d+41) then
tmp = 1.0d0 - x
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3e+15) {
tmp = -y;
} else if (y <= 6.8e+41) {
tmp = 1.0 - x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3e+15: tmp = -y elif y <= 6.8e+41: tmp = 1.0 - x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -3e+15) tmp = Float64(-y); elseif (y <= 6.8e+41) tmp = Float64(1.0 - x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3e+15) tmp = -y; elseif (y <= 6.8e+41) tmp = 1.0 - x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3e+15], (-y), If[LessEqual[y, 6.8e+41], N[(1.0 - x), $MachinePrecision], (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+15}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{+41}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -3e15 or 6.79999999999999996e41 < y Initial program 100.0%
Taylor expanded in y around inf 79.1%
neg-mul-179.1%
Simplified79.1%
if -3e15 < y < 6.79999999999999996e41Initial program 100.0%
Taylor expanded in y around 0 99.2%
Final simplification89.3%
(FPCore (x y) :precision binary64 (if (<= y -4.2e+15) (- 1.0 y) (if (<= y 3e+40) (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
double tmp;
if (y <= -4.2e+15) {
tmp = 1.0 - y;
} else if (y <= 3e+40) {
tmp = 1.0 - x;
} else {
tmp = 1.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 <= (-4.2d+15)) then
tmp = 1.0d0 - y
else if (y <= 3d+40) then
tmp = 1.0d0 - x
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.2e+15) {
tmp = 1.0 - y;
} else if (y <= 3e+40) {
tmp = 1.0 - x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.2e+15: tmp = 1.0 - y elif y <= 3e+40: tmp = 1.0 - x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.2e+15) tmp = Float64(1.0 - y); elseif (y <= 3e+40) tmp = Float64(1.0 - x); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.2e+15) tmp = 1.0 - y; elseif (y <= 3e+40) tmp = 1.0 - x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.2e+15], N[(1.0 - y), $MachinePrecision], If[LessEqual[y, 3e+40], N[(1.0 - x), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+15}:\\
\;\;\;\;1 - y\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+40}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if y < -4.2e15 or 3.0000000000000002e40 < y Initial program 100.0%
Taylor expanded in x around 0 79.1%
if -4.2e15 < y < 3.0000000000000002e40Initial program 100.0%
Taylor expanded in y around 0 99.2%
Final simplification89.3%
(FPCore (x y) :precision binary64 (if (<= y -8.4e+15) (- y) (if (<= y 3.1e+38) (- x) (- y))))
double code(double x, double y) {
double tmp;
if (y <= -8.4e+15) {
tmp = -y;
} else if (y <= 3.1e+38) {
tmp = -x;
} 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 <= (-8.4d+15)) then
tmp = -y
else if (y <= 3.1d+38) then
tmp = -x
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -8.4e+15) {
tmp = -y;
} else if (y <= 3.1e+38) {
tmp = -x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8.4e+15: tmp = -y elif y <= 3.1e+38: tmp = -x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -8.4e+15) tmp = Float64(-y); elseif (y <= 3.1e+38) tmp = Float64(-x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -8.4e+15) tmp = -y; elseif (y <= 3.1e+38) tmp = -x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8.4e+15], (-y), If[LessEqual[y, 3.1e+38], (-x), (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{+15}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+38}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -8.4e15 or 3.10000000000000018e38 < y Initial program 100.0%
Taylor expanded in y around inf 79.1%
neg-mul-179.1%
Simplified79.1%
if -8.4e15 < y < 3.10000000000000018e38Initial program 100.0%
Taylor expanded in x around inf 49.5%
neg-mul-149.5%
Simplified49.5%
Final simplification64.1%
(FPCore (x y) :precision binary64 (- x))
double code(double x, double y) {
return -x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x
end function
public static double code(double x, double y) {
return -x;
}
def code(x, y): return -x
function code(x, y) return Float64(-x) end
function tmp = code(x, y) tmp = -x; end
code[x_, y_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 36.4%
neg-mul-136.4%
Simplified36.4%
Final simplification36.4%
herbie shell --seed 2023181
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))