
(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%
(FPCore (x y) :precision binary64 (if (<= x -1.6e+32) (- x) (if (or (<= x -0.032) (not (<= x -1.08e-228))) (- y) 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.6e+32) {
tmp = -x;
} else if ((x <= -0.032) || !(x <= -1.08e-228)) {
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 <= (-1.6d+32)) then
tmp = -x
else if ((x <= (-0.032d0)) .or. (.not. (x <= (-1.08d-228)))) 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 <= -1.6e+32) {
tmp = -x;
} else if ((x <= -0.032) || !(x <= -1.08e-228)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.6e+32: tmp = -x elif (x <= -0.032) or not (x <= -1.08e-228): tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.6e+32) tmp = Float64(-x); elseif ((x <= -0.032) || !(x <= -1.08e-228)) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.6e+32) tmp = -x; elseif ((x <= -0.032) || ~((x <= -1.08e-228))) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.6e+32], (-x), If[Or[LessEqual[x, -0.032], N[Not[LessEqual[x, -1.08e-228]], $MachinePrecision]], (-y), 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+32}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -0.032 \lor \neg \left(x \leq -1.08 \cdot 10^{-228}\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.5999999999999999e32Initial program 100.0%
Taylor expanded in x around inf 76.7%
neg-mul-176.7%
Simplified76.7%
if -1.5999999999999999e32 < x < -0.032000000000000001 or -1.0799999999999999e-228 < x Initial program 100.0%
Taylor expanded in y around inf 41.8%
neg-mul-141.8%
Simplified41.8%
if -0.032000000000000001 < x < -1.0799999999999999e-228Initial program 100.0%
Taylor expanded in x around 0 99.6%
Taylor expanded in y around 0 44.7%
Final simplification50.4%
(FPCore (x y) :precision binary64 (if (<= (- 1.0 x) 5e+31) (- 1.0 y) (- x)))
double code(double x, double y) {
double tmp;
if ((1.0 - x) <= 5e+31) {
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) <= 5d+31) 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) <= 5e+31) {
tmp = 1.0 - y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (1.0 - x) <= 5e+31: tmp = 1.0 - y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (Float64(1.0 - x) <= 5e+31) 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) <= 5e+31) tmp = 1.0 - y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 5e+31], N[(1.0 - y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 5 \cdot 10^{+31}:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) x) < 5.00000000000000027e31Initial program 100.0%
Taylor expanded in x around 0 74.6%
if 5.00000000000000027e31 < (-.f64 #s(literal 1 binary64) x) Initial program 100.0%
Taylor expanded in x around inf 76.7%
neg-mul-176.7%
Simplified76.7%
(FPCore (x y) :precision binary64 (if (<= y 7.2e+29) (- 1.0 x) (- y)))
double code(double x, double y) {
double tmp;
if (y <= 7.2e+29) {
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 <= 7.2d+29) 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 <= 7.2e+29) {
tmp = 1.0 - x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 7.2e+29: tmp = 1.0 - x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= 7.2e+29) tmp = Float64(1.0 - x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 7.2e+29) tmp = 1.0 - x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 7.2e+29], N[(1.0 - x), $MachinePrecision], (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.2 \cdot 10^{+29}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 7.19999999999999952e29Initial program 100.0%
Taylor expanded in y around 0 69.9%
if 7.19999999999999952e29 < y Initial program 100.0%
Taylor expanded in y around inf 72.5%
neg-mul-172.5%
Simplified72.5%
(FPCore (x y) :precision binary64 (if (<= x -14000000000000.0) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (x <= -14000000000000.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 <= (-14000000000000.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 <= -14000000000000.0) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -14000000000000.0: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -14000000000000.0) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -14000000000000.0) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -14000000000000.0], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -14000000000000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.4e13Initial program 100.0%
Taylor expanded in x around inf 72.8%
neg-mul-172.8%
Simplified72.8%
if -1.4e13 < x Initial program 100.0%
Taylor expanded in x around 0 74.7%
Taylor expanded in y around 0 31.1%
(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%
Taylor expanded in x around 0 62.9%
Taylor expanded in y around 0 24.3%
herbie shell --seed 2024139
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))