
(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 6 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 (or (<= y -8.5e+127)
(and (not (<= y -1.5e+37))
(or (<= y 1.1e+84)
(and (not (<= y 2.45e+138))
(or (<= y 6e+186)
(and (not (<= y 2.8e+276)) (<= y 5e+298)))))))
(- y x)
(* y x)))
double code(double x, double y) {
double tmp;
if ((y <= -8.5e+127) || (!(y <= -1.5e+37) && ((y <= 1.1e+84) || (!(y <= 2.45e+138) && ((y <= 6e+186) || (!(y <= 2.8e+276) && (y <= 5e+298))))))) {
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 <= (-8.5d+127)) .or. (.not. (y <= (-1.5d+37))) .and. (y <= 1.1d+84) .or. (.not. (y <= 2.45d+138)) .and. (y <= 6d+186) .or. (.not. (y <= 2.8d+276)) .and. (y <= 5d+298)) 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 <= -8.5e+127) || (!(y <= -1.5e+37) && ((y <= 1.1e+84) || (!(y <= 2.45e+138) && ((y <= 6e+186) || (!(y <= 2.8e+276) && (y <= 5e+298))))))) {
tmp = y - x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -8.5e+127) or (not (y <= -1.5e+37) and ((y <= 1.1e+84) or (not (y <= 2.45e+138) and ((y <= 6e+186) or (not (y <= 2.8e+276) and (y <= 5e+298)))))): tmp = y - x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if ((y <= -8.5e+127) || (!(y <= -1.5e+37) && ((y <= 1.1e+84) || (!(y <= 2.45e+138) && ((y <= 6e+186) || (!(y <= 2.8e+276) && (y <= 5e+298))))))) tmp = Float64(y - x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -8.5e+127) || (~((y <= -1.5e+37)) && ((y <= 1.1e+84) || (~((y <= 2.45e+138)) && ((y <= 6e+186) || (~((y <= 2.8e+276)) && (y <= 5e+298))))))) tmp = y - x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -8.5e+127], And[N[Not[LessEqual[y, -1.5e+37]], $MachinePrecision], Or[LessEqual[y, 1.1e+84], And[N[Not[LessEqual[y, 2.45e+138]], $MachinePrecision], Or[LessEqual[y, 6e+186], And[N[Not[LessEqual[y, 2.8e+276]], $MachinePrecision], LessEqual[y, 5e+298]]]]]]], N[(y - x), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{+127} \lor \neg \left(y \leq -1.5 \cdot 10^{+37}\right) \land \left(y \leq 1.1 \cdot 10^{+84} \lor \neg \left(y \leq 2.45 \cdot 10^{+138}\right) \land \left(y \leq 6 \cdot 10^{+186} \lor \neg \left(y \leq 2.8 \cdot 10^{+276}\right) \land y \leq 5 \cdot 10^{+298}\right)\right):\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.4999999999999997e127 or -1.50000000000000011e37 < y < 1.0999999999999999e84 or 2.44999999999999992e138 < y < 5.99999999999999964e186 or 2.79999999999999995e276 < y < 5.0000000000000003e298Initial program 100.0%
Taylor expanded in x around 0 88.9%
if -8.4999999999999997e127 < y < -1.50000000000000011e37 or 1.0999999999999999e84 < y < 2.44999999999999992e138 or 5.99999999999999964e186 < y < 2.79999999999999995e276 or 5.0000000000000003e298 < y Initial program 100.0%
Taylor expanded in x around inf 72.2%
*-commutative72.2%
Simplified72.2%
Taylor expanded in y around inf 72.2%
Final simplification85.1%
(FPCore (x y) :precision binary64 (if (or (<= x -2.0) (not (<= x 1.0))) (- (* y x) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -2.0) || !(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 <= (-2.0d0)) .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 <= -2.0) || !(x <= 1.0)) {
tmp = (y * x) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.0) or not (x <= 1.0): tmp = (y * x) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.0) || !(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 <= -2.0) || ~((x <= 1.0))) tmp = (y * x) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.0], 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 -2 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -2 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 97.7%
*-commutative97.7%
Simplified97.7%
if -2 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.6%
Final simplification98.2%
(FPCore (x y) :precision binary64 (if (or (<= y -0.00023) (not (<= y 0.0038))) (* y x) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -0.00023) || !(y <= 0.0038)) {
tmp = y * x;
} 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 ((y <= (-0.00023d0)) .or. (.not. (y <= 0.0038d0))) then
tmp = y * x
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -0.00023) || !(y <= 0.0038)) {
tmp = y * x;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.00023) or not (y <= 0.0038): tmp = y * x else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.00023) || !(y <= 0.0038)) tmp = Float64(y * x); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -0.00023) || ~((y <= 0.0038))) tmp = y * x; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.00023], N[Not[LessEqual[y, 0.0038]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00023 \lor \neg \left(y \leq 0.0038\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -2.3000000000000001e-4 or 0.00379999999999999999 < y Initial program 100.0%
Taylor expanded in x around inf 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in y around inf 47.9%
if -2.3000000000000001e-4 < y < 0.00379999999999999999Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 73.2%
mul-1-neg73.2%
Simplified73.2%
Final simplification60.8%
(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 (- x))
double code(double x, double y) {
return -x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x
end function
public static double code(double x, double y) {
return -x;
}
def code(x, y): return -x
function code(x, y) return Float64(-x) end
function tmp = code(x, y) tmp = -x; end
code[x_, y_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 38.5%
mul-1-neg38.5%
Simplified38.5%
Final simplification38.5%
herbie shell --seed 2024044
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))