
(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 11 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
(let* ((t_0 (+ 1.0 (/ (+ x -1.0) y))))
(if (<= x -1e+24)
t_0
(if (<= x 3800000000.0) (/ (fma (/ x y) x x) (+ x 1.0)) t_0))))
double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (x <= -1e+24) {
tmp = t_0;
} else if (x <= 3800000000.0) {
tmp = fma((x / y), x, x) / (x + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(x + -1.0) / y)) tmp = 0.0 if (x <= -1e+24) tmp = t_0; elseif (x <= 3800000000.0) tmp = Float64(fma(Float64(x / y), x, x) / Float64(x + 1.0)); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1e+24], t$95$0, If[LessEqual[x, 3800000000.0], N[(N[(N[(x / y), $MachinePrecision] * x + x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x + -1}{y}\\
\mathbf{if}\;x \leq -1 \cdot 10^{+24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3800000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.9999999999999998e23 or 3.8e9 < x Initial program 75.3%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft1-inN/A
lower-fma.f6475.3
Applied rewrites75.3%
lift-/.f64N/A
lift-fma.f64N/A
distribute-lft1-inN/A
lift-/.f64N/A
associate-/l*N/A
clear-numN/A
lift-/.f64N/A
un-div-invN/A
lower-/.f64N/A
lift-/.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
distribute-rgt-inN/A
lft-mult-inverseN/A
associate-*l/N/A
*-lft-identityN/A
associate-+r+N/A
sub-negN/A
lower-+.f64N/A
div-subN/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f64100.0
Applied rewrites100.0%
if -9.9999999999999998e23 < x < 3.8e9Initial program 99.8%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft1-inN/A
lower-fma.f6499.8
Applied rewrites99.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (<= t_0 -1e+79)
(/ x y)
(if (<= t_0 5e-21)
(fma x (/ x y) x)
(if (<= t_0 2.0) (/ x (+ 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 <= -1e+79) {
tmp = x / y;
} else if (t_0 <= 5e-21) {
tmp = fma(x, (x / y), x);
} else if (t_0 <= 2.0) {
tmp = x / (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 <= -1e+79) tmp = Float64(x / y); elseif (t_0 <= 5e-21) tmp = fma(x, Float64(x / y), x); elseif (t_0 <= 2.0) tmp = Float64(x / Float64(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, -1e+79], N[(x / y), $MachinePrecision], If[LessEqual[t$95$0, 5e-21], N[(x * N[(x / y), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(x / N[(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 -1 \cdot 10^{+79}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{x}{y}, x\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{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))) < -9.99999999999999967e78 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 65.7%
Taylor expanded in x around inf
lower-/.f6485.1
Applied rewrites85.1%
if -9.99999999999999967e78 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 4.99999999999999973e-21Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
distribute-rgt-out--N/A
associate-*l/N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6493.1
Applied rewrites93.1%
Taylor expanded in y around 0
Applied rewrites92.7%
if 4.99999999999999973e-21 < (/.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
+-commutativeN/A
lower-+.f6496.5
Applied rewrites96.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (<= t_0 -2.0)
(/ x y)
(if (<= t_0 0.2)
(fma x (- (* x x) x) x)
(if (<= t_0 2.0) (+ 1.0 (/ -1.0 x)) (/ x y))))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if (t_0 <= -2.0) {
tmp = x / y;
} else if (t_0 <= 0.2) {
tmp = fma(x, ((x * x) - x), x);
} else if (t_0 <= 2.0) {
tmp = 1.0 + (-1.0 / x);
} 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 <= -2.0) tmp = Float64(x / y); elseif (t_0 <= 0.2) tmp = fma(x, Float64(Float64(x * x) - x), x); elseif (t_0 <= 2.0) tmp = Float64(1.0 + Float64(-1.0 / x)); 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, -2.0], N[(x / y), $MachinePrecision], If[LessEqual[t$95$0, 0.2], N[(x * N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(1.0 + N[(-1.0 / x), $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 -2:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;t\_0 \leq 0.2:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot x - x, x\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1 + \frac{-1}{x}\\
\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))) < -2 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 72.2%
Taylor expanded in x around inf
lower-/.f6476.7
Applied rewrites76.7%
if -2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.20000000000000001Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f6484.5
Applied rewrites84.5%
Taylor expanded in x around 0
Applied rewrites83.9%
if 0.20000000000000001 < (/.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
+-commutativeN/A
lower-+.f6496.3
Applied rewrites96.3%
Taylor expanded in x around inf
Applied rewrites94.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (<= t_0 -2.0)
(/ x y)
(if (<= t_0 0.2)
(- x (* x x))
(if (<= t_0 2.0) (+ 1.0 (/ -1.0 x)) (/ x y))))))
double code(double x, double y) {
double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
double tmp;
if (t_0 <= -2.0) {
tmp = x / y;
} else if (t_0 <= 0.2) {
tmp = x - (x * x);
} else if (t_0 <= 2.0) {
tmp = 1.0 + (-1.0 / x);
} else {
tmp = x / y;
}
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 <= (-2.0d0)) then
tmp = x / y
else if (t_0 <= 0.2d0) then
tmp = x - (x * x)
else if (t_0 <= 2.0d0) then
tmp = 1.0d0 + ((-1.0d0) / x)
else
tmp = x / y
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 <= -2.0) {
tmp = x / y;
} else if (t_0 <= 0.2) {
tmp = x - (x * x);
} else if (t_0 <= 2.0) {
tmp = 1.0 + (-1.0 / x);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x + 1.0) tmp = 0 if t_0 <= -2.0: tmp = x / y elif t_0 <= 0.2: tmp = x - (x * x) elif t_0 <= 2.0: tmp = 1.0 + (-1.0 / x) 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 <= -2.0) tmp = Float64(x / y); elseif (t_0 <= 0.2) tmp = Float64(x - Float64(x * x)); elseif (t_0 <= 2.0) tmp = Float64(1.0 + Float64(-1.0 / x)); else tmp = Float64(x / y); 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 <= -2.0) tmp = x / y; elseif (t_0 <= 0.2) tmp = x - (x * x); elseif (t_0 <= 2.0) tmp = 1.0 + (-1.0 / x); else tmp = x / y; 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[LessEqual[t$95$0, -2.0], N[(x / y), $MachinePrecision], If[LessEqual[t$95$0, 0.2], N[(x - N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(1.0 + N[(-1.0 / x), $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 -2:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;t\_0 \leq 0.2:\\
\;\;\;\;x - x \cdot x\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;1 + \frac{-1}{x}\\
\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))) < -2 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 72.2%
Taylor expanded in x around inf
lower-/.f6476.7
Applied rewrites76.7%
if -2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.20000000000000001Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f6484.5
Applied rewrites84.5%
Taylor expanded in x around 0
Applied rewrites83.5%
if 0.20000000000000001 < (/.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
+-commutativeN/A
lower-+.f6496.3
Applied rewrites96.3%
Taylor expanded in x around inf
Applied rewrites94.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
(if (<= t_0 -2.0)
(/ x y)
(if (<= t_0 0.2) (- x (* x x)) (if (<= t_0 20.0) 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 <= -2.0) {
tmp = x / y;
} else if (t_0 <= 0.2) {
tmp = x - (x * x);
} else if (t_0 <= 20.0) {
tmp = 1.0;
} else {
tmp = x / y;
}
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 <= (-2.0d0)) then
tmp = x / y
else if (t_0 <= 0.2d0) then
tmp = x - (x * x)
else if (t_0 <= 20.0d0) then
tmp = 1.0d0
else
tmp = x / y
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 <= -2.0) {
tmp = x / y;
} else if (t_0 <= 0.2) {
tmp = x - (x * x);
} else if (t_0 <= 20.0) {
tmp = 1.0;
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x + 1.0) tmp = 0 if t_0 <= -2.0: tmp = x / y elif t_0 <= 0.2: tmp = x - (x * x) elif t_0 <= 20.0: tmp = 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 <= -2.0) tmp = Float64(x / y); elseif (t_0 <= 0.2) tmp = Float64(x - Float64(x * x)); elseif (t_0 <= 20.0) tmp = 1.0; else tmp = Float64(x / y); 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 <= -2.0) tmp = x / y; elseif (t_0 <= 0.2) tmp = x - (x * x); elseif (t_0 <= 20.0) tmp = 1.0; else tmp = x / y; 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[LessEqual[t$95$0, -2.0], N[(x / y), $MachinePrecision], If[LessEqual[t$95$0, 0.2], N[(x - N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 20.0], 1.0, 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 -2:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;t\_0 \leq 0.2:\\
\;\;\;\;x - x \cdot x\\
\mathbf{elif}\;t\_0 \leq 20:\\
\;\;\;\;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))) < -2 or 20 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 72.0%
Taylor expanded in x around inf
lower-/.f6477.5
Applied rewrites77.5%
if -2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.20000000000000001Initial program 99.9%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f6484.5
Applied rewrites84.5%
Taylor expanded in x around 0
Applied rewrites83.5%
if 0.20000000000000001 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 20Initial program 99.8%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f6494.1
Applied rewrites94.1%
Taylor expanded in x around inf
Applied rewrites91.2%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))) (if (<= t_0 -2.0) (/ x y) (if (<= t_0 2.0) (/ x (+ 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 <= -2.0) {
tmp = x / y;
} else if (t_0 <= 2.0) {
tmp = x / (x + 1.0);
} else {
tmp = x / y;
}
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 <= (-2.0d0)) then
tmp = x / y
else if (t_0 <= 2.0d0) then
tmp = x / (x + 1.0d0)
else
tmp = x / y
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 <= -2.0) {
tmp = x / y;
} else if (t_0 <= 2.0) {
tmp = x / (x + 1.0);
} else {
tmp = x / y;
}
return tmp;
}
def code(x, y): t_0 = (x * ((x / y) + 1.0)) / (x + 1.0) tmp = 0 if t_0 <= -2.0: tmp = x / y elif t_0 <= 2.0: tmp = x / (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 <= -2.0) tmp = Float64(x / y); elseif (t_0 <= 2.0) tmp = Float64(x / Float64(x + 1.0)); else tmp = Float64(x / y); 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 <= -2.0) tmp = x / y; elseif (t_0 <= 2.0) tmp = x / (x + 1.0); else tmp = x / y; 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[LessEqual[t$95$0, -2.0], N[(x / y), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(x / N[(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 -2:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x}{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))) < -2 or 2 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 72.2%
Taylor expanded in x around inf
lower-/.f6476.7
Applied rewrites76.7%
if -2 < (/.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
+-commutativeN/A
lower-+.f6487.5
Applied rewrites87.5%
(FPCore (x y) :precision binary64 (if (<= (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)) 0.2) (- x (* x x)) 1.0))
double code(double x, double y) {
double tmp;
if (((x * ((x / y) + 1.0)) / (x + 1.0)) <= 0.2) {
tmp = x - (x * 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 (((x * ((x / y) + 1.0d0)) / (x + 1.0d0)) <= 0.2d0) then
tmp = x - (x * x)
else
tmp = 1.0d0
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)) <= 0.2) {
tmp = x - (x * x);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * ((x / y) + 1.0)) / (x + 1.0)) <= 0.2: tmp = x - (x * x) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) <= 0.2) tmp = Float64(x - Float64(x * x)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x * ((x / y) + 1.0)) / (x + 1.0)) <= 0.2) tmp = x - (x * x); else tmp = 1.0; 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], 0.2], N[(x - N[(x * x), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \leq 0.2:\\
\;\;\;\;x - x \cdot x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) < 0.20000000000000001Initial program 92.9%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f6457.2
Applied rewrites57.2%
Taylor expanded in x around 0
Applied rewrites63.5%
if 0.20000000000000001 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) #s(literal 1 binary64))) (+.f64 x #s(literal 1 binary64))) Initial program 81.0%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f6449.5
Applied rewrites49.5%
Taylor expanded in x around inf
Applied rewrites48.3%
(FPCore (x y) :precision binary64 (/ (+ (/ x y) 1.0) (/ (+ x 1.0) x)))
double code(double x, double y) {
return ((x / y) + 1.0) / ((x + 1.0) / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x / y) + 1.0d0) / ((x + 1.0d0) / x)
end function
public static double code(double x, double y) {
return ((x / y) + 1.0) / ((x + 1.0) / x);
}
def code(x, y): return ((x / y) + 1.0) / ((x + 1.0) / x)
function code(x, y) return Float64(Float64(Float64(x / y) + 1.0) / Float64(Float64(x + 1.0) / x)) end
function tmp = code(x, y) tmp = ((x / y) + 1.0) / ((x + 1.0) / x); end
code[x_, y_] := N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}
\end{array}
Initial program 89.2%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft1-inN/A
lower-fma.f6489.2
Applied rewrites89.2%
lift-/.f64N/A
lift-fma.f64N/A
distribute-lft1-inN/A
lift-/.f64N/A
associate-/l*N/A
clear-numN/A
lift-/.f64N/A
un-div-invN/A
lower-/.f64N/A
lift-/.f64N/A
lower-+.f6499.8
Applied rewrites99.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ 1.0 (/ (+ x -1.0) y)))) (if (<= x -1.0) t_0 (if (<= x 1.0) (fma x (- (/ x y) x) x) t_0))))
double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = fma(x, ((x / y) - x), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(x + -1.0) / y)) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = fma(x, Float64(Float64(x / y) - x), x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], N[(x * N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x + -1}{y}\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{x}{y} - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 76.6%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft1-inN/A
lower-fma.f6476.6
Applied rewrites76.6%
lift-/.f64N/A
lift-fma.f64N/A
distribute-lft1-inN/A
lift-/.f64N/A
associate-/l*N/A
clear-numN/A
lift-/.f64N/A
un-div-invN/A
lower-/.f64N/A
lift-/.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
distribute-rgt-inN/A
lft-mult-inverseN/A
associate-*l/N/A
*-lft-identityN/A
associate-+r+N/A
sub-negN/A
lower-+.f64N/A
div-subN/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f6498.3
Applied rewrites98.3%
if -1 < x < 1Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
distribute-rgt-out--N/A
associate-*l/N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ 1.0 (/ (+ x -1.0) y)))) (if (<= x -1.0) t_0 (if (<= x 1.2) (fma x (/ x y) x) t_0))))
double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.2) {
tmp = fma(x, (x / y), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(x + -1.0) / y)) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.2) tmp = fma(x, Float64(x / y), x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.2], N[(x * N[(x / y), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x + -1}{y}\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.2:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{x}{y}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1.19999999999999996 < x Initial program 76.6%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
distribute-lft1-inN/A
lower-fma.f6476.6
Applied rewrites76.6%
lift-/.f64N/A
lift-fma.f64N/A
distribute-lft1-inN/A
lift-/.f64N/A
associate-/l*N/A
clear-numN/A
lift-/.f64N/A
un-div-invN/A
lower-/.f64N/A
lift-/.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
associate-/r*N/A
associate-*r/N/A
rgt-mult-inverseN/A
distribute-rgt-inN/A
lft-mult-inverseN/A
associate-*l/N/A
*-lft-identityN/A
associate-+r+N/A
sub-negN/A
lower-+.f64N/A
div-subN/A
lower-/.f64N/A
sub-negN/A
metadata-evalN/A
lower-+.f6498.3
Applied rewrites98.3%
if -1 < x < 1.19999999999999996Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
distribute-rgt-out--N/A
associate-*l/N/A
*-lft-identityN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
Taylor expanded in y around 0
Applied rewrites97.8%
(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 89.2%
Taylor expanded in y around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f6454.8
Applied rewrites54.8%
Taylor expanded in x around inf
Applied rewrites17.0%
(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 2024238
(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)))