
(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%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -5.4e-6)
(- x)
(if (<= x -1.1e-44)
(- y)
(if (<= x 2.05e-277)
1.0
(if (<= x 7e-261) (- y) (if (<= x 1.05e-188) 1.0 (- y)))))))
double code(double x, double y) {
double tmp;
if (x <= -5.4e-6) {
tmp = -x;
} else if (x <= -1.1e-44) {
tmp = -y;
} else if (x <= 2.05e-277) {
tmp = 1.0;
} else if (x <= 7e-261) {
tmp = -y;
} else if (x <= 1.05e-188) {
tmp = 1.0;
} 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 (x <= (-5.4d-6)) then
tmp = -x
else if (x <= (-1.1d-44)) then
tmp = -y
else if (x <= 2.05d-277) then
tmp = 1.0d0
else if (x <= 7d-261) then
tmp = -y
else if (x <= 1.05d-188) then
tmp = 1.0d0
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5.4e-6) {
tmp = -x;
} else if (x <= -1.1e-44) {
tmp = -y;
} else if (x <= 2.05e-277) {
tmp = 1.0;
} else if (x <= 7e-261) {
tmp = -y;
} else if (x <= 1.05e-188) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.4e-6: tmp = -x elif x <= -1.1e-44: tmp = -y elif x <= 2.05e-277: tmp = 1.0 elif x <= 7e-261: tmp = -y elif x <= 1.05e-188: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (x <= -5.4e-6) tmp = Float64(-x); elseif (x <= -1.1e-44) tmp = Float64(-y); elseif (x <= 2.05e-277) tmp = 1.0; elseif (x <= 7e-261) tmp = Float64(-y); elseif (x <= 1.05e-188) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5.4e-6) tmp = -x; elseif (x <= -1.1e-44) tmp = -y; elseif (x <= 2.05e-277) tmp = 1.0; elseif (x <= 7e-261) tmp = -y; elseif (x <= 1.05e-188) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.4e-6], (-x), If[LessEqual[x, -1.1e-44], (-y), If[LessEqual[x, 2.05e-277], 1.0, If[LessEqual[x, 7e-261], (-y), If[LessEqual[x, 1.05e-188], 1.0, (-y)]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{-6}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -1.1 \cdot 10^{-44}:\\
\;\;\;\;-y\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-277}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-261}:\\
\;\;\;\;-y\\
\mathbf{elif}\;x \leq 1.05 \cdot 10^{-188}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if x < -5.39999999999999997e-6Initial program 100.0%
Taylor expanded in x around inf 79.1%
neg-mul-179.1%
Simplified79.1%
if -5.39999999999999997e-6 < x < -1.10000000000000006e-44 or 2.04999999999999994e-277 < x < 6.9999999999999995e-261 or 1.05e-188 < x Initial program 100.0%
Taylor expanded in y around inf 46.5%
neg-mul-146.5%
Simplified46.5%
if -1.10000000000000006e-44 < x < 2.04999999999999994e-277 or 6.9999999999999995e-261 < x < 1.05e-188Initial program 100.0%
associate--l-100.0%
flip--78.0%
metadata-eval78.0%
Applied egg-rr78.0%
+-commutative78.0%
+-commutative78.0%
associate-+r+78.0%
Simplified78.0%
Taylor expanded in y around 0 57.0%
unpow257.0%
Simplified57.0%
Taylor expanded in x around 0 57.0%
Final simplification58.1%
(FPCore (x y) :precision binary64 (if (<= (- 1.0 x) 1.0) (- 1.0 y) (- 1.0 x)))
double code(double x, double y) {
double tmp;
if ((1.0 - x) <= 1.0) {
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) <= 1.0d0) 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) <= 1.0) {
tmp = 1.0 - y;
} else {
tmp = 1.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (1.0 - x) <= 1.0: tmp = 1.0 - y else: tmp = 1.0 - x return tmp
function code(x, y) tmp = 0.0 if (Float64(1.0 - x) <= 1.0) 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) <= 1.0) tmp = 1.0 - y; else tmp = 1.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(1.0 - x), $MachinePrecision], 1.0], N[(1.0 - y), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - x \leq 1:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;1 - x\\
\end{array}
\end{array}
if (-.f64 1 x) < 1Initial program 100.0%
Taylor expanded in x around 0 74.1%
if 1 < (-.f64 1 x) Initial program 100.0%
Taylor expanded in y around 0 84.2%
Final simplification76.8%
(FPCore (x y) :precision binary64 (if (<= y 920000.0) (- 1.0 x) (- y)))
double code(double x, double y) {
double tmp;
if (y <= 920000.0) {
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 <= 920000.0d0) 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 <= 920000.0) {
tmp = 1.0 - x;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 920000.0: tmp = 1.0 - x else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= 920000.0) tmp = Float64(1.0 - x); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 920000.0) tmp = 1.0 - x; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 920000.0], N[(1.0 - x), $MachinePrecision], (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 920000:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 9.2e5Initial program 100.0%
Taylor expanded in y around 0 72.3%
if 9.2e5 < y Initial program 100.0%
Taylor expanded in y around inf 77.3%
neg-mul-177.3%
Simplified77.3%
Final simplification73.2%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (x <= -1.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 <= (-1.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 <= -1.0) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 82.1%
neg-mul-182.1%
Simplified82.1%
if -1 < x Initial program 100.0%
associate--l-100.0%
flip--63.0%
metadata-eval63.0%
Applied egg-rr63.0%
+-commutative63.0%
+-commutative63.0%
associate-+r+63.0%
Simplified63.0%
Taylor expanded in y around 0 42.6%
unpow242.6%
Simplified42.6%
Taylor expanded in x around 0 30.7%
Final simplification43.8%
(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%
associate--l-100.0%
flip--57.8%
metadata-eval57.8%
Applied egg-rr57.8%
+-commutative57.8%
+-commutative57.8%
associate-+r+57.8%
Simplified57.8%
Taylor expanded in y around 0 41.6%
unpow241.6%
Simplified41.6%
Taylor expanded in x around 0 24.2%
Final simplification24.2%
herbie shell --seed 2023256
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))