
(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 8 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 (- (+ y (* y x)) x))
double code(double x, double y) {
return (y + (y * x)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + (y * x)) - x
end function
public static double code(double x, double y) {
return (y + (y * x)) - x;
}
def code(x, y): return (y + (y * x)) - x
function code(x, y) return Float64(Float64(y + Float64(y * x)) - x) end
function tmp = code(x, y) tmp = (y + (y * x)) - x; end
code[x_, y_] := N[(N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(y + y \cdot x\right) - x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -3.8e+240)
(* y x)
(if (<= y -4.1e+135)
y
(if (<= y -1.25e+107)
(* y x)
(if (<= y -3.2e-76)
y
(if (<= y 3.4e-123)
(- x)
(if (<= y 1.3e+31) y (if (<= y 1.7e+203) (* y x) y))))))))
double code(double x, double y) {
double tmp;
if (y <= -3.8e+240) {
tmp = y * x;
} else if (y <= -4.1e+135) {
tmp = y;
} else if (y <= -1.25e+107) {
tmp = y * x;
} else if (y <= -3.2e-76) {
tmp = y;
} else if (y <= 3.4e-123) {
tmp = -x;
} else if (y <= 1.3e+31) {
tmp = y;
} else if (y <= 1.7e+203) {
tmp = y * 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 <= (-3.8d+240)) then
tmp = y * x
else if (y <= (-4.1d+135)) then
tmp = y
else if (y <= (-1.25d+107)) then
tmp = y * x
else if (y <= (-3.2d-76)) then
tmp = y
else if (y <= 3.4d-123) then
tmp = -x
else if (y <= 1.3d+31) then
tmp = y
else if (y <= 1.7d+203) then
tmp = y * x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.8e+240) {
tmp = y * x;
} else if (y <= -4.1e+135) {
tmp = y;
} else if (y <= -1.25e+107) {
tmp = y * x;
} else if (y <= -3.2e-76) {
tmp = y;
} else if (y <= 3.4e-123) {
tmp = -x;
} else if (y <= 1.3e+31) {
tmp = y;
} else if (y <= 1.7e+203) {
tmp = y * x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.8e+240: tmp = y * x elif y <= -4.1e+135: tmp = y elif y <= -1.25e+107: tmp = y * x elif y <= -3.2e-76: tmp = y elif y <= 3.4e-123: tmp = -x elif y <= 1.3e+31: tmp = y elif y <= 1.7e+203: tmp = y * x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -3.8e+240) tmp = Float64(y * x); elseif (y <= -4.1e+135) tmp = y; elseif (y <= -1.25e+107) tmp = Float64(y * x); elseif (y <= -3.2e-76) tmp = y; elseif (y <= 3.4e-123) tmp = Float64(-x); elseif (y <= 1.3e+31) tmp = y; elseif (y <= 1.7e+203) tmp = Float64(y * x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.8e+240) tmp = y * x; elseif (y <= -4.1e+135) tmp = y; elseif (y <= -1.25e+107) tmp = y * x; elseif (y <= -3.2e-76) tmp = y; elseif (y <= 3.4e-123) tmp = -x; elseif (y <= 1.3e+31) tmp = y; elseif (y <= 1.7e+203) tmp = y * x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.8e+240], N[(y * x), $MachinePrecision], If[LessEqual[y, -4.1e+135], y, If[LessEqual[y, -1.25e+107], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.2e-76], y, If[LessEqual[y, 3.4e-123], (-x), If[LessEqual[y, 1.3e+31], y, If[LessEqual[y, 1.7e+203], N[(y * x), $MachinePrecision], y]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+240}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -4.1 \cdot 10^{+135}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{+107}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.2 \cdot 10^{-76}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-123}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{+31}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+203}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -3.8000000000000003e240 or -4.1e135 < y < -1.25e107 or 1.3e31 < y < 1.7000000000000001e203Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 76.2%
*-commutative76.2%
Simplified76.2%
if -3.8000000000000003e240 < y < -4.1e135 or -1.25e107 < y < -3.1999999999999998e-76 or 3.4000000000000001e-123 < y < 1.3e31 or 1.7000000000000001e203 < y Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 63.3%
if -3.1999999999999998e-76 < y < 3.4000000000000001e-123Initial program 100.0%
Taylor expanded in y around 0 83.8%
neg-mul-183.8%
Simplified83.8%
(FPCore (x y)
:precision binary64
(if (<= y -5e+242)
(* y x)
(if (<= y -2.15e+135)
(- y x)
(if (<= y -2.7e+110)
(* y x)
(if (<= y 1.95e+30) (- y x) (if (<= y 2.25e+207) (* y x) y))))))
double code(double x, double y) {
double tmp;
if (y <= -5e+242) {
tmp = y * x;
} else if (y <= -2.15e+135) {
tmp = y - x;
} else if (y <= -2.7e+110) {
tmp = y * x;
} else if (y <= 1.95e+30) {
tmp = y - x;
} else if (y <= 2.25e+207) {
tmp = y * 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 <= (-5d+242)) then
tmp = y * x
else if (y <= (-2.15d+135)) then
tmp = y - x
else if (y <= (-2.7d+110)) then
tmp = y * x
else if (y <= 1.95d+30) then
tmp = y - x
else if (y <= 2.25d+207) then
tmp = y * x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -5e+242) {
tmp = y * x;
} else if (y <= -2.15e+135) {
tmp = y - x;
} else if (y <= -2.7e+110) {
tmp = y * x;
} else if (y <= 1.95e+30) {
tmp = y - x;
} else if (y <= 2.25e+207) {
tmp = y * x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5e+242: tmp = y * x elif y <= -2.15e+135: tmp = y - x elif y <= -2.7e+110: tmp = y * x elif y <= 1.95e+30: tmp = y - x elif y <= 2.25e+207: tmp = y * x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -5e+242) tmp = Float64(y * x); elseif (y <= -2.15e+135) tmp = Float64(y - x); elseif (y <= -2.7e+110) tmp = Float64(y * x); elseif (y <= 1.95e+30) tmp = Float64(y - x); elseif (y <= 2.25e+207) tmp = Float64(y * x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -5e+242) tmp = y * x; elseif (y <= -2.15e+135) tmp = y - x; elseif (y <= -2.7e+110) tmp = y * x; elseif (y <= 1.95e+30) tmp = y - x; elseif (y <= 2.25e+207) tmp = y * x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5e+242], N[(y * x), $MachinePrecision], If[LessEqual[y, -2.15e+135], N[(y - x), $MachinePrecision], If[LessEqual[y, -2.7e+110], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.95e+30], N[(y - x), $MachinePrecision], If[LessEqual[y, 2.25e+207], N[(y * x), $MachinePrecision], y]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+242}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.15 \cdot 10^{+135}:\\
\;\;\;\;y - x\\
\mathbf{elif}\;y \leq -2.7 \cdot 10^{+110}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{+30}:\\
\;\;\;\;y - x\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{+207}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -5.0000000000000004e242 or -2.14999999999999986e135 < y < -2.7000000000000001e110 or 1.95000000000000005e30 < y < 2.25000000000000002e207Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 76.2%
*-commutative76.2%
Simplified76.2%
if -5.0000000000000004e242 < y < -2.14999999999999986e135 or -2.7000000000000001e110 < y < 1.95000000000000005e30Initial program 100.0%
Taylor expanded in x around 0 92.5%
if 2.25000000000000002e207 < y Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 61.3%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.029))) (* x (- y 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.029)) {
tmp = x * (y - 1.0);
} 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.029d0))) then
tmp = x * (y - 1.0d0)
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.029)) {
tmp = x * (y - 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.029): tmp = x * (y - 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.029)) tmp = Float64(x * Float64(y - 1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.029))) tmp = x * (y - 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.029]], $MachinePrecision]], N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.029\right):\\
\;\;\;\;x \cdot \left(y - 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 0.0290000000000000015 < x Initial program 100.0%
Taylor expanded in x around inf 99.3%
if -1 < x < 0.0290000000000000015Initial program 100.0%
Taylor expanded in x around 0 99.4%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (- (* y x) x) (if (<= x 0.029) (- y x) (* x (- y 1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (y * x) - x;
} else if (x <= 0.029) {
tmp = y - x;
} else {
tmp = x * (y - 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 = (y * x) - x
else if (x <= 0.029d0) then
tmp = y - x
else
tmp = x * (y - 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (y * x) - x;
} else if (x <= 0.029) {
tmp = y - x;
} else {
tmp = x * (y - 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = (y * x) - x elif x <= 0.029: tmp = y - x else: tmp = x * (y - 1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(y * x) - x); elseif (x <= 0.029) tmp = Float64(y - x); else tmp = Float64(x * Float64(y - 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = (y * x) - x; elseif (x <= 0.029) tmp = y - x; else tmp = x * (y - 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 0.029], N[(y - x), $MachinePrecision], N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;y \cdot x - x\\
\mathbf{elif}\;x \leq 0.029:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y - 1\right)\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 98.9%
*-commutative98.9%
Simplified98.9%
if -1 < x < 0.0290000000000000015Initial program 100.0%
Taylor expanded in x around 0 99.4%
if 0.0290000000000000015 < x Initial program 100.0%
Taylor expanded in x around inf 99.7%
(FPCore (x y) :precision binary64 (if (or (<= x -4.6e-12) (not (<= x 1.25e-15))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -4.6e-12) || !(x <= 1.25e-15)) {
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 ((x <= (-4.6d-12)) .or. (.not. (x <= 1.25d-15))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -4.6e-12) || !(x <= 1.25e-15)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.6e-12) or not (x <= 1.25e-15): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.6e-12) || !(x <= 1.25e-15)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -4.6e-12) || ~((x <= 1.25e-15))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.6e-12], N[Not[LessEqual[x, 1.25e-15]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-12} \lor \neg \left(x \leq 1.25 \cdot 10^{-15}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.59999999999999979e-12 or 1.25e-15 < x Initial program 100.0%
Taylor expanded in y around 0 51.4%
neg-mul-151.4%
Simplified51.4%
if -4.59999999999999979e-12 < x < 1.25e-15Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 77.6%
Final simplification64.0%
(FPCore (x y) :precision binary64 (- (* y (+ x 1.0)) x))
double code(double x, double y) {
return (y * (x + 1.0)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (x + 1.0d0)) - x
end function
public static double code(double x, double y) {
return (y * (x + 1.0)) - x;
}
def code(x, y): return (y * (x + 1.0)) - x
function code(x, y) return Float64(Float64(y * Float64(x + 1.0)) - x) end
function tmp = code(x, y) tmp = (y * (x + 1.0)) - x; end
code[x_, y_] := N[(N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x + 1\right) - x
\end{array}
Initial program 100.0%
Final simplification100.0%
(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%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 39.4%
herbie shell --seed 2024084
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))