
(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 6.1e-245) (- x) (if (<= y 1.0) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= 6.1e-245) {
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 <= 6.1d-245) 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 <= 6.1e-245) {
tmp = -x;
} else if (y <= 1.0) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6.1e-245: tmp = -x elif y <= 1.0: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= 6.1e-245) 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 <= 6.1e-245) tmp = -x; elseif (y <= 1.0) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6.1e-245], (-x), If[LessEqual[y, 1.0], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.1 \cdot 10^{-245}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 6.10000000000000023e-245Initial program 100.0%
Taylor expanded in x around inf 74.3%
neg-mul-174.3%
Simplified74.3%
neg-mul-174.3%
*-commutative74.3%
add-sqr-sqrt34.2%
sqrt-unprod39.1%
sqr-neg39.1%
sqrt-unprod16.9%
add-sqr-sqrt32.7%
add-sqr-sqrt0.2%
sqrt-unprod1.5%
sqr-neg1.5%
sqrt-unprod1.3%
add-sqr-sqrt1.4%
add-cube-cbrt1.4%
distribute-rgt-neg-in1.4%
prod-diff1.4%
Applied egg-rr40.2%
fma-undefine40.2%
*-commutative40.2%
fma-undefine40.2%
remove-double-neg40.2%
distribute-lft-neg-out40.2%
unpow240.2%
rem-3cbrt-rft40.2%
mul-1-neg40.2%
fma-define40.2%
unpow240.2%
rem-3cbrt-rft40.2%
distribute-rgt1-in40.2%
metadata-eval40.2%
mul0-lft40.2%
+-rgt-identity40.2%
Simplified40.2%
Taylor expanded in y around 0 41.1%
neg-mul-141.1%
Simplified41.1%
if 6.10000000000000023e-245 < y < 1Initial program 100.0%
Taylor expanded in x around 0 41.3%
Taylor expanded in y around 0 40.3%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 79.2%
neg-mul-179.2%
Simplified79.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 99.0%
neg-mul-199.0%
Simplified99.0%
if -1 < x Initial program 100.0%
Taylor expanded in x around 0 72.4%
(FPCore (x y) :precision binary64 (if (<= x -1600000000.0) (- x) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if (x <= -1600000000.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 <= (-1600000000.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 <= -1600000000.0) {
tmp = -x;
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1600000000.0: tmp = -x else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if (x <= -1600000000.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 <= -1600000000.0) tmp = -x; else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1600000000.0], (-x), N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1600000000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -1.6e9Initial program 100.0%
Taylor expanded in x around inf 99.9%
neg-mul-199.9%
Simplified99.9%
neg-mul-199.9%
*-commutative99.9%
add-sqr-sqrt0.0%
sqrt-unprod22.4%
sqr-neg22.4%
sqrt-unprod29.0%
add-sqr-sqrt29.0%
add-sqr-sqrt16.3%
sqrt-unprod5.1%
sqr-neg5.1%
sqrt-unprod0.2%
add-sqr-sqrt0.5%
add-cube-cbrt0.5%
distribute-rgt-neg-in0.5%
prod-diff0.5%
Applied egg-rr69.2%
fma-undefine69.2%
*-commutative69.2%
fma-undefine69.2%
remove-double-neg69.2%
distribute-lft-neg-out69.2%
unpow269.2%
rem-3cbrt-rft69.2%
mul-1-neg69.2%
fma-define69.2%
unpow269.2%
rem-3cbrt-rft69.2%
distribute-rgt1-in69.2%
metadata-eval69.2%
mul0-lft69.2%
+-rgt-identity69.2%
Simplified69.2%
Taylor expanded in y around 0 69.9%
neg-mul-169.9%
Simplified69.9%
if -1.6e9 < x Initial program 100.0%
Taylor expanded in x around 0 72.2%
(FPCore (x y) :precision binary64 (if (<= x -0.000165) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (x <= -0.000165) {
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 <= (-0.000165d0)) 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 <= -0.000165) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.000165: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -0.000165) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.000165) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.000165], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.000165:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.65e-4Initial program 100.0%
Taylor expanded in x around inf 99.1%
neg-mul-199.1%
Simplified99.1%
neg-mul-199.1%
*-commutative99.1%
add-sqr-sqrt0.0%
sqrt-unprod24.2%
sqr-neg24.2%
sqrt-unprod30.6%
add-sqr-sqrt30.6%
add-sqr-sqrt17.0%
sqrt-unprod5.0%
sqr-neg5.0%
sqrt-unprod0.2%
add-sqr-sqrt0.5%
add-cube-cbrt0.5%
distribute-rgt-neg-in0.5%
prod-diff0.5%
Applied egg-rr66.9%
fma-undefine66.9%
*-commutative66.9%
fma-undefine66.9%
remove-double-neg66.9%
distribute-lft-neg-out66.9%
unpow266.9%
rem-3cbrt-rft66.9%
mul-1-neg66.9%
fma-define66.9%
unpow266.9%
rem-3cbrt-rft66.9%
distribute-rgt1-in66.9%
metadata-eval66.9%
mul0-lft66.9%
+-rgt-identity66.9%
Simplified66.9%
Taylor expanded in y around 0 67.7%
neg-mul-167.7%
Simplified67.7%
if -1.65e-4 < x Initial program 100.0%
Taylor expanded in x around 0 72.2%
Taylor expanded in y around 0 32.4%
(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 61.0%
Taylor expanded in y around 0 24.1%
herbie shell --seed 2024113
(FPCore (x y)
:name "Data.Colour.CIE.Chromaticity:chromaCoords from colour-2.3.3"
:precision binary64
(- (- 1.0 x) y))