
(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 (* 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-negN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= x -0.0014) (- 0.0 x) (if (<= x 1.3e-8) y (if (<= x 2.1e+247) (* y x) (- 0.0 x)))))
double code(double x, double y) {
double tmp;
if (x <= -0.0014) {
tmp = 0.0 - x;
} else if (x <= 1.3e-8) {
tmp = y;
} else if (x <= 2.1e+247) {
tmp = y * x;
} else {
tmp = 0.0 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.0014d0)) then
tmp = 0.0d0 - x
else if (x <= 1.3d-8) then
tmp = y
else if (x <= 2.1d+247) then
tmp = y * x
else
tmp = 0.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.0014) {
tmp = 0.0 - x;
} else if (x <= 1.3e-8) {
tmp = y;
} else if (x <= 2.1e+247) {
tmp = y * x;
} else {
tmp = 0.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.0014: tmp = 0.0 - x elif x <= 1.3e-8: tmp = y elif x <= 2.1e+247: tmp = y * x else: tmp = 0.0 - x return tmp
function code(x, y) tmp = 0.0 if (x <= -0.0014) tmp = Float64(0.0 - x); elseif (x <= 1.3e-8) tmp = y; elseif (x <= 2.1e+247) tmp = Float64(y * x); else tmp = Float64(0.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.0014) tmp = 0.0 - x; elseif (x <= 1.3e-8) tmp = y; elseif (x <= 2.1e+247) tmp = y * x; else tmp = 0.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.0014], N[(0.0 - x), $MachinePrecision], If[LessEqual[x, 1.3e-8], y, If[LessEqual[x, 2.1e+247], N[(y * x), $MachinePrecision], N[(0.0 - x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0014:\\
\;\;\;\;0 - x\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-8}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{+247}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;0 - x\\
\end{array}
\end{array}
if x < -0.00139999999999999999 or 2.1e247 < x Initial program 100.0%
sub-negN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6459.4%
Simplified59.4%
sub0-negN/A
neg-lowering-neg.f6459.4%
Applied egg-rr59.4%
if -0.00139999999999999999 < x < 1.3000000000000001e-8Initial program 100.0%
sub-negN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified78.6%
if 1.3000000000000001e-8 < x < 2.1e247Initial program 100.0%
sub-negN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6458.7%
Simplified58.7%
Taylor expanded in x around inf
Simplified57.1%
Final simplification68.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (+ y -1.0)))) (if (<= x -1400.0) t_0 (if (<= x 1.3e-8) (- y x) t_0))))
double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -1400.0) {
tmp = t_0;
} else if (x <= 1.3e-8) {
tmp = y - x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x * (y + (-1.0d0))
if (x <= (-1400.0d0)) then
tmp = t_0
else if (x <= 1.3d-8) then
tmp = y - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -1400.0) {
tmp = t_0;
} else if (x <= 1.3e-8) {
tmp = y - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (y + -1.0) tmp = 0 if x <= -1400.0: tmp = t_0 elif x <= 1.3e-8: tmp = y - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(y + -1.0)) tmp = 0.0 if (x <= -1400.0) tmp = t_0; elseif (x <= 1.3e-8) tmp = Float64(y - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (y + -1.0); tmp = 0.0; if (x <= -1400.0) tmp = t_0; elseif (x <= 1.3e-8) tmp = y - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1400.0], t$95$0, If[LessEqual[x, 1.3e-8], N[(y - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + -1\right)\\
\mathbf{if}\;x \leq -1400:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-8}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1400 or 1.3000000000000001e-8 < x Initial program 100.0%
sub-negN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f6499.4%
Simplified99.4%
if -1400 < x < 1.3000000000000001e-8Initial program 100.0%
Taylor expanded in x around 0
Simplified98.7%
Final simplification99.0%
(FPCore (x y) :precision binary64 (if (<= x -0.0014) (- 0.0 x) (if (<= x 3.7e-11) y (- 0.0 x))))
double code(double x, double y) {
double tmp;
if (x <= -0.0014) {
tmp = 0.0 - x;
} else if (x <= 3.7e-11) {
tmp = y;
} else {
tmp = 0.0 - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.0014d0)) then
tmp = 0.0d0 - x
else if (x <= 3.7d-11) then
tmp = y
else
tmp = 0.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.0014) {
tmp = 0.0 - x;
} else if (x <= 3.7e-11) {
tmp = y;
} else {
tmp = 0.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.0014: tmp = 0.0 - x elif x <= 3.7e-11: tmp = y else: tmp = 0.0 - x return tmp
function code(x, y) tmp = 0.0 if (x <= -0.0014) tmp = Float64(0.0 - x); elseif (x <= 3.7e-11) tmp = y; else tmp = Float64(0.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.0014) tmp = 0.0 - x; elseif (x <= 3.7e-11) tmp = y; else tmp = 0.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.0014], N[(0.0 - x), $MachinePrecision], If[LessEqual[x, 3.7e-11], y, N[(0.0 - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0014:\\
\;\;\;\;0 - x\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-11}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;0 - x\\
\end{array}
\end{array}
if x < -0.00139999999999999999 or 3.7000000000000001e-11 < x Initial program 100.0%
sub-negN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in y around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f6453.2%
Simplified53.2%
sub0-negN/A
neg-lowering-neg.f6453.2%
Applied egg-rr53.2%
if -0.00139999999999999999 < x < 3.7000000000000001e-11Initial program 100.0%
sub-negN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified78.6%
Final simplification66.3%
(FPCore (x y) :precision binary64 (if (<= y -3.3e+213) (* y x) (- y x)))
double code(double x, double y) {
double tmp;
if (y <= -3.3e+213) {
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.3d+213)) 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.3e+213) {
tmp = y * x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.3e+213: tmp = y * x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (y <= -3.3e+213) 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.3e+213) tmp = y * x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.3e+213], N[(y * x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+213}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -3.3000000000000001e213Initial program 100.0%
sub-negN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around inf
Simplified72.3%
if -3.3000000000000001e213 < y Initial program 100.0%
Taylor expanded in x around 0
Simplified79.5%
(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-negN/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-+l+N/A
+-lowering-+.f64N/A
neg-mul-1N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
+-lowering-+.f64100.0%
Simplified100.0%
Taylor expanded in x around 0
Simplified42.1%
herbie shell --seed 2024158
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))