
(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 (<= x -6e+248)
(* y x)
(if (<= x -7.2e-9)
(- x)
(if (<= x 7.8e-22) y (if (<= x 4e+164) (- x) (* y x))))))
double code(double x, double y) {
double tmp;
if (x <= -6e+248) {
tmp = y * x;
} else if (x <= -7.2e-9) {
tmp = -x;
} else if (x <= 7.8e-22) {
tmp = y;
} else if (x <= 4e+164) {
tmp = -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 <= (-6d+248)) then
tmp = y * x
else if (x <= (-7.2d-9)) then
tmp = -x
else if (x <= 7.8d-22) then
tmp = y
else if (x <= 4d+164) then
tmp = -x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6e+248) {
tmp = y * x;
} else if (x <= -7.2e-9) {
tmp = -x;
} else if (x <= 7.8e-22) {
tmp = y;
} else if (x <= 4e+164) {
tmp = -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6e+248: tmp = y * x elif x <= -7.2e-9: tmp = -x elif x <= 7.8e-22: tmp = y elif x <= 4e+164: tmp = -x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -6e+248) tmp = Float64(y * x); elseif (x <= -7.2e-9) tmp = Float64(-x); elseif (x <= 7.8e-22) tmp = y; elseif (x <= 4e+164) tmp = Float64(-x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6e+248) tmp = y * x; elseif (x <= -7.2e-9) tmp = -x; elseif (x <= 7.8e-22) tmp = y; elseif (x <= 4e+164) tmp = -x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6e+248], N[(y * x), $MachinePrecision], If[LessEqual[x, -7.2e-9], (-x), If[LessEqual[x, 7.8e-22], y, If[LessEqual[x, 4e+164], (-x), N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{+248}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -7.2 \cdot 10^{-9}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{-22}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+164}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -6e248 or 4e164 < x Initial program 100.0%
Taylor expanded in y around inf 74.2%
Taylor expanded in x around inf 74.2%
if -6e248 < x < -7.2e-9 or 7.79999999999999996e-22 < x < 4e164Initial program 100.0%
Taylor expanded in y around 0 65.8%
neg-mul-165.8%
Simplified65.8%
if -7.2e-9 < x < 7.79999999999999996e-22Initial program 100.0%
Taylor expanded in x around 0 85.3%
(FPCore (x y) :precision binary64 (if (or (<= y -17000.0) (not (<= y 0.000232))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -17000.0) || !(y <= 0.000232)) {
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 <= (-17000.0d0)) .or. (.not. (y <= 0.000232d0))) 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 <= -17000.0) || !(y <= 0.000232)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -17000.0) or not (y <= 0.000232): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -17000.0) || !(y <= 0.000232)) 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 <= -17000.0) || ~((y <= 0.000232))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -17000.0], N[Not[LessEqual[y, 0.000232]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -17000 \lor \neg \left(y \leq 0.000232\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -17000 or 2.32e-4 < y Initial program 100.0%
Taylor expanded in y around inf 99.2%
if -17000 < y < 2.32e-4Initial program 100.0%
Taylor expanded in x around 0 99.4%
Taylor expanded in y around 0 99.4%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (<= y -17000.0) (* y (+ x 1.0)) (if (<= y 0.000232) (- y x) (+ y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -17000.0) {
tmp = y * (x + 1.0);
} else if (y <= 0.000232) {
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 <= (-17000.0d0)) then
tmp = y * (x + 1.0d0)
else if (y <= 0.000232d0) 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 <= -17000.0) {
tmp = y * (x + 1.0);
} else if (y <= 0.000232) {
tmp = y - x;
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -17000.0: tmp = y * (x + 1.0) elif y <= 0.000232: tmp = y - x else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= -17000.0) tmp = Float64(y * Float64(x + 1.0)); elseif (y <= 0.000232) 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 <= -17000.0) tmp = y * (x + 1.0); elseif (y <= 0.000232) tmp = y - x; else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -17000.0], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.000232], N[(y - x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -17000:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{elif}\;y \leq 0.000232:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < -17000Initial program 100.0%
Taylor expanded in y around inf 99.2%
if -17000 < y < 2.32e-4Initial program 100.0%
Taylor expanded in x around 0 99.4%
Taylor expanded in y around 0 99.4%
if 2.32e-4 < y Initial program 100.0%
Taylor expanded in y around inf 99.2%
distribute-rgt-in99.3%
*-un-lft-identity99.3%
*-commutative99.3%
+-commutative99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (or (<= x -5.6e+248) (not (<= x 5.8e+165))) (* y x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -5.6e+248) || !(x <= 5.8e+165)) {
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 <= (-5.6d+248)) .or. (.not. (x <= 5.8d+165))) 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 <= -5.6e+248) || !(x <= 5.8e+165)) {
tmp = y * x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5.6e+248) or not (x <= 5.8e+165): tmp = y * x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -5.6e+248) || !(x <= 5.8e+165)) tmp = Float64(y * x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -5.6e+248) || ~((x <= 5.8e+165))) tmp = y * x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5.6e+248], N[Not[LessEqual[x, 5.8e+165]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{+248} \lor \neg \left(x \leq 5.8 \cdot 10^{+165}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -5.6000000000000004e248 or 5.80000000000000011e165 < x Initial program 100.0%
Taylor expanded in y around inf 74.2%
Taylor expanded in x around inf 74.2%
if -5.6000000000000004e248 < x < 5.80000000000000011e165Initial program 100.0%
Taylor expanded in x around 0 86.9%
Taylor expanded in y around 0 86.9%
Final simplification85.0%
(FPCore (x y) :precision binary64 (if (or (<= x -6.6e-7) (not (<= x 1.4e-21))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -6.6e-7) || !(x <= 1.4e-21)) {
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 <= (-6.6d-7)) .or. (.not. (x <= 1.4d-21))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -6.6e-7) || !(x <= 1.4e-21)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -6.6e-7) or not (x <= 1.4e-21): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -6.6e-7) || !(x <= 1.4e-21)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -6.6e-7) || ~((x <= 1.4e-21))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -6.6e-7], N[Not[LessEqual[x, 1.4e-21]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.6 \cdot 10^{-7} \lor \neg \left(x \leq 1.4 \cdot 10^{-21}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -6.6000000000000003e-7 or 1.40000000000000002e-21 < x Initial program 100.0%
Taylor expanded in y around 0 54.1%
neg-mul-154.1%
Simplified54.1%
if -6.6000000000000003e-7 < x < 1.40000000000000002e-21Initial program 100.0%
Taylor expanded in x around 0 85.3%
Final simplification70.2%
(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 45.9%
herbie shell --seed 2024165
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))