Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: I'm afraid of own routine!

7 views
Skip to first unread message
Message has been deleted

K.S. Bhaskar

unread,
Oct 1, 2008, 2:22:43 PM10/1/08
to
On Oct 1, 11:35 am, al.vel...@gmail.com wrote:
> Hi there! Of course it is a joke. But
>
> Select aTruth from ThisJoke.
>
> A year ago I read a Ivan Bratko's book about Prolog. His example
> for finding largest common divider was so excellent, so I wanted to
> write somethithing like.
> Here it is:
>
> sample ;
> ;creates row of simple numbers(1,2,3,5,7,11...)
> ;and rows of dividers of first simple number(2,4,6...)
> ;from 1 to Lim
> set Lim=1000000
> for i=1:1:Lim s ^a(i)=i ;create a row from numbers
> for i=2:1:Lim j a^sample(i,Lim)
> quit
> a(i,Lim) for j=i:i:Lim s ^b(i,j)=j k ^a(j)
> q
>
> As You see, the arithmetical task without any calculations.But I don't
> think that it could work an any computer.
> It does not contain any errors, but work like "fork bomb". In that
> reason I am afraid of it.
> Have somebody any suggestions?

[KSB] Why don't you try it and see? What are you afraid of? Make
sure you have enough disk. In the worst case you will have to take
control of your computer by powering it down. If you afraid of
powering down your computer try it in a virtual machine (you can get
one with GT.M pre-instlaled at http://downloads.sourceforge.net/fis-gtm/Ubuntu804JeosGTMV53002.zip
with instructions at http://downloads.sourceforge.net/fis-gtm/080903-1GTMV53002VirtualMachineInstructions.html).
Tell us how it works.

Regards
-- Bhaskar

al.v...@gmail.com

unread,
Oct 1, 2008, 6:57:24 PM10/1/08
to
> with instructions athttp://downloads.sourceforge.net/fis-gtm/080903-1GTMV53002VirtualMach...).

> Tell us how it works.
>
> Regards
> -- Bhaskar

Thanks, Bhaskar!
You are right. Now is a time to start. And excuse me for my mistake in
the former code.
The right code is follows:

sample ;
 ;creates row of simple numbers(1,2,3,5,7,11...)
 ;and rows of dividers of first simple number(2,4,6...)
 ;from 1 to Lim
 set Lim=1000000

 for i=1:1:Lim set ^a(i)=i ;create a row from numbers
 s i=1 for set i=$o(^a(i)) q:i="" job a^sample(i,Lim) ;that's it!
 quit
a(i,Lim) for j=i:i:Lim kill ^a(j) set ^b(i,j)=j
 quit

With do a^sample it is trivial. But with job...
My reasons to afraid:
1)All former mumpses had fixed quality of jobs
2)I was not sure in $order for that case
3)So simple, powerful and elegant things I wrote twice in my practice.

Also I happy to tell you that the problems with my site seems have
coming to the finish.
The new provider now is registering me url for it.
I am waiting for result and after testing will post a new messages.

Alexander.

Message has been deleted

al.v...@gmail.com

unread,
Oct 7, 2008, 2:34:45 PM10/7/08
to
Instead copy of answer to K.S.Bhaskar I deleted primary post.
The result of typing error was the new routine.
Russians say in such cases:"There is not bad without good".
So I renew this post with the TESTED routines.


example1 ;good for initialising the database for future use
;after such operation database answers faster
;select Your Lim value for that
k ^a,^b,^pid
s Lim=1000000,^pid=0,h1=$h
f i=1:1:Lim s ^a(i)=i
f j=1:1:Lim d
.j a(j,Lim)::0 i d c
.e d a(j,Lim) w "L ",j,!
s h2=$h zwr q
a(v1,v2) s ^pid($j)=""
f n=v1:v1:v2 k ^a(n) s ^b(v1,n)=n
k ^pid($j) q
c k p m p=^pid
s c="" f s=0:1 s c=$o(p(c)) q:c=""
s c=p s:c<s ^pid=s w "P ",j," ",s," ",c,!
q

example2 ;
;useful rows of numbers a,b,c
;a is row of simple numbers (1,2,3,5,7,11 ... )
;b is rows with multipliers of natural numbers (2,4,6,8,10 ...)
;c is row of natural numbers (1,2,3,4,5,6 ... )
;ariphmetical task without calculations!
;
k ^a,^b,^c,^pid s Lim=1000000,^p=0,h1=$h
f i=1:1:Lim s ^a(i)=i
s i=1
f s i=$o(^a(i)) q:i="" d
.j a(i,Lim)::0 i d c
.e d a(i,Lim) w "L ",i,!
s h2=$h zwr q
a(v1,v2) s ^pid($j)="",(^b(v1,v1),^c(v1))=v1,c=v1+v1
i c<v2 f n=c:v1:v2 k ^a(n) s (^b(v1,n),^c(n))=n
k ^pid($j) q
c k p m p=^pid s c=""
f s=0:1 s c=$o(p(c)) q:c=""
s c=$g(p) s:c<s ^pid=s w "P ",i," ",s," ",c,!
q

The story about testing and some statistics follows in the next post.

al.v...@gmail.com

unread,
Oct 7, 2008, 2:35:47 PM10/7/08
to
Yesterday I bought a new notebook.
To renew it (in this case renewing is the slavian celebration of
making/byeing/receiving/etc. something new)
I decided instead of darting at the notebook by bottle of champaign to
start working with the good task.
For that case I had two examples from the previous post. So, the test
was successful!

Some statistics:
1) in both examples subroutine a^example* did not called no once as
subroutine
- all the job calls were successful!
2) size of database increased from 477 KBytes to 527195 Kbytes.
3) example1 ran 116 min, max jobs=357, processor load->100%, memory
load->100%.
4) example2 ran 33 min 18 sec, max jobs=293, processor load->100%,
memory load->80%.

As for HP Compaq nc8000 (1700Mhz/512Mb RAM/40GB HDD) is not bad.
I think, it would run too much faster on the multiprocessor compruter,
for these tasks processor is the most critical thing.

Welcome to parallel spaces with GT.M !)

Thanks, Bhaskar, for GT.M and Your advices!

0 new messages