Valid Matrix 
Author Message
 Valid Matrix

Hi everyone,

I need to implement a predicate "validmatrix(M)" that is satisfied provided
that M is a list containing one or more sublists. But I have no idea
whatsoever how to start (I'm new to Prolog).

Please advise.

Thanks.



Mon, 13 Jun 2005 05:32:09 GMT  
 Valid Matrix
To be a successful cheater, you need to learn to write a sensible
specification. This is what you SAY you want:

 validmatrix(M) :- member(Xs,M), is_list(Xs).

I'm pretty sure this is not what your teachers want, though.

-- Torbj?rn


Quote:
> Hi everyone,

> I need to implement a predicate "validmatrix(M)" that is satisfied provided
> that M is a list containing one or more sublists. But I have no idea
> whatsoever how to start (I'm new to Prolog).

> Please advise.

> Thanks.



Mon, 13 Jun 2005 21:15:39 GMT  
 Valid Matrix
Please do not be mistaken...

I do not intend to cheat. I had the validmatrix coded, validated by the
length of each sublists.

If I query without having any sublist,
|?- validmatrix(a,b,c).
no

I will encounter an exception "cannot find validmatrix/3" in the debugging
option. Is there a way to capture that exception and display better
constructed error message rather than just simply 'no'?


Quote:
> To be a successful cheater, you need to learn to write a sensible
> specification. This is what you SAY you want:

>  validmatrix(M) :- member(Xs,M), is_list(Xs).

> I'm pretty sure this is not what your teachers want, though.

> -- Torbj?rn




Quote:
> > Hi everyone,

> > I need to implement a predicate "validmatrix(M)" that is satisfied
provided
> > that M is a list containing one or more sublists. But I have no idea
> > whatsoever how to start (I'm new to Prolog).

> > Please advise.

> > Thanks.



Mon, 13 Jun 2005 23:19:02 GMT  
 Valid Matrix
I have to correct myself...

It doesn't reply 'no', instead,

! Existence error in user:validmatrix/3
! procedure user:validmatrix/3 does not exist
! goal:  user:validmatrix(a,b,c)

Is there a way to capture a 'valid' matrix rather than just using each
sublist's length?

Thanks.



Quote:
> Please do not be mistaken...

> I do not intend to cheat. I had the validmatrix coded, validated by the
> length of each sublists.

> If I query without having any sublist,
> |?- validmatrix(a,b,c).
> no

> I will encounter an exception "cannot find validmatrix/3" in the debugging
> option. Is there a way to capture that exception and display better
> constructed error message rather than just simply 'no'?



> > To be a successful cheater, you need to learn to write a sensible
> > specification. This is what you SAY you want:

> >  validmatrix(M) :- member(Xs,M), is_list(Xs).

> > I'm pretty sure this is not what your teachers want, though.

> > -- Torbj?rn



> > > Hi everyone,

> > > I need to implement a predicate "validmatrix(M)" that is satisfied
> provided
> > > that M is a list containing one or more sublists. But I have no idea
> > > whatsoever how to start (I'm new to Prolog).

> > > Please advise.

> > > Thanks.



Mon, 13 Jun 2005 23:26:11 GMT  
 Valid Matrix

Quote:

> If I query without having any sublist,
> |?- validmatrix(a,b,c).
> no

> I will encounter an exception "cannot find validmatrix/3" in the debugging
> option. Is there a way to capture that exception and display better
> constructed error message rather than just simply 'no'?

   This is because when you asked Prolog the question

       validmatrix(a,b,c)?

Prolog went looking for clauses of the form

   validmatrix(X,Y,Z) :- ...

and didn't find any.

  The first thing you must understand about Prolog is that nouns are
used in predicate language in the same way they are used in everyday
language.

For example

     Fido is a dog.

translates as

     dog(fido).

but

     Fido, Biff, and Pluto are dogs.

translates not as

     dog(fido,biff,pluto).

but as

     dog(fido).
     dog(biff).
     dog(pluto).

because it /means/

      Fido is a dog and Biff is a dog and Pluto is a dog.

So, when you ask Prolog a question like

          validmatrix(a,b,c)?

it goes looking for clauses of the form

          validmatrix(X,Y,Z) :- ...

and if it doesn't find any, it issues the error message you got.

  I suggest you shut off your computer, sit down with a pencil and a
piece of paper, and write out the full definition of what you mean by
'valid matrix' in English (say):

   M is a valid matrix if and only if ....

  Draw pictures!

  Force yourself to rewrite this definition ten times, each time making
it a little better.

  All the while you are doing this, forget all about Prolog and forget
all about computers.

  You already know how to do what you need to know how to do to use the
Prolog Inference Engine; the tricky part is to do /that/ using only
sentences of the form required by the Prolog Inference Engine.

--
Bill
http://www.sonic.net/~sequitur



Tue, 14 Jun 2005 05:26:17 GMT  
 Valid Matrix
On Thu, 26 Dec 2002 15:19:02 -0000, "Ang, Wee Tiong"

Quote:

>Please do not be mistaken...

>I do not intend to cheat. I had the validmatrix coded, validated by the
>length of each sublists.

>If I query without having any sublist,
>|?- validmatrix(a,b,c).
>no

Where is your code?...

A.L.



Tue, 14 Jun 2005 23:46:17 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Matrix Multiplication: 2 n x n matrices

2. Complex Matrix => Inverese Matrix

3. Education Centre .msi not considered "valid"?

4. Erroneous but valid APL/J, (Transpositions)

5. HELP: is valid url? (VW 2.5.2)

6. Valid XML.Document, now what?

7. Off Topic but very valid from programmers and those that empy them

8. Valid E-mail address characters

9. WeakDictionary value 0 for valid key

10. Clipboard does not contain a valid File Structure

11. What is a valid Compiler "context"

12. Listing Valid Drives and Drive Types

 

 
Powered by phpBB® Forum Software