
(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 x) (* x y)))
double code(double x, double y) {
return (y - x) + (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y - x) + (x * y)
end function
public static double code(double x, double y) {
return (y - x) + (x * y);
}
def code(x, y): return (y - x) + (x * y)
function code(x, y) return Float64(Float64(y - x) + Float64(x * y)) end
function tmp = code(x, y) tmp = (y - x) + (x * y); end
code[x_, y_] := N[(N[(y - x), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y - x\right) + x \cdot y
\end{array}
Initial program 100.0%
distribute-lft1-in100.0%
associate--l+100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -2.2e+219)
(* x y)
(if (<= x -1.6e+135)
(- x)
(if (<= x -3.2e+100)
(* x y)
(if (<= x -9e+58)
(- x)
(if (<= x -5400000000.0)
(* x y)
(if (<= x -4.8e-32) (- x) (if (<= x 6e-31) y (- x)))))))))
double code(double x, double y) {
double tmp;
if (x <= -2.2e+219) {
tmp = x * y;
} else if (x <= -1.6e+135) {
tmp = -x;
} else if (x <= -3.2e+100) {
tmp = x * y;
} else if (x <= -9e+58) {
tmp = -x;
} else if (x <= -5400000000.0) {
tmp = x * y;
} else if (x <= -4.8e-32) {
tmp = -x;
} else if (x <= 6e-31) {
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 <= (-2.2d+219)) then
tmp = x * y
else if (x <= (-1.6d+135)) then
tmp = -x
else if (x <= (-3.2d+100)) then
tmp = x * y
else if (x <= (-9d+58)) then
tmp = -x
else if (x <= (-5400000000.0d0)) then
tmp = x * y
else if (x <= (-4.8d-32)) then
tmp = -x
else if (x <= 6d-31) then
tmp = y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.2e+219) {
tmp = x * y;
} else if (x <= -1.6e+135) {
tmp = -x;
} else if (x <= -3.2e+100) {
tmp = x * y;
} else if (x <= -9e+58) {
tmp = -x;
} else if (x <= -5400000000.0) {
tmp = x * y;
} else if (x <= -4.8e-32) {
tmp = -x;
} else if (x <= 6e-31) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.2e+219: tmp = x * y elif x <= -1.6e+135: tmp = -x elif x <= -3.2e+100: tmp = x * y elif x <= -9e+58: tmp = -x elif x <= -5400000000.0: tmp = x * y elif x <= -4.8e-32: tmp = -x elif x <= 6e-31: tmp = y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -2.2e+219) tmp = Float64(x * y); elseif (x <= -1.6e+135) tmp = Float64(-x); elseif (x <= -3.2e+100) tmp = Float64(x * y); elseif (x <= -9e+58) tmp = Float64(-x); elseif (x <= -5400000000.0) tmp = Float64(x * y); elseif (x <= -4.8e-32) tmp = Float64(-x); elseif (x <= 6e-31) tmp = y; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.2e+219) tmp = x * y; elseif (x <= -1.6e+135) tmp = -x; elseif (x <= -3.2e+100) tmp = x * y; elseif (x <= -9e+58) tmp = -x; elseif (x <= -5400000000.0) tmp = x * y; elseif (x <= -4.8e-32) tmp = -x; elseif (x <= 6e-31) tmp = y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.2e+219], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.6e+135], (-x), If[LessEqual[x, -3.2e+100], N[(x * y), $MachinePrecision], If[LessEqual[x, -9e+58], (-x), If[LessEqual[x, -5400000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, -4.8e-32], (-x), If[LessEqual[x, 6e-31], y, (-x)]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.2 \cdot 10^{+219}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.6 \cdot 10^{+135}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -3.2 \cdot 10^{+100}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -9 \cdot 10^{+58}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -5400000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -4.8 \cdot 10^{-32}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-31}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -2.2000000000000001e219 or -1.59999999999999987e135 < x < -3.1999999999999999e100 or -8.9999999999999996e58 < x < -5.4e9Initial program 100.0%
Taylor expanded in x around inf 99.4%
Taylor expanded in y around inf 76.4%
if -2.2000000000000001e219 < x < -1.59999999999999987e135 or -3.1999999999999999e100 < x < -8.9999999999999996e58 or -5.4e9 < x < -4.8000000000000003e-32 or 5.99999999999999962e-31 < x Initial program 100.0%
Taylor expanded in y around 0 66.1%
neg-mul-166.1%
Simplified66.1%
if -4.8000000000000003e-32 < x < 5.99999999999999962e-31Initial program 100.0%
distribute-lft1-in100.0%
associate--l+100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 83.7%
Final simplification75.0%
(FPCore (x y)
:precision binary64
(if (<= x -2.35e+219)
(* x y)
(if (<= x -2.05e+135)
(- x)
(if (<= x -8.2e+99)
(* x y)
(if (<= x -5e+57) (- x) (if (<= x -58000000000.0) (* x y) (- y x)))))))
double code(double x, double y) {
double tmp;
if (x <= -2.35e+219) {
tmp = x * y;
} else if (x <= -2.05e+135) {
tmp = -x;
} else if (x <= -8.2e+99) {
tmp = x * y;
} else if (x <= -5e+57) {
tmp = -x;
} else if (x <= -58000000000.0) {
tmp = x * y;
} 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 <= (-2.35d+219)) then
tmp = x * y
else if (x <= (-2.05d+135)) then
tmp = -x
else if (x <= (-8.2d+99)) then
tmp = x * y
else if (x <= (-5d+57)) then
tmp = -x
else if (x <= (-58000000000.0d0)) then
tmp = x * y
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.35e+219) {
tmp = x * y;
} else if (x <= -2.05e+135) {
tmp = -x;
} else if (x <= -8.2e+99) {
tmp = x * y;
} else if (x <= -5e+57) {
tmp = -x;
} else if (x <= -58000000000.0) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.35e+219: tmp = x * y elif x <= -2.05e+135: tmp = -x elif x <= -8.2e+99: tmp = x * y elif x <= -5e+57: tmp = -x elif x <= -58000000000.0: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (x <= -2.35e+219) tmp = Float64(x * y); elseif (x <= -2.05e+135) tmp = Float64(-x); elseif (x <= -8.2e+99) tmp = Float64(x * y); elseif (x <= -5e+57) tmp = Float64(-x); elseif (x <= -58000000000.0) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.35e+219) tmp = x * y; elseif (x <= -2.05e+135) tmp = -x; elseif (x <= -8.2e+99) tmp = x * y; elseif (x <= -5e+57) tmp = -x; elseif (x <= -58000000000.0) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.35e+219], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.05e+135], (-x), If[LessEqual[x, -8.2e+99], N[(x * y), $MachinePrecision], If[LessEqual[x, -5e+57], (-x), If[LessEqual[x, -58000000000.0], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.35 \cdot 10^{+219}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -2.05 \cdot 10^{+135}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -8.2 \cdot 10^{+99}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -5 \cdot 10^{+57}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -58000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -2.35000000000000007e219 or -2.05e135 < x < -8.19999999999999959e99 or -4.99999999999999972e57 < x < -5.8e10Initial program 100.0%
Taylor expanded in x around inf 99.4%
Taylor expanded in y around inf 76.4%
if -2.35000000000000007e219 < x < -2.05e135 or -8.19999999999999959e99 < x < -4.99999999999999972e57Initial program 100.0%
Taylor expanded in y around 0 73.8%
neg-mul-173.8%
Simplified73.8%
if -5.8e10 < x Initial program 100.0%
Taylor expanded in x around 0 85.1%
Final simplification82.6%
(FPCore (x y) :precision binary64 (if (or (<= y -3e+20) (not (<= y 1.7e-7))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -3e+20) || !(y <= 1.7e-7)) {
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 <= (-3d+20)) .or. (.not. (y <= 1.7d-7))) 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 <= -3e+20) || !(y <= 1.7e-7)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3e+20) or not (y <= 1.7e-7): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3e+20) || !(y <= 1.7e-7)) 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 <= -3e+20) || ~((y <= 1.7e-7))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3e+20], N[Not[LessEqual[y, 1.7e-7]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+20} \lor \neg \left(y \leq 1.7 \cdot 10^{-7}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -3e20 or 1.69999999999999987e-7 < y Initial program 100.0%
distribute-lft1-in100.0%
associate--l+100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 99.5%
if -3e20 < y < 1.69999999999999987e-7Initial program 100.0%
Taylor expanded in x around 0 98.8%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (or (<= x -32.0) (not (<= x 0.000285))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -32.0) || !(x <= 0.000285)) {
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 <= (-32.0d0)) .or. (.not. (x <= 0.000285d0))) 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 <= -32.0) || !(x <= 0.000285)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -32.0) or not (x <= 0.000285): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -32.0) || !(x <= 0.000285)) 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 <= -32.0) || ~((x <= 0.000285))) tmp = x * (y + -1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -32.0], N[Not[LessEqual[x, 0.000285]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -32 \lor \neg \left(x \leq 0.000285\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -32 or 2.8499999999999999e-4 < x Initial program 100.0%
Taylor expanded in x around inf 99.1%
if -32 < x < 2.8499999999999999e-4Initial program 100.0%
Taylor expanded in x around 0 99.3%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (<= x -32.0) (* x (+ y -1.0)) (if (<= x 0.000285) (- y x) (- (* x y) x))))
double code(double x, double y) {
double tmp;
if (x <= -32.0) {
tmp = x * (y + -1.0);
} else if (x <= 0.000285) {
tmp = y - x;
} else {
tmp = (x * 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 <= (-32.0d0)) then
tmp = x * (y + (-1.0d0))
else if (x <= 0.000285d0) then
tmp = y - x
else
tmp = (x * y) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -32.0) {
tmp = x * (y + -1.0);
} else if (x <= 0.000285) {
tmp = y - x;
} else {
tmp = (x * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -32.0: tmp = x * (y + -1.0) elif x <= 0.000285: tmp = y - x else: tmp = (x * y) - x return tmp
function code(x, y) tmp = 0.0 if (x <= -32.0) tmp = Float64(x * Float64(y + -1.0)); elseif (x <= 0.000285) tmp = Float64(y - x); else tmp = Float64(Float64(x * y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -32.0) tmp = x * (y + -1.0); elseif (x <= 0.000285) tmp = y - x; else tmp = (x * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -32.0], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.000285], N[(y - x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -32:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{elif}\;x \leq 0.000285:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if x < -32Initial program 100.0%
Taylor expanded in x around inf 99.1%
if -32 < x < 2.8499999999999999e-4Initial program 100.0%
Taylor expanded in x around 0 99.3%
if 2.8499999999999999e-4 < x Initial program 100.0%
Taylor expanded in x around inf 99.2%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (<= x -9.5e-31) (- x) (if (<= x 6.5e-36) y (- x))))
double code(double x, double y) {
double tmp;
if (x <= -9.5e-31) {
tmp = -x;
} else if (x <= 6.5e-36) {
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 <= (-9.5d-31)) then
tmp = -x
else if (x <= 6.5d-36) then
tmp = y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -9.5e-31) {
tmp = -x;
} else if (x <= 6.5e-36) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9.5e-31: tmp = -x elif x <= 6.5e-36: tmp = y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -9.5e-31) tmp = Float64(-x); elseif (x <= 6.5e-36) tmp = y; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -9.5e-31) tmp = -x; elseif (x <= 6.5e-36) tmp = y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9.5e-31], (-x), If[LessEqual[x, 6.5e-36], y, (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-31}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{-36}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -9.5000000000000008e-31 or 6.50000000000000012e-36 < x Initial program 100.0%
Taylor expanded in y around 0 55.9%
neg-mul-155.9%
Simplified55.9%
if -9.5000000000000008e-31 < x < 6.50000000000000012e-36Initial program 100.0%
distribute-lft1-in100.0%
associate--l+100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 83.7%
Final simplification67.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%
distribute-lft1-in100.0%
associate--l+100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 37.3%
Final simplification37.3%
herbie shell --seed 2023230
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))