
(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 7 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 (+ y -1.0))))
double code(double x, double y) {
return y + (x * (y + -1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x * (y + (-1.0d0)))
end function
public static double code(double x, double y) {
return y + (x * (y + -1.0));
}
def code(x, y): return y + (x * (y + -1.0))
function code(x, y) return Float64(y + Float64(x * Float64(y + -1.0))) end
function tmp = code(x, y) tmp = y + (x * (y + -1.0)); end
code[x_, y_] := N[(y + N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + x \cdot \left(y + -1\right)
\end{array}
Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -1.0)
(* y x)
(if (<= y 6e-40)
(- x)
(if (<= y 3650000000000.0) y (if (<= y 6e+69) (* y x) y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 6e-40) {
tmp = -x;
} else if (y <= 3650000000000.0) {
tmp = y;
} else if (y <= 6e+69) {
tmp = y * 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 <= (-1.0d0)) then
tmp = y * x
else if (y <= 6d-40) then
tmp = -x
else if (y <= 3650000000000.0d0) then
tmp = y
else if (y <= 6d+69) then
tmp = y * x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 6e-40) {
tmp = -x;
} else if (y <= 3650000000000.0) {
tmp = y;
} else if (y <= 6e+69) {
tmp = y * x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = y * x elif y <= 6e-40: tmp = -x elif y <= 3650000000000.0: tmp = y elif y <= 6e+69: tmp = y * x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * x); elseif (y <= 6e-40) tmp = Float64(-x); elseif (y <= 3650000000000.0) tmp = y; elseif (y <= 6e+69) tmp = Float64(y * x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = y * x; elseif (y <= 6e-40) tmp = -x; elseif (y <= 3650000000000.0) tmp = y; elseif (y <= 6e+69) tmp = y * x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 6e-40], (-x), If[LessEqual[y, 3650000000000.0], y, If[LessEqual[y, 6e+69], N[(y * x), $MachinePrecision], y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-40}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 3650000000000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+69}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 3.65e12 < y < 5.99999999999999967e69Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around inf 99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in x around inf 60.2%
*-commutative60.2%
Simplified60.2%
if -1 < y < 6.00000000000000039e-40Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around 0 80.5%
neg-mul-180.5%
Simplified80.5%
if 6.00000000000000039e-40 < y < 3.65e12 or 5.99999999999999967e69 < y Initial program 99.9%
sub-neg99.9%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in x around 0 63.5%
Final simplification70.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.4e-21) (not (<= y 6e-32))) (* y (+ x 1.0)) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.4e-21) || !(y <= 6e-32)) {
tmp = y * (x + 1.0);
} 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 <= (-1.4d-21)) .or. (.not. (y <= 6d-32))) then
tmp = y * (x + 1.0d0)
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.4e-21) || !(y <= 6e-32)) {
tmp = y * (x + 1.0);
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.4e-21) or not (y <= 6e-32): tmp = y * (x + 1.0) else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.4e-21) || !(y <= 6e-32)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.4e-21) || ~((y <= 6e-32))) tmp = y * (x + 1.0); else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.4e-21], N[Not[LessEqual[y, 6e-32]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-21} \lor \neg \left(y \leq 6 \cdot 10^{-32}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -1.40000000000000002e-21 or 6.0000000000000001e-32 < y Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around inf 97.1%
+-commutative97.1%
Simplified97.1%
if -1.40000000000000002e-21 < y < 6.0000000000000001e-32Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around 0 82.2%
neg-mul-182.2%
Simplified82.2%
Final simplification90.2%
(FPCore (x y) :precision binary64 (if (<= y -6.4e-21) (* y (+ x 1.0)) (if (<= y 5.5e-33) (- x) (+ y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -6.4e-21) {
tmp = y * (x + 1.0);
} else if (y <= 5.5e-33) {
tmp = -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 <= (-6.4d-21)) then
tmp = y * (x + 1.0d0)
else if (y <= 5.5d-33) then
tmp = -x
else
tmp = y + (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6.4e-21) {
tmp = y * (x + 1.0);
} else if (y <= 5.5e-33) {
tmp = -x;
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.4e-21: tmp = y * (x + 1.0) elif y <= 5.5e-33: tmp = -x else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= -6.4e-21) tmp = Float64(y * Float64(x + 1.0)); elseif (y <= 5.5e-33) tmp = Float64(-x); else tmp = Float64(y + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6.4e-21) tmp = y * (x + 1.0); elseif (y <= 5.5e-33) tmp = -x; else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.4e-21], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.5e-33], (-x), N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{-21}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-33}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < -6.4000000000000003e-21Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around inf 96.0%
+-commutative96.0%
Simplified96.0%
if -6.4000000000000003e-21 < y < 5.5e-33Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around 0 82.2%
neg-mul-182.2%
Simplified82.2%
if 5.5e-33 < y Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around inf 98.2%
+-commutative98.2%
Simplified98.2%
distribute-lft-in98.2%
*-rgt-identity98.2%
Applied egg-rr98.2%
Final simplification90.2%
(FPCore (x y) :precision binary64 (if (<= y -140000.0) (* y (+ x 1.0)) (if (<= y 5e-32) (- (* y x) x) (+ y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -140000.0) {
tmp = y * (x + 1.0);
} else if (y <= 5e-32) {
tmp = (y * x) - 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 <= (-140000.0d0)) then
tmp = y * (x + 1.0d0)
else if (y <= 5d-32) then
tmp = (y * x) - x
else
tmp = y + (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -140000.0) {
tmp = y * (x + 1.0);
} else if (y <= 5e-32) {
tmp = (y * x) - x;
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -140000.0: tmp = y * (x + 1.0) elif y <= 5e-32: tmp = (y * x) - x else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= -140000.0) tmp = Float64(y * Float64(x + 1.0)); elseif (y <= 5e-32) tmp = Float64(Float64(y * x) - x); else tmp = Float64(y + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -140000.0) tmp = y * (x + 1.0); elseif (y <= 5e-32) tmp = (y * x) - x; else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -140000.0], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5e-32], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -140000:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-32}:\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < -1.4e5Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
Simplified100.0%
if -1.4e5 < y < 5e-32Initial program 100.0%
Taylor expanded in x around inf 81.4%
if 5e-32 < y Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around inf 98.2%
+-commutative98.2%
Simplified98.2%
distribute-lft-in98.2%
*-rgt-identity98.2%
Applied egg-rr98.2%
Final simplification90.4%
(FPCore (x y) :precision binary64 (if (<= y -4.2e-19) y (if (<= y 5.2e-33) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -4.2e-19) {
tmp = y;
} else if (y <= 5.2e-33) {
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 <= (-4.2d-19)) then
tmp = y
else if (y <= 5.2d-33) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.2e-19) {
tmp = y;
} else if (y <= 5.2e-33) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.2e-19: tmp = y elif y <= 5.2e-33: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.2e-19) tmp = y; elseif (y <= 5.2e-33) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.2e-19) tmp = y; elseif (y <= 5.2e-33) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.2e-19], y, If[LessEqual[y, 5.2e-33], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{-19}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-33}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -4.1999999999999998e-19 or 5.19999999999999988e-33 < y Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in x around 0 49.3%
if -4.1999999999999998e-19 < y < 5.19999999999999988e-33Initial program 100.0%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in y around 0 82.2%
neg-mul-182.2%
Simplified82.2%
Final simplification64.7%
(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%
sub-neg100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in x around 0 35.0%
Final simplification35.0%
herbie shell --seed 2024048
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))