
(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 (if (<= x -0.019) (- x) (if (or (<= x -3.4e-79) (not (<= x 5.1e-222))) (- y) 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -0.019) {
tmp = -x;
} else if ((x <= -3.4e-79) || !(x <= 5.1e-222)) {
tmp = -y;
} 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 <= (-0.019d0)) then
tmp = -x
else if ((x <= (-3.4d-79)) .or. (.not. (x <= 5.1d-222))) then
tmp = -y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.019) {
tmp = -x;
} else if ((x <= -3.4e-79) || !(x <= 5.1e-222)) {
tmp = -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.019: tmp = -x elif (x <= -3.4e-79) or not (x <= 5.1e-222): tmp = -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -0.019) tmp = Float64(-x); elseif ((x <= -3.4e-79) || !(x <= 5.1e-222)) tmp = Float64(-y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.019) tmp = -x; elseif ((x <= -3.4e-79) || ~((x <= 5.1e-222))) tmp = -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.019], (-x), If[Or[LessEqual[x, -3.4e-79], N[Not[LessEqual[x, 5.1e-222]], $MachinePrecision]], (-y), 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.019:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -3.4 \cdot 10^{-79} \lor \neg \left(x \leq 5.1 \cdot 10^{-222}\right):\\
\;\;\;\;-y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -0.0189999999999999995Initial program 100.0%
Taylor expanded in x around inf 97.4%
neg-mul-197.4%
Simplified97.4%
neg-mul-197.4%
*-commutative97.4%
add-sqr-sqrt0.0%
sqrt-unprod12.9%
sqr-neg12.9%
sqrt-unprod23.7%
add-sqr-sqrt23.7%
add-sqr-sqrt12.9%
sqrt-unprod2.8%
sqr-neg2.8%
sqrt-unprod0.2%
add-sqr-sqrt0.6%
add-cube-cbrt0.6%
distribute-rgt-neg-in0.6%
prod-diff0.6%
Applied egg-rr71.3%
fma-undefine71.3%
*-commutative71.3%
fma-undefine71.3%
remove-double-neg71.3%
distribute-lft-neg-out71.3%
unpow271.3%
rem-3cbrt-rft71.3%
mul-1-neg71.3%
fma-define71.3%
unpow271.3%
rem-3cbrt-rft71.3%
distribute-rgt1-in71.3%
metadata-eval71.3%
mul0-lft71.3%
+-rgt-identity71.3%
Simplified71.3%
Taylor expanded in y around 0 72.2%
neg-mul-172.2%
Simplified72.2%
if -0.0189999999999999995 < x < -3.39999999999999976e-79 or 5.1000000000000002e-222 < x Initial program 100.0%
Taylor expanded in y around inf 42.9%
neg-mul-142.9%
Simplified42.9%
if -3.39999999999999976e-79 < x < 5.1000000000000002e-222Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around 0 61.3%
Final simplification55.2%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (- (- x) y) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (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 (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 (x <= -1.0) {
tmp = -x - y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = -x - y else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (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 (x <= -1.0) tmp = -x - y; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[((-x) - y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\left(-x\right) - y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 98.8%
neg-mul-198.8%
Simplified98.8%
if -1 < x Initial program 100.0%
Taylor expanded in x around 0 76.3%
(FPCore (x y) :precision binary64 (if (<= x -65.0) (- x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (x <= -65.0) {
tmp = -x;
} 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 (x <= (-65.0d0)) then
tmp = -x
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -65.0) {
tmp = -x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -65.0: tmp = -x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (x <= -65.0) tmp = Float64(-x); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -65.0) tmp = -x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -65.0], (-x), N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -65:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -65Initial program 100.0%
Taylor expanded in x around inf 98.8%
neg-mul-198.8%
Simplified98.8%
neg-mul-198.8%
*-commutative98.8%
add-sqr-sqrt0.0%
sqrt-unprod13.1%
sqr-neg13.1%
sqrt-unprod24.1%
add-sqr-sqrt24.1%
add-sqr-sqrt13.1%
sqrt-unprod2.8%
sqr-neg2.8%
sqrt-unprod0.2%
add-sqr-sqrt0.6%
add-cube-cbrt0.6%
distribute-rgt-neg-in0.6%
prod-diff0.6%
Applied egg-rr72.2%
fma-undefine72.2%
*-commutative72.2%
fma-undefine72.2%
remove-double-neg72.2%
distribute-lft-neg-out72.2%
unpow272.2%
rem-3cbrt-rft72.2%
mul-1-neg72.2%
fma-define72.2%
unpow272.2%
rem-3cbrt-rft72.2%
distribute-rgt1-in72.2%
metadata-eval72.2%
mul0-lft72.2%
+-rgt-identity72.2%
Simplified72.2%
Taylor expanded in y around 0 73.1%
neg-mul-173.1%
Simplified73.1%
if -65 < x Initial program 100.0%
Taylor expanded in x around 0 76.3%
(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 98.8%
neg-mul-198.8%
Simplified98.8%
neg-mul-198.8%
*-commutative98.8%
add-sqr-sqrt0.0%
sqrt-unprod13.1%
sqr-neg13.1%
sqrt-unprod24.1%
add-sqr-sqrt24.1%
add-sqr-sqrt13.1%
sqrt-unprod2.8%
sqr-neg2.8%
sqrt-unprod0.2%
add-sqr-sqrt0.6%
add-cube-cbrt0.6%
distribute-rgt-neg-in0.6%
prod-diff0.6%
Applied egg-rr72.2%
fma-undefine72.2%
*-commutative72.2%
fma-undefine72.2%
remove-double-neg72.2%
distribute-lft-neg-out72.2%
unpow272.2%
rem-3cbrt-rft72.2%
mul-1-neg72.2%
fma-define72.2%
unpow272.2%
rem-3cbrt-rft72.2%
distribute-rgt1-in72.2%
metadata-eval72.2%
mul0-lft72.2%
+-rgt-identity72.2%
Simplified72.2%
Taylor expanded in y around 0 73.1%
neg-mul-173.1%
Simplified73.1%
if -1 < x Initial program 100.0%
Taylor expanded in x around 0 76.3%
Taylor expanded in y around 0 35.9%
(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 x around 0 64.8%
Taylor expanded in y around 0 28.6%
herbie shell --seed 2024116
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))