Skip to main content
21 votes
Accepted

Using Sequence to delete a part of an expression

What happens to the list after we assign an element to Sequence[] The answers given so far already contain most of the pieces needed to explain this behavior, but I ...
Leonid Shifrin's user avatar
16 votes
Accepted

Select data from a structured list

Maybe there is something more elegant, but there you go: Cases[data, {n_Integer} | {_?(LessThan[2]), b__} :> {n, b}]
Najib Idrissi's user avatar
14 votes

Select data from a structured list

SequenceReplace[{ a : {_, _, _, _} ...} :> Sequence @@ (Rest /@ Select[First@# <= 2 &]@{a})] @ data {{1}, {-12.7758, -0.00980164, 0.00032368}, {-12....
kglr's user avatar
  • 398k
12 votes
Accepted

How do I test if a variable represents a sequence?

You may make a helper function with attribute SequenceHold. ...
Edmund's user avatar
  • 42.4k
12 votes
Accepted

Build general form of an infinite sequence

...
Roman's user avatar
  • 48.3k
12 votes
Accepted

Split list into ascending sublists

I think this must be a duplicate, but as the answer below is (almost) identical to an example in Split, I have tagged it ...
12 votes
Accepted

Peaks, plateaus and ledges

list = {0, 0, 1, 2, 2, 3, 4, 4, 5, 5, 5, 4, 3, 3, 2, 2, 3, 2, 1, 1, 2, 2, 1}; Using SequencePosition with patterns that ...
kglr's user avatar
  • 398k
11 votes

Split list into ascending sublists

Using SequenceSplit: SequenceSplit[ls, {x_, y___}?OrderedQ :> {x, y}] (*{{2, 3}, {1, 2, 3, 3}, {2}, {1}}*)
E. Chan-López's user avatar
11 votes

How can I define a sequence of Integers which only contains the first k integers, then doesnt contain the next j integers, and so on

Flatten@Partition[Range[listmax], k + j][[All, ;; k]] Edit: Or, using the 3rd argument to Partition, ...
Alan's user avatar
  • 13.8k
11 votes
Accepted

How can I define a sequence of Integers which only contains the first k integers, then doesnt contain the next j integers, and so on

BlockMap[Splice, Range@listmax, k, k + j] Since you haven't defined the edge case behavior, this might not actually give you what you want. For example: ...
lericr's user avatar
  • 30.2k
11 votes

Peaks, plateaus and ledges

...
kglr's user avatar
  • 398k
10 votes
Accepted

Find Sequence Function Error?

If you examine the documentation page of FindSequenceFunction you'll see it has an option called FunctionSpace. Its doc page ...
Sjoerd C. de Vries's user avatar
9 votes

Locate Start and End Positions of Repeated Sequences in a list

In versions 10 and later, you can get the result using a single function SequencePosition: ...
kglr's user avatar
  • 398k
9 votes
Accepted

The use of SlotSequence in If[#1 > #2, ##] &

The answer is simple: First, you really need to look up the documentation of ##. It means "take all arguments". But more importantly, you can use the property that <...
halirutan's user avatar
  • 113k
9 votes

Computing limit of $\frac{1}{n \sin \left(\pi ^6 n\right)}$ over integers

An appropriate tool for calculating limits of sequences over integers is DiscreteLimit. However ...
Artes's user avatar
  • 57.5k
9 votes
Accepted

A possible issue in combination of the Infix operator ~ with Sequence

Look at: Attributes[If] (* {HoldRest, Protected} *) Now consider: If[#1, Sequence @@ {2, 3}] & Because of the "...
Daniel Huber's user avatar
9 votes
Accepted

Replacing string values with one of the sequence-functions

sr = SequenceReplace[{a : (_ -> n_?NumberQ), b : (_ -> _String) ..} :> Sequence[a, Splice[# -> n & @@@ {b}]]] sr @ list ...
kglr's user avatar
  • 398k
8 votes
Accepted

Summing factors of binomial coefficients - get general formula?

By inspection of the first few terms we can infer that the correct generalization should be: fun[m_, n_] := Sum[(-1)^(q + m) Binomial[m - 1, q - 1] q^n, {q, 1, m}] ...
Kagaratsch's user avatar
8 votes
Accepted

Turning arguments into exponents

Here's an explanation of why you get {4}. As mentioned above, your problem is the use of Rule instead of ...
Carl Woll's user avatar
  • 131k
8 votes
Accepted

Splice matching function arguments

The docs say that Splice[{e1,e2,…}] is equivalent to Sequence[e1,e2,…] when the outer wrapping head is ...
evanb's user avatar
  • 6,151
8 votes
Accepted

What does Sequence[2,4]^2 mean?

Switching away from infix notation might make things more clear: Sequence[2, 4]^2 === Power[Sequence[2, 4], 2] === Power[2, 4, 2] According to the documentation ...
Greg Hurst's user avatar
  • 36.3k
8 votes
Accepted

Find the longest sequence of "1" in a SubList

It's because of the canonical order of expressions. Even though -∞ < 4 is true, Order[-∞, 4] is ...
Coolwater's user avatar
  • 20.3k
8 votes
Accepted

Determining the run length of elements in a list that satisfy a pattern

digit = {0.2, 0.9, 0.6, 0.6, 0.7, 0.4, 0.3, 0.2}; SequenceSplit[digit, {_?(# <= 0.5 &)}] {{0.9, 0.6, 0.6, 0.7}} This ...
Syed's user avatar
  • 55.6k
8 votes

Select data from a structured list

A trivial way: select those data for which the first number of the four is less than 2 keep the counting lone integers keep only the last three columns of the sets. translate: ...
AsukaMinato's user avatar
  • 9,978
8 votes

Select data from a structured list

res1 = data /. {{a_, b_, c_, d_} :> {b, c, d} /; a < 2 , {a_, b_, c_, d_} :> Nothing} Or phrased the other way round: ...
Syed's user avatar
  • 55.6k
8 votes

Split list into ascending sublists

Found a solution by myself: SequenceCases[ls, {__}?OrderedQ] Wonder if there's a neater one :)
SnzFor16Min's user avatar
  • 2,240
7 votes

Positions of elements in the initial flattened list in a split list

Internal`CopyListStructure is quite fast: Internal`CopyListStructure[Split @ #, Range @ Length @ #] & @ m1 ...
kglr's user avatar
  • 398k
7 votes

How do I test if a variable represents a sequence?

Internal`InheritedBlock[{FreeQ}, SetAttributes[FreeQ, SequenceHold]; FreeQ[mySeq, 1] ] False
Kuba's user avatar
  • 137k
7 votes

How do I test if a variable represents a sequence?

This tests if a symbol represents a Sequence: With[{a = mySeq}, HoldComplete[a][[1, 0]]] === Sequence or: ...
Coolwater's user avatar
  • 20.3k
7 votes
Accepted

Are there different Method options that can be used with FindSequenceFunction?

This is not a complete answer. It is a long comment about what I found when I looked at the inspectable source code of this function using various spelunking tools (e.g.. Spelunking package, ...
Szabolcs's user avatar
  • 236k

Only top scored, non community-wiki answers of a minimum length are eligible