
(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 6 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 -4.2e+36)
(- y)
(if (<= y 2.1e-210)
(- x)
(if (<= y 1.45e-171) 1.0 (if (<= y 2.6e+14) (- x) (- y))))))
double code(double x, double y) {
double tmp;
if (y <= -4.2e+36) {
tmp = -y;
} else if (y <= 2.1e-210) {
tmp = -x;
} else if (y <= 1.45e-171) {
tmp = 1.0;
} else if (y <= 2.6e+14) {
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 <= (-4.2d+36)) then
tmp = -y
else if (y <= 2.1d-210) then
tmp = -x
else if (y <= 1.45d-171) then
tmp = 1.0d0
else if (y <= 2.6d+14) then
tmp = -x
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.2e+36) {
tmp = -y;
} else if (y <= 2.1e-210) {
tmp = -x;
} else if (y <= 1.45e-171) {
tmp = 1.0;
} else if (y <= 2.6e+14) {
tmp = -x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.2e+36: tmp = -y elif y <= 2.1e-210: tmp = -x elif y <= 1.45e-171: tmp = 1.0 elif y <= 2.6e+14: tmp = -x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.2e+36) tmp = Float64(-y); elseif (y <= 2.1e-210) tmp = Float64(-x); elseif (y <= 1.45e-171) tmp = 1.0; elseif (y <= 2.6e+14) tmp = Float64(-x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.2e+36) tmp = -y; elseif (y <= 2.1e-210) tmp = -x; elseif (y <= 1.45e-171) tmp = 1.0; elseif (y <= 2.6e+14) tmp = -x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.2e+36], (-y), If[LessEqual[y, 2.1e-210], (-x), If[LessEqual[y, 1.45e-171], 1.0, If[LessEqual[y, 2.6e+14], (-x), (-y)]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+36}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-210}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-171}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{+14}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -4.20000000000000009e36 or 2.6e14 < y Initial program 100.0%
Taylor expanded in y around inf 84.0%
mul-1-neg84.0%
Simplified84.0%
if -4.20000000000000009e36 < y < 2.10000000000000016e-210 or 1.4499999999999999e-171 < y < 2.6e14Initial program 100.0%
Taylor expanded in x around inf 62.4%
mul-1-neg62.4%
Simplified62.4%
if 2.10000000000000016e-210 < y < 1.4499999999999999e-171Initial program 100.0%
flip--100.0%
clear-num100.0%
clear-num100.0%
flip--100.0%
associate--l-100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 80.8%
Final simplification73.7%
(FPCore (x y) :precision binary64 (if (or (<= y -5e+38) (not (<= y 4.3e+23))) (- y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -5e+38) || !(y <= 4.3e+23)) {
tmp = -y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-5d+38)) .or. (.not. (y <= 4.3d+23))) then
tmp = -y
else
tmp = 1.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -5e+38) || !(y <= 4.3e+23)) {
tmp = -y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5e+38) or not (y <= 4.3e+23): tmp = -y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -5e+38) || !(y <= 4.3e+23)) tmp = Float64(-y); else tmp = Float64(1.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -5e+38) || ~((y <= 4.3e+23))) tmp = -y; else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5e+38], N[Not[LessEqual[y, 4.3e+23]], $MachinePrecision]], (-y), N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+38} \lor \neg \left(y \leq 4.3 \cdot 10^{+23}\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -4.9999999999999997e38 or 4.2999999999999999e23 < y Initial program 100.0%
Taylor expanded in y around inf 84.0%
mul-1-neg84.0%
Simplified84.0%
if -4.9999999999999997e38 < y < 4.2999999999999999e23Initial program 100.0%
Taylor expanded in y around 0 96.9%
Final simplification90.6%
(FPCore (x y) :precision binary64 (if (<= y -2.6e+35) (- y) (if (<= y 6e+23) (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
double tmp;
if (y <= -2.6e+35) {
tmp = -y;
} else if (y <= 6e+23) {
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 <= (-2.6d+35)) then
tmp = -y
else if (y <= 6d+23) 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 <= -2.6e+35) {
tmp = -y;
} else if (y <= 6e+23) {
tmp = 1.0 - x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.6e+35: tmp = -y elif y <= 6e+23: tmp = 1.0 - x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.6e+35) tmp = Float64(-y); elseif (y <= 6e+23) 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 <= -2.6e+35) tmp = -y; elseif (y <= 6e+23) tmp = 1.0 - x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.6e+35], (-y), If[LessEqual[y, 6e+23], N[(1.0 - x), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+35}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+23}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if y < -2.60000000000000007e35Initial program 100.0%
Taylor expanded in y around inf 83.7%
mul-1-neg83.7%
Simplified83.7%
if -2.60000000000000007e35 < y < 6.0000000000000002e23Initial program 100.0%
Taylor expanded in y around 0 96.9%
if 6.0000000000000002e23 < y Initial program 100.0%
Taylor expanded in x around 0 84.3%
Final simplification90.6%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (- x) 1.0))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -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 ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = -x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 69.3%
mul-1-neg69.3%
Simplified69.3%
if -1 < x < 1Initial program 100.0%
flip--71.6%
clear-num71.5%
clear-num71.5%
flip--99.8%
associate--l-99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 43.6%
Taylor expanded in x around 0 41.9%
Final simplification56.6%
(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%
flip--54.3%
clear-num54.2%
clear-num54.2%
flip--99.8%
associate--l-99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 57.7%
Taylor expanded in x around 0 20.9%
Final simplification20.9%
herbie shell --seed 2023326
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))