
(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 (/ 1.0 (/ (- x y) (+ x y))))
double code(double x, double y) {
return 1.0 / ((x - y) / (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 / ((x - y) / (x + y))
end function
public static double code(double x, double y) {
return 1.0 / ((x - y) / (x + y));
}
def code(x, y): return 1.0 / ((x - y) / (x + y))
function code(x, y) return Float64(1.0 / Float64(Float64(x - y) / Float64(x + y))) end
function tmp = code(x, y) tmp = 1.0 / ((x - y) / (x + y)); end
code[x_, y_] := N[(1.0 / N[(N[(x - y), $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{x - y}{x + y}}
\end{array}
Initial program 99.9%
clear-numN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
+-lowering-+.f6499.9%
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ -1.0 (* -2.0 (/ x y))))) (if (<= y -4.1e+24) t_0 (if (<= y 1.45e+43) (+ 1.0 (/ y x)) t_0))))
double code(double x, double y) {
double t_0 = -1.0 + (-2.0 * (x / y));
double tmp;
if (y <= -4.1e+24) {
tmp = t_0;
} else if (y <= 1.45e+43) {
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) + ((-2.0d0) * (x / y))
if (y <= (-4.1d+24)) then
tmp = t_0
else if (y <= 1.45d+43) 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 + (-2.0 * (x / y));
double tmp;
if (y <= -4.1e+24) {
tmp = t_0;
} else if (y <= 1.45e+43) {
tmp = 1.0 + (y / x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = -1.0 + (-2.0 * (x / y)) tmp = 0 if y <= -4.1e+24: tmp = t_0 elif y <= 1.45e+43: tmp = 1.0 + (y / x) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(-1.0 + Float64(-2.0 * Float64(x / y))) tmp = 0.0 if (y <= -4.1e+24) tmp = t_0; elseif (y <= 1.45e+43) 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 + (-2.0 * (x / y)); tmp = 0.0; if (y <= -4.1e+24) tmp = t_0; elseif (y <= 1.45e+43) 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[(-2.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.1e+24], t$95$0, If[LessEqual[y, 1.45e+43], N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + -2 \cdot \frac{x}{y}\\
\mathbf{if}\;y \leq -4.1 \cdot 10^{+24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+43}:\\
\;\;\;\;1 + \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.1000000000000001e24 or 1.4500000000000001e43 < y Initial program 99.9%
Taylor expanded in x around 0
sub-negN/A
*-commutativeN/A
associate-*l/N/A
metadata-evalN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/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-/.f6481.0%
Simplified81.0%
if -4.1000000000000001e24 < y < 1.4500000000000001e43Initial program 99.9%
Taylor expanded in x around inf
Simplified75.8%
clear-numN/A
associate-/r/N/A
+-commutativeN/A
distribute-rgt-inN/A
div-invN/A
div-invN/A
*-inversesN/A
+-lowering-+.f64N/A
/-lowering-/.f6475.8%
Applied egg-rr75.8%
Final simplification78.2%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ y (- x y)))) (if (<= y -3.75e+24) t_0 (if (<= y 1.3e+38) (+ 1.0 (/ y x)) t_0))))
double code(double x, double y) {
double t_0 = y / (x - y);
double tmp;
if (y <= -3.75e+24) {
tmp = t_0;
} else if (y <= 1.3e+38) {
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 <= (-3.75d+24)) then
tmp = t_0
else if (y <= 1.3d+38) 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 <= -3.75e+24) {
tmp = t_0;
} else if (y <= 1.3e+38) {
tmp = 1.0 + (y / x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y / (x - y) tmp = 0 if y <= -3.75e+24: tmp = t_0 elif y <= 1.3e+38: 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 <= -3.75e+24) tmp = t_0; elseif (y <= 1.3e+38) 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 <= -3.75e+24) tmp = t_0; elseif (y <= 1.3e+38) 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, -3.75e+24], t$95$0, If[LessEqual[y, 1.3e+38], 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 -3.75 \cdot 10^{+24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{+38}:\\
\;\;\;\;1 + \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.75000000000000007e24 or 1.3e38 < y Initial program 99.9%
Taylor expanded in x around 0
Simplified80.0%
if -3.75000000000000007e24 < y < 1.3e38Initial program 99.9%
Taylor expanded in x around inf
Simplified76.2%
clear-numN/A
associate-/r/N/A
+-commutativeN/A
distribute-rgt-inN/A
div-invN/A
div-invN/A
*-inversesN/A
+-lowering-+.f64N/A
/-lowering-/.f6476.2%
Applied egg-rr76.2%
Final simplification77.9%
(FPCore (x y) :precision binary64 (let* ((t_0 (- -1.0 (/ x y)))) (if (<= y -6.4e+23) t_0 (if (<= y 1.1e+41) (+ 1.0 (/ y x)) t_0))))
double code(double x, double y) {
double t_0 = -1.0 - (x / y);
double tmp;
if (y <= -6.4e+23) {
tmp = t_0;
} else if (y <= 1.1e+41) {
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 <= (-6.4d+23)) then
tmp = t_0
else if (y <= 1.1d+41) 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 <= -6.4e+23) {
tmp = t_0;
} else if (y <= 1.1e+41) {
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 <= -6.4e+23: tmp = t_0 elif y <= 1.1e+41: 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 <= -6.4e+23) tmp = t_0; elseif (y <= 1.1e+41) 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 <= -6.4e+23) tmp = t_0; elseif (y <= 1.1e+41) 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, -6.4e+23], t$95$0, If[LessEqual[y, 1.1e+41], 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 -6.4 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+41}:\\
\;\;\;\;1 + \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -6.4e23 or 1.09999999999999995e41 < y Initial program 99.9%
Taylor expanded in x around 0
Simplified80.4%
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-/.f6480.1%
Simplified80.1%
if -6.4e23 < y < 1.09999999999999995e41Initial program 99.9%
Taylor expanded in x around inf
Simplified75.8%
clear-numN/A
associate-/r/N/A
+-commutativeN/A
distribute-rgt-inN/A
div-invN/A
div-invN/A
*-inversesN/A
+-lowering-+.f64N/A
/-lowering-/.f6475.8%
Applied egg-rr75.8%
Final simplification77.8%
(FPCore (x y) :precision binary64 (if (<= y -7.8e+23) -1.0 (if (<= y 2.8e+39) (+ 1.0 (/ y x)) -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -7.8e+23) {
tmp = -1.0;
} else if (y <= 2.8e+39) {
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 <= (-7.8d+23)) then
tmp = -1.0d0
else if (y <= 2.8d+39) 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 <= -7.8e+23) {
tmp = -1.0;
} else if (y <= 2.8e+39) {
tmp = 1.0 + (y / x);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.8e+23: tmp = -1.0 elif y <= 2.8e+39: tmp = 1.0 + (y / x) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -7.8e+23) tmp = -1.0; elseif (y <= 2.8e+39) 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 <= -7.8e+23) tmp = -1.0; elseif (y <= 2.8e+39) tmp = 1.0 + (y / x); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.8e+23], -1.0, If[LessEqual[y, 2.8e+39], N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+23}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+39}:\\
\;\;\;\;1 + \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -7.8000000000000001e23 or 2.80000000000000001e39 < y Initial program 99.9%
Taylor expanded in x around 0
Simplified79.2%
if -7.8000000000000001e23 < y < 2.80000000000000001e39Initial program 99.9%
Taylor expanded in x around inf
Simplified76.2%
clear-numN/A
associate-/r/N/A
+-commutativeN/A
distribute-rgt-inN/A
div-invN/A
div-invN/A
*-inversesN/A
+-lowering-+.f64N/A
/-lowering-/.f6476.2%
Applied egg-rr76.2%
Final simplification77.6%
(FPCore (x y) :precision binary64 (if (<= y -1e+24) -1.0 (if (<= y 5e+28) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1e+24) {
tmp = -1.0;
} else if (y <= 5e+28) {
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 <= (-1d+24)) then
tmp = -1.0d0
else if (y <= 5d+28) 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 <= -1e+24) {
tmp = -1.0;
} else if (y <= 5e+28) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1e+24: tmp = -1.0 elif y <= 5e+28: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1e+24) tmp = -1.0; elseif (y <= 5e+28) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1e+24) tmp = -1.0; elseif (y <= 5e+28) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1e+24], -1.0, If[LessEqual[y, 5e+28], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+24}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5 \cdot 10^{+28}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -9.9999999999999998e23 or 4.99999999999999957e28 < y Initial program 99.9%
Taylor expanded in x around 0
Simplified78.8%
if -9.9999999999999998e23 < y < 4.99999999999999957e28Initial program 99.9%
Taylor expanded in x around inf
Simplified75.8%
(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 99.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 99.9%
Taylor expanded in x around 0
Simplified49.5%
(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 2024138
(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)))