
(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 (+ 1.0 x)) x))
double code(double x, double y) {
return (y * (1.0 + x)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (1.0d0 + x)) - x
end function
public static double code(double x, double y) {
return (y * (1.0 + x)) - x;
}
def code(x, y): return (y * (1.0 + x)) - x
function code(x, y) return Float64(Float64(y * Float64(1.0 + x)) - x) end
function tmp = code(x, y) tmp = (y * (1.0 + x)) - x; end
code[x_, y_] := N[(N[(y * N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(1 + x\right) - x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (* y x) x))) (if (<= x -1.0) t_0 (if (<= x 0.00012) (- (* 1.0 y) x) t_0))))
double code(double x, double y) {
double t_0 = (y * x) - x;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 0.00012) {
tmp = (1.0 * 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 = (y * x) - x
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 0.00012d0) then
tmp = (1.0d0 * y) - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (y * x) - x;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 0.00012) {
tmp = (1.0 * y) - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = (y * x) - x tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 0.00012: tmp = (1.0 * y) - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(y * x) - x) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 0.00012) tmp = Float64(Float64(1.0 * y) - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = (y * x) - x; tmp = 0.0; if (x <= -1.0) tmp = t_0; elseif (x <= 0.00012) tmp = (1.0 * y) - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 0.00012], N[(N[(1.0 * y), $MachinePrecision] - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot x - x\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.00012:\\
\;\;\;\;1 \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1.20000000000000003e-4 < x Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6498.7
Applied rewrites98.7%
if -1 < x < 1.20000000000000003e-4Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.9%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (<= y -2.3e-71) (fma x y y) (if (<= y 9.8e-5) (- (* y x) x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -2.3e-71) {
tmp = fma(x, y, y);
} else if (y <= 9.8e-5) {
tmp = (y * x) - x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2.3e-71) tmp = fma(x, y, y); elseif (y <= 9.8e-5) tmp = Float64(Float64(y * x) - x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -2.3e-71], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 9.8e-5], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-71}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{-5}:\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -2.2999999999999998e-71 or 9.8e-5 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6497.3
Applied rewrites97.3%
if -2.2999999999999998e-71 < y < 9.8e-5Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6475.8
Applied rewrites75.8%
Final simplification87.8%
(FPCore (x y) :precision binary64 (if (<= y -2.3e-71) (fma x y y) (if (<= y 1.1e-20) (- x) (fma x y y))))
double code(double x, double y) {
double tmp;
if (y <= -2.3e-71) {
tmp = fma(x, y, y);
} else if (y <= 1.1e-20) {
tmp = -x;
} else {
tmp = fma(x, y, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -2.3e-71) tmp = fma(x, y, y); elseif (y <= 1.1e-20) tmp = Float64(-x); else tmp = fma(x, y, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -2.3e-71], N[(x * y + y), $MachinePrecision], If[LessEqual[y, 1.1e-20], (-x), N[(x * y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-71}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-20}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, y\right)\\
\end{array}
\end{array}
if y < -2.2999999999999998e-71 or 1.09999999999999995e-20 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6495.4
Applied rewrites95.4%
if -2.2999999999999998e-71 < y < 1.09999999999999995e-20Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6477.1
Applied rewrites77.1%
(FPCore (x y) :precision binary64 (if (<= y -2.9e+26) (* y x) (if (<= y 0.55) (- x) (* y x))))
double code(double x, double y) {
double tmp;
if (y <= -2.9e+26) {
tmp = y * x;
} else if (y <= 0.55) {
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 (y <= (-2.9d+26)) then
tmp = y * x
else if (y <= 0.55d0) then
tmp = -x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.9e+26) {
tmp = y * x;
} else if (y <= 0.55) {
tmp = -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.9e+26: tmp = y * x elif y <= 0.55: tmp = -x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -2.9e+26) tmp = Float64(y * x); elseif (y <= 0.55) tmp = Float64(-x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.9e+26) tmp = y * x; elseif (y <= 0.55) tmp = -x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.9e+26], N[(y * x), $MachinePrecision], If[LessEqual[y, 0.55], (-x), N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+26}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 0.55:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.9e26 or 0.55000000000000004 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6499.1
Applied rewrites99.1%
Taylor expanded in x around inf
Applied rewrites53.4%
if -2.9e26 < y < 0.55000000000000004Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6468.5
Applied rewrites68.5%
(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%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6435.4
Applied rewrites35.4%
herbie shell --seed 2024243
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))