The Table[ ]
command usually returns a list with the same cardinality of its iterator.
Table[i, {i,4}]
(*
->{1,2,3,4}
*)
It is easy to show that is possible to return a list with a greater cardinality than the iterator
Table[Sequence @@ ConstantArray[1, i], {i, 2}]
(*
->{1,1,1}
*)
But ... Are there ways to return a list with LESS cardinality than the iterator?
Assuming that I now understand your intent, I do not see the advantage to "on the fly" elimination within
Table
itself. One could accomplish it with something like:but it is faster to use
Join
:or
DeleteCases
:and in this simple case,
Select
is more than twice as fast:If it is a matter of memory usage, the first method using
Sequence
does come out ahead, but theJoin
method is not far behind.This should work:
A simple example:
This need not always return a list with smaller cardinality. For e.g.,
{i,3}
returns equal and{i,4}
returns more.Or an even sillier example would be
but I don't know if it counts.
You could also use
Piecewise
insideTable