
(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 7 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 -20000.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 <= -20000.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 <= (-20000.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 <= -20000.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 <= -20000.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 <= -20000.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 <= -20000.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, -20000.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 -20000:\\
\;\;\;\;-y\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if (-.f64 (-.f64 #s(literal 1 binary64) x) y) < -2e4Initial program 100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6449.7
Applied rewrites49.7%
if -2e4 < (-.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 rewrites94.9%
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.3
Applied rewrites49.3%
herbie shell --seed 2024230
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))