
(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 -9e+19)
(* y x)
(if (<= y -3.1e-21)
y
(if (<= y 5.2e-78)
(- x)
(if (or (<= y 1.55e+101) (and (not (<= y 6.5e+202)) (<= y 9.8e+294)))
y
(* y x))))))
double code(double x, double y) {
double tmp;
if (y <= -9e+19) {
tmp = y * x;
} else if (y <= -3.1e-21) {
tmp = y;
} else if (y <= 5.2e-78) {
tmp = -x;
} else if ((y <= 1.55e+101) || (!(y <= 6.5e+202) && (y <= 9.8e+294))) {
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 <= (-9d+19)) then
tmp = y * x
else if (y <= (-3.1d-21)) then
tmp = y
else if (y <= 5.2d-78) then
tmp = -x
else if ((y <= 1.55d+101) .or. (.not. (y <= 6.5d+202)) .and. (y <= 9.8d+294)) 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 <= -9e+19) {
tmp = y * x;
} else if (y <= -3.1e-21) {
tmp = y;
} else if (y <= 5.2e-78) {
tmp = -x;
} else if ((y <= 1.55e+101) || (!(y <= 6.5e+202) && (y <= 9.8e+294))) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9e+19: tmp = y * x elif y <= -3.1e-21: tmp = y elif y <= 5.2e-78: tmp = -x elif (y <= 1.55e+101) or (not (y <= 6.5e+202) and (y <= 9.8e+294)): tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -9e+19) tmp = Float64(y * x); elseif (y <= -3.1e-21) tmp = y; elseif (y <= 5.2e-78) tmp = Float64(-x); elseif ((y <= 1.55e+101) || (!(y <= 6.5e+202) && (y <= 9.8e+294))) tmp = y; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -9e+19) tmp = y * x; elseif (y <= -3.1e-21) tmp = y; elseif (y <= 5.2e-78) tmp = -x; elseif ((y <= 1.55e+101) || (~((y <= 6.5e+202)) && (y <= 9.8e+294))) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9e+19], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.1e-21], y, If[LessEqual[y, 5.2e-78], (-x), If[Or[LessEqual[y, 1.55e+101], And[N[Not[LessEqual[y, 6.5e+202]], $MachinePrecision], LessEqual[y, 9.8e+294]]], y, N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+19}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.1 \cdot 10^{-21}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-78}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{+101} \lor \neg \left(y \leq 6.5 \cdot 10^{+202}\right) \land y \leq 9.8 \cdot 10^{+294}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -9e19 or 1.55e101 < y < 6.4999999999999996e202 or 9.7999999999999995e294 < y Initial program 100.0%
Taylor expanded in x around inf 62.6%
*-commutative62.6%
Simplified62.6%
Taylor expanded in y around inf 62.6%
if -9e19 < y < -3.0999999999999998e-21 or 5.2000000000000002e-78 < y < 1.55e101 or 6.4999999999999996e202 < y < 9.7999999999999995e294Initial 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 67.8%
if -3.0999999999999998e-21 < y < 5.2000000000000002e-78Initial program 100.0%
Taylor expanded in y around 0 82.9%
mul-1-neg82.9%
Simplified82.9%
Final simplification71.6%
(FPCore (x y) :precision binary64 (if (or (<= x -2.0) (and (not (<= x 4.6e+213)) (<= x 1.15e+260))) (* y x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -2.0) || (!(x <= 4.6e+213) && (x <= 1.15e+260))) {
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 ((x <= (-2.0d0)) .or. (.not. (x <= 4.6d+213)) .and. (x <= 1.15d+260)) 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 ((x <= -2.0) || (!(x <= 4.6e+213) && (x <= 1.15e+260))) {
tmp = y * x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.0) or (not (x <= 4.6e+213) and (x <= 1.15e+260)): tmp = y * x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.0) || (!(x <= 4.6e+213) && (x <= 1.15e+260))) tmp = Float64(y * x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.0) || (~((x <= 4.6e+213)) && (x <= 1.15e+260))) tmp = y * x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.0], And[N[Not[LessEqual[x, 4.6e+213]], $MachinePrecision], LessEqual[x, 1.15e+260]]], N[(y * x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \lor \neg \left(x \leq 4.6 \cdot 10^{+213}\right) \land x \leq 1.15 \cdot 10^{+260}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -2 or 4.59999999999999996e213 < x < 1.15000000000000005e260Initial program 100.0%
Taylor expanded in x around inf 98.0%
*-commutative98.0%
Simplified98.0%
Taylor expanded in y around inf 63.6%
if -2 < x < 4.59999999999999996e213 or 1.15000000000000005e260 < x Initial program 100.0%
Taylor expanded in x around 0 85.5%
Final simplification78.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.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 <= (-1.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 <= -1.0) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.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 <= -1.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 <= -1.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, -1.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 -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial 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 99.4%
+-commutative99.4%
Simplified99.4%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.6%
Final simplification99.1%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (+ y (* y x)) (if (<= y 1.0) (- y x) (* y (+ x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y + (y * x);
} 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 <= (-1.0d0)) then
tmp = y + (y * x)
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 <= -1.0) {
tmp = y + (y * x);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = y + (y * x) elif y <= 1.0: tmp = y - x else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y + Float64(y * x)); 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 <= -1.0) tmp = y + (y * x); elseif (y <= 1.0) tmp = y - x; else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(y + N[(y * x), $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 -1:\\
\;\;\;\;y + y \cdot x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < -1Initial 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 98.9%
+-commutative98.9%
Simplified98.9%
distribute-lft-in98.9%
*-rgt-identity98.9%
Applied egg-rr98.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.6%
if 1 < y Initial 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%
+-commutative100.0%
Simplified100.0%
Final simplification99.1%
(FPCore (x y) :precision binary64 (if (<= y -2.6e-20) y (if (<= y 5.2e-78) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -2.6e-20) {
tmp = y;
} else if (y <= 5.2e-78) {
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 <= (-2.6d-20)) then
tmp = y
else if (y <= 5.2d-78) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.6e-20) {
tmp = y;
} else if (y <= 5.2e-78) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.6e-20: tmp = y elif y <= 5.2e-78: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.6e-20) tmp = y; elseif (y <= 5.2e-78) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.6e-20) tmp = y; elseif (y <= 5.2e-78) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.6e-20], y, If[LessEqual[y, 5.2e-78], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{-20}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-78}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.59999999999999995e-20 or 5.2000000000000002e-78 < 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 49.1%
if -2.59999999999999995e-20 < y < 5.2000000000000002e-78Initial program 100.0%
Taylor expanded in y around 0 82.9%
mul-1-neg82.9%
Simplified82.9%
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%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 37.9%
Final simplification37.9%
herbie shell --seed 2024085
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))