Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
count inferences and write them to stdout
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jaroslav Dobrek  
View profile  
 More options May 16 2012, 1:06 pm
Newsgroups: comp.lang.prolog
From: Jaroslav Dobrek <jaroslav.dob...@gmail.com>
Date: Wed, 16 May 2012 10:06:48 -0700 (PDT)
Local: Wed, May 16 2012 1:06 pm
Subject: count inferences and write them to stdout
Hello,

I tried to time programs, i.e. to count the number of logical
inferences in Prolog scripts. I didn't  manage to use a timing
predicate in Yap at all (use_module(library(swi)) only produced error
messages.). In Swi, there is the predicate time/1, but it doesn't seem
to be usable inside scripts.

I would like to do something like:

main :-
    time(my_program, T),
    write(T),
    nl.

Is this possible with Swi or some other Prolog?

I can't do this in the Prolog shell, because I want to test a very
large number of (automatically generated) programs.

Jaroslav


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paulo Moura  
View profile  
 More options May 18 2012, 7:29 am
Newsgroups: comp.lang.prolog
From: Paulo Moura <pjlmo...@gmail.com>
Date: Fri, 18 May 2012 04:29:50 -0700 (PDT)
Local: Fri, May 18 2012 7:29 am
Subject: Re: count inferences and write them to stdout
On May 16, 6:06 pm, Jaroslav Dobrek <jaroslav.dob...@gmail.com> wrote:

> Hello,

> I tried to time programs, i.e. to count the number of logical
> inferences in Prolog scripts. I didn't  manage to use a timing
> predicate in Yap at all (use_module(library(swi)) only produced error
> messages.).

You don't say which YAP version are you using... recent ones provide a
time/1 built-in predicate. Same for recent versions of XSB. But
neither YAP or XSB will give you the number of inferences as with time/
1 in SWI-Prolog.

> In Swi, there is the predicate time/1, but it doesn't seem
> to be usable inside scripts.

> I would like to do something like:

> main :-
>     time(my_program, T),
>     write(T),
>     nl.

> Is this possible with Swi or some other Prolog?

> I can't do this in the Prolog shell, because I want to test a very
> large number of (automatically generated) programs.

The time/1 predicate in SWI-Prolog seems to write to user_error. Maybe
there's a way to redirect it to e.g. a file for collecting the
results?

Counting the number of inferences can also be done using a meta-
interpreter, assuming you can afford the slowdown.

Cheers,

Paulo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jan Wielemaker  
View profile  
 More options May 23 2012, 3:23 pm
Newsgroups: comp.lang.prolog
From: Jan Wielemaker <j...@invalid.invalid>
Date: 23 May 2012 19:23:51 GMT
Local: Wed, May 23 2012 3:23 pm
Subject: Re: count inferences and write them to stdout
On 2012-05-18, Paulo Moura <pjlmo...@gmail.com> wrote:

It uses print_message/2, which can be hooked using message_hook/3.
Way easier is simply this (assuming G succeeds deterministically).

inferences(G, Count) :-
        statistics(inferences, Inferences0),
        G,
        statistics(inferences, Inferences1),
        Count is Inferences1 - Inferences0.

> Counting the number of inferences can also be done using a meta-
> interpreter, assuming you can afford the slowdown.

There is some point in that. The statistics counts passes through the
call and redo ports, but not everything really goes through these ports.
Some predicates are inlined in the VM. Others are mapped to C-functions,
etc.

        Cheers --- Jan

P.s.    Simply type ?- edit(time/1). to see the implementation.  That
        easily lets you figure out the above alternative yourself.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »