
(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 (<= y -4.1e-252) (- x) (if (<= y 1.0) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -4.1e-252) {
tmp = -x;
} else if (y <= 1.0) {
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 (y <= (-4.1d-252)) then
tmp = -x
else if (y <= 1.0d0) then
tmp = 1.0d0
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.1e-252) {
tmp = -x;
} else if (y <= 1.0) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.1e-252: tmp = -x elif y <= 1.0: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.1e-252) tmp = Float64(-x); elseif (y <= 1.0) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.1e-252) tmp = -x; elseif (y <= 1.0) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.1e-252], (-x), If[LessEqual[y, 1.0], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-252}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -4.10000000000000014e-252Initial program 100.0%
Taylor expanded in x around inf 77.3%
neg-mul-177.3%
Simplified77.3%
neg-mul-177.3%
*-commutative77.3%
add-sqr-sqrt31.2%
sqrt-unprod41.6%
sqr-neg41.6%
sqrt-unprod22.4%
add-sqr-sqrt34.1%
add-sqr-sqrt0.0%
sqrt-unprod1.2%
sqr-neg1.2%
sqrt-unprod1.1%
add-sqr-sqrt1.1%
add-cube-cbrt1.1%
distribute-rgt-neg-in1.1%
prod-diff1.1%
Applied egg-rr42.7%
fma-undefine42.7%
*-commutative42.7%
fma-undefine42.7%
remove-double-neg42.7%
distribute-lft-neg-out42.7%
unpow242.7%
rem-3cbrt-rft42.7%
mul-1-neg42.7%
fma-define42.7%
unpow242.7%
rem-3cbrt-rft42.7%
distribute-rgt1-in42.7%
metadata-eval42.7%
mul0-lft42.7%
+-rgt-identity42.7%
Simplified42.7%
Taylor expanded in y around 0 44.2%
neg-mul-144.2%
Simplified44.2%
if -4.10000000000000014e-252 < y < 1Initial program 100.0%
Taylor expanded in x around 0 43.0%
Taylor expanded in y around 0 42.0%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 77.9%
neg-mul-177.9%
Simplified77.9%
(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 99.2%
neg-mul-199.2%
Simplified99.2%
if -1 < x Initial program 100.0%
Taylor expanded in x around 0 70.6%
(FPCore (x y) :precision binary64 (if (<= x -3000000000.0) (- x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (x <= -3000000000.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 <= (-3000000000.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 <= -3000000000.0) {
tmp = -x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3000000000.0: tmp = -x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (x <= -3000000000.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 <= -3000000000.0) tmp = -x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3000000000.0], (-x), N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3000000000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -3e9Initial program 100.0%
Taylor expanded in x around inf 99.2%
neg-mul-199.2%
Simplified99.2%
neg-mul-199.2%
*-commutative99.2%
add-sqr-sqrt0.0%
sqrt-unprod20.2%
sqr-neg20.2%
sqrt-unprod26.4%
add-sqr-sqrt26.4%
add-sqr-sqrt10.1%
sqrt-unprod3.6%
sqr-neg3.6%
sqrt-unprod0.3%
add-sqr-sqrt0.5%
add-cube-cbrt0.5%
distribute-rgt-neg-in0.5%
prod-diff0.5%
Applied egg-rr71.0%
fma-undefine71.0%
*-commutative71.0%
fma-undefine71.0%
remove-double-neg71.0%
distribute-lft-neg-out71.0%
unpow271.0%
rem-3cbrt-rft71.0%
mul-1-neg71.0%
fma-define71.0%
unpow271.0%
rem-3cbrt-rft71.0%
distribute-rgt1-in71.0%
metadata-eval71.0%
mul0-lft71.0%
+-rgt-identity71.0%
Simplified71.0%
Taylor expanded in y around 0 72.2%
neg-mul-172.2%
Simplified72.2%
if -3e9 < x Initial program 100.0%
Taylor expanded in x around 0 70.6%
(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 99.2%
neg-mul-199.2%
Simplified99.2%
neg-mul-199.2%
*-commutative99.2%
add-sqr-sqrt0.0%
sqrt-unprod20.2%
sqr-neg20.2%
sqrt-unprod26.4%
add-sqr-sqrt26.4%
add-sqr-sqrt10.1%
sqrt-unprod3.6%
sqr-neg3.6%
sqrt-unprod0.3%
add-sqr-sqrt0.5%
add-cube-cbrt0.5%
distribute-rgt-neg-in0.5%
prod-diff0.5%
Applied egg-rr71.0%
fma-undefine71.0%
*-commutative71.0%
fma-undefine71.0%
remove-double-neg71.0%
distribute-lft-neg-out71.0%
unpow271.0%
rem-3cbrt-rft71.0%
mul-1-neg71.0%
fma-define71.0%
unpow271.0%
rem-3cbrt-rft71.0%
distribute-rgt1-in71.0%
metadata-eval71.0%
mul0-lft71.0%
+-rgt-identity71.0%
Simplified71.0%
Taylor expanded in y around 0 72.2%
neg-mul-172.2%
Simplified72.2%
if -1 < x Initial program 100.0%
Taylor expanded in x around 0 70.6%
Taylor expanded in y around 0 31.3%
(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 58.3%
Taylor expanded in y around 0 23.2%
herbie shell --seed 2024137
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))