
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y y)))
double code(double x, double y) {
return (x + y) / (y + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + y)
end function
public static double code(double x, double y) {
return (x + y) / (y + y);
}
def code(x, y): return (x + y) / (y + y)
function code(x, y) return Float64(Float64(x + y) / Float64(y + y)) end
function tmp = code(x, y) tmp = (x + y) / (y + y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y y)))
double code(double x, double y) {
return (x + y) / (y + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + y)
end function
public static double code(double x, double y) {
return (x + y) / (y + y);
}
def code(x, y): return (x + y) / (y + y)
function code(x, y) return Float64(Float64(x + y) / Float64(y + y)) end
function tmp = code(x, y) tmp = (x + y) / (y + y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + y}
\end{array}
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y y)))
double code(double x, double y) {
return (x + y) / (y + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + y)
end function
public static double code(double x, double y) {
return (x + y) / (y + y);
}
def code(x, y): return (x + y) / (y + y)
function code(x, y) return Float64(Float64(x + y) / Float64(y + y)) end
function tmp = code(x, y) tmp = (x + y) / (y + y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + y}
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (+ x y) (+ y y)))) (if (or (<= t_0 -400000000.0) (not (<= t_0 1.0))) (/ (* 0.5 x) y) 0.5)))
double code(double x, double y) {
double t_0 = (x + y) / (y + y);
double tmp;
if ((t_0 <= -400000000.0) || !(t_0 <= 1.0)) {
tmp = (0.5 * x) / y;
} else {
tmp = 0.5;
}
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) / (y + y)
if ((t_0 <= (-400000000.0d0)) .or. (.not. (t_0 <= 1.0d0))) then
tmp = (0.5d0 * x) / y
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x + y) / (y + y);
double tmp;
if ((t_0 <= -400000000.0) || !(t_0 <= 1.0)) {
tmp = (0.5 * x) / y;
} else {
tmp = 0.5;
}
return tmp;
}
def code(x, y): t_0 = (x + y) / (y + y) tmp = 0 if (t_0 <= -400000000.0) or not (t_0 <= 1.0): tmp = (0.5 * x) / y else: tmp = 0.5 return tmp
function code(x, y) t_0 = Float64(Float64(x + y) / Float64(y + y)) tmp = 0.0 if ((t_0 <= -400000000.0) || !(t_0 <= 1.0)) tmp = Float64(Float64(0.5 * x) / y); else tmp = 0.5; end return tmp end
function tmp_2 = code(x, y) t_0 = (x + y) / (y + y); tmp = 0.0; if ((t_0 <= -400000000.0) || ~((t_0 <= 1.0))) tmp = (0.5 * x) / y; else tmp = 0.5; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] / N[(y + y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -400000000.0], N[Not[LessEqual[t$95$0, 1.0]], $MachinePrecision]], N[(N[(0.5 * x), $MachinePrecision] / y), $MachinePrecision], 0.5]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x + y}{y + y}\\
\mathbf{if}\;t\_0 \leq -400000000 \lor \neg \left(t\_0 \leq 1\right):\\
\;\;\;\;\frac{0.5 \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if (/.f64 (+.f64 x y) (+.f64 y y)) < -4e8 or 1 < (/.f64 (+.f64 x y) (+.f64 y y)) Initial program 100.0%
Taylor expanded in x around inf
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
lower-*.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.8
Applied rewrites98.8%
Applied rewrites99.1%
if -4e8 < (/.f64 (+.f64 x y) (+.f64 y y)) < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites97.8%
Final simplification98.4%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (+ x y) (+ y y)))) (if (or (<= t_0 -400000000.0) (not (<= t_0 1.0))) (* (/ 0.5 y) x) 0.5)))
double code(double x, double y) {
double t_0 = (x + y) / (y + y);
double tmp;
if ((t_0 <= -400000000.0) || !(t_0 <= 1.0)) {
tmp = (0.5 / y) * x;
} else {
tmp = 0.5;
}
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) / (y + y)
if ((t_0 <= (-400000000.0d0)) .or. (.not. (t_0 <= 1.0d0))) then
tmp = (0.5d0 / y) * x
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x + y) / (y + y);
double tmp;
if ((t_0 <= -400000000.0) || !(t_0 <= 1.0)) {
tmp = (0.5 / y) * x;
} else {
tmp = 0.5;
}
return tmp;
}
def code(x, y): t_0 = (x + y) / (y + y) tmp = 0 if (t_0 <= -400000000.0) or not (t_0 <= 1.0): tmp = (0.5 / y) * x else: tmp = 0.5 return tmp
function code(x, y) t_0 = Float64(Float64(x + y) / Float64(y + y)) tmp = 0.0 if ((t_0 <= -400000000.0) || !(t_0 <= 1.0)) tmp = Float64(Float64(0.5 / y) * x); else tmp = 0.5; end return tmp end
function tmp_2 = code(x, y) t_0 = (x + y) / (y + y); tmp = 0.0; if ((t_0 <= -400000000.0) || ~((t_0 <= 1.0))) tmp = (0.5 / y) * x; else tmp = 0.5; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] / N[(y + y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -400000000.0], N[Not[LessEqual[t$95$0, 1.0]], $MachinePrecision]], N[(N[(0.5 / y), $MachinePrecision] * x), $MachinePrecision], 0.5]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x + y}{y + y}\\
\mathbf{if}\;t\_0 \leq -400000000 \lor \neg \left(t\_0 \leq 1\right):\\
\;\;\;\;\frac{0.5}{y} \cdot x\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if (/.f64 (+.f64 x y) (+.f64 y y)) < -4e8 or 1 < (/.f64 (+.f64 x y) (+.f64 y y)) Initial program 100.0%
Taylor expanded in x around inf
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
lower-*.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.8
Applied rewrites98.8%
if -4e8 < (/.f64 (+.f64 x y) (+.f64 y y)) < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites97.8%
Final simplification98.3%
(FPCore (x y) :precision binary64 (fma (/ 0.5 y) x 0.5))
double code(double x, double y) {
return fma((0.5 / y), x, 0.5);
}
function code(x, y) return fma(Float64(0.5 / y), x, 0.5) end
code[x_, y_] := N[(N[(0.5 / y), $MachinePrecision] * x + 0.5), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{0.5}{y}, x, 0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
lower-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6499.9
Applied rewrites99.9%
(FPCore (x y) :precision binary64 0.5)
double code(double x, double y) {
return 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.5d0
end function
public static double code(double x, double y) {
return 0.5;
}
def code(x, y): return 0.5
function code(x, y) return 0.5 end
function tmp = code(x, y) tmp = 0.5; end
code[x_, y_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites49.6%
(FPCore (x y) :precision binary64 (+ (* 0.5 (/ x y)) 0.5))
double code(double x, double y) {
return (0.5 * (x / y)) + 0.5;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (0.5d0 * (x / y)) + 0.5d0
end function
public static double code(double x, double y) {
return (0.5 * (x / y)) + 0.5;
}
def code(x, y): return (0.5 * (x / y)) + 0.5
function code(x, y) return Float64(Float64(0.5 * Float64(x / y)) + 0.5) end
function tmp = code(x, y) tmp = (0.5 * (x / y)) + 0.5; end
code[x_, y_] := N[(N[(0.5 * N[(x / y), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{x}{y} + 0.5
\end{array}
herbie shell --seed 2024313
(FPCore (x y)
:name "Data.Random.Distribution.T:$ccdf from random-fu-0.2.6.2"
:precision binary64
:alt
(! :herbie-platform default (+ (* 1/2 (/ x y)) 1/2))
(/ (+ x y) (+ y y)))