Ehrenfest's urn

12292021, 10:16 PM
Post: #1




Ehrenfest's urn
Ehrenfest's urn
Hi Everyone (from France ) I'm trying this algorythm on my prime without success , of course i've tried to debug . EXPORT EHRENFEST1() BEGIN LOCAL n,p,K; INPUT(p); L1:={1,2}; L2:={}; FOR K FROM 1 TO p DO n:=RANDINT(1,2); IF L1(1)==n OR L1(2)==n THEN L1:=SUPPRESS(L1,n); L2:=INSERT(L2,1,n); ELSE L2:=SUPPRESS(L2,n); L1:=INSERT(L1,1,n); END; END; PRINT(L1); PRINT(L2); END; Could you help me ? It seems that the problem occurs when i write " n:=RANDINT(1,2); " . Thank you . 

12292021, 11:11 PM
Post: #2




RE: Ehrenfest's urn
(12292021 10:16 PM)zahi48g Wrote: Ehrenfest's urn L2 only has one element. If n=2 you get an error when you try to SUPPRESS L2(n) since L2(2) doesn't exist. Tom L Cui bono? 

12292021, 11:53 PM
Post: #3




RE: Ehrenfest's urn
Hi
Thank you for replying. First , the algorithme is from a book, I've just translated it into the prime language . Second , it does not try to remove L2(2) from L2 but n from L2 . According to the Ehrenfest'urns model an urn can be empty (this is anticipated in the IF...THEN...ELSE), so L2(2) may not exist . I should have the following outcomes : {1,2} {} or {1} {2} or {} {1,2} or {2} {1} If you get these results , could copy and paste you code ? Thank you . 

12302021, 05:28 AM
Post: #4




RE: Ehrenfest's urn
(12292021 11:53 PM)zahi48g Wrote: it does not try to remove L2(2) from L2 but n from L2 . With SUPPRESS(L2,n) you are removing from L2 the element at the nth position, so if L2={2} then SUPRESS(L2,2) will fail because there is only one element in the list. The correct instruction to remove 2 from the list is SUPPRESS(L2,POS(L2,2))) which will remove 2 from the list whatever it’s position in the list. (12292021 11:53 PM)zahi48g Wrote: If you get these results , could copy and paste you code ? Here is a working code, I’ve added the number of elements in the urns as a parameter of the program so you can test with more than two: Code: #pragma mode( separator(.,;) integer(h32) ) 

12302021, 10:30 PM
Post: #5




RE: Ehrenfest's urn
Thanks for the interesting post, this problem is new to me.
Section 2.1 of this article suggests an alternate representation of the urns that may lead to a simpler program. Instead of two lists, one initially empty, one has a single list of (initially) all zeros. At each iteration, the state of a randomly selected element is flipped using NOT. The number of balls in urn "A" is the number of zeros in the list; the number of balls in urn "B" is similarly the number of ones. My PPL is a bit rusty but it should be fairly simple. 

01032022, 11:10 PM
(This post was last modified: 01032022 11:17 PM by zahi48g.)
Post: #6




RE: Ehrenfest's urn
Thank you D Lachieze and John Keith.
I've learned two things : How to remove properly an object from a list and that L1(0) refers to the last element of list L1 (am I right ?) . But i've got one question for D Lachieze . In order to know if n belongs to L1, shouldn't you write " IF POS(L1,n)>0 THEN ..." instead of " IF POS(L1,n) THEN ..." ? Thank you 

01042022, 02:09 AM
Post: #7




RE: Ehrenfest's urn
(01032022 11:10 PM)zahi48g Wrote: Thank you D Lachieze and John Keith. Since false is 0 and the true condition is anything other than 0, either test works. Tom L Cui bono? 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)