
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
(FPCore (x y) :precision binary64 (if (<= x -2e-58) (/ (* (/ x (+ 1.0 x)) (+ y x)) y) (if (<= x 2e+16) (/ (fma (/ x y) x x) (+ x 1.0)) (+ (/ (- x 1.0) y) 1.0))))
double code(double x, double y) {
double tmp;
if (x <= -2e-58) {
tmp = ((x / (1.0 + x)) * (y + x)) / y;
} else if (x <= 2e+16) {
tmp = fma((x / y), x, x) / (x + 1.0);
} else {
tmp = ((x - 1.0) / y) + 1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -2e-58) tmp = Float64(Float64(Float64(x / Float64(1.0 + x)) * Float64(y + x)) / y); elseif (x <= 2e+16) tmp = Float64(fma(Float64(x / y), x, x) / Float64(x + 1.0)); else tmp = Float64(Float64(Float64(x - 1.0) / y) + 1.0); end return tmp end
code[x_, y_] := If[LessEqual[x, -2e-58], N[(N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[x, 2e+16], N[(N[(N[(x / y), $MachinePrecision] * x + x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision] + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-58}:\\
\;\;\;\;\frac{\frac{x}{1 + x} \cdot \left(y + x\right)}{y}\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+16}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - 1}{y} + 1\\
\end{array}
\end{array}
if x < -2.0000000000000001e-58Initial program 86.5%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
if -2.0000000000000001e-58 < x < 2e16Initial program 99.9%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft1-inN/A
lower-fma.f6499.9
Applied rewrites99.9%
if 2e16 < x Initial program 78.6%
Taylor expanded in x around inf
associate--l+N/A
+-commutativeN/A
distribute-lft-inN/A
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
neg-mul-1N/A
distribute-rgt-outN/A
rgt-mult-inverseN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (<= t_0 -1000.0)
(/ x y)
(if (<= t_0 0.5)
(* (fma (- x 1.0) x 1.0) x)
(if (<= t_0 2.0) (- 1.0 (pow x -1.0)) (/ x y))))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if (t_0 <= -1000.0) {
tmp = x / y;
} else if (t_0 <= 0.5) {
tmp = fma((x - 1.0), x, 1.0) * x;
} else if (t_0 <= 2.0) {
tmp = 1.0 - pow(x, -1.0);
} else {
tmp = x / y;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) tmp = 0.0 if (t_0 <= -1000.0) tmp = Float64(x / y); elseif (t_0 <= 0.5) tmp = Float64(fma(Float64(x - 1.0), x, 1.0) * x); elseif (t_0 <= 2.0) tmp = Float64(1.0 - (x ^ -1.0)); else tmp = Float64(x / y); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1000.0], N[(x / y), $MachinePrecision], If[LessEqual[t$95$0, 0.5], N[(N[(N[(x - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(1.0 - N[Power[x, -1.0], $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t\_0 \leq -1000:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;t\_0 \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(x - 1, x, 1\right) \cdot x\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1 - {x}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1e3 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 79.9%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites75.7%
Taylor expanded in x around inf
lower-/.f6481.9
Applied rewrites81.9%
if -1e3 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.5Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6486.7
Applied rewrites86.7%
Taylor expanded in x around 0
Applied rewrites86.0%
if 0.5 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6497.6
Applied rewrites97.6%
Taylor expanded in x around inf
Applied rewrites93.8%
Final simplification85.2%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (+ (/ (- x 1.0) y) 1.0) (fma (- (pow (/ y x) -1.0) x) x x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = ((x - 1.0) / y) + 1.0;
} else {
tmp = fma((pow((y / x), -1.0) - x), x, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(Float64(x - 1.0) / y) + 1.0); else tmp = fma(Float64((Float64(y / x) ^ -1.0) - x), x, x); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[Power[N[(y / x), $MachinePrecision], -1.0], $MachinePrecision] - x), $MachinePrecision] * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{x - 1}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\left(\frac{y}{x}\right)}^{-1} - x, x, x\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 81.9%
Taylor expanded in x around inf
associate--l+N/A
+-commutativeN/A
distribute-lft-inN/A
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
neg-mul-1N/A
distribute-rgt-outN/A
rgt-mult-inverseN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-+.f6498.3
Applied rewrites98.3%
Applied rewrites98.4%
if -1 < x < 1Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
distribute-lft-out--N/A
associate-*r/N/A
*-rgt-identityN/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
Applied rewrites98.3%
Final simplification98.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))) (if (or (<= t_0 -1000.0) (not (<= t_0 2.0))) (/ x y) (/ x (+ 1.0 x)))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if ((t_0 <= -1000.0) || !(t_0 <= 2.0)) {
tmp = x / y;
} else {
tmp = x / (1.0 + x);
}
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 * ((x / y) + 1.0d0)) / (x + 1.0d0)
if ((t_0 <= (-1000.0d0)) .or. (.not. (t_0 <= 2.0d0))) then
tmp = x / y
else
tmp = x / (1.0d0 + x)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if ((t_0 <= -1000.0) || !(t_0 <= 2.0)) {
tmp = x / y;
} else {
tmp = x / (1.0 + x);
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x + 1.0) tmp = 0 if (t_0 <= -1000.0) or not (t_0 <= 2.0): tmp = x / y else: tmp = x / (1.0 + x) return tmp
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) tmp = 0.0 if ((t_0 <= -1000.0) || !(t_0 <= 2.0)) tmp = Float64(x / y); else tmp = Float64(x / Float64(1.0 + x)); end return tmp end
function tmp_2 = code(x, y) t_0 = (x * ((x / y) + 1.0)) / (x + 1.0); tmp = 0.0; if ((t_0 <= -1000.0) || ~((t_0 <= 2.0))) tmp = x / y; else tmp = x / (1.0 + x); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1000.0], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t\_0 \leq -1000 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 + x}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1e3 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 79.9%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites75.7%
Taylor expanded in x around inf
lower-/.f6481.9
Applied rewrites81.9%
if -1e3 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6489.0
Applied rewrites89.0%
Final simplification85.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (or (<= t_0 -1000.0) (not (<= t_0 0.9999999999999987)))
(/ x y)
(* (fma (- x 1.0) x 1.0) x))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if ((t_0 <= -1000.0) || !(t_0 <= 0.9999999999999987)) {
tmp = x / y;
} else {
tmp = fma((x - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) tmp = 0.0 if ((t_0 <= -1000.0) || !(t_0 <= 0.9999999999999987)) tmp = Float64(x / y); else tmp = Float64(fma(Float64(x - 1.0), x, 1.0) * x); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1000.0], N[Not[LessEqual[t$95$0, 0.9999999999999987]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(N[(N[(x - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t\_0 \leq -1000 \lor \neg \left(t\_0 \leq 0.9999999999999987\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1e3 or 0.99999999999999867 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 83.7%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites72.3%
Taylor expanded in x around inf
lower-/.f6467.2
Applied rewrites67.2%
if -1e3 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.99999999999999867Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6486.8
Applied rewrites86.8%
Taylor expanded in x around 0
Applied rewrites83.3%
Final simplification74.6%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))) (if (or (<= t_0 -1000.0) (not (<= t_0 0.5))) (/ x y) (fma (- x) x x))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if ((t_0 <= -1000.0) || !(t_0 <= 0.5)) {
tmp = x / y;
} else {
tmp = fma(-x, x, x);
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) tmp = 0.0 if ((t_0 <= -1000.0) || !(t_0 <= 0.5)) tmp = Float64(x / y); else tmp = fma(Float64(-x), x, x); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1000.0], N[Not[LessEqual[t$95$0, 0.5]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[((-x) * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t\_0 \leq -1000 \lor \neg \left(t\_0 \leq 0.5\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, x, x\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -1e3 or 0.5 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 84.1%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
associate-/l*N/A
unpow2N/A
associate-/l*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites72.4%
Taylor expanded in x around inf
lower-/.f6465.4
Applied rewrites65.4%
if -1e3 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.5Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6486.7
Applied rewrites86.7%
Taylor expanded in x around 0
Applied rewrites85.9%
Final simplification74.5%
(FPCore (x y) :precision binary64 (if (<= (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)) -2e+44) (* (- x) x) (* 1.0 x)))
double code(double x, double y) {
double tmp;
if (((x * ((x / y) + 1.0)) / (x + 1.0)) <= -2e+44) {
tmp = -x * x;
} else {
tmp = 1.0 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((x * ((x / y) + 1.0d0)) / (x + 1.0d0)) <= (-2d+44)) then
tmp = -x * x
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x * ((x / y) + 1.0)) / (x + 1.0)) <= -2e+44) {
tmp = -x * x;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * ((x / y) + 1.0)) / (x + 1.0)) <= -2e+44: tmp = -x * x else: tmp = 1.0 * x return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) <= -2e+44) tmp = Float64(Float64(-x) * x); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x * ((x / y) + 1.0)) / (x + 1.0)) <= -2e+44) tmp = -x * x; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], -2e+44], N[((-x) * x), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \leq -2 \cdot 10^{+44}:\\
\;\;\;\;\left(-x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < -2.0000000000000002e44Initial program 76.3%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f641.1
Applied rewrites1.1%
Taylor expanded in x around 0
Applied rewrites35.6%
Taylor expanded in x around inf
Applied rewrites35.7%
if -2.0000000000000002e44 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 94.3%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6461.8
Applied rewrites61.8%
Taylor expanded in x around 0
Applied rewrites50.0%
Taylor expanded in x around 0
Applied rewrites47.5%
(FPCore (x y) :precision binary64 (if (or (<= x -1e+103) (not (<= x 2e+16))) (+ (/ (- x 1.0) y) 1.0) (/ (fma (/ x y) x x) (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -1e+103) || !(x <= 2e+16)) {
tmp = ((x - 1.0) / y) + 1.0;
} else {
tmp = fma((x / y), x, x) / (x + 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -1e+103) || !(x <= 2e+16)) tmp = Float64(Float64(Float64(x - 1.0) / y) + 1.0); else tmp = Float64(fma(Float64(x / y), x, x) / Float64(x + 1.0)); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -1e+103], N[Not[LessEqual[x, 2e+16]], $MachinePrecision]], N[(N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] * x + x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+103} \lor \neg \left(x \leq 2 \cdot 10^{+16}\right):\\
\;\;\;\;\frac{x - 1}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x + 1}\\
\end{array}
\end{array}
if x < -1e103 or 2e16 < x Initial program 78.2%
Taylor expanded in x around inf
associate--l+N/A
+-commutativeN/A
distribute-lft-inN/A
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
neg-mul-1N/A
distribute-rgt-outN/A
rgt-mult-inverseN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites100.0%
if -1e103 < x < 2e16Initial program 99.9%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft1-inN/A
lower-fma.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (+ (/ (- x 1.0) y) 1.0) (fma (- (/ x y) x) x x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = ((x - 1.0) / y) + 1.0;
} else {
tmp = fma(((x / y) - x), x, x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(Float64(x - 1.0) / y) + 1.0); else tmp = fma(Float64(Float64(x / y) - x), x, x); end return tmp end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision] * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{x - 1}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y} - x, x, x\right)\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 81.9%
Taylor expanded in x around inf
associate--l+N/A
+-commutativeN/A
distribute-lft-inN/A
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
neg-mul-1N/A
distribute-rgt-outN/A
rgt-mult-inverseN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-+.f6498.3
Applied rewrites98.3%
Applied rewrites98.4%
if -1 < x < 1Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
distribute-lft-out--N/A
associate-*r/N/A
*-rgt-identityN/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
Final simplification98.3%
(FPCore (x y) :precision binary64 (if (or (<= x -5.4e+17) (not (<= x 5200000000000.0))) (+ (/ (- x 1.0) y) 1.0) (/ x (+ 1.0 x))))
double code(double x, double y) {
double tmp;
if ((x <= -5.4e+17) || !(x <= 5200000000000.0)) {
tmp = ((x - 1.0) / y) + 1.0;
} else {
tmp = x / (1.0 + x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-5.4d+17)) .or. (.not. (x <= 5200000000000.0d0))) then
tmp = ((x - 1.0d0) / y) + 1.0d0
else
tmp = x / (1.0d0 + x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -5.4e+17) || !(x <= 5200000000000.0)) {
tmp = ((x - 1.0) / y) + 1.0;
} else {
tmp = x / (1.0 + x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5.4e+17) or not (x <= 5200000000000.0): tmp = ((x - 1.0) / y) + 1.0 else: tmp = x / (1.0 + x) return tmp
function code(x, y) tmp = 0.0 if ((x <= -5.4e+17) || !(x <= 5200000000000.0)) tmp = Float64(Float64(Float64(x - 1.0) / y) + 1.0); else tmp = Float64(x / Float64(1.0 + x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -5.4e+17) || ~((x <= 5200000000000.0))) tmp = ((x - 1.0) / y) + 1.0; else tmp = x / (1.0 + x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5.4e+17], N[Not[LessEqual[x, 5200000000000.0]], $MachinePrecision]], N[(N[(N[(x - 1.0), $MachinePrecision] / y), $MachinePrecision] + 1.0), $MachinePrecision], N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+17} \lor \neg \left(x \leq 5200000000000\right):\\
\;\;\;\;\frac{x - 1}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 + x}\\
\end{array}
\end{array}
if x < -5.4e17 or 5.2e12 < x Initial program 81.2%
Taylor expanded in x around inf
associate--l+N/A
+-commutativeN/A
distribute-lft-inN/A
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
neg-mul-1N/A
distribute-rgt-outN/A
rgt-mult-inverseN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites100.0%
if -5.4e17 < x < 5.2e12Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6476.2
Applied rewrites76.2%
Final simplification87.2%
(FPCore (x y) :precision binary64 (fma (- x) x x))
double code(double x, double y) {
return fma(-x, x, x);
}
function code(x, y) return fma(Float64(-x), x, x) end
code[x_, y_] := N[((-x) * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-x, x, x\right)
\end{array}
Initial program 91.2%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6451.4
Applied rewrites51.4%
Taylor expanded in x around 0
Applied rewrites44.8%
(FPCore (x y) :precision binary64 (* 1.0 x))
double code(double x, double y) {
return 1.0 * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 * x
end function
public static double code(double x, double y) {
return 1.0 * x;
}
def code(x, y): return 1.0 * x
function code(x, y) return Float64(1.0 * x) end
function tmp = code(x, y) tmp = 1.0 * x; end
code[x_, y_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 91.2%
Taylor expanded in y around inf
lower-/.f64N/A
lower-+.f6451.4
Applied rewrites51.4%
Taylor expanded in x around 0
Applied rewrites44.4%
Taylor expanded in x around 0
Applied rewrites39.9%
(FPCore (x y) :precision binary64 (* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0))))
double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / 1.0d0) * (((x / y) + 1.0d0) / (x + 1.0d0))
end function
public static double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
def code(x, y): return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0))
function code(x, y) return Float64(Float64(x / 1.0) * Float64(Float64(Float64(x / y) + 1.0) / Float64(x + 1.0))) end
function tmp = code(x, y) tmp = (x / 1.0) * (((x / y) + 1.0) / (x + 1.0)); end
code[x_, y_] := N[(N[(x / 1.0), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1} \cdot \frac{\frac{x}{y} + 1}{x + 1}
\end{array}
herbie shell --seed 2024298
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:alt
(! :herbie-platform default (* (/ x 1) (/ (+ (/ x y) 1) (+ x 1))))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))