I'm afraid of own routine!

I'm afraid of own routine!

Post by al.velie » Fri, 03 Oct 2008 00:35:11


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?

Thanks.
 
 
 

I'm afraid of own routine!

Post by K.S. Bhask » Fri, 03 Oct 2008 03:22:43


[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://www.yqcomputer.com/
with instructions at http://www.yqcomputer.com/ ).
Tell us how it works.

Regards
-- Bhaskar

 
 
 

I'm afraid of own routine!

Post by al.velie » Fri, 03 Oct 2008 07:57:24


>> >> >> >> >> >>>> Hi there! Of course it is a joke. But >> >>>> elect aTruth from ThisJ>ke> >>
> > A year ago I read a Ivan Bratko's book about Prolog. His exa>p>e
> > for finding largest common divider was so excellent, so I wante> >o
> > write somethithing l>k>.
> > Here it>is> >>
> > samp>e>;
> > creates row of simple numbers(1,2,3,5,7,1>.>.)
> > and rows of dividers of first simple number(2,4>6>..)
> > from 1>t> Lim
> > et Lim=>0>0000
> > or i=1:1:Lim s ^a(i)=i ;create a row from >u>bers
> > or i=2:1:Lim j a^sample>i>Lim)
> > >quit
> > a(i,Lim) for j=i:i:Lim s ^b(i,j)=j > >a(j) >> > >q
>
> > As You see, the arithmetical task without any calculations.But > >on't
> > think that it could work an any co>p>ter.
> > It does not contain any errors, but work like "fork bomb". >n>that
> > reason I am afraid>o> it.
> > Have somebody any sugge>ti>ns?
>
> [KSB] Why don't you try it and see? hat are you afraid of> ake
> sure you have enough disk. n the worst case you will have >o take
> control of your computer by powering it down. f you af>aid of
> powering down your computer try it in a virtual machine (you >an get
> one with GT.M pre-instlaled at http://www.yqcomputer.com/ ;02.zip
> with instructions at http://www.yqcomputer.com/ ;h...).
> Tell us how it>wo>ks.
>
> >egards
> -- 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
et Lim=1000000
or i=1:1:Lim set ^a(i)=i ;create a row from numbers
i=1 for set i=$o(^a(i)) q:i="" job a^sample(i,Lim) ;that's it!
uit
a(i,Lim) for j=i:i:Lim kill ^a(j) set ^b(i,j)=j
uit

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.
 
 
 

I'm afraid of own routine!

Post by al.velie » Fri, 03 Oct 2008 08:13:32


>> >> >> >> >> >>>> Hi there! Of course it is a joke. But >> >>>> elect aTruth from ThisJ>ke> >>
> > A year ago I read a Ivan Bratko's book about Prolog. His exa>p>e
> > for finding largest common divider was so excellent, so I wante> >o
> > write somethithing l>k>.
> > Here it>is> >>
> > samp>e>;
> > creates row of simple numbers(1,2,3,5,7,1>.>.)
> > and rows of dividers of first simple number(2,4>6>..)
> > from 1>t> Lim
> > et Lim=>0>0000
> > or i=1:1:Lim s ^a(i)=i ;create a row from >u>bers
> > or i=2:1:Lim j a^sample>i>Lim)
> > >quit
> > a(i,Lim) for j=i:i:Lim s ^b(i,j)=j > >a(j) >> > >q
>
> > As You see, the arithmetical task without any calculations.But > >on't
> > think that it could work an any co>p>ter.
> > It does not contain any errors, but work like "fork bomb". >n>that
> > reason I am afraid>o> it.
> > Have somebody any sugge>ti>ns?
>
> [KSB] Why don't you try it and see? hat are you afraid of> ake
> sure you have enough disk. n the worst case you will have >o take
> control of your computer by powering it down. f you af>aid of
> powering down your computer try it in a virtual machine (you >an get
> one with GT.M pre-instlaled at http://www.yqcomputer.com/ ;02.zip
> with instructions at http://www.yqcomputer.com/ ;h...).
> Tell us how it>wo>ks.
>
> >egards
> -- Bhaskar

Thanks? You are right. Now is time to start.
And excuse me for mistake in the source. 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
et Lim=1000000
or i=1:1:Lim s ^a(i)=i ;create a row from numbers
et i=1 for set i=$o(^>(i)) quit:i>Lim job a^sample(i,Lim)
uit
a(i,Lim) for j=i:i:Lim kill ^a(j) set ^b(i,j)=j
uit

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

I'm afraid of own routine!

Post by al.velie » Thu, 09 Oct 2008 03:34:45

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.
 
 
 

I'm afraid of own routine!

Post by al.velie » Thu, 09 Oct 2008 03:35:47

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!