Skip to content

Does recursion find all the solutions? #4

@stefan-c-kremer

Description

@stefan-c-kremer

This project is great. I have been working on some examples and came across what I think may be an issue. I would like some feedback whether I'm wrong in my thinking...

I have the following Prolog code:

predecessor( one, zero ).
predecessor( two, one ).
plus( two, zero, two ).
plus( two, one, three ).
plus( two, two, four ).

times( X, zero, zero ).
times( X, Y, Z ) :- predecessor( Y, Y1 ), times( X, Y1, P ), plus( X, P, Z ).

I am issuing the query:

times( two, Y, Z )

I was expecting to get:

Y = [zero, one, two]
Z = [zero, two, four]

but only the first two answers appear.

Any ideas why?

Stefan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions