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

New SIG on logic/CLP programming in Python

0 views
Skip to first unread message

Nicolas Chauvat

unread,
Mar 22, 2002, 12:44:20 PM3/22/02
to
Hello Pythonistas,

I'd like to entertain you with a new subject: logic programming and
constraint-propagation features in Python.

I teach Python and advocate it often. One argument I use is that you
have several "programming paradigms" available in Python. You need
simple things and scripts? Use procedural programming, with variables
and functions. You need more structure? Use object-oriented programming.
You miss Lisp and need to process lists? use (some) functionnal
programming. You need concurrency? Look at Python 2.2's future and
stackless. It's all there. Mix'n match as you wish, you're not tied to
a specific approach, just use what fits best your model and data. No
need to mix languages.

Now, what if you need logical programming? Use pyprolog. And copy
your data back-and-forth from prolog-space to python space. Or look
at Mozart/Oz. Yeah, it's all there too: procedure, functions, objects,
concurrency, logic, constraint-propagation, even distribution and
security.

Right, but the syntax is... difficult. I'm sorry to have to tell
Mozart folks lurking here, that I'm a big fan of "indent-what-you-mean"
and will have trouble telling our new programmers that this complicated
syntax is good for them. And that brackets have different meanings
depending on where they are.

And Python already has a user-base that's increasing at rocket-speed.
When teaching Python I often tell people "if you need to code something
in Python, go to google first, you'll probably find it there and move
to more important matters".

As you already understood, I am thinking about implenting some
logical/constraint-propagation features on Python. My (rough)
understanding is that is would be doable on top of
microthreads/stackless/generators.

I am looking for interested people to form a Logic-SIG or CLP-SIG.
You think this is a great idea? You think this is stupid? Please
speak up! If you have no idea what I am talking about, don't worry,
I'll try to post an example here this week-end.

Waiting for your comments.

--
Nicolas Chauvat

http://www.logilab.com - "Mais oů est donc Ornicar ?" - LOGILAB, Paris (France)

Gerhard Häring

unread,
Mar 22, 2002, 12:53:30 PM3/22/02
to
Nicolas Chauvat wrote in comp.lang.python:
> [About Mozart] the syntax is... difficult.

That's putting it nicely.

Not that I've done very much besides 'Hello, world' in the Mozart
tutorial, though.

Gerhard
--
mail: gerhard <at> bigfoot <dot> de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))

Laura Creighton

unread,
Mar 22, 2002, 1:46:03 PM3/22/02
to
I am most interested in this. (But then you knew you would say that,
didn't you.) I want to see if we can get Michel Sanner involved
as well.

Laura Creighton


Joel Bender

unread,
Mar 22, 2002, 3:32:34 PM3/22/02
to
> I am looking for interested people to form a Logic-SIG or CLP-SIG.

Count me in.

> I'll try to post an example here this week-end.

Looking forward to it, I'll have a counter example on Monday. :-)


Joel

Benji York

unread,
Mar 22, 2002, 5:33:42 PM3/22/02
to
ni...@aries.logilab.fr (Nicolas Chauvat) wrote in message news:<slrna9mrb...@aries.logilab.fr>...

> I'd like to entertain you with a new subject: logic programming and
> constraint-propagation features in Python.

I would be very interested in a finite domain constraint slover
in/connected-to Python.

though-not-volunteering-to-implement-it-<wink>-ly y'rs

Benji York

Peter Norvig

unread,
Mar 23, 2002, 1:41:15 AM3/23/02
to
I have some simple, inefficient CSP code in Python at
http://www.norvig.com/python/csp.html

Includes fintie domain backtracking search (with optional forward
checking, domain ordering, and variable ordering); hill-climbing
min-conflicts search; examples from map coloring, n-queens, and the
zebra puzzle.

-Peter


benji...@cal-na.com (Benji York) wrote in message news:<59667b81.02032...@posting.google.com>...

Robin Becker

unread,
Mar 23, 2002, 5:34:17 AM3/23/02
to
In article <da69ff6a.02032...@posting.google.com>, Peter
Norvig <pe...@norvig.com> writes

>I have some simple, inefficient CSP code in Python at
>http://www.norvig.com/python/csp.html
>
>Includes fintie domain backtracking search (with optional forward
>checking, domain ordering, and variable ordering); hill-climbing
>min-conflicts search; examples from map coloring, n-queens, and the
>zebra puzzle.
>
>-Peter
>
>
.....
so I guess I need to know what search and utils are or can CSP discover
that?
-dazed and confused-ly yrs-
Robin Becker

Magnus Lie Hetland

unread,
Mar 23, 2002, 7:43:51 AM3/23/02
to
In article <slrna9mrb...@aries.logilab.fr>, Nicolas Chauvat wrote:
>Hello Pythonistas,
>
>I'd like to entertain you with a new subject: logic programming and
>constraint-propagation features in Python.
[...]

>I am looking for interested people to form a Logic-SIG or CLP-SIG.
>You think this is a great idea? You think this is stupid? Please
>speak up! If you have no idea what I am talking about, don't worry,
>I'll try to post an example here this week-end.
>
>Waiting for your comments.

Go for it!

Logic programming (or even something similar, with implicit
backtracking etc.) would be very nice to have, IMO. The backtracking
stuff itself ought to be easy to implement (efficiently, even) with
generators.

(So, yes, I'm interested :)

--
Magnus Lie Hetland The Anygui Project
http://hetland.org http://anygui.org

Boris^2

unread,
Mar 23, 2002, 7:51:13 AM3/23/02
to
Nicolas Chauvat wrote:
>
> Now, what if you need logical programming? Use pyprolog. And copy
> your data back-and-forth from prolog-space to python space. Or look
> at Mozart/Oz. Yeah, it's all there too: procedure, functions, objects,
> concurrency, logic, constraint-propagation, even distribution and
> security.
>
> Right, but the syntax is... difficult.

Rather. And makes one wonder if the way to go would not be to compile
python source syntax to the Oz or Erlang VM... while adding to it
something in the way Screamer adds to Common Lisp. (Erlang has a nice
syntax, BTW).

Another thing I am missing in python is Prolog-type metaprogramming
and/or lisp-type macro; first step would be S-expressions; the closest
python provides are the syntax trees from the parser module, but...
well, they really don't provide a similar facility. Now what about
defining a two-way translation to a syntax Lisp or Scheme systems could
read as S-expressions that could then be intelligently manipulated
by lisp-technology macros ?

> I am looking for interested people to form a Logic-SIG or CLP-SIG.

Count me in, especially for useless commenting :)

Regards,

Boris Borcic
--
Python >>> filter(lambda W : W not in "ILLITERATE","BULLSHIT")

Robin Becker

unread,
Mar 23, 2002, 8:28:20 AM3/23/02
to
In article <da69ff6a.02032...@posting.google.com>, Peter
Norvig <pe...@norvig.com> writes
>I have some simple, inefficient CSP code in Python at
>http://www.norvig.com/python/csp.html
>
>Includes fintie domain backtracking search (with optional forward
>checking, domain ordering, and variable ordering); hill-climbing
>min-conflicts search; examples from map coloring, n-queens, and the
>zebra puzzle.
>
>-Peter
>
OK I searched and found the search.py and utils.py files at

http://www.norvig.com/python

does the use of generators imply that I need Python 2.2?
--
Robin Becker

Terry Reedy

unread,
Mar 23, 2002, 10:26:03 AM3/23/02
to

"Magnus Lie Hetland" <m...@vier.idi.ntnu.no> wrote in message
news:slrna9ou4...@vier.idi.ntnu.no...

> Logic programming (or even something similar, with implicit
> backtracking etc.) would be very nice to have, IMO. The backtracking
> stuff itself ought to be easy to implement (efficiently, even) with
> generators.

There are some very interesting examples of using generators to do
backtracking in, I believe, test_generators.py in the distribution.
As I remember, both n-queens and knights tour examples are present.

Terry J. Reedy

Joel Bender

unread,
Mar 25, 2002, 3:23:43 PM3/25/02
to
I so boldly said "counter example" on Friday, and while that may have
been misinterpreted as a counter example to forming a Logic-SIG, what I
ment was that I had something to kick off a discussion.

I propose to add a few keywords, hopefully I'll be using terms
consistent with Prolog, but it's been a while, and other comments are
welcome.

First, add 'goal' to define goals, like functions:

goal sibling(X,Y):
parent(Z,X)
parent(Z,Y)

A goal looks like a function call in the code.

adam, betsy, clide, dave, edith = range(5)

assert(parent(adam, clide)) # needs help...
assert(parent(adam, dave))

def test1():
print "Ah!"
sibling(clide, dave)
print "Yes!"

>>> test1()
Ah!
Yes!

Then add 'cut' and 'fail' as statements:

def test2():
sibling(clide,X)
print X
cut
print "-cut-"
fail

>>> test2()
3
-cut-

Without the cut statement the output would look like this, because clide
is considered a sibling of himself:

def test3():
sibling(clide,X)
print X
fail

>>> test3()
3
2

Unlike Python functions, the same goal could be defined more than one
way:

goal sibling(X,Y):
mom(Z,X)
mom(Z,Y)

goal sibling(X,Y):
dad(Z,X)
dad(Z,Y)

With my limited Python experience I get the impression that the variable
'_' is frowned upon, so I would replace it with the keyword 'Any'.

goal isachild(X):
parent(Any,X)

Goals can return values, so they can be used like functions:

goal sibling2(X,Y):
parent(Z,X)
parent(Z,Y)
return Z

def test4():
p = sibling2(clide,dave)
print p

>>> test4()
0

Almost every Prolog book has an example of list membership, but while
the slicing operation can be done simply in Prolog:

member(X,[X|_]).
member(X,[_|Y]) :- member(X,Y).

The same kind of thing doesn't seem to fit Python:

goal member(X,[X|_]): pass

So it would have to be done with a some statements:

goal member(X,L):
if (len(x) == 0):
fail
if (X != L[0]):
fail

goal member(X,L):
member(X,L[1:])

Comments?


Joel

Joel Bender

unread,
Mar 25, 2002, 3:27:25 PM3/25/02
to
> goal member(X,L):
> if (len(x) == 0):
> fail
> if (X != L[0]):
> fail

Oops.

goal member(X,L):
if (len(L) == 0):

0 new messages