MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Delete elements from list..

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117040] Re: Delete elements from list..
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Tue, 8 Mar 2011 05:36:39 -0500 (EST)

That's out of context, so I don't know what "mylist" and "list" are.

Supposing they're supposed to be the same, and assuming the problem hasn't  
changed when I wasn't looking...

FoldList gives a sorted result in this case, so Union is only removing  
duplicates.

Below is an example where LongestCommonSequence retains more  
non-decreasing data points, and you can see what Union does after FoldList:

n = 100;
list = Range@n + RandomReal[3, n]

{1.02733, 3.17254, 5.17674, 5.2861, 5.04068, 8.9508, 7.2135, 10.0236, \
11.175, 12.2148, 12.4254, 14.9471, 13.6866, 16.3746, 16.4642, 18.372, \
18.0959, 20.0512, 21.6585, 20.608, 23.1185, 23.811, 24.0284, 26.67, \
25.5743, 27.9566, 29.7231, 30.0656, 30.3435, 32.3596, 32.9342, \
34.0286, 34.277, 36.6335, 37.9767, 38.1788, 38.1195, 39.3129, \
41.3666, 41.0886, 41.2983, 44.7717, 44.8021, 45.6002, 47.761, \
48.0595, 48.1493, 49.8181, 51.693, 51.6437, 53.7093, 54.2232, \
54.4077, 54.3111, 56.8476, 58.4407, 57.6213, 60.7089, 60.7277, \
61.8168, 62.4806, 63.7318, 63.0886, 66.5942, 66.8879, 66.6313, \
69.7475, 69.7805, 71.3846, 71.0386, 73.3049, 74.788, 73.5233, \
75.4171, 76.8464, 78.3174, 78.1189, 79.3608, 80.0954, 80.9175, \
82.1813, 83.8998, 84.1629, 84.6603, 86.9477, 86.1115, 87.1072, \
88.5944, 90.4489, 92.5951, 93.5649, 92.4799, 94.4784, 95.8025, \
97.427, 98.7723, 97.8943, 98.6345, 101.071, 102.092}

f = FoldList[Max, First@list, Rest@list]
Length@f
OrderedQ@f

{1.02733, 3.17254, 5.17674, 5.2861, 5.2861, 8.9508, 8.9508, 10.0236, \
11.175, 12.2148, 12.4254, 14.9471, 14.9471, 16.3746, 16.4642, 18.372, \
18.372, 20.0512, 21.6585, 21.6585, 23.1185, 23.811, 24.0284, 26.67, \
26.67, 27.9566, 29.7231, 30.0656, 30.3435, 32.3596, 32.9342, 34.0286, \
34.277, 36.6335, 37.9767, 38.1788, 38.1788, 39.3129, 41.3666, \
41.3666, 41.3666, 44.7717, 44.8021, 45.6002, 47.761, 48.0595, \
48.1493, 49.8181, 51.693, 51.693, 53.7093, 54.2232, 54.4077, 54.4077, \
56.8476, 58.4407, 58.4407, 60.7089, 60.7277, 61.8168, 62.4806, \
63.7318, 63.7318, 66.5942, 66.8879, 66.8879, 69.7475, 69.7805, \
71.3846, 71.3846, 73.3049, 74.788, 74.788, 75.4171, 76.8464, 78.3174, \
78.3174, 79.3608, 80.0954, 80.9175, 82.1813, 83.8998, 84.1629, \
84.6603, 86.9477, 86.9477, 87.1072, 88.5944, 90.4489, 92.5951, \
93.5649, 93.5649, 94.4784, 95.8025, 97.427, 98.7723, 98.7723, \
98.7723, 101.071, 102.092}

100

True

Union@f
Length@%

{1.02733, 3.17254, 5.17674, 5.2861, 8.9508, 10.0236, 11.175, 12.2148, \
12.4254, 14.9471, 16.3746, 16.4642, 18.372, 20.0512, 21.6585, \
23.1185, 23.811, 24.0284, 26.67, 27.9566, 29.7231, 30.0656, 30.3435, \
32.3596, 32.9342, 34.0286, 34.277, 36.6335, 37.9767, 38.1788, \
39.3129, 41.3666, 44.7717, 44.8021, 45.6002, 47.761, 48.0595, \
48.1493, 49.8181, 51.693, 53.7093, 54.2232, 54.4077, 56.8476, \
58.4407, 60.7089, 60.7277, 61.8168, 62.4806, 63.7318, 66.5942, \
66.8879, 69.7475, 69.7805, 71.3846, 73.3049, 74.788, 75.4171, \
76.8464, 78.3174, 79.3608, 80.0954, 80.9175, 82.1813, 83.8998, \
84.1629, 84.6603, 86.9477, 87.1072, 88.5944, 90.4489, 92.5951, \
93.5649, 94.4784, 95.8025, 97.427, 98.7723, 101.071, 102.092}

79

LongestCommonSequence[list, Sort@list]
Length@%

{1.02733, 3.17254, 5.17674, 5.2861, 8.9508, 10.0236, 11.175, 12.2148, \
12.4254, 14.9471, 16.3746, 16.4642, 18.372, 20.0512, 21.6585, \
23.1185, 23.811, 24.0284, 26.67, 27.9566, 29.7231, 30.0656, 30.3435, \
32.3596, 32.9342, 34.0286, 34.277, 36.6335, 37.9767, 38.1788, \
39.3129, 41.0886, 41.2983, 44.7717, 44.8021, 45.6002, 47.761, \
48.0595, 48.1493, 49.8181, 51.693, 53.7093, 54.2232, 54.4077, \
56.8476, 58.4407, 60.7089, 60.7277, 61.8168, 62.4806, 63.7318, \
66.5942, 66.8879, 69.7475, 69.7805, 71.3846, 73.3049, 74.788, \
75.4171, 76.8464, 78.3174, 79.3608, 80.0954, 80.9175, 82.1813, \
83.8998, 84.1629, 84.6603, 86.9477, 87.1072, 88.5944, 90.4489, \
92.5951, 93.5649, 94.4784, 95.8025, 97.427, 97.8943, 98.6345, \
101.071, 102.092}

81

There won't always be a difference, but the last method will never retain  
fewer data points than the first.

Bobby

On Mon, 07 Mar 2011 04:49:35 -0600, BoLe <bole79 at gmail.com> wrote:

> On Feb 22, 10:44 am, Ray Koopman <koop... at sfu.ca> wrote:
>>
>> Union@FoldList[Max,First@mylist,Rest@list]
>>
>
> Wov, that is elegant to me, and fast. DeleteDuplicates speeds it a
> tiny bit up. ;-) Since Union sorts the result (already sorted in this
> case) or does it do something else too?
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Problem exporting to LaTex
  • Next by Date: Re: Select from Tuplet using logical expression
  • Previous by thread: Re: Delete elements from list..
  • Next by thread: Show Rotate doesn't work