
(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 (<= (- 1.0 x) 2.0) (- 1.0 y) (- (- y) x)))
double code(double x, double y) {
double tmp;
if ((1.0 - x) <= 2.0) {
tmp = 1.0 - y;
} else {
tmp = -y - 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) <= 2.0d0) then
tmp = 1.0d0 - y
else
tmp = -y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((1.0 - x) <= 2.0) {
tmp = 1.0 - y;
} else {
tmp = -y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (1.0 - x) <= 2.0: tmp = 1.0 - y else: tmp = -y - x return tmp
function code(x, y) tmp = 0.0 if (Float64(1.0 - x) <= 2.0) tmp = Float64(1.0 - y); else tmp = Float64(Float64(-y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((1.0 - x) <= 2.0) tmp = 1.0 - y; else tmp = -y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 2.0], N[(1.0 - y), $MachinePrecision], N[((-y) - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 2:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) - x\\
\end{array}
\end{array}
if (-.f64 1 x) < 2Initial program 100.0%
Taylor expanded in x around 0 76.3%
if 2 < (-.f64 1 x) Initial program 100.0%
flip3--20.9%
pow220.9%
distribute-rgt-out20.9%
+-commutative20.9%
Applied egg-rr20.9%
unpow220.9%
+-commutative20.9%
distribute-rgt-in20.9%
flip3--100.0%
flip3--28.2%
div-inv28.2%
fma-neg28.2%
metadata-eval28.2%
metadata-eval28.2%
*-un-lft-identity28.2%
fma-def28.2%
Applied egg-rr28.2%
Taylor expanded in x around inf 27.5%
unpow227.5%
associate-/r*27.7%
Simplified27.7%
Taylor expanded in x around inf 99.3%
neg-mul-199.3%
+-commutative99.3%
sub-neg99.3%
mul-1-neg99.3%
Simplified99.3%
Final simplification81.5%
(FPCore (x y) :precision binary64 (if (<= (- 1.0 x) 1.000000001) (- 1.0 y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((1.0 - x) <= 1.000000001) {
tmp = 1.0 - 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 ((1.0d0 - x) <= 1.000000001d0) then
tmp = 1.0d0 - y
else
tmp = 1.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((1.0 - x) <= 1.000000001) {
tmp = 1.0 - y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (1.0 - x) <= 1.000000001: tmp = 1.0 - y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if (Float64(1.0 - x) <= 1.000000001) tmp = Float64(1.0 - y); else tmp = Float64(1.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((1.0 - x) <= 1.000000001) tmp = 1.0 - y; else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 1.000000001], N[(1.0 - y), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 1.000000001:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if (-.f64 1 x) < 1.0000000010000001Initial program 100.0%
Taylor expanded in x around 0 76.4%
if 1.0000000010000001 < (-.f64 1 x) Initial program 100.0%
Taylor expanded in y around 0 73.4%
Final simplification75.7%
(FPCore (x y) :precision binary64 (if (<= y 14000.0) (- 1.0 x) (- y)))
double code(double x, double y) {
double tmp;
if (y <= 14000.0) {
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 <= 14000.0d0) 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 <= 14000.0) {
tmp = 1.0 - x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 14000.0: tmp = 1.0 - x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= 14000.0) tmp = Float64(1.0 - x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 14000.0) tmp = 1.0 - x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 14000.0], N[(1.0 - x), $MachinePrecision], (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 14000:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 14000Initial program 100.0%
Taylor expanded in y around 0 70.1%
if 14000 < y Initial program 100.0%
Taylor expanded in y around inf 76.6%
neg-mul-176.6%
Simplified76.6%
Final simplification71.8%
(FPCore (x y) :precision binary64 (if (<= x -1.46e-9) (- x) (- y)))
double code(double x, double y) {
double tmp;
if (x <= -1.46e-9) {
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.46d-9)) 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.46e-9) {
tmp = -x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.46e-9: tmp = -x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.46e-9) tmp = Float64(-x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.46e-9) tmp = -x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.46e-9], (-x), (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.46 \cdot 10^{-9}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if x < -1.4599999999999999e-9Initial program 100.0%
Taylor expanded in x around inf 71.2%
neg-mul-171.2%
Simplified71.2%
if -1.4599999999999999e-9 < x Initial program 100.0%
Taylor expanded in y around inf 47.5%
neg-mul-147.5%
Simplified47.5%
Final simplification53.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 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))