
(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 5 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 (or (<= (- 1.0 x) -50000000.0) (not (<= (- 1.0 x) 1.0))) (- (- x) y) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (((1.0 - x) <= -50000000.0) || !((1.0 - x) <= 1.0)) {
tmp = -x - y;
} 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 (((1.0d0 - x) <= (-50000000.0d0)) .or. (.not. ((1.0d0 - x) <= 1.0d0))) then
tmp = -x - y
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((1.0 - x) <= -50000000.0) || !((1.0 - x) <= 1.0)) {
tmp = -x - y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) <= -50000000.0) or not ((1.0 - x) <= 1.0): tmp = -x - y else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((Float64(1.0 - x) <= -50000000.0) || !(Float64(1.0 - x) <= 1.0)) tmp = Float64(Float64(-x) - y); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - x) <= -50000000.0) || ~(((1.0 - x) <= 1.0))) tmp = -x - y; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(1.0 - x), $MachinePrecision], -50000000.0], N[Not[LessEqual[N[(1.0 - x), $MachinePrecision], 1.0]], $MachinePrecision]], N[((-x) - y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq -50000000 \lor \neg \left(1 - x \leq 1\right):\\
\;\;\;\;\left(-x\right) - y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if (-.f64 1 x) < -5e7 or 1 < (-.f64 1 x) Initial program 100.0%
flip--51.8%
div-inv51.7%
fma-neg51.7%
metadata-eval51.7%
pow251.7%
Applied egg-rr51.7%
Taylor expanded in x around inf 51.1%
Taylor expanded in x around inf 99.5%
mul-1-neg99.5%
unsub-neg99.5%
mul-1-neg99.5%
Simplified99.5%
if -5e7 < (-.f64 1 x) < 1Initial program 100.0%
Taylor expanded in x around 0 99.5%
Final simplification99.5%
(FPCore (x y) :precision binary64 (if (or (<= y -4.4e+25) (not (<= y 6e+31))) (- y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -4.4e+25) || !(y <= 6e+31)) {
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 ((y <= (-4.4d+25)) .or. (.not. (y <= 6d+31))) 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 ((y <= -4.4e+25) || !(y <= 6e+31)) {
tmp = -y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.4e+25) or not (y <= 6e+31): tmp = -y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.4e+25) || !(y <= 6e+31)) tmp = Float64(-y); else tmp = Float64(1.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4.4e+25) || ~((y <= 6e+31))) tmp = -y; else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.4e+25], N[Not[LessEqual[y, 6e+31]], $MachinePrecision]], (-y), N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+25} \lor \neg \left(y \leq 6 \cdot 10^{+31}\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if y < -4.4000000000000001e25 or 5.99999999999999978e31 < y Initial program 100.0%
Taylor expanded in y around inf 78.6%
neg-mul-178.6%
Simplified78.6%
if -4.4000000000000001e25 < y < 5.99999999999999978e31Initial program 100.0%
Taylor expanded in y around 0 93.7%
Final simplification87.7%
(FPCore (x y) :precision binary64 (if (or (<= y -6.2e+24) (not (<= y 1.15e+32))) (- y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -6.2e+24) || !(y <= 1.15e+32)) {
tmp = -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 ((y <= (-6.2d+24)) .or. (.not. (y <= 1.15d+32))) then
tmp = -y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -6.2e+24) || !(y <= 1.15e+32)) {
tmp = -y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.2e+24) or not (y <= 1.15e+32): tmp = -y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.2e+24) || !(y <= 1.15e+32)) tmp = Float64(-y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -6.2e+24) || ~((y <= 1.15e+32))) tmp = -y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.2e+24], N[Not[LessEqual[y, 1.15e+32]], $MachinePrecision]], (-y), (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{+24} \lor \neg \left(y \leq 1.15 \cdot 10^{+32}\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -6.20000000000000022e24 or 1.15e32 < y Initial program 100.0%
Taylor expanded in y around inf 78.6%
neg-mul-178.6%
Simplified78.6%
if -6.20000000000000022e24 < y < 1.15e32Initial program 100.0%
Taylor expanded in x around inf 59.6%
neg-mul-159.6%
Simplified59.6%
Final simplification67.3%
(FPCore (x y) :precision binary64 (- x))
double code(double x, double y) {
return -x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x
end function
public static double code(double x, double y) {
return -x;
}
def code(x, y): return -x
function code(x, y) return Float64(-x) end
function tmp = code(x, y) tmp = -x; end
code[x_, y_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 44.3%
neg-mul-144.3%
Simplified44.3%
Final simplification44.3%
herbie shell --seed 2024034
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))