
(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 9 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 (- (* (+ 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}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.75e+168) (* x y) (if (<= x -1.4e-62) (- 0.0 x) (if (<= x 2.3e-24) y (- 0.0 x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.75e+168) {
tmp = x * y;
} else if (x <= -1.4e-62) {
tmp = 0.0 - x;
} else if (x <= 2.3e-24) {
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 <= (-1.75d+168)) then
tmp = x * y
else if (x <= (-1.4d-62)) then
tmp = 0.0d0 - x
else if (x <= 2.3d-24) 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 <= -1.75e+168) {
tmp = x * y;
} else if (x <= -1.4e-62) {
tmp = 0.0 - x;
} else if (x <= 2.3e-24) {
tmp = y;
} else {
tmp = 0.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.75e+168: tmp = x * y elif x <= -1.4e-62: tmp = 0.0 - x elif x <= 2.3e-24: tmp = y else: tmp = 0.0 - x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.75e+168) tmp = Float64(x * y); elseif (x <= -1.4e-62) tmp = Float64(0.0 - x); elseif (x <= 2.3e-24) tmp = y; else tmp = Float64(0.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.75e+168) tmp = x * y; elseif (x <= -1.4e-62) tmp = 0.0 - x; elseif (x <= 2.3e-24) tmp = y; else tmp = 0.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.75e+168], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.4e-62], N[(0.0 - x), $MachinePrecision], If[LessEqual[x, 2.3e-24], y, N[(0.0 - x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{+168}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.4 \cdot 10^{-62}:\\
\;\;\;\;0 - x\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{-24}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;0 - x\\
\end{array}
\end{array}
if x < -1.7500000000000001e168Initial 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-+.f6460.9%
Simplified60.9%
Taylor expanded in x around inf
Simplified60.9%
if -1.7500000000000001e168 < x < -1.40000000000000001e-62 or 2.3000000000000001e-24 < 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.5%
Simplified59.5%
sub0-negN/A
neg-lowering-neg.f6459.5%
Applied egg-rr59.5%
if -1.40000000000000001e-62 < x < 2.3000000000000001e-24Initial 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
Simplified80.7%
Final simplification68.5%
(FPCore (x y) :precision binary64 (if (<= x -12500000.0) (* x (+ y -1.0)) (if (<= x 1.0) (- y x) (- (* x y) x))))
double code(double x, double y) {
double tmp;
if (x <= -12500000.0) {
tmp = x * (y + -1.0);
} else if (x <= 1.0) {
tmp = y - x;
} else {
tmp = (x * 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 <= (-12500000.0d0)) then
tmp = x * (y + (-1.0d0))
else if (x <= 1.0d0) then
tmp = y - x
else
tmp = (x * y) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -12500000.0) {
tmp = x * (y + -1.0);
} else if (x <= 1.0) {
tmp = y - x;
} else {
tmp = (x * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -12500000.0: tmp = x * (y + -1.0) elif x <= 1.0: tmp = y - x else: tmp = (x * y) - x return tmp
function code(x, y) tmp = 0.0 if (x <= -12500000.0) tmp = Float64(x * Float64(y + -1.0)); elseif (x <= 1.0) tmp = Float64(y - x); else tmp = Float64(Float64(x * y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -12500000.0) tmp = x * (y + -1.0); elseif (x <= 1.0) tmp = y - x; else tmp = (x * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -12500000.0], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(y - x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -12500000:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if x < -1.25e7Initial 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.9%
Simplified99.9%
if -1.25e7 < x < 1Initial program 100.0%
Taylor expanded in x around 0
Simplified98.7%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f6498.7%
Simplified98.7%
Final simplification99.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* x (+ y -1.0)))) (if (<= x -12500000.0) t_0 (if (<= x 1.0) (- y x) t_0))))
double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -12500000.0) {
tmp = t_0;
} else if (x <= 1.0) {
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 <= (-12500000.0d0)) then
tmp = t_0
else if (x <= 1.0d0) 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 <= -12500000.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (y + -1.0) tmp = 0 if x <= -12500000.0: tmp = t_0 elif x <= 1.0: 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 <= -12500000.0) tmp = t_0; elseif (x <= 1.0) 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 <= -12500000.0) tmp = t_0; elseif (x <= 1.0) 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, -12500000.0], t$95$0, If[LessEqual[x, 1.0], 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 -12500000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.25e7 or 1 < 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.3%
Simplified99.3%
if -1.25e7 < x < 1Initial program 100.0%
Taylor expanded in x around 0
Simplified98.7%
Final simplification99.0%
(FPCore (x y) :precision binary64 (if (<= x -2.5e-62) (- 0.0 x) (if (<= x 7e-25) y (- 0.0 x))))
double code(double x, double y) {
double tmp;
if (x <= -2.5e-62) {
tmp = 0.0 - x;
} else if (x <= 7e-25) {
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 <= (-2.5d-62)) then
tmp = 0.0d0 - x
else if (x <= 7d-25) 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 <= -2.5e-62) {
tmp = 0.0 - x;
} else if (x <= 7e-25) {
tmp = y;
} else {
tmp = 0.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.5e-62: tmp = 0.0 - x elif x <= 7e-25: tmp = y else: tmp = 0.0 - x return tmp
function code(x, y) tmp = 0.0 if (x <= -2.5e-62) tmp = Float64(0.0 - x); elseif (x <= 7e-25) tmp = y; else tmp = Float64(0.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.5e-62) tmp = 0.0 - x; elseif (x <= 7e-25) tmp = y; else tmp = 0.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.5e-62], N[(0.0 - x), $MachinePrecision], If[LessEqual[x, 7e-25], y, N[(0.0 - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-62}:\\
\;\;\;\;0 - x\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-25}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;0 - x\\
\end{array}
\end{array}
if x < -2.5000000000000001e-62 or 7.0000000000000004e-25 < 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--.f6455.4%
Simplified55.4%
sub0-negN/A
neg-lowering-neg.f6455.4%
Applied egg-rr55.4%
if -2.5000000000000001e-62 < x < 7.0000000000000004e-25Initial 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
Simplified80.7%
Final simplification66.0%
(FPCore (x y) :precision binary64 (if (<= y -1260000000.0) (* x y) (- y x)))
double code(double x, double y) {
double tmp;
if (y <= -1260000000.0) {
tmp = x * 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 <= (-1260000000.0d0)) then
tmp = x * y
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1260000000.0) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1260000000.0: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (y <= -1260000000.0) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1260000000.0) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1260000000.0], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1260000000:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1.26e9Initial 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
Simplified57.7%
if -1.26e9 < y Initial program 100.0%
Taylor expanded in x around 0
Simplified85.1%
Final simplification78.3%
(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 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
Simplified36.4%
(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 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-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--.f6441.0%
Simplified41.0%
sub0-negN/A
neg-lowering-neg.f6441.0%
Applied egg-rr41.0%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
neg-sub0N/A
cube-negN/A
sqr-powN/A
unpow-prod-downN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow12.7%
Applied egg-rr2.7%
herbie shell --seed 2024161
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))