
(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 9 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 (- (fma x y y) x))
double code(double x, double y) {
return fma(x, y, y) - x;
}
function code(x, y) return Float64(fma(x, y, y) - x) end
code[x_, y_] := N[(N[(x * y + y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, y\right) - x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-rgt-in100.0%
fma-def100.0%
*-lft-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -4.1e+265)
y
(if (<= y -2e+116)
(* x y)
(if (<= y -5.3e-17)
y
(if (<= y 5e-5) (- x) (if (<= y 8.2e+178) y (* x y)))))))
double code(double x, double y) {
double tmp;
if (y <= -4.1e+265) {
tmp = y;
} else if (y <= -2e+116) {
tmp = x * y;
} else if (y <= -5.3e-17) {
tmp = y;
} else if (y <= 5e-5) {
tmp = -x;
} else if (y <= 8.2e+178) {
tmp = y;
} 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 <= (-4.1d+265)) then
tmp = y
else if (y <= (-2d+116)) then
tmp = x * y
else if (y <= (-5.3d-17)) then
tmp = y
else if (y <= 5d-5) then
tmp = -x
else if (y <= 8.2d+178) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.1e+265) {
tmp = y;
} else if (y <= -2e+116) {
tmp = x * y;
} else if (y <= -5.3e-17) {
tmp = y;
} else if (y <= 5e-5) {
tmp = -x;
} else if (y <= 8.2e+178) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.1e+265: tmp = y elif y <= -2e+116: tmp = x * y elif y <= -5.3e-17: tmp = y elif y <= 5e-5: tmp = -x elif y <= 8.2e+178: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.1e+265) tmp = y; elseif (y <= -2e+116) tmp = Float64(x * y); elseif (y <= -5.3e-17) tmp = y; elseif (y <= 5e-5) tmp = Float64(-x); elseif (y <= 8.2e+178) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.1e+265) tmp = y; elseif (y <= -2e+116) tmp = x * y; elseif (y <= -5.3e-17) tmp = y; elseif (y <= 5e-5) tmp = -x; elseif (y <= 8.2e+178) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.1e+265], y, If[LessEqual[y, -2e+116], N[(x * y), $MachinePrecision], If[LessEqual[y, -5.3e-17], y, If[LessEqual[y, 5e-5], (-x), If[LessEqual[y, 8.2e+178], y, N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{+265}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -2 \cdot 10^{+116}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -5.3 \cdot 10^{-17}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-5}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+178}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -4.1000000000000003e265 or -2.00000000000000003e116 < y < -5.2999999999999998e-17 or 5.00000000000000024e-5 < y < 8.19999999999999993e178Initial program 99.9%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 61.9%
if -4.1000000000000003e265 < y < -2.00000000000000003e116 or 8.19999999999999993e178 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 68.7%
if -5.2999999999999998e-17 < y < 5.00000000000000024e-5Initial program 100.0%
Taylor expanded in y around 0 78.8%
neg-mul-178.8%
Simplified78.8%
Final simplification71.4%
(FPCore (x y)
:precision binary64
(if (<= y -3.45e+264)
y
(if (<= y -1.4e+117)
(* x y)
(if (<= y 4.5e+28)
(- y x)
(if (<= y 8.2e+83) (* x y) (if (<= y 7.8e+173) y (* x y)))))))
double code(double x, double y) {
double tmp;
if (y <= -3.45e+264) {
tmp = y;
} else if (y <= -1.4e+117) {
tmp = x * y;
} else if (y <= 4.5e+28) {
tmp = y - x;
} else if (y <= 8.2e+83) {
tmp = x * y;
} else if (y <= 7.8e+173) {
tmp = y;
} 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 <= (-3.45d+264)) then
tmp = y
else if (y <= (-1.4d+117)) then
tmp = x * y
else if (y <= 4.5d+28) then
tmp = y - x
else if (y <= 8.2d+83) then
tmp = x * y
else if (y <= 7.8d+173) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.45e+264) {
tmp = y;
} else if (y <= -1.4e+117) {
tmp = x * y;
} else if (y <= 4.5e+28) {
tmp = y - x;
} else if (y <= 8.2e+83) {
tmp = x * y;
} else if (y <= 7.8e+173) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.45e+264: tmp = y elif y <= -1.4e+117: tmp = x * y elif y <= 4.5e+28: tmp = y - x elif y <= 8.2e+83: tmp = x * y elif y <= 7.8e+173: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -3.45e+264) tmp = y; elseif (y <= -1.4e+117) tmp = Float64(x * y); elseif (y <= 4.5e+28) tmp = Float64(y - x); elseif (y <= 8.2e+83) tmp = Float64(x * y); elseif (y <= 7.8e+173) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.45e+264) tmp = y; elseif (y <= -1.4e+117) tmp = x * y; elseif (y <= 4.5e+28) tmp = y - x; elseif (y <= 8.2e+83) tmp = x * y; elseif (y <= 7.8e+173) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.45e+264], y, If[LessEqual[y, -1.4e+117], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.5e+28], N[(y - x), $MachinePrecision], If[LessEqual[y, 8.2e+83], N[(x * y), $MachinePrecision], If[LessEqual[y, 7.8e+173], y, N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.45 \cdot 10^{+264}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{+117}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+28}:\\
\;\;\;\;y - x\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{+83}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+173}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3.4500000000000002e264 or 8.2000000000000002e83 < y < 7.7999999999999996e173Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 72.7%
if -3.4500000000000002e264 < y < -1.39999999999999999e117 or 4.4999999999999997e28 < y < 8.2000000000000002e83 or 7.7999999999999996e173 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 68.0%
if -1.39999999999999999e117 < y < 4.4999999999999997e28Initial program 100.0%
Taylor expanded in x around 0 91.9%
Final simplification83.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1200000.0) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1200000.0) || !(y <= 1.0)) {
tmp = y * (x + 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 ((y <= (-1200000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x + 1.0d0)
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1200000.0) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1200000.0) or not (y <= 1.0): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1200000.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1200000.0) || ~((y <= 1.0))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1200000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1200000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1.2e6 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.0%
if -1.2e6 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.8%
Final simplification98.9%
(FPCore (x y) :precision binary64 (if (<= y -1200000.0) (+ y (* x y)) (if (<= y 1.0) (- y x) (* y (+ x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -1200000.0) {
tmp = y + (x * y);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1200000.0d0)) then
tmp = y + (x * y)
else if (y <= 1.0d0) then
tmp = y - x
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1200000.0) {
tmp = y + (x * y);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1200000.0: tmp = y + (x * y) elif y <= 1.0: tmp = y - x else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -1200000.0) tmp = Float64(y + Float64(x * y)); elseif (y <= 1.0) tmp = Float64(y - x); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1200000.0) tmp = y + (x * y); elseif (y <= 1.0) tmp = y - x; else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1200000.0], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], N[(y - x), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1200000:\\
\;\;\;\;y + x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < -1.2e6Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.3%
Taylor expanded in x around 0 99.3%
if -1.2e6 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.8%
if 1 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 98.8%
Final simplification99.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 (* x y)) x))
double code(double x, double y) {
return (y + (x * y)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + (x * y)) - x
end function
public static double code(double x, double y) {
return (y + (x * y)) - x;
}
def code(x, y): return (y + (x * y)) - x
function code(x, y) return Float64(Float64(y + Float64(x * y)) - x) end
function tmp = code(x, y) tmp = (y + (x * y)) - x; end
code[x_, y_] := N[(N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x \cdot y\right) - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -6.5e-52) (- x) (if (<= x 4.2e-22) y (- x))))
double code(double x, double y) {
double tmp;
if (x <= -6.5e-52) {
tmp = -x;
} else if (x <= 4.2e-22) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-6.5d-52)) then
tmp = -x
else if (x <= 4.2d-22) then
tmp = y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6.5e-52) {
tmp = -x;
} else if (x <= 4.2e-22) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.5e-52: tmp = -x elif x <= 4.2e-22: tmp = y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -6.5e-52) tmp = Float64(-x); elseif (x <= 4.2e-22) tmp = y; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6.5e-52) tmp = -x; elseif (x <= 4.2e-22) tmp = y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.5e-52], (-x), If[LessEqual[x, 4.2e-22], y, (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-52}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-22}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -6.5e-52 or 4.20000000000000016e-22 < x Initial program 100.0%
Taylor expanded in y around 0 51.8%
neg-mul-151.8%
Simplified51.8%
if -6.5e-52 < x < 4.20000000000000016e-22Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 79.7%
Final simplification63.8%
(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 100.0%
Taylor expanded in x around 0 37.0%
Final simplification37.0%
herbie shell --seed 2023242
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))