
(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 (let* ((t_0 (- (- 1.0 x) y))) (if (<= t_0 -4e+18) (- y) (if (<= t_0 2.0) 1.0 (- x)))))
double code(double x, double y) {
double t_0 = (1.0 - x) - y;
double tmp;
if (t_0 <= -4e+18) {
tmp = -y;
} else if (t_0 <= 2.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = (1.0d0 - x) - y
if (t_0 <= (-4d+18)) then
tmp = -y
else if (t_0 <= 2.0d0) then
tmp = 1.0d0
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (1.0 - x) - y;
double tmp;
if (t_0 <= -4e+18) {
tmp = -y;
} else if (t_0 <= 2.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): t_0 = (1.0 - x) - y tmp = 0 if t_0 <= -4e+18: tmp = -y elif t_0 <= 2.0: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) t_0 = Float64(Float64(1.0 - x) - y) tmp = 0.0 if (t_0 <= -4e+18) tmp = Float64(-y); elseif (t_0 <= 2.0) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) t_0 = (1.0 - x) - y; tmp = 0.0; if (t_0 <= -4e+18) tmp = -y; elseif (t_0 <= 2.0) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[t$95$0, -4e+18], (-y), If[LessEqual[t$95$0, 2.0], 1.0, (-x)]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) - y\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{+18}:\\
\;\;\;\;-y\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if (-.f64 (-.f64 #s(literal 1 binary64) x) y) < -4e18Initial program 100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6450.0
Applied rewrites50.0%
if -4e18 < (-.f64 (-.f64 #s(literal 1 binary64) x) y) < 2Initial program 100.0%
Taylor expanded in y around 0
lower--.f6497.2
Applied rewrites97.2%
Taylor expanded in x around 0
Applied rewrites95.1%
if 2 < (-.f64 (-.f64 #s(literal 1 binary64) x) y) Initial program 100.0%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6449.0
Applied rewrites49.0%
(FPCore (x y) :precision binary64 (if (<= (- (- 1.0 x) y) 0.9999999999999999) (- 1.0 y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if (((1.0 - x) - y) <= 0.9999999999999999) {
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) - y) <= 0.9999999999999999d0) 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) - y) <= 0.9999999999999999) {
tmp = 1.0 - y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) - y) <= 0.9999999999999999: tmp = 1.0 - y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) - y) <= 0.9999999999999999) 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) - y) <= 0.9999999999999999) tmp = 1.0 - y; else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] - y), $MachinePrecision], 0.9999999999999999], N[(1.0 - y), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) - y \leq 0.9999999999999999:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if (-.f64 (-.f64 #s(literal 1 binary64) x) y) < 0.999999999999999889Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites51.6%
if 0.999999999999999889 < (-.f64 (-.f64 #s(literal 1 binary64) x) y) Initial program 100.0%
Taylor expanded in y around 0
lower--.f6471.3
Applied rewrites71.3%
(FPCore (x y) :precision binary64 (if (<= (- (- 1.0 x) y) -4e+18) (- y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if (((1.0 - x) - y) <= -4e+18) {
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 (((1.0d0 - x) - y) <= (-4d+18)) 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 (((1.0 - x) - y) <= -4e+18) {
tmp = -y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) - y) <= -4e+18: tmp = -y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) - y) <= -4e+18) tmp = Float64(-y); else tmp = Float64(1.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - x) - y) <= -4e+18) tmp = -y; else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] - y), $MachinePrecision], -4e+18], (-y), N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) - y \leq -4 \cdot 10^{+18}:\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if (-.f64 (-.f64 #s(literal 1 binary64) x) y) < -4e18Initial program 100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6450.0
Applied rewrites50.0%
if -4e18 < (-.f64 (-.f64 #s(literal 1 binary64) x) y) Initial program 100.0%
Taylor expanded in y around 0
lower--.f6471.8
Applied rewrites71.8%
(FPCore (x y) :precision binary64 (if (<= (- (- 1.0 x) y) 2.0) 1.0 (- x)))
double code(double x, double y) {
double tmp;
if (((1.0 - x) - y) <= 2.0) {
tmp = 1.0;
} 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) - y) <= 2.0d0) then
tmp = 1.0d0
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((1.0 - x) - y) <= 2.0) {
tmp = 1.0;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) - y) <= 2.0: tmp = 1.0 else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) - y) <= 2.0) tmp = 1.0; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - x) - y) <= 2.0) tmp = 1.0; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] - y), $MachinePrecision], 2.0], 1.0, (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) - y \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if (-.f64 (-.f64 #s(literal 1 binary64) x) y) < 2Initial program 100.0%
Taylor expanded in y around 0
lower--.f6474.1
Applied rewrites74.1%
Taylor expanded in x around 0
Applied rewrites47.2%
if 2 < (-.f64 (-.f64 #s(literal 1 binary64) x) y) Initial program 100.0%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6449.0
Applied rewrites49.0%
(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 y around 0
lower--.f6465.4
Applied rewrites65.4%
Taylor expanded in x around 0
Applied rewrites31.5%
herbie shell --seed 2024226
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))