
(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 (- (* (+ 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 (or (<= x -1.0) (not (<= x 4.5e-5))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.5e-5)) {
tmp = x * (y + -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 ((x <= (-1.0d0)) .or. (.not. (x <= 4.5d-5))) then
tmp = x * (y + (-1.0d0))
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.5e-5)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 4.5e-5): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 4.5e-5)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 4.5e-5))) tmp = x * (y + -1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 4.5e-5]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 4.5 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 4.50000000000000028e-5 < x Initial program 100.0%
Taylor expanded in x around inf 97.7%
if -1 < x < 4.50000000000000028e-5Initial program 100.0%
Taylor expanded in x around 0 99.0%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (* x (+ y -1.0)) (if (<= x 4.5e-5) (- y x) (- (* x y) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * (y + -1.0);
} else if (x <= 4.5e-5) {
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 <= (-1.0d0)) then
tmp = x * (y + (-1.0d0))
else if (x <= 4.5d-5) 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 <= -1.0) {
tmp = x * (y + -1.0);
} else if (x <= 4.5e-5) {
tmp = y - x;
} else {
tmp = (x * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = x * (y + -1.0) elif x <= 4.5e-5: tmp = y - x else: tmp = (x * y) - x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * Float64(y + -1.0)); elseif (x <= 4.5e-5) 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 <= -1.0) tmp = x * (y + -1.0); elseif (x <= 4.5e-5) tmp = y - x; else tmp = (x * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.5e-5], N[(y - x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-5}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 97.4%
if -1 < x < 4.50000000000000028e-5Initial program 100.0%
Taylor expanded in x around 0 99.0%
if 4.50000000000000028e-5 < x Initial program 100.0%
Taylor expanded in x around inf 98.1%
*-commutative98.1%
Simplified98.1%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (or (<= y -6.5e-12) (not (<= y 16000000.0))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -6.5e-12) || !(y <= 16000000.0)) {
tmp = x * y;
} 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 <= (-6.5d-12)) .or. (.not. (y <= 16000000.0d0))) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -6.5e-12) || !(y <= 16000000.0)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.5e-12) or not (y <= 16000000.0): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.5e-12) || !(y <= 16000000.0)) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -6.5e-12) || ~((y <= 16000000.0))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.5e-12], N[Not[LessEqual[y, 16000000.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-12} \lor \neg \left(y \leq 16000000\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -6.5000000000000002e-12 or 1.6e7 < y Initial program 100.0%
Taylor expanded in x around inf 47.6%
Taylor expanded in y around inf 47.1%
if -6.5000000000000002e-12 < y < 1.6e7Initial program 100.0%
Taylor expanded in y around 0 78.4%
neg-mul-178.4%
Simplified78.4%
Final simplification62.4%
(FPCore (x y) :precision binary64 (if (<= x -2.15e+158) (- x) (if (<= x -2.4e+32) (* x y) (- y x))))
double code(double x, double y) {
double tmp;
if (x <= -2.15e+158) {
tmp = -x;
} else if (x <= -2.4e+32) {
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 (x <= (-2.15d+158)) then
tmp = -x
else if (x <= (-2.4d+32)) 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 (x <= -2.15e+158) {
tmp = -x;
} else if (x <= -2.4e+32) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.15e+158: tmp = -x elif x <= -2.4e+32: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (x <= -2.15e+158) tmp = Float64(-x); elseif (x <= -2.4e+32) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.15e+158) tmp = -x; elseif (x <= -2.4e+32) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.15e+158], (-x), If[LessEqual[x, -2.4e+32], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{+158}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -2.4 \cdot 10^{+32}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -2.15e158Initial program 100.0%
Taylor expanded in y around 0 62.5%
neg-mul-162.5%
Simplified62.5%
if -2.15e158 < x < -2.39999999999999991e32Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 77.9%
if -2.39999999999999991e32 < x Initial program 100.0%
Taylor expanded in x around 0 83.6%
(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 39.7%
neg-mul-139.7%
Simplified39.7%
(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%
Taylor expanded in y around 0 39.7%
neg-mul-139.7%
Simplified39.7%
neg-sub039.7%
sub-neg39.7%
add-sqr-sqrt18.8%
sqrt-unprod14.9%
sqr-neg14.9%
sqrt-unprod1.4%
add-sqr-sqrt2.8%
Applied egg-rr2.8%
+-lft-identity2.8%
Simplified2.8%
herbie shell --seed 2024132
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))