
(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 -3.3e-12) (- x) (if (<= x -1.7e-206) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (x <= -3.3e-12) {
tmp = -x;
} else if (x <= -1.7e-206) {
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 <= (-3.3d-12)) then
tmp = -x
else if (x <= (-1.7d-206)) 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 <= -3.3e-12) {
tmp = -x;
} else if (x <= -1.7e-206) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.3e-12: tmp = -x elif x <= -1.7e-206: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (x <= -3.3e-12) tmp = Float64(-x); elseif (x <= -1.7e-206) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.3e-12) tmp = -x; elseif (x <= -1.7e-206) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.3e-12], (-x), If[LessEqual[x, -1.7e-206], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-12}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -1.7 \cdot 10^{-206}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if x < -3.3000000000000001e-12Initial program 100.0%
Taylor expanded in x around inf 96.4%
neg-mul-196.4%
Simplified96.4%
add-sqr-sqrt52.5%
sqrt-unprod66.0%
sqr-neg66.0%
sqrt-unprod31.6%
add-sqr-sqrt68.9%
neg-mul-168.9%
*-commutative68.9%
add-sqr-sqrt0.0%
sqrt-unprod0.8%
sqr-neg0.8%
sqrt-unprod0.6%
add-sqr-sqrt0.6%
add-cube-cbrt0.6%
distribute-rgt-neg-in0.6%
prod-diff0.6%
Applied egg-rr68.9%
fma-undefine68.9%
*-commutative68.9%
fma-undefine68.9%
remove-double-neg68.9%
distribute-lft-neg-out68.9%
unpow268.9%
rem-3cbrt-rft68.9%
mul-1-neg68.9%
fma-define68.9%
unpow268.9%
rem-3cbrt-rft68.9%
distribute-rgt1-in68.9%
metadata-eval68.9%
mul0-lft68.9%
+-rgt-identity68.9%
fma-undefine68.9%
Simplified68.9%
Taylor expanded in y around 0 69.7%
neg-mul-169.7%
Simplified69.7%
if -3.3000000000000001e-12 < x < -1.69999999999999992e-206Initial program 100.0%
Taylor expanded in x around 0 99.7%
Taylor expanded in y around 0 51.7%
if -1.69999999999999992e-206 < x Initial program 100.0%
Taylor expanded in y around inf 47.2%
neg-mul-147.2%
Simplified47.2%
(FPCore (x y) :precision binary64 (if (<= x -21.0) (- (- x) y) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (x <= -21.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 <= (-21.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 <= -21.0) {
tmp = -x - y;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -21.0: tmp = -x - y else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (x <= -21.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 <= -21.0) tmp = -x - y; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -21.0], N[((-x) - y), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -21:\\
\;\;\;\;\left(-x\right) - y\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -21Initial program 100.0%
Taylor expanded in x around inf 96.3%
neg-mul-196.3%
Simplified96.3%
if -21 < x Initial program 100.0%
Taylor expanded in x around 0 77.5%
(FPCore (x y) :precision binary64 (if (<= x -145.0) (- x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (x <= -145.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 <= (-145.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 <= -145.0) {
tmp = -x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -145.0: tmp = -x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (x <= -145.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 <= -145.0) tmp = -x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -145.0], (-x), N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -145:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -145Initial program 100.0%
Taylor expanded in x around inf 96.3%
neg-mul-196.3%
Simplified96.3%
add-sqr-sqrt51.1%
sqrt-unprod67.7%
sqr-neg67.7%
sqrt-unprod32.5%
add-sqr-sqrt70.8%
neg-mul-170.8%
*-commutative70.8%
add-sqr-sqrt0.0%
sqrt-unprod0.9%
sqr-neg0.9%
sqrt-unprod0.6%
add-sqr-sqrt0.6%
add-cube-cbrt0.6%
distribute-rgt-neg-in0.6%
prod-diff0.6%
Applied egg-rr70.8%
fma-undefine70.8%
*-commutative70.8%
fma-undefine70.8%
remove-double-neg70.8%
distribute-lft-neg-out70.8%
unpow270.8%
rem-3cbrt-rft70.8%
mul-1-neg70.8%
fma-define70.8%
unpow270.8%
rem-3cbrt-rft70.8%
distribute-rgt1-in70.8%
metadata-eval70.8%
mul0-lft70.8%
+-rgt-identity70.8%
fma-undefine70.8%
Simplified70.8%
Taylor expanded in y around 0 71.7%
neg-mul-171.7%
Simplified71.7%
if -145 < x Initial program 100.0%
Taylor expanded in x around 0 77.5%
(FPCore (x y) :precision binary64 (if (<= x -3.3e-12) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (x <= -3.3e-12) {
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 <= (-3.3d-12)) 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 <= -3.3e-12) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.3e-12: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.3e-12) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.3e-12) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.3e-12], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-12}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.3000000000000001e-12Initial program 100.0%
Taylor expanded in x around inf 96.4%
neg-mul-196.4%
Simplified96.4%
add-sqr-sqrt52.5%
sqrt-unprod66.0%
sqr-neg66.0%
sqrt-unprod31.6%
add-sqr-sqrt68.9%
neg-mul-168.9%
*-commutative68.9%
add-sqr-sqrt0.0%
sqrt-unprod0.8%
sqr-neg0.8%
sqrt-unprod0.6%
add-sqr-sqrt0.6%
add-cube-cbrt0.6%
distribute-rgt-neg-in0.6%
prod-diff0.6%
Applied egg-rr68.9%
fma-undefine68.9%
*-commutative68.9%
fma-undefine68.9%
remove-double-neg68.9%
distribute-lft-neg-out68.9%
unpow268.9%
rem-3cbrt-rft68.9%
mul-1-neg68.9%
fma-define68.9%
unpow268.9%
rem-3cbrt-rft68.9%
distribute-rgt1-in68.9%
metadata-eval68.9%
mul0-lft68.9%
+-rgt-identity68.9%
fma-undefine68.9%
Simplified68.9%
Taylor expanded in y around 0 69.7%
neg-mul-169.7%
Simplified69.7%
if -3.3000000000000001e-12 < x Initial program 100.0%
Taylor expanded in x around 0 77.3%
Taylor expanded in y around 0 30.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%
Taylor expanded in x around 0 63.5%
Taylor expanded in y around 0 23.3%
herbie shell --seed 2024111
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))