
(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 (- (+ 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 -5e+168)
(* y x)
(if (<= y -850000000.0)
y
(if (<= y 5e-31) (- x) (if (<= y 1.75e+16) y (* y x))))))
double code(double x, double y) {
double tmp;
if (y <= -5e+168) {
tmp = y * x;
} else if (y <= -850000000.0) {
tmp = y;
} else if (y <= 5e-31) {
tmp = -x;
} else if (y <= 1.75e+16) {
tmp = 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 (y <= (-5d+168)) then
tmp = y * x
else if (y <= (-850000000.0d0)) then
tmp = y
else if (y <= 5d-31) then
tmp = -x
else if (y <= 1.75d+16) then
tmp = y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -5e+168) {
tmp = y * x;
} else if (y <= -850000000.0) {
tmp = y;
} else if (y <= 5e-31) {
tmp = -x;
} else if (y <= 1.75e+16) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5e+168: tmp = y * x elif y <= -850000000.0: tmp = y elif y <= 5e-31: tmp = -x elif y <= 1.75e+16: tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -5e+168) tmp = Float64(y * x); elseif (y <= -850000000.0) tmp = y; elseif (y <= 5e-31) tmp = Float64(-x); elseif (y <= 1.75e+16) tmp = y; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -5e+168) tmp = y * x; elseif (y <= -850000000.0) tmp = y; elseif (y <= 5e-31) tmp = -x; elseif (y <= 1.75e+16) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5e+168], N[(y * x), $MachinePrecision], If[LessEqual[y, -850000000.0], y, If[LessEqual[y, 5e-31], (-x), If[LessEqual[y, 1.75e+16], y, N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+168}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -850000000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-31}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{+16}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.99999999999999967e168 or 1.75e16 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 67.6%
if -4.99999999999999967e168 < y < -8.5e8 or 5e-31 < y < 1.75e16Initial program 100.0%
Taylor expanded in x around 0 67.5%
if -8.5e8 < y < 5e-31Initial program 100.0%
Taylor expanded in y around 0 73.1%
neg-mul-173.1%
Simplified73.1%
(FPCore (x y) :precision binary64 (if (or (<= x -3.25) (not (<= x 1.0))) (- (* y x) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -3.25) || !(x <= 1.0)) {
tmp = (y * x) - 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 <= (-3.25d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (y * x) - x
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -3.25) || !(x <= 1.0)) {
tmp = (y * x) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.25) or not (x <= 1.0): tmp = (y * x) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.25) || !(x <= 1.0)) tmp = Float64(Float64(y * x) - x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3.25) || ~((x <= 1.0))) tmp = (y * x) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.25], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.25 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -3.25 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.2%
if -3.25 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.5%
Taylor expanded in y around 0 98.5%
Final simplification98.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 2.15e-10))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 2.15e-10)) {
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 <= (-1.0d0)) .or. (.not. (y <= 2.15d-10))) 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 <= -1.0) || !(y <= 2.15e-10)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 2.15e-10): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 2.15e-10)) 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 <= -1.0) || ~((y <= 2.15e-10))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 2.15e-10]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 2.15 \cdot 10^{-10}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1 or 2.15000000000000007e-10 < y Initial program 100.0%
Taylor expanded in y around inf 97.7%
if -1 < y < 2.15000000000000007e-10Initial program 100.0%
Taylor expanded in x around 0 99.1%
Taylor expanded in y around 0 99.1%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* y (+ x 1.0)) (if (<= y 2.15e-10) (- y x) (+ y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * (x + 1.0);
} else if (y <= 2.15e-10) {
tmp = y - x;
} else {
tmp = y + (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 <= (-1.0d0)) then
tmp = y * (x + 1.0d0)
else if (y <= 2.15d-10) then
tmp = y - x
else
tmp = y + (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * (x + 1.0);
} else if (y <= 2.15e-10) {
tmp = y - x;
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = y * (x + 1.0) elif y <= 2.15e-10: tmp = y - x else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * Float64(x + 1.0)); elseif (y <= 2.15e-10) tmp = Float64(y - x); else tmp = Float64(y + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = y * (x + 1.0); elseif (y <= 2.15e-10) tmp = y - x; else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.15e-10], N[(y - x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{elif}\;y \leq 2.15 \cdot 10^{-10}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < -1Initial program 100.0%
Taylor expanded in y around inf 95.3%
if -1 < y < 2.15000000000000007e-10Initial program 100.0%
Taylor expanded in x around 0 99.1%
Taylor expanded in y around 0 99.1%
if 2.15000000000000007e-10 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
*-commutative100.0%
+-commutative100.0%
Applied egg-rr100.0%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (or (<= y -3.35e+162) (not (<= y 3.9e+15))) (* y x) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -3.35e+162) || !(y <= 3.9e+15)) {
tmp = 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 ((y <= (-3.35d+162)) .or. (.not. (y <= 3.9d+15))) then
tmp = y * x
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3.35e+162) || !(y <= 3.9e+15)) {
tmp = y * x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.35e+162) or not (y <= 3.9e+15): tmp = y * x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.35e+162) || !(y <= 3.9e+15)) tmp = Float64(y * x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3.35e+162) || ~((y <= 3.9e+15))) tmp = y * x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.35e+162], N[Not[LessEqual[y, 3.9e+15]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.35 \cdot 10^{+162} \lor \neg \left(y \leq 3.9 \cdot 10^{+15}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -3.34999999999999995e162 or 3.9e15 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 67.6%
if -3.34999999999999995e162 < y < 3.9e15Initial program 100.0%
Taylor expanded in x around 0 89.5%
Taylor expanded in y around 0 89.5%
Final simplification82.7%
(FPCore (x y) :precision binary64 (if (or (<= x -4.9e-73) (not (<= x 26.5))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -4.9e-73) || !(x <= 26.5)) {
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.9d-73)) .or. (.not. (x <= 26.5d0))) 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.9e-73) || !(x <= 26.5)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.9e-73) or not (x <= 26.5): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.9e-73) || !(x <= 26.5)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -4.9e-73) || ~((x <= 26.5))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.9e-73], N[Not[LessEqual[x, 26.5]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.9 \cdot 10^{-73} \lor \neg \left(x \leq 26.5\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.90000000000000028e-73 or 26.5 < x Initial program 100.0%
Taylor expanded in y around 0 51.0%
neg-mul-151.0%
Simplified51.0%
if -4.90000000000000028e-73 < x < 26.5Initial program 100.0%
Taylor expanded in x around 0 78.1%
Final simplification61.9%
(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%
Taylor expanded in x around 0 35.0%
herbie shell --seed 2024141
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))