
(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 -50000.0) (- 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 <= -50000.0) {
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 <= (-50000.0d0)) 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 <= -50000.0) {
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 <= -50000.0: 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 <= -50000.0) 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 <= -50000.0) 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, -50000.0], (-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 -50000:\\
\;\;\;\;-y\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if (-.f64 (-.f64 #s(literal 1 binary64) x) y) < -5e4Initial program 100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6446.9
Applied rewrites46.9%
if -5e4 < (-.f64 (-.f64 #s(literal 1 binary64) x) y) < 2Initial program 100.0%
Taylor expanded in y around 0
lower--.f6497.7
Applied rewrites97.7%
Taylor expanded in x around 0
Applied rewrites95.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.f6442.2
Applied rewrites42.2%
(FPCore (x y) :precision binary64 (if (<= (- (- 1.0 x) y) 0.9999999999999951) (- 1.0 y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if (((1.0 - x) - y) <= 0.9999999999999951) {
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.9999999999999951d0) 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.9999999999999951) {
tmp = 1.0 - y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) - y) <= 0.9999999999999951: 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.9999999999999951) 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.9999999999999951) 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.9999999999999951], 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.9999999999999951:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if (-.f64 (-.f64 #s(literal 1 binary64) x) y) < 0.99999999999999512Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites48.4%
if 0.99999999999999512 < (-.f64 (-.f64 #s(literal 1 binary64) x) y) Initial program 100.0%
Taylor expanded in y around 0
lower--.f6465.3
Applied rewrites65.3%
(FPCore (x y) :precision binary64 (if (<= (- (- 1.0 x) y) -50000.0) (- y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if (((1.0 - x) - y) <= -50000.0) {
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) <= (-50000.0d0)) 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) <= -50000.0) {
tmp = -y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) - y) <= -50000.0: tmp = -y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) - y) <= -50000.0) 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) <= -50000.0) 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], -50000.0], (-y), N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) - y \leq -50000:\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if (-.f64 (-.f64 #s(literal 1 binary64) x) y) < -5e4Initial program 100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6446.9
Applied rewrites46.9%
if -5e4 < (-.f64 (-.f64 #s(literal 1 binary64) x) y) Initial program 100.0%
Taylor expanded in y around 0
lower--.f6465.9
Applied rewrites65.9%
(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--.f6472.4
Applied rewrites72.4%
Taylor expanded in x around 0
Applied rewrites40.7%
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.f6442.2
Applied rewrites42.2%
(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--.f6461.6
Applied rewrites61.6%
Taylor expanded in x around 0
Applied rewrites27.2%
herbie shell --seed 2024221
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))