Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

List quastion
Hi There,

I want to make a predicate that do the following:

poly([1,2,3],2,Z).

Z= [2,4,6].

so it multiply the 2 with the list.

and another predicate that do the following:

prod_poly([1,2,3],[3,2,1],Z).

Z= [3,9,4,8,3]

this one see the elements in the list as 1 number so in this example
it will multiply 123 * 321   and return the answer in list Z.  this
one is hard i hope someone can tell me how.

Thanks in advance
Kimos

Report this thread to moderator Post Follow-up to this message
Old Post
kimos
10-10-04 01:56 PM


Re: List quastion
Dear Kimos,

> prod_poly([1,2,3],[3,2,1],Z).
>
> Z= [3,9,4,8,3]
>
> this one see the elements in the list as 1 number so in this example
> it will multiply 123 * 321   and return the answer in list Z.  this
> one is hard i hope someone can tell me how.
>

Hint: How do you multiply polynomials?

Best wishes,

Bill

Report this thread to moderator Post Follow-up to this message
Old Post
Bill Spight
10-10-04 08:56 PM


Re: List quastion
"kimos" <urdad@hotmail.com> a écrit dans le message de news:
ae02c0a1.0410100403.3094ca9a@posting.google.com...
> Hi There,
>
> I want to make a predicate that do the following:
>
> poly([1,2,3],2,Z).
>
> Z= [2,4,6].
>
> so it multiply the 2 with the list.


poly([],[]).
poly([X|L],[X2|L2]):-
X2 is X*2,
poly(L,L2).



Report this thread to moderator Post Follow-up to this message
Old Post
ezze
10-10-04 08:56 PM


Re: List quastion
"ezze" <ezze@wanadoo.fr> wrote in message news:<4169565a$0$28826$8fcfb975@news.wanadoo.fr>.
.
> "kimos" <urdad@hotmail.com> a écrit dans le message de news:
> ae02c0a1.0410100403.3094ca9a@posting.google.com... 
>
>
> poly([],[]).
> poly([X|L],[X2|L2]):-
>     X2 is X*2,
>     poly(L,L2).

ezze thanks for replay but this isnt what i want. my poly is with 3 inputs
poly([],[],[]).


Bill Spight i dont get your hint. how do you multiply polynomials ?

hope someone can help  im realy stuck with thos 2 predicates

Report this thread to moderator Post Follow-up to this message
Old Post
kimos
10-11-04 08:59 PM


Re: List quastion
Dear kimos,

> Bill Spight i dont get your hint. how do you multiply polynomials ?

Example:

(5x^2 + 3x + 2) * (-4x^2 - 2x + 1) = y

prod_poly([5, 3, 2], [-4, -2, 1], Y).

Now the example you gave is not exactly that, but appears to assume that
x = 10, and carries partial products. However, given the name,
"prod_poly", I suspect that the meat of your assignment is to write a
program to multiply polynomials, represented as lists. That is something
that you learned to do in high school, I suspect.

Best wishes,

Bill

Report this thread to moderator Post Follow-up to this message
Old Post
Bill Spight
10-11-04 08:59 PM


Re: List quastion
 
>
> ezze thanks for replay but this isnt what i want. my poly is with 3 inputs
> poly([],[],[]).
>

sure,
poly([],_,[]).
poly([X|L],V,[X2|L2]):-
X2 is X*V,
poly(L,V,L2).

its the first predicate youre looking for (in your first message)



Report this thread to moderator Post Follow-up to this message
Old Post
ezze
10-12-04 08:58 PM


Re: List quastion
Bill Spight <bspight@pacXbell.net> wrote in message news:<416AE319.CF646229@pacXbell.net>..
.
> Dear kimos,
> 
>
> Example:
>
>     (5x^2 + 3x + 2) * (-4x^2 - 2x + 1) = y
>
>     prod_poly([5, 3, 2], [-4, -2, 1], Y).
>
> Now the example you gave is not exactly that, but appears to assume that
> x = 10, and carries partial products. However, given the name,
> "prod_poly", I suspect that the meat of your assignment is to write a
> program to multiply polynomials, represented as lists. That is something
> that you learned to do in high school, I suspect.
>
> Best wishes,
>
> Bill


Dear Bill

thanks for the replay.

i solved the first predicate afer hard work

poly([],N,[]).
poly([X|L],N,[X2|L2]):-
X2 is X*N,
poly(L,L2).

but im still stuck with the second one as u mention "multiply
polynomials, represented as lists"  they didnt learned prolog im doing
this for my graduation project.

Report this thread to moderator Post Follow-up to this message
Old Post
kimos
10-12-04 08:58 PM


Re: List quastion
Dear kimos,

> but im still stuck with the second one as u mention "multiply
> polynomials, represented as lists"

Did you take algebra, and learn how to multiply (x^2 - x + 3) and (2X^2
+ 3x - 10)? What steps did you take to do that multiplication?

If you did not take algebra, think back to when you learned arithmetic.
What steps did you take to multiply  234 and 637? They are equvalent to
(2x^2 + 3x + 4) times (6x^2 + 3x + 7), where x = 10.

Good luck!

Bill

Report this thread to moderator Post Follow-up to this message
Old Post
Bill Spight
10-12-04 08:58 PM


Re: List quastion
Bill Spight <bspight@pacXbell.net> wrote in message news:<416C3295.F1F417B7@pacXbell.net>..
.
> Dear kimos,
> 
>
> Did you take algebra, and learn how to multiply (x^2 - x + 3) and (2X^2
> + 3x - 10)? What steps did you take to do that multiplication?
>
> If you did not take algebra, think back to when you learned arithmetic.
> What steps did you take to multiply  234 and 637? They are equvalent to
> (2x^2 + 3x + 4) times (6x^2 + 3x + 7), where x = 10.

It could be a little bit easier to solve the problem by representing
(2x^2 + 3x + 4) with [4,3,2] ...

Report this thread to moderator Post Follow-up to this message
Old Post
Sangai
10-13-04 08:56 AM


Re: List quastion
sangai@freemail.hu (Sangai) wrote in message news:<f3c0ce7.0410122226.296b1e63@posting.goog
le.com>...
> Bill Spight <bspight@pacXbell.net> wrote in message news:<416C3295.F1F417B
7@pacXbell.net>... 
>
> It could be a little bit easier to solve the problem by representing
> (2x^2 + 3x + 4) with [4,3,2] ...


Thats true and thats what im trying to do  represent it as [4,3,2].
but i cant find any answer for it

Report this thread to moderator Post Follow-up to this message
Old Post
kimos
10-13-04 08:59 PM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:51 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.