
(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 (or (<= (- 1.0 x) -10000.0) (not (<= (- 1.0 x) 2.0))) (- (- x) y) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (((1.0 - x) <= -10000.0) || !((1.0 - x) <= 2.0)) {
tmp = -x - y;
} 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 (((1.0d0 - x) <= (-10000.0d0)) .or. (.not. ((1.0d0 - x) <= 2.0d0))) then
tmp = -x - y
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((1.0 - x) <= -10000.0) || !((1.0 - x) <= 2.0)) {
tmp = -x - y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) <= -10000.0) or not ((1.0 - x) <= 2.0): tmp = -x - y else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((Float64(1.0 - x) <= -10000.0) || !(Float64(1.0 - x) <= 2.0)) tmp = Float64(Float64(-x) - y); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - x) <= -10000.0) || ~(((1.0 - x) <= 2.0))) tmp = -x - y; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(1.0 - x), $MachinePrecision], -10000.0], N[Not[LessEqual[N[(1.0 - x), $MachinePrecision], 2.0]], $MachinePrecision]], N[((-x) - y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq -10000 \lor \neg \left(1 - x \leq 2\right):\\
\;\;\;\;\left(-x\right) - y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if (-.f64 1 x) < -1e4 or 2 < (-.f64 1 x) Initial program 100.0%
flip3--28.5%
div-inv28.4%
fma-neg28.4%
metadata-eval28.4%
metadata-eval28.4%
+-commutative28.4%
distribute-rgt-out28.4%
+-commutative28.4%
fma-def28.4%
Applied egg-rr28.4%
fma-neg28.4%
Simplified28.4%
Taylor expanded in x around inf 99.1%
neg-mul-199.1%
Simplified99.1%
if -1e4 < (-.f64 1 x) < 2Initial program 100.0%
Taylor expanded in x around 0 99.0%
Final simplification99.1%
(FPCore (x y)
:precision binary64
(if (or (<= y -7.2e+102)
(and (not (<= y -7.8e+59)) (or (<= y -24500.0) (not (<= y 7.4e+36)))))
(- y)
(- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -7.2e+102) || (!(y <= -7.8e+59) && ((y <= -24500.0) || !(y <= 7.4e+36)))) {
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 <= (-7.2d+102)) .or. (.not. (y <= (-7.8d+59))) .and. (y <= (-24500.0d0)) .or. (.not. (y <= 7.4d+36))) 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 <= -7.2e+102) || (!(y <= -7.8e+59) && ((y <= -24500.0) || !(y <= 7.4e+36)))) {
tmp = -y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.2e+102) or (not (y <= -7.8e+59) and ((y <= -24500.0) or not (y <= 7.4e+36))): tmp = -y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.2e+102) || (!(y <= -7.8e+59) && ((y <= -24500.0) || !(y <= 7.4e+36)))) tmp = Float64(-y); else tmp = Float64(1.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.2e+102) || (~((y <= -7.8e+59)) && ((y <= -24500.0) || ~((y <= 7.4e+36))))) tmp = -y; else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.2e+102], And[N[Not[LessEqual[y, -7.8e+59]], $MachinePrecision], Or[LessEqual[y, -24500.0], N[Not[LessEqual[y, 7.4e+36]], $MachinePrecision]]]], (-y), N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{+102} \lor \neg \left(y \leq -7.8 \cdot 10^{+59}\right) \land \left(y \leq -24500 \lor \neg \left(y \leq 7.4 \cdot 10^{+36}\right)\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -7.2000000000000003e102 or -7.80000000000000043e59 < y < -24500 or 7.40000000000000058e36 < y Initial program 100.0%
Taylor expanded in y around inf 80.8%
neg-mul-180.8%
Simplified80.8%
if -7.2000000000000003e102 < y < -7.80000000000000043e59 or -24500 < y < 7.40000000000000058e36Initial program 100.0%
Taylor expanded in y around 0 94.7%
Final simplification88.0%
(FPCore (x y) :precision binary64 (if (<= (- 1.0 x) -10000.0) (- 1.0 x) (if (<= (- 1.0 x) 5e+54) (- 1.0 y) (- x))))
double code(double x, double y) {
double tmp;
if ((1.0 - x) <= -10000.0) {
tmp = 1.0 - x;
} else if ((1.0 - x) <= 5e+54) {
tmp = 1.0 - y;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((1.0d0 - x) <= (-10000.0d0)) then
tmp = 1.0d0 - x
else if ((1.0d0 - x) <= 5d+54) then
tmp = 1.0d0 - y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((1.0 - x) <= -10000.0) {
tmp = 1.0 - x;
} else if ((1.0 - x) <= 5e+54) {
tmp = 1.0 - y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (1.0 - x) <= -10000.0: tmp = 1.0 - x elif (1.0 - x) <= 5e+54: tmp = 1.0 - y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (Float64(1.0 - x) <= -10000.0) tmp = Float64(1.0 - x); elseif (Float64(1.0 - x) <= 5e+54) tmp = Float64(1.0 - y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((1.0 - x) <= -10000.0) tmp = 1.0 - x; elseif ((1.0 - x) <= 5e+54) tmp = 1.0 - y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], -10000.0], N[(1.0 - x), $MachinePrecision], If[LessEqual[N[(1.0 - x), $MachinePrecision], 5e+54], N[(1.0 - y), $MachinePrecision], (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq -10000:\\
\;\;\;\;1 - x\\
\mathbf{elif}\;1 - x \leq 5 \cdot 10^{+54}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if (-.f64 1 x) < -1e4Initial program 100.0%
Taylor expanded in y around 0 74.8%
if -1e4 < (-.f64 1 x) < 5.00000000000000005e54Initial program 100.0%
Taylor expanded in x around 0 96.7%
if 5.00000000000000005e54 < (-.f64 1 x) Initial program 100.0%
Taylor expanded in x around inf 80.8%
neg-mul-180.8%
Simplified80.8%
Final simplification88.4%
(FPCore (x y) :precision binary64 (if (or (<= x -1.65e+56) (not (<= x 2.25e+19))) (- x) (- y)))
double code(double x, double y) {
double tmp;
if ((x <= -1.65e+56) || !(x <= 2.25e+19)) {
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 ((x <= (-1.65d+56)) .or. (.not. (x <= 2.25d+19))) then
tmp = -x
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.65e+56) || !(x <= 2.25e+19)) {
tmp = -x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.65e+56) or not (x <= 2.25e+19): tmp = -x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.65e+56) || !(x <= 2.25e+19)) tmp = Float64(-x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.65e+56) || ~((x <= 2.25e+19))) tmp = -x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.65e+56], N[Not[LessEqual[x, 2.25e+19]], $MachinePrecision]], (-x), (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+56} \lor \neg \left(x \leq 2.25 \cdot 10^{+19}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if x < -1.65000000000000001e56 or 2.25e19 < x Initial program 100.0%
Taylor expanded in x around inf 78.5%
neg-mul-178.5%
Simplified78.5%
if -1.65000000000000001e56 < x < 2.25e19Initial program 100.0%
Taylor expanded in y around inf 57.0%
neg-mul-157.0%
Simplified57.0%
Final simplification66.0%
(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 35.8%
neg-mul-135.8%
Simplified35.8%
Final simplification35.8%
herbie shell --seed 2023309
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))