
(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 3.2e-179) (- x) (if (<= y 1.0) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= 3.2e-179) {
tmp = -x;
} else if (y <= 1.0) {
tmp = 1.0;
} 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.2d-179) then
tmp = -x
else if (y <= 1.0d0) then
tmp = 1.0d0
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.2e-179) {
tmp = -x;
} else if (y <= 1.0) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.2e-179: tmp = -x elif y <= 1.0: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= 3.2e-179) tmp = Float64(-x); elseif (y <= 1.0) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.2e-179) tmp = -x; elseif (y <= 1.0) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.2e-179], (-x), If[LessEqual[y, 1.0], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{-179}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 3.2000000000000001e-179Initial program 100.0%
Taylor expanded in x around inf 45.7%
neg-mul-145.7%
Simplified45.7%
if 3.2000000000000001e-179 < y < 1Initial program 100.0%
associate--l-100.0%
flip3--49.2%
metadata-eval49.2%
metadata-eval49.2%
*-un-lft-identity49.2%
Applied egg-rr49.2%
+-commutative49.2%
distribute-lft1-in49.2%
+-commutative49.2%
associate-+r+49.2%
+-commutative49.2%
Simplified49.2%
Taylor expanded in x around 0 41.7%
Taylor expanded in y around 0 36.6%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 69.4%
neg-mul-169.4%
Simplified69.4%
Final simplification50.0%
(FPCore (x y) :precision binary64 (if (<= y 2.5e+36) (- 1.0 x) (- y)))
double code(double x, double y) {
double tmp;
if (y <= 2.5e+36) {
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 <= 2.5d+36) 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 <= 2.5e+36) {
tmp = 1.0 - x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.5e+36: tmp = 1.0 - x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.5e+36) tmp = Float64(1.0 - x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.5e+36) tmp = 1.0 - x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.5e+36], N[(1.0 - x), $MachinePrecision], (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.5 \cdot 10^{+36}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 2.49999999999999988e36Initial program 100.0%
Taylor expanded in y around 0 74.7%
if 2.49999999999999988e36 < y Initial program 100.0%
Taylor expanded in y around inf 75.6%
neg-mul-175.6%
Simplified75.6%
Final simplification74.9%
(FPCore (x y) :precision binary64 (if (<= y 1.7e-7) (- 1.0 x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (y <= 1.7e-7) {
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.7d-7) 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.7e-7) {
tmp = 1.0 - x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.7e-7: tmp = 1.0 - x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.7e-7) 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.7e-7) tmp = 1.0 - x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.7e-7], N[(1.0 - x), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.7 \cdot 10^{-7}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if y < 1.69999999999999987e-7Initial program 100.0%
Taylor expanded in y around 0 75.6%
if 1.69999999999999987e-7 < y Initial program 100.0%
Taylor expanded in x around 0 71.9%
Final simplification74.7%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (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)) 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) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (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) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 71.1%
neg-mul-171.1%
Simplified71.1%
if -1 < x Initial program 100.0%
associate--l-100.0%
flip3--45.2%
metadata-eval45.2%
metadata-eval45.2%
*-un-lft-identity45.2%
Applied egg-rr45.2%
+-commutative45.2%
distribute-lft1-in45.2%
+-commutative45.2%
associate-+r+45.2%
+-commutative45.2%
Simplified45.2%
Taylor expanded in x around 0 37.8%
Taylor expanded in y around 0 28.3%
Final simplification39.8%
(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%
flip3--38.4%
metadata-eval38.4%
metadata-eval38.4%
*-un-lft-identity38.4%
Applied egg-rr38.4%
+-commutative38.4%
distribute-lft1-in38.4%
+-commutative38.4%
associate-+r+38.4%
+-commutative38.4%
Simplified38.4%
Taylor expanded in x around 0 28.9%
Taylor expanded in y around 0 21.8%
Final simplification21.8%
herbie shell --seed 2023230
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))