
(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 8 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 (/ x (/ (+ x 1.0) (+ 1.0 (/ x y)))))
double code(double x, double y) {
return x / ((x + 1.0) / (1.0 + (x / y)));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / ((x + 1.0d0) / (1.0d0 + (x / y)))
end function
public static double code(double x, double y) {
return x / ((x + 1.0) / (1.0 + (x / y)));
}
def code(x, y): return x / ((x + 1.0) / (1.0 + (x / y)))
function code(x, y) return Float64(x / Float64(Float64(x + 1.0) / Float64(1.0 + Float64(x / y)))) end
function tmp = code(x, y) tmp = x / ((x + 1.0) / (1.0 + (x / y))); end
code[x_, y_] := N[(x / N[(N[(x + 1.0), $MachinePrecision] / N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{x + 1}{1 + \frac{x}{y}}}
\end{array}
Initial program 88.2%
associate-/l*99.8%
Simplified99.8%
clear-num99.8%
un-div-inv99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (<= x -500000000.0) (+ 1.0 (/ x y)) (if (<= x 230000.0) (/ x (+ x 1.0)) (+ 1.0 (* (/ 1.0 y) (+ x -1.0))))))
double code(double x, double y) {
double tmp;
if (x <= -500000000.0) {
tmp = 1.0 + (x / y);
} else if (x <= 230000.0) {
tmp = x / (x + 1.0);
} else {
tmp = 1.0 + ((1.0 / y) * (x + -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 <= (-500000000.0d0)) then
tmp = 1.0d0 + (x / y)
else if (x <= 230000.0d0) then
tmp = x / (x + 1.0d0)
else
tmp = 1.0d0 + ((1.0d0 / y) * (x + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -500000000.0) {
tmp = 1.0 + (x / y);
} else if (x <= 230000.0) {
tmp = x / (x + 1.0);
} else {
tmp = 1.0 + ((1.0 / y) * (x + -1.0));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -500000000.0: tmp = 1.0 + (x / y) elif x <= 230000.0: tmp = x / (x + 1.0) else: tmp = 1.0 + ((1.0 / y) * (x + -1.0)) return tmp
function code(x, y) tmp = 0.0 if (x <= -500000000.0) tmp = Float64(1.0 + Float64(x / y)); elseif (x <= 230000.0) tmp = Float64(x / Float64(x + 1.0)); else tmp = Float64(1.0 + Float64(Float64(1.0 / y) * Float64(x + -1.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -500000000.0) tmp = 1.0 + (x / y); elseif (x <= 230000.0) tmp = x / (x + 1.0); else tmp = 1.0 + ((1.0 / y) * (x + -1.0)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -500000000.0], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 230000.0], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(1.0 / y), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -500000000:\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{elif}\;x \leq 230000:\\
\;\;\;\;\frac{x}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{1}{y} \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -5e8Initial program 71.6%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 69.2%
*-commutative69.2%
+-commutative69.2%
associate-/l*73.0%
*-lft-identity73.0%
associate-*l/73.0%
unpow273.0%
+-commutative73.0%
associate-/l*99.9%
*-lft-identity99.9%
associate-*l/99.8%
distribute-rgt-out99.8%
associate-*l/100.0%
*-lft-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around 0 100.0%
+-commutative100.0%
*-lft-identity100.0%
associate-*l/99.6%
+-commutative99.6%
distribute-rgt-in99.6%
associate-*r/99.9%
*-rgt-identity99.9%
rgt-mult-inverse100.0%
Simplified100.0%
if -5e8 < x < 2.3e5Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 76.9%
if 2.3e5 < x Initial program 79.7%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 67.5%
*-commutative67.5%
+-commutative67.5%
associate-/l*70.3%
*-lft-identity70.3%
associate-*l/70.3%
unpow270.3%
+-commutative70.3%
associate-/l*99.9%
*-lft-identity99.9%
associate-*l/99.8%
distribute-rgt-out99.8%
associate-*l/100.0%
*-lft-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 99.5%
associate--l+99.5%
distribute-lft-in99.5%
*-commutative99.5%
lft-mult-inverse99.5%
sub-neg99.5%
distribute-lft-in99.5%
associate-/r*99.5%
distribute-frac-neg299.5%
associate-*r/99.5%
*-commutative99.5%
lft-mult-inverse99.5%
distribute-frac-neg299.5%
fma-define99.5%
fma-neg99.5%
*-lft-identity99.5%
distribute-rgt-out--99.5%
sub-neg99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification88.2%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 4.1e-8))) (+ 1.0 (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.1e-8)) {
tmp = 1.0 + (x / y);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 4.1d-8))) then
tmp = 1.0d0 + (x / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.1e-8)) {
tmp = 1.0 + (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 4.1e-8): tmp = 1.0 + (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 4.1e-8)) tmp = Float64(1.0 + Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 4.1e-8))) tmp = 1.0 + (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 4.1e-8]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 4.1 \cdot 10^{-8}\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 4.10000000000000032e-8 < x Initial program 77.5%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 69.8%
*-commutative69.8%
+-commutative69.8%
associate-/l*72.9%
*-lft-identity72.9%
associate-*l/72.9%
unpow272.9%
+-commutative72.9%
associate-/l*99.9%
*-lft-identity99.9%
associate-*l/99.8%
distribute-rgt-out99.8%
associate-*l/100.0%
*-lft-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 95.8%
Taylor expanded in y around 0 95.8%
+-commutative95.8%
*-lft-identity95.8%
associate-*l/95.5%
+-commutative95.5%
distribute-rgt-in95.5%
associate-*r/95.8%
*-rgt-identity95.8%
rgt-mult-inverse95.8%
Simplified95.8%
if -1 < x < 4.10000000000000032e-8Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.8%
Final simplification87.2%
(FPCore (x y) :precision binary64 (if (or (<= x -380000000.0) (not (<= x 340000.0))) (+ 1.0 (/ x y)) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -380000000.0) || !(x <= 340000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (x + 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 <= (-380000000.0d0)) .or. (.not. (x <= 340000.0d0))) then
tmp = 1.0d0 + (x / y)
else
tmp = x / (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -380000000.0) || !(x <= 340000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -380000000.0) or not (x <= 340000.0): tmp = 1.0 + (x / y) else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -380000000.0) || !(x <= 340000.0)) tmp = Float64(1.0 + Float64(x / y)); else tmp = Float64(x / Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -380000000.0) || ~((x <= 340000.0))) tmp = 1.0 + (x / y); else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -380000000.0], N[Not[LessEqual[x, 340000.0]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -380000000 \lor \neg \left(x \leq 340000\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -3.8e8 or 3.4e5 < x Initial program 76.3%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 68.2%
*-commutative68.2%
+-commutative68.2%
associate-/l*71.4%
*-lft-identity71.4%
associate-*l/71.4%
unpow271.4%
+-commutative71.4%
associate-/l*99.9%
*-lft-identity99.9%
associate-*l/99.8%
distribute-rgt-out99.8%
associate-*l/100.0%
*-lft-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 99.5%
Taylor expanded in y around 0 99.5%
+-commutative99.5%
*-lft-identity99.5%
associate-*l/99.1%
+-commutative99.1%
distribute-rgt-in99.2%
associate-*r/99.5%
*-rgt-identity99.5%
rgt-mult-inverse99.5%
Simplified99.5%
if -3.8e8 < x < 3.4e5Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 76.9%
Final simplification88.1%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 4.1e-8))) (/ x y) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.1e-8)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 4.1d-8))) then
tmp = x / y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.1e-8)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 4.1e-8): tmp = x / y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 4.1e-8)) tmp = Float64(x / y); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 4.1e-8))) tmp = x / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 4.1e-8]], $MachinePrecision]], N[(x / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 4.1 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 4.10000000000000032e-8 < x Initial program 77.5%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 75.9%
if -1 < x < 4.10000000000000032e-8Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.8%
Final simplification76.8%
(FPCore (x y) :precision binary64 (if (<= x -3.8e-5) 1.0 (if (<= x 4.1e-8) x 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -3.8e-5) {
tmp = 1.0;
} else if (x <= 4.1e-8) {
tmp = 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 <= (-3.8d-5)) then
tmp = 1.0d0
else if (x <= 4.1d-8) then
tmp = x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.8e-5) {
tmp = 1.0;
} else if (x <= 4.1e-8) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.8e-5: tmp = 1.0 elif x <= 4.1e-8: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.8e-5) tmp = 1.0; elseif (x <= 4.1e-8) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.8e-5) tmp = 1.0; elseif (x <= 4.1e-8) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.8e-5], 1.0, If[LessEqual[x, 4.1e-8], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-5}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.8000000000000002e-5 or 4.10000000000000032e-8 < x Initial program 77.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 70.3%
*-commutative70.3%
+-commutative70.3%
associate-/l*73.3%
*-lft-identity73.3%
associate-*l/73.3%
unpow273.3%
+-commutative73.3%
associate-/l*99.9%
*-lft-identity99.9%
associate-*l/99.8%
distribute-rgt-out99.8%
associate-*l/100.0%
*-lft-identity100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 94.4%
Taylor expanded in y around inf 21.2%
if -3.8000000000000002e-5 < x < 4.10000000000000032e-8Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 79.0%
Final simplification48.3%
(FPCore (x y) :precision binary64 (* x (/ (+ 1.0 (/ x y)) (+ x 1.0))))
double code(double x, double y) {
return x * ((1.0 + (x / y)) / (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)) / (x + 1.0d0))
end function
public static double code(double x, double y) {
return x * ((1.0 + (x / y)) / (x + 1.0));
}
def code(x, y): return x * ((1.0 + (x / y)) / (x + 1.0))
function code(x, y) return Float64(x * Float64(Float64(1.0 + Float64(x / y)) / Float64(x + 1.0))) end
function tmp = code(x, y) tmp = x * ((1.0 + (x / y)) / (x + 1.0)); end
code[x_, y_] := N[(x * N[(N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{1 + \frac{x}{y}}{x + 1}
\end{array}
Initial program 88.2%
associate-/l*99.8%
Simplified99.8%
Final simplification99.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 88.2%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 75.6%
*-commutative75.6%
+-commutative75.6%
associate-/l*77.2%
*-lft-identity77.2%
associate-*l/77.2%
unpow277.2%
+-commutative77.2%
associate-/l*91.4%
*-lft-identity91.4%
associate-*l/91.3%
distribute-rgt-out91.3%
associate-*l/91.4%
*-lft-identity91.4%
+-commutative91.4%
Simplified91.4%
Taylor expanded in x around inf 51.8%
Taylor expanded in y around inf 12.9%
Final simplification12.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 2024096
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:alt
(* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0)))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))