Subsequences
Subsequences[list]
gives the list of all possible subsequences of list.
Subsequences[list,n]
gives all subsequences containing at most n elements.
Subsequences[list,{n}]
gives all subsequences containing exactly n elements.
Subsequences[list,{nmin,nmax}]
gives all subsequences containing between nmin and nmax elements.
Subsequences[list,nspec,s]
limits the result to the first s subsequences.
Subsequences[list,nspec,{s}]
gives if possible the s subsequence.
Details
- Subsequences[list,All] is equivalent to Subsequences[list].
- Subsequences[list,{nmin,nmax,dn}] gives subsequences containing nmin, nmin+dn, … elements.
- Subsequences[list,nspec,All] is equivalent to Subsequences[list,nspec].
- Subsequences[list,nspec,spec] gives the same result as Take[Subsequences[list,nspec],spec], provided that the elements specified by spec are present.
- Subsequences[list,nspec,UpTo[s]] returns s subsequences, or as many as are available.
- The head of list in Subsequences[list,nspec,spec] does not need to be List.
- Subsequences[BioSequence["type","seq"],nspec,…] gives the specified subsequences of the given BioSequence.
Examples
open allclose allBasic Examples (3)
Scope (6)
All subsequences of {a,b,c,d}:
The first 2 subsequences containing 3 elements:
All subsequences with even length:
The odd-numbered subsequences of {a,b,c,d} in reverse order:
Use Subsequences with UpTo:
Applications (2)
Use Subsequences to obtain all subsequences common to two lists:
Or specify the length of the common subsequences to consider:
Compare to LongestCommonSubsequence:
Construct the boundary of a hexagon and color its sides randomly:
Properties & Relations (5)
Subsequences is equivalent to a form of Partition:
Subsequences preserves the order of the input:
Different occurrences of the same element are treated as distinct:
SequenceCases can also find the subsequences of a list:
Possible Issues (2)
Subsequences[list,nspec,spec] only evaluates when all requested items are present:
Subsequences generates only one list of length 0:
This follows the behavior of Subsets:
Text
Wolfram Research (2016), Subsequences, Wolfram Language function, https://reference.wolfram.com/language/ref/Subsequences.html (updated 2020).
CMS
Wolfram Language. 2016. "Subsequences." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/Subsequences.html.
APA
Wolfram Language. (2016). Subsequences. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Subsequences.html