
(FPCore (x y) :precision binary64 (+ x (/ (- x y) 2.0)))
double code(double x, double y) {
return x + ((x - y) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((x - y) / 2.0d0)
end function
public static double code(double x, double y) {
return x + ((x - y) / 2.0);
}
def code(x, y): return x + ((x - y) / 2.0)
function code(x, y) return Float64(x + Float64(Float64(x - y) / 2.0)) end
function tmp = code(x, y) tmp = x + ((x - y) / 2.0); end
code[x_, y_] := N[(x + N[(N[(x - y), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{x - y}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ x (/ (- x y) 2.0)))
double code(double x, double y) {
return x + ((x - y) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((x - y) / 2.0d0)
end function
public static double code(double x, double y) {
return x + ((x - y) / 2.0);
}
def code(x, y): return x + ((x - y) / 2.0)
function code(x, y) return Float64(x + Float64(Float64(x - y) / 2.0)) end
function tmp = code(x, y) tmp = x + ((x - y) / 2.0); end
code[x_, y_] := N[(x + N[(N[(x - y), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{x - y}{2}
\end{array}
(FPCore (x y) :precision binary64 (fma x 1.5 (/ y -2.0)))
double code(double x, double y) {
return fma(x, 1.5, (y / -2.0));
}
function code(x, y) return fma(x, 1.5, Float64(y / -2.0)) end
code[x_, y_] := N[(x * 1.5 + N[(y / -2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 1.5, \frac{y}{-2}\right)
\end{array}
Initial program 99.9%
Simplified0
Applied egg-rr0
(FPCore (x y)
:precision binary64
(if (<= x -3.8e+79)
(* 1.5 x)
(if (<= x -2.5e+28)
(* -0.5 y)
(if (<= x -1.15e-46)
(/ -0.6666666666666666 (/ -0.4444444444444444 x))
(if (<= x 6e-35) (* -0.5 y) (* 1.5 x))))))
double code(double x, double y) {
double tmp;
if (x <= -3.8e+79) {
tmp = 1.5 * x;
} else if (x <= -2.5e+28) {
tmp = -0.5 * y;
} else if (x <= -1.15e-46) {
tmp = -0.6666666666666666 / (-0.4444444444444444 / x);
} else if (x <= 6e-35) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-3.8d+79)) then
tmp = 1.5d0 * x
else if (x <= (-2.5d+28)) then
tmp = (-0.5d0) * y
else if (x <= (-1.15d-46)) then
tmp = (-0.6666666666666666d0) / ((-0.4444444444444444d0) / x)
else if (x <= 6d-35) then
tmp = (-0.5d0) * y
else
tmp = 1.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.8e+79) {
tmp = 1.5 * x;
} else if (x <= -2.5e+28) {
tmp = -0.5 * y;
} else if (x <= -1.15e-46) {
tmp = -0.6666666666666666 / (-0.4444444444444444 / x);
} else if (x <= 6e-35) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.8e+79: tmp = 1.5 * x elif x <= -2.5e+28: tmp = -0.5 * y elif x <= -1.15e-46: tmp = -0.6666666666666666 / (-0.4444444444444444 / x) elif x <= 6e-35: tmp = -0.5 * y else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (x <= -3.8e+79) tmp = Float64(1.5 * x); elseif (x <= -2.5e+28) tmp = Float64(-0.5 * y); elseif (x <= -1.15e-46) tmp = Float64(-0.6666666666666666 / Float64(-0.4444444444444444 / x)); elseif (x <= 6e-35) tmp = Float64(-0.5 * y); else tmp = Float64(1.5 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.8e+79) tmp = 1.5 * x; elseif (x <= -2.5e+28) tmp = -0.5 * y; elseif (x <= -1.15e-46) tmp = -0.6666666666666666 / (-0.4444444444444444 / x); elseif (x <= 6e-35) tmp = -0.5 * y; else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.8e+79], N[(1.5 * x), $MachinePrecision], If[LessEqual[x, -2.5e+28], N[(-0.5 * y), $MachinePrecision], If[LessEqual[x, -1.15e-46], N[(-0.6666666666666666 / N[(-0.4444444444444444 / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6e-35], N[(-0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+79}:\\
\;\;\;\;1.5 \cdot x\\
\mathbf{elif}\;x \leq -2.5 \cdot 10^{+28}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{elif}\;x \leq -1.15 \cdot 10^{-46}:\\
\;\;\;\;\frac{-0.6666666666666666}{\frac{-0.4444444444444444}{x}}\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-35}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if x < -3.8000000000000002e79 or 5.99999999999999978e-35 < x Initial program 99.8%
Simplified0
Taylor expanded in y around 0 0
Simplified0
if -3.8000000000000002e79 < x < -2.49999999999999979e28 or -1.15e-46 < x < 5.99999999999999978e-35Initial program 99.9%
Simplified0
Taylor expanded in y around inf 0
Simplified0
if -2.49999999999999979e28 < x < -1.15e-46Initial program 99.6%
Simplified0
Applied egg-rr0
Taylor expanded in x around inf 0
Simplified0
Applied egg-rr0
Applied egg-rr0
(FPCore (x y)
:precision binary64
(if (<= x -4e+79)
(* 1.5 x)
(if (<= x -2.45e+30)
(* -0.5 y)
(if (<= x -2.1e-48) (* 1.5 x) (if (<= x 8.8e-36) (* -0.5 y) (* 1.5 x))))))
double code(double x, double y) {
double tmp;
if (x <= -4e+79) {
tmp = 1.5 * x;
} else if (x <= -2.45e+30) {
tmp = -0.5 * y;
} else if (x <= -2.1e-48) {
tmp = 1.5 * x;
} else if (x <= 8.8e-36) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4d+79)) then
tmp = 1.5d0 * x
else if (x <= (-2.45d+30)) then
tmp = (-0.5d0) * y
else if (x <= (-2.1d-48)) then
tmp = 1.5d0 * x
else if (x <= 8.8d-36) then
tmp = (-0.5d0) * y
else
tmp = 1.5d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4e+79) {
tmp = 1.5 * x;
} else if (x <= -2.45e+30) {
tmp = -0.5 * y;
} else if (x <= -2.1e-48) {
tmp = 1.5 * x;
} else if (x <= 8.8e-36) {
tmp = -0.5 * y;
} else {
tmp = 1.5 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4e+79: tmp = 1.5 * x elif x <= -2.45e+30: tmp = -0.5 * y elif x <= -2.1e-48: tmp = 1.5 * x elif x <= 8.8e-36: tmp = -0.5 * y else: tmp = 1.5 * x return tmp
function code(x, y) tmp = 0.0 if (x <= -4e+79) tmp = Float64(1.5 * x); elseif (x <= -2.45e+30) tmp = Float64(-0.5 * y); elseif (x <= -2.1e-48) tmp = Float64(1.5 * x); elseif (x <= 8.8e-36) tmp = Float64(-0.5 * y); else tmp = Float64(1.5 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4e+79) tmp = 1.5 * x; elseif (x <= -2.45e+30) tmp = -0.5 * y; elseif (x <= -2.1e-48) tmp = 1.5 * x; elseif (x <= 8.8e-36) tmp = -0.5 * y; else tmp = 1.5 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4e+79], N[(1.5 * x), $MachinePrecision], If[LessEqual[x, -2.45e+30], N[(-0.5 * y), $MachinePrecision], If[LessEqual[x, -2.1e-48], N[(1.5 * x), $MachinePrecision], If[LessEqual[x, 8.8e-36], N[(-0.5 * y), $MachinePrecision], N[(1.5 * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+79}:\\
\;\;\;\;1.5 \cdot x\\
\mathbf{elif}\;x \leq -2.45 \cdot 10^{+30}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{elif}\;x \leq -2.1 \cdot 10^{-48}:\\
\;\;\;\;1.5 \cdot x\\
\mathbf{elif}\;x \leq 8.8 \cdot 10^{-36}:\\
\;\;\;\;-0.5 \cdot y\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot x\\
\end{array}
\end{array}
if x < -3.99999999999999987e79 or -2.44999999999999992e30 < x < -2.09999999999999989e-48 or 8.7999999999999997e-36 < x Initial program 99.8%
Simplified0
Taylor expanded in y around 0 0
Simplified0
if -3.99999999999999987e79 < x < -2.44999999999999992e30 or -2.09999999999999989e-48 < x < 8.7999999999999997e-36Initial program 99.9%
Simplified0
Taylor expanded in y around inf 0
Simplified0
(FPCore (x y) :precision binary64 (+ (/ y -2.0) (* x 1.5)))
double code(double x, double y) {
return (y / -2.0) + (x * 1.5);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y / (-2.0d0)) + (x * 1.5d0)
end function
public static double code(double x, double y) {
return (y / -2.0) + (x * 1.5);
}
def code(x, y): return (y / -2.0) + (x * 1.5)
function code(x, y) return Float64(Float64(y / -2.0) + Float64(x * 1.5)) end
function tmp = code(x, y) tmp = (y / -2.0) + (x * 1.5); end
code[x_, y_] := N[(N[(y / -2.0), $MachinePrecision] + N[(x * 1.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{-2} + x \cdot 1.5
\end{array}
Initial program 99.9%
Simplified0
(FPCore (x y) :precision binary64 (+ x (/ (- x y) 2.0)))
double code(double x, double y) {
return x + ((x - y) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((x - y) / 2.0d0)
end function
public static double code(double x, double y) {
return x + ((x - y) / 2.0);
}
def code(x, y): return x + ((x - y) / 2.0)
function code(x, y) return Float64(x + Float64(Float64(x - y) / 2.0)) end
function tmp = code(x, y) tmp = x + ((x - y) / 2.0); end
code[x_, y_] := N[(x + N[(N[(x - y), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{x - y}{2}
\end{array}
Initial program 99.9%
(FPCore (x y) :precision binary64 (* -0.5 y))
double code(double x, double y) {
return -0.5 * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (-0.5d0) * y
end function
public static double code(double x, double y) {
return -0.5 * y;
}
def code(x, y): return -0.5 * y
function code(x, y) return Float64(-0.5 * y) end
function tmp = code(x, y) tmp = -0.5 * y; end
code[x_, y_] := N[(-0.5 * y), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot y
\end{array}
Initial program 99.9%
Simplified0
Taylor expanded in y around inf 0
Simplified0
(FPCore (x y) :precision binary64 (- (* 1.5 x) (* 0.5 y)))
double code(double x, double y) {
return (1.5 * x) - (0.5 * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.5d0 * x) - (0.5d0 * y)
end function
public static double code(double x, double y) {
return (1.5 * x) - (0.5 * y);
}
def code(x, y): return (1.5 * x) - (0.5 * y)
function code(x, y) return Float64(Float64(1.5 * x) - Float64(0.5 * y)) end
function tmp = code(x, y) tmp = (1.5 * x) - (0.5 * y); end
code[x_, y_] := N[(N[(1.5 * x), $MachinePrecision] - N[(0.5 * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1.5 \cdot x - 0.5 \cdot y
\end{array}
herbie shell --seed 2024110
(FPCore (x y)
:name "Graphics.Rendering.Chart.Axis.Types:hBufferRect from Chart-1.5.3"
:precision binary64
:alt
(- (* 1.5 x) (* 0.5 y))
(+ x (/ (- x y) 2.0)))