unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Finding repetitions of 8-tuples
@ 2022-12-31 17:00 Hans Lonsdale
  2023-01-01 15:13 ` Arthur Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Hans Lonsdale @ 2022-12-31 17:00 UTC (permalink / raw)
  To: Help Gnu Emacs

I have 16 collections of 8 numbers

(11 12 11 44 11 12 11 23)
(12 21 11 44 11 12 11 23)
and so on

I want to find whether there are repetitions of each 8-tuple.
The order in which the numbers occur is not important.

-- 
Sent with https://mailfence.com  
Secure and private email



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finding repetitions of 8-tuples
  2022-12-31 17:00 Finding repetitions of 8-tuples Hans Lonsdale
@ 2023-01-01 15:13 ` Arthur Miller
  2023-01-01 16:00   ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-01-01 16:39   ` Yuri Khan
  2023-01-01 15:16 ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-01-08  4:39 ` Emanuel Berg
  2 siblings, 2 replies; 8+ messages in thread
From: Arthur Miller @ 2023-01-01 15:13 UTC (permalink / raw)
  To: Hans Lonsdale; +Cc: Help Gnu Emacs

Hans Lonsdale <hanslonsdale@mailfence.com> writes:

> I have 16 collections of 8 numbers
>
> (11 12 11 44 11 12 11 23)
> (12 21 11 44 11 12 11 23)
> and so on
>
> I want to find whether there are repetitions of each 8-tuple.
> The order in which the numbers occur is not important.

Have you looked at "lists as sets" chapter in the manual?

There is a 'cl-subsetp' you could start with:

  cl-subsetp is an autoloaded native-compiled Lisp function in ‘cl-seq.el’.

  (cl-subsetp LIST1 LIST2 [KEYWORD VALUE]...)

  Return true if LIST1 is a subset of LIST2.
  I.e., if every element of LIST1 also appears in LIST2.

  Keywords supported:  :test :test-not :key


(defvar l1 '(11 12 11 44 11 12 11 23))
(defvar l2 '(12 21 11 44 11 12 11 23))

(cl-subsetp l1 l2) ;; returns t

However there is a slight problem since it tests for the subset:

(defvar l3 '(12 21 11 44 11 12 11))

(cl-subsetp l3 l2) ;; returns t also

(and (cl-subsetp l3 l2)
     (= (length l3) (length l2))) ;; should do


Alternatively there functions to test membership, so you could easily roll your
own little defun with 'member' or something else.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finding repetitions of 8-tuples
  2022-12-31 17:00 Finding repetitions of 8-tuples Hans Lonsdale
  2023-01-01 15:13 ` Arthur Miller
@ 2023-01-01 15:16 ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-01-01 15:38   ` Hans Lonsdale
  2023-01-08  4:39 ` Emanuel Berg
  2 siblings, 1 reply; 8+ messages in thread
From: Ruijie Yu via Users list for the GNU Emacs text editor @ 2023-01-01 15:16 UTC (permalink / raw)
  To: Hans Lonsdale; +Cc: help-gnu-emacs


Hans Lonsdale <hanslonsdale@mailfence.com> writes:

> I have 16 collections of 8 numbers
>
> (11 12 11 44 11 12 11 23)
> (12 21 11 44 11 12 11 23)
> and so on
>
> I want to find whether there are repetitions of each 8-tuple.
> The order in which the numbers occur is not important.

I think your best bet is to sort each 8-tuple and compare the sorted
lists afterwards.  Can't think of anything better at the moment.

Best,


RY



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finding repetitions of 8-tuples
  2023-01-01 15:16 ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-01-01 15:38   ` Hans Lonsdale
  0 siblings, 0 replies; 8+ messages in thread
From: Hans Lonsdale @ 2023-01-01 15:38 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: help-gnu-emacs



> ----------------------------------------
> From: Ruijie Yu via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> Sent: Sun Jan 01 16:16:35 CET 2023
> To: Hans Lonsdale <hanslonsdale@mailfence.com>
> Cc: <help-gnu-emacs@gnu.org>
> Subject: Re: Finding repetitions of 8-tuples
> 
> 
> 
> Hans Lonsdale <hanslonsdale@mailfence.com> writes:
> 
> > I have 16 collections of 8 numbers
> >
> > (11 12 11 44 11 12 11 23)
> > (12 21 11 44 11 12 11 23)
> > and so on
> >
> > I want to find whether there are repetitions of each 8-tuple.
> > The order in which the numbers occur is not important.
> 
> I think your best bet is to sort each 8-tuple and compare the sorted
> lists afterwards.  Can't think of anything better at the moment.
> 
> Best,
> RY

Sorting is a very good idea for an suitable algorithm. 


-- 
Sent with https://mailfence.com  
Secure and private email



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finding repetitions of 8-tuples
  2023-01-01 15:13 ` Arthur Miller
@ 2023-01-01 16:00   ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-01-01 16:39   ` Yuri Khan
  1 sibling, 0 replies; 8+ messages in thread
From: Ruijie Yu via Users list for the GNU Emacs text editor @ 2023-01-01 16:00 UTC (permalink / raw)
  To: Arthur Miller; +Cc: Hans Lonsdale, help-gnu-emacs


Arthur Miller <arthur.miller@live.com> writes:

> Hans Lonsdale <hanslonsdale@mailfence.com> writes:
>
>> I have 16 collections of 8 numbers
>>
>> (11 12 11 44 11 12 11 23)
>> (12 21 11 44 11 12 11 23)
>> and so on
>>
>> I want to find whether there are repetitions of each 8-tuple.
>> The order in which the numbers occur is not important.
>
> Have you looked at "lists as sets" chapter in the manual?
>
> There is a 'cl-subsetp' you could start with:
>
>   cl-subsetp is an autoloaded native-compiled Lisp function in ‘cl-seq.el’.
>
>   (cl-subsetp LIST1 LIST2 [KEYWORD VALUE]...)
>
>   Return true if LIST1 is a subset of LIST2.
>   I.e., if every element of LIST1 also appears in LIST2.
>
>   Keywords supported:  :test :test-not :key
>
>
> (defvar l1 '(11 12 11 44 11 12 11 23))
> (defvar l2 '(12 21 11 44 11 12 11 23))
>
> (cl-subsetp l1 l2) ;; returns t

I looked around and found out that `seq-set-equal-p' might be more
suitable for this task: this function performs a set-equality check
between the two lists (or, more broadly, sequences) whereas `cl-subsetp'
checks for subsets, as you have noted later in your message.

> [...]

Best,


RY



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finding repetitions of 8-tuples
  2023-01-01 15:13 ` Arthur Miller
  2023-01-01 16:00   ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-01-01 16:39   ` Yuri Khan
  2023-01-01 17:08     ` Hans Lonsdale
  1 sibling, 1 reply; 8+ messages in thread
From: Yuri Khan @ 2023-01-01 16:39 UTC (permalink / raw)
  To: Arthur Miller; +Cc: Hans Lonsdale, Help Gnu Emacs

On Sun, 1 Jan 2023 at 22:19, Arthur Miller <arthur.miller@live.com> wrote:

> > I have 16 collections of 8 numbers
> >
> > (11 12 11 44 11 12 11 23)
> > (12 21 11 44 11 12 11 23)
> > and so on
> >
> > I want to find whether there are repetitions of each 8-tuple.
> > The order in which the numbers occur is not important.
>
> Have you looked at "lists as sets" chapter in the manual?

This line of thought leads nowhere because treating a list as a set
ignores its duplicate counts. I take it that in the OP’s problem
statement (1 1 1 1 1 2 2 2) is to be considered distinct from (1 1 1 1
2 2 2 2), but, treated as sets, they are both equivalent to (1 2). The
original problem calls for multisets — containers where the order is
not significant but the counts of duplicates are.

Sorting each list and comparing the result of sorting, as suggested in
another reply, is going to be a better approach.

Alternatively, one might hash each element and xor the hashes
together. However, this carries collision risk inherent in hash-based
solutions — if hashes are different, the multisets are different, but
if the hashes are equal, this does not guarantee the equality of
multisets.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finding repetitions of 8-tuples
  2023-01-01 16:39   ` Yuri Khan
@ 2023-01-01 17:08     ` Hans Lonsdale
  0 siblings, 0 replies; 8+ messages in thread
From: Hans Lonsdale @ 2023-01-01 17:08 UTC (permalink / raw)
  To: Arthur Miller, Yuri Khan; +Cc: Help Gnu Emacs



> ----------------------------------------
> From: Yuri Khan <yuri.v.khan@gmail.com>
> Sent: Sun Jan 01 17:39:36 CET 2023
> To: Arthur Miller <arthur.miller@live.com>
> Cc: Hans Lonsdale <hanslonsdale@mailfence.com>, Help Gnu Emacs <help-gnu-emacs@gnu.org>
> Subject: Re: Finding repetitions of 8-tuples
> 
> 
> On Sun, 1 Jan 2023 at 22:19, Arthur Miller <arthur.miller@live.com> wrote:
> 
> > > I have 16 collections of 8 numbers
> > >
> > > (11 12 11 44 11 12 11 23)
> > > (12 21 11 44 11 12 11 23)
> > > and so on
> > >
> > > I want to find whether there are repetitions of each 8-tuple.
> > > The order in which the numbers occur is not important.
> >
> > Have you looked at "lists as sets" chapter in the manual?
> 
> This line of thought leads nowhere because treating a list as a set
> ignores its duplicate counts. I take it that in the OP’s problem
> statement (1 1 1 1 1 2 2 2) is to be considered distinct from (1 1 1 1
> 2 2 2 2), but, treated as sets, they are both equivalent to (1 2). The
> original problem calls for multisets — containers where the order is
> not significant but the counts of duplicates are.

That's correct.
 
> Sorting each list and comparing the result of sorting, as suggested in
> another reply, is going to be a better approach.

Agreed
 
> Alternatively, one might hash each element and xor the hashes
> together. However, this carries collision risk inherent in hash-based
> solutions — if hashes are different, the multisets are different, but
> if the hashes are equal, this does not guarantee the equality of
> multisets.
> 


-- 
Sent with https://mailfence.com  
Secure and private email



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Finding repetitions of 8-tuples
  2022-12-31 17:00 Finding repetitions of 8-tuples Hans Lonsdale
  2023-01-01 15:13 ` Arthur Miller
  2023-01-01 15:16 ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-01-08  4:39 ` Emanuel Berg
  2 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg @ 2023-01-08  4:39 UTC (permalink / raw)
  To: help-gnu-emacs

Hans Lonsdale wrote:

> I have 16 collections of 8 numbers
>
> (11 12 11 44 11 12 11 23)
> (12 21 11 44 11 12 11 23)
> and so on
>
> I want to find whether there are repetitions of each
> 8-tuple. The order in which the numbers occur is
> not important.

(require 'cl-lib)

(let ((sl '( (11 12 11 44 11 12 11 23)
             (12 21 11 44 11 12 11 23)
             (12 21 11 44 11 12 11 23)
             ;; etc
             )))
  (cl-delete-duplicates
    (mapcar (lambda (s) (sort s #'<)) sl)
    :test #'equal) )

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-01-08  4:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-31 17:00 Finding repetitions of 8-tuples Hans Lonsdale
2023-01-01 15:13 ` Arthur Miller
2023-01-01 16:00   ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-01-01 16:39   ` Yuri Khan
2023-01-01 17:08     ` Hans Lonsdale
2023-01-01 15:16 ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-01-01 15:38   ` Hans Lonsdale
2023-01-08  4:39 ` Emanuel Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).