
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.02))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.02)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
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)) .or. (.not. (x <= 0.02d0))) then
tmp = (x * y) - x
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.02)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.02): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.02)) tmp = Float64(Float64(x * y) - x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.02))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.02]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.02\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 0.0200000000000000004 < x Initial program 100.0%
Taylor expanded in x around inf 98.1%
*-commutative98.1%
Simplified98.1%
if -1 < x < 0.0200000000000000004Initial program 100.0%
Taylor expanded in x around 0 98.6%
Final simplification98.3%
(FPCore (x y) :precision binary64 (if (<= y -2.5e-105) y (if (<= y 1.2e-20) (- x) (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -2.5e-105) {
tmp = y;
} else if (y <= 1.2e-20) {
tmp = -x;
} else {
tmp = x + y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2.5d-105)) then
tmp = y
else if (y <= 1.2d-20) then
tmp = -x
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.5e-105) {
tmp = y;
} else if (y <= 1.2e-20) {
tmp = -x;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5e-105: tmp = y elif y <= 1.2e-20: tmp = -x else: tmp = x + y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.5e-105) tmp = y; elseif (y <= 1.2e-20) tmp = Float64(-x); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.5e-105) tmp = y; elseif (y <= 1.2e-20) tmp = -x; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.5e-105], y, If[LessEqual[y, 1.2e-20], (-x), N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-105}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-20}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -2.49999999999999982e-105Initial program 100.0%
Taylor expanded in x around 0 72.7%
sub-neg72.7%
add-sqr-sqrt36.2%
sqrt-unprod75.6%
sqr-neg75.6%
sqrt-unprod31.6%
add-sqr-sqrt62.8%
Applied egg-rr62.8%
Taylor expanded in y around inf 63.2%
if -2.49999999999999982e-105 < y < 1.19999999999999996e-20Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 86.3%
neg-mul-186.3%
Simplified86.3%
if 1.19999999999999996e-20 < y Initial program 100.0%
Taylor expanded in x around 0 51.4%
sub-neg51.4%
add-sqr-sqrt25.7%
sqrt-unprod59.7%
sqr-neg59.7%
sqrt-unprod26.3%
add-sqr-sqrt51.8%
Applied egg-rr51.8%
Final simplification69.2%
(FPCore (x y) :precision binary64 (if (<= y -1.95e-103) y (if (<= y 4.2e-19) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.95e-103) {
tmp = y;
} else if (y <= 4.2e-19) {
tmp = -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 <= (-1.95d-103)) then
tmp = y
else if (y <= 4.2d-19) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.95e-103) {
tmp = y;
} else if (y <= 4.2e-19) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.95e-103: tmp = y elif y <= 4.2e-19: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.95e-103) tmp = y; elseif (y <= 4.2e-19) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.95e-103) tmp = y; elseif (y <= 4.2e-19) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.95e-103], y, If[LessEqual[y, 4.2e-19], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{-103}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-19}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.9500000000000001e-103 or 4.1999999999999998e-19 < y Initial program 100.0%
Taylor expanded in x around 0 62.8%
sub-neg62.8%
add-sqr-sqrt31.3%
sqrt-unprod68.2%
sqr-neg68.2%
sqrt-unprod29.2%
add-sqr-sqrt57.6%
Applied egg-rr57.6%
Taylor expanded in y around inf 57.3%
if -1.9500000000000001e-103 < y < 4.1999999999999998e-19Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 86.3%
neg-mul-186.3%
Simplified86.3%
(FPCore (x y) :precision binary64 (- y x))
double code(double x, double y) {
return y - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y - x
end function
public static double code(double x, double y) {
return y - x;
}
def code(x, y): return y - x
function code(x, y) return Float64(y - x) end
function tmp = code(x, y) tmp = y - x; end
code[x_, y_] := N[(y - x), $MachinePrecision]
\begin{array}{l}
\\
y - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 77.6%
(FPCore (x y) :precision binary64 y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 77.6%
sub-neg77.6%
add-sqr-sqrt39.0%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod19.8%
add-sqr-sqrt40.0%
Applied egg-rr40.0%
Taylor expanded in y around inf 40.5%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 39.0%
neg-mul-139.0%
Simplified39.0%
neg-sub039.0%
sub-neg39.0%
add-sqr-sqrt19.3%
sqrt-unprod19.4%
sqr-neg19.4%
sqrt-unprod1.2%
add-sqr-sqrt2.7%
Applied egg-rr2.7%
+-lft-identity2.7%
Simplified2.7%
herbie shell --seed 2024111
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))