
(FPCore (x y) :precision binary64 (/ (+ x y) (- x y)))
double code(double x, double y) {
return (x + y) / (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (x - y)
end function
public static double code(double x, double y) {
return (x + y) / (x - y);
}
def code(x, y): return (x + y) / (x - y)
function code(x, y) return Float64(Float64(x + y) / Float64(x - y)) end
function tmp = code(x, y) tmp = (x + y) / (x - y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{x - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (+ x y) (- x y)))
double code(double x, double y) {
return (x + y) / (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (x - y)
end function
public static double code(double x, double y) {
return (x + y) / (x - y);
}
def code(x, y): return (x + y) / (x - y)
function code(x, y) return Float64(Float64(x + y) / Float64(x - y)) end
function tmp = code(x, y) tmp = (x + y) / (x - y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{x - y}
\end{array}
(FPCore (x y) :precision binary64 (/ (+ x y) (- x y)))
double code(double x, double y) {
return (x + y) / (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (x - y)
end function
public static double code(double x, double y) {
return (x + y) / (x - y);
}
def code(x, y): return (x + y) / (x - y)
function code(x, y) return Float64(Float64(x + y) / Float64(x - y)) end
function tmp = code(x, y) tmp = (x + y) / (x - y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{x - y}
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= y -6.6e-75) (/ y (- x y)) (if (<= y 1.85e+50) (+ 1.0 (/ (* y 2.0) x)) (+ -1.0 (* -2.0 (/ x y))))))
double code(double x, double y) {
double tmp;
if (y <= -6.6e-75) {
tmp = y / (x - y);
} else if (y <= 1.85e+50) {
tmp = 1.0 + ((y * 2.0) / x);
} else {
tmp = -1.0 + (-2.0 * (x / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-6.6d-75)) then
tmp = y / (x - y)
else if (y <= 1.85d+50) then
tmp = 1.0d0 + ((y * 2.0d0) / x)
else
tmp = (-1.0d0) + ((-2.0d0) * (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6.6e-75) {
tmp = y / (x - y);
} else if (y <= 1.85e+50) {
tmp = 1.0 + ((y * 2.0) / x);
} else {
tmp = -1.0 + (-2.0 * (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.6e-75: tmp = y / (x - y) elif y <= 1.85e+50: tmp = 1.0 + ((y * 2.0) / x) else: tmp = -1.0 + (-2.0 * (x / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= -6.6e-75) tmp = Float64(y / Float64(x - y)); elseif (y <= 1.85e+50) tmp = Float64(1.0 + Float64(Float64(y * 2.0) / x)); else tmp = Float64(-1.0 + Float64(-2.0 * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6.6e-75) tmp = y / (x - y); elseif (y <= 1.85e+50) tmp = 1.0 + ((y * 2.0) / x); else tmp = -1.0 + (-2.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.6e-75], N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.85e+50], N[(1.0 + N[(N[(y * 2.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(-2.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.6 \cdot 10^{-75}:\\
\;\;\;\;\frac{y}{x - y}\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+50}:\\
\;\;\;\;1 + \frac{y \cdot 2}{x}\\
\mathbf{else}:\\
\;\;\;\;-1 + -2 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < -6.5999999999999999e-75Initial program 100.0%
Taylor expanded in x around 0
Simplified80.9%
if -6.5999999999999999e-75 < y < 1.85e50Initial program 100.0%
Taylor expanded in x around inf
associate--l+N/A
*-lft-identityN/A
distribute-rgt-out--N/A
*-rgt-identityN/A
associate-*r/N/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
+-lowering-+.f64N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
metadata-evalN/A
distribute-rgt-out--N/A
*-lft-identityN/A
/-lowering-/.f64N/A
*-lft-identityN/A
distribute-rgt-out--N/A
metadata-evalN/A
*-lowering-*.f6478.9%
Simplified78.9%
if 1.85e50 < y Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
*-commutativeN/A
metadata-evalN/A
associate-*l/N/A
metadata-evalN/A
distribute-rgt-out--N/A
*-lft-identityN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-lft-identityN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*l/N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6478.2%
Simplified78.2%
(FPCore (x y) :precision binary64 (if (<= y -1.3e-73) (/ y (- x y)) (if (<= y 1.8e+49) (+ 1.0 (/ y x)) (+ -1.0 (* -2.0 (/ x y))))))
double code(double x, double y) {
double tmp;
if (y <= -1.3e-73) {
tmp = y / (x - y);
} else if (y <= 1.8e+49) {
tmp = 1.0 + (y / x);
} else {
tmp = -1.0 + (-2.0 * (x / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.3d-73)) then
tmp = y / (x - y)
else if (y <= 1.8d+49) then
tmp = 1.0d0 + (y / x)
else
tmp = (-1.0d0) + ((-2.0d0) * (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.3e-73) {
tmp = y / (x - y);
} else if (y <= 1.8e+49) {
tmp = 1.0 + (y / x);
} else {
tmp = -1.0 + (-2.0 * (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.3e-73: tmp = y / (x - y) elif y <= 1.8e+49: tmp = 1.0 + (y / x) else: tmp = -1.0 + (-2.0 * (x / y)) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.3e-73) tmp = Float64(y / Float64(x - y)); elseif (y <= 1.8e+49) tmp = Float64(1.0 + Float64(y / x)); else tmp = Float64(-1.0 + Float64(-2.0 * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.3e-73) tmp = y / (x - y); elseif (y <= 1.8e+49) tmp = 1.0 + (y / x); else tmp = -1.0 + (-2.0 * (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.3e-73], N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.8e+49], N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(-2.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{-73}:\\
\;\;\;\;\frac{y}{x - y}\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+49}:\\
\;\;\;\;1 + \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1 + -2 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < -1.3e-73Initial program 100.0%
Taylor expanded in x around 0
Simplified80.9%
if -1.3e-73 < y < 1.79999999999999998e49Initial program 100.0%
Taylor expanded in x around inf
Simplified78.5%
Taylor expanded in x around inf
+-lowering-+.f64N/A
/-lowering-/.f6478.5%
Simplified78.5%
if 1.79999999999999998e49 < y Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
*-commutativeN/A
metadata-evalN/A
associate-*l/N/A
metadata-evalN/A
distribute-rgt-out--N/A
*-lft-identityN/A
+-commutativeN/A
+-lowering-+.f64N/A
*-lft-identityN/A
distribute-rgt-out--N/A
metadata-evalN/A
associate-*l/N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6478.2%
Simplified78.2%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ y (- x y)))) (if (<= y -1.8e-73) t_0 (if (<= y 7.2e-6) (+ 1.0 (/ y x)) t_0))))
double code(double x, double y) {
double t_0 = y / (x - y);
double tmp;
if (y <= -1.8e-73) {
tmp = t_0;
} else if (y <= 7.2e-6) {
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 - y)
if (y <= (-1.8d-73)) then
tmp = t_0
else if (y <= 7.2d-6) 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 - y);
double tmp;
if (y <= -1.8e-73) {
tmp = t_0;
} else if (y <= 7.2e-6) {
tmp = 1.0 + (y / x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y / (x - y) tmp = 0 if y <= -1.8e-73: tmp = t_0 elif y <= 7.2e-6: tmp = 1.0 + (y / x) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y / Float64(x - y)) tmp = 0.0 if (y <= -1.8e-73) tmp = t_0; elseif (y <= 7.2e-6) tmp = Float64(1.0 + Float64(y / x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y / (x - y); tmp = 0.0; if (y <= -1.8e-73) tmp = t_0; elseif (y <= 7.2e-6) tmp = 1.0 + (y / x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.8e-73], t$95$0, If[LessEqual[y, 7.2e-6], N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{x - y}\\
\mathbf{if}\;y \leq -1.8 \cdot 10^{-73}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{-6}:\\
\;\;\;\;1 + \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.8e-73 or 7.19999999999999967e-6 < y Initial program 100.0%
Taylor expanded in x around 0
Simplified78.0%
if -1.8e-73 < y < 7.19999999999999967e-6Initial program 100.0%
Taylor expanded in x around inf
Simplified80.4%
Taylor expanded in x around inf
+-lowering-+.f64N/A
/-lowering-/.f6480.4%
Simplified80.4%
(FPCore (x y) :precision binary64 (let* ((t_0 (- -1.0 (/ x y)))) (if (<= y -8e-74) t_0 (if (<= y 1.6e+48) (+ 1.0 (/ y x)) t_0))))
double code(double x, double y) {
double t_0 = -1.0 - (x / y);
double tmp;
if (y <= -8e-74) {
tmp = t_0;
} else if (y <= 1.6e+48) {
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 = (-1.0d0) - (x / y)
if (y <= (-8d-74)) then
tmp = t_0
else if (y <= 1.6d+48) 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 = -1.0 - (x / y);
double tmp;
if (y <= -8e-74) {
tmp = t_0;
} else if (y <= 1.6e+48) {
tmp = 1.0 + (y / x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = -1.0 - (x / y) tmp = 0 if y <= -8e-74: tmp = t_0 elif y <= 1.6e+48: tmp = 1.0 + (y / x) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(-1.0 - Float64(x / y)) tmp = 0.0 if (y <= -8e-74) tmp = t_0; elseif (y <= 1.6e+48) tmp = Float64(1.0 + Float64(y / x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = -1.0 - (x / y); tmp = 0.0; if (y <= -8e-74) tmp = t_0; elseif (y <= 1.6e+48) tmp = 1.0 + (y / x); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(-1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8e-74], t$95$0, If[LessEqual[y, 1.6e+48], N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -8 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{+48}:\\
\;\;\;\;1 + \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.99999999999999966e-74 or 1.6000000000000001e48 < y Initial program 100.0%
Taylor expanded in x around 0
Simplified79.5%
Taylor expanded in y around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6479.3%
Simplified79.3%
if -7.99999999999999966e-74 < y < 1.6000000000000001e48Initial program 100.0%
Taylor expanded in x around inf
Simplified78.5%
Taylor expanded in x around inf
+-lowering-+.f64N/A
/-lowering-/.f6478.5%
Simplified78.5%
(FPCore (x y) :precision binary64 (if (<= y -2e-73) -1.0 (if (<= y 2.3e+53) (+ 1.0 (/ y x)) -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2e-73) {
tmp = -1.0;
} else if (y <= 2.3e+53) {
tmp = 1.0 + (y / x);
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2d-73)) then
tmp = -1.0d0
else if (y <= 2.3d+53) then
tmp = 1.0d0 + (y / x)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2e-73) {
tmp = -1.0;
} else if (y <= 2.3e+53) {
tmp = 1.0 + (y / x);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2e-73: tmp = -1.0 elif y <= 2.3e+53: tmp = 1.0 + (y / x) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2e-73) tmp = -1.0; elseif (y <= 2.3e+53) tmp = Float64(1.0 + Float64(y / x)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2e-73) tmp = -1.0; elseif (y <= 2.3e+53) tmp = 1.0 + (y / x); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2e-73], -1.0, If[LessEqual[y, 2.3e+53], N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-73}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+53}:\\
\;\;\;\;1 + \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -1.99999999999999999e-73 or 2.3000000000000002e53 < y Initial program 100.0%
Taylor expanded in x around 0
Simplified78.9%
if -1.99999999999999999e-73 < y < 2.3000000000000002e53Initial program 100.0%
Taylor expanded in x around inf
Simplified78.5%
Taylor expanded in x around inf
+-lowering-+.f64N/A
/-lowering-/.f6478.5%
Simplified78.5%
(FPCore (x y) :precision binary64 (if (<= y -2.05e-73) -1.0 (if (<= y 9.5e-6) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.05e-73) {
tmp = -1.0;
} else if (y <= 9.5e-6) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2.05d-73)) then
tmp = -1.0d0
else if (y <= 9.5d-6) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.05e-73) {
tmp = -1.0;
} else if (y <= 9.5e-6) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.05e-73: tmp = -1.0 elif y <= 9.5e-6: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.05e-73) tmp = -1.0; elseif (y <= 9.5e-6) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.05e-73) tmp = -1.0; elseif (y <= 9.5e-6) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.05e-73], -1.0, If[LessEqual[y, 9.5e-6], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.05 \cdot 10^{-73}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-6}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -2.05000000000000008e-73 or 9.5000000000000005e-6 < y Initial program 100.0%
Taylor expanded in x around 0
Simplified77.3%
if -2.05000000000000008e-73 < y < 9.5000000000000005e-6Initial program 100.0%
Taylor expanded in x around inf
Simplified79.9%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
public static double code(double x, double y) {
return -1.0;
}
def code(x, y): return -1.0
function code(x, y) return -1.0 end
function tmp = code(x, y) tmp = -1.0; end
code[x_, y_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Simplified51.7%
(FPCore (x y) :precision binary64 (/ 1.0 (- (/ x (+ x y)) (/ y (+ x y)))))
double code(double x, double y) {
return 1.0 / ((x / (x + y)) - (y / (x + y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 / ((x / (x + y)) - (y / (x + y)))
end function
public static double code(double x, double y) {
return 1.0 / ((x / (x + y)) - (y / (x + y)));
}
def code(x, y): return 1.0 / ((x / (x + y)) - (y / (x + y)))
function code(x, y) return Float64(1.0 / Float64(Float64(x / Float64(x + y)) - Float64(y / Float64(x + y)))) end
function tmp = code(x, y) tmp = 1.0 / ((x / (x + y)) - (y / (x + y))); end
code[x_, y_] := N[(1.0 / N[(N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision] - N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{x}{x + y} - \frac{y}{x + y}}
\end{array}
herbie shell --seed 2024161
(FPCore (x y)
:name "Linear.Projection:perspective from linear-1.19.1.3, A"
:precision binary64
:alt
(! :herbie-platform default (/ 1 (- (/ x (+ x y)) (/ y (+ x y)))))
(/ (+ x y) (- x y)))