ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 11 Apr 2019 15:33:37 +0200Constructing all NE-lattice paths from $(0,0)$ to $(m,n)$https://ask.sagemath.org/question/46087/constructing-all-ne-lattice-paths-from-00-to-mn/If I consider only [Dyck Paths](http://mathworld.wolfram.com/DyckPath.html), I can do write something like this:
DWS=DyckWords(3).list()
for D in DWS:
print(D.height())
to obtain the height of all Dyck paths of length $3$. However, I would like to do the same thing but using [$NE$-lattice paths](https://en.wikipedia.org/wiki/Lattice_path#North-East_lattice_paths) from $(0,0)$ to $(m,n)$. Is there an easy way to do this in Sage?Thu, 11 Apr 2019 08:50:27 +0200https://ask.sagemath.org/question/46087/constructing-all-ne-lattice-paths-from-00-to-mn/Comment by rburing for <p>If I consider only <a href="http://mathworld.wolfram.com/DyckPath.html">Dyck Paths</a>, I can do write something like this:</p>
<pre><code>DWS=DyckWords(3).list()
for D in DWS:
print(D.height())
</code></pre>
<p>to obtain the height of all Dyck paths of length $3$. However, I would like to do the same thing but using <a href="https://en.wikipedia.org/wiki/Lattice_path#North-East_lattice_paths">$NE$-lattice paths</a> from $(0,0)$ to $(m,n)$. Is there an easy way to do this in Sage?</p>
https://ask.sagemath.org/question/46087/constructing-all-ne-lattice-paths-from-00-to-mn/?comment=46088#post-id-46088You could try using a bijection with something that *is* in Sage, e.g. see [Ferrers diagram](http://mathworld.wolfram.com/FerrersDiagram.html) of a partition.Thu, 11 Apr 2019 09:43:27 +0200https://ask.sagemath.org/question/46087/constructing-all-ne-lattice-paths-from-00-to-mn/?comment=46088#post-id-46088Answer by joakim_uhlin for <p>If I consider only <a href="http://mathworld.wolfram.com/DyckPath.html">Dyck Paths</a>, I can do write something like this:</p>
<pre><code>DWS=DyckWords(3).list()
for D in DWS:
print(D.height())
</code></pre>
<p>to obtain the height of all Dyck paths of length $3$. However, I would like to do the same thing but using <a href="https://en.wikipedia.org/wiki/Lattice_path#North-East_lattice_paths">$NE$-lattice paths</a> from $(0,0)$ to $(m,n)$. Is there an easy way to do this in Sage?</p>
https://ask.sagemath.org/question/46087/constructing-all-ne-lattice-paths-from-00-to-mn/?answer=46095#post-id-46095I fixed this myself but in case anyone is interested I will leave this as an answer.
I decided to use the kbits from this [thread](https://stackoverflow.com/questions/1851134/generate-all-binary-strings-of-length-n-with-k-bits-set) to generate all binary strings of length $n$ with $m$ ones. Such strings are in a natural bijection with $NE$-lattice paths from $(0,0)$ to $(n,m)$. After that, I can get the heights of all the paths by writing
Paths = WordPaths('01', steps=[(1,-1),(1,1)])
for b in kbits(m+n,m):
print(Paths(b).ymax())
Note: Sage has a "height" function on words, but this is not what I am looking for. In the definition of height that I am using, the height of an $NE$-path is geometrically the biggest distance that the path is away from the main diagonal.Thu, 11 Apr 2019 15:33:37 +0200https://ask.sagemath.org/question/46087/constructing-all-ne-lattice-paths-from-00-to-mn/?answer=46095#post-id-46095