
(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(1.0 - Float64(x + y)) end
function tmp = code(x, y) tmp = 1.0 - (x + y); end
code[x_, y_] := N[(1.0 - N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \left(x + y\right)
\end{array}
Initial program 100.0%
associate--l-100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= x -18500000.0) (- x) (if (or (<= x -1.75e-9) (not (<= x -1.65e-202))) (- y) 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -18500000.0) {
tmp = -x;
} else if ((x <= -1.75e-9) || !(x <= -1.65e-202)) {
tmp = -y;
} 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 <= (-18500000.0d0)) then
tmp = -x
else if ((x <= (-1.75d-9)) .or. (.not. (x <= (-1.65d-202)))) then
tmp = -y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -18500000.0) {
tmp = -x;
} else if ((x <= -1.75e-9) || !(x <= -1.65e-202)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -18500000.0: tmp = -x elif (x <= -1.75e-9) or not (x <= -1.65e-202): tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -18500000.0) tmp = Float64(-x); elseif ((x <= -1.75e-9) || !(x <= -1.65e-202)) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -18500000.0) tmp = -x; elseif ((x <= -1.75e-9) || ~((x <= -1.65e-202))) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -18500000.0], (-x), If[Or[LessEqual[x, -1.75e-9], N[Not[LessEqual[x, -1.65e-202]], $MachinePrecision]], (-y), 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -18500000:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -1.75 \cdot 10^{-9} \lor \neg \left(x \leq -1.65 \cdot 10^{-202}\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.85e7Initial program 100.0%
associate--l-100.0%
Simplified100.0%
Taylor expanded in x around inf 70.3%
mul-1-neg70.3%
Simplified70.3%
if -1.85e7 < x < -1.75e-9 or -1.64999999999999995e-202 < x Initial program 100.0%
associate--l-100.0%
Simplified100.0%
Taylor expanded in y around inf 49.2%
neg-mul-149.2%
Simplified49.2%
if -1.75e-9 < x < -1.64999999999999995e-202Initial program 100.0%
associate--l-100.0%
Simplified100.0%
Taylor expanded in y around 0 55.8%
Taylor expanded in x around 0 55.3%
Final simplification54.2%
(FPCore (x y) :precision binary64 (if (<= y 1.26e-6) (- 1.0 x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (y <= 1.26e-6) {
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 <= 1.26d-6) 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 <= 1.26e-6) {
tmp = 1.0 - x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.26e-6: tmp = 1.0 - x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.26e-6) 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 <= 1.26e-6) tmp = 1.0 - x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.26e-6], N[(1.0 - x), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.26 \cdot 10^{-6}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if y < 1.26000000000000001e-6Initial program 100.0%
associate--l-100.0%
Simplified100.0%
Taylor expanded in y around 0 70.3%
if 1.26000000000000001e-6 < y Initial program 100.0%
associate--l-100.0%
Simplified100.0%
Taylor expanded in x around 0 83.3%
(FPCore (x y) :precision binary64 (if (<= y 3.3e+16) (- 1.0 x) (- y)))
double code(double x, double y) {
double tmp;
if (y <= 3.3e+16) {
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 <= 3.3d+16) 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 <= 3.3e+16) {
tmp = 1.0 - x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.3e+16: tmp = 1.0 - x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= 3.3e+16) tmp = Float64(1.0 - x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.3e+16) tmp = 1.0 - x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.3e+16], N[(1.0 - x), $MachinePrecision], (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.3 \cdot 10^{+16}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 3.3e16Initial program 100.0%
associate--l-100.0%
Simplified100.0%
Taylor expanded in y around 0 69.8%
if 3.3e16 < y Initial program 100.0%
associate--l-100.0%
Simplified100.0%
Taylor expanded in y around inf 85.1%
neg-mul-185.1%
Simplified85.1%
(FPCore (x y) :precision binary64 (if (<= x -28.0) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (x <= -28.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 <= (-28.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 <= -28.0) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -28.0: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -28.0) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -28.0) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -28.0], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -28:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -28Initial program 100.0%
associate--l-100.0%
Simplified100.0%
Taylor expanded in x around inf 68.9%
mul-1-neg68.9%
Simplified68.9%
if -28 < x Initial program 100.0%
associate--l-100.0%
Simplified100.0%
Taylor expanded in y around 0 52.3%
Taylor expanded in x around 0 28.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%
associate--l-100.0%
Simplified100.0%
Taylor expanded in y around 0 55.7%
Taylor expanded in x around 0 23.9%
herbie shell --seed 2024177
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))