Expression Evaluate - PROLOG

This is a discussion on Expression Evaluate - PROLOG ; i want to write program in Prolog to evaluate this expression so any body can Guide me how to proced For example: ( 3 mul ( 4 add 1 ) ) is a valid expression, whose value is 15....

1. Expression Evaluate

i want to write program in Prolog to evaluate this expression so any
body can Guide me how to proced

For example:

( 3 mul ( 4 add 1 ) )

is a valid expression, whose value is 15.

2. Re: Expression Evaluate

Hi,
this is the kind of reply I want to give in order to say myself "dont worry
if nobody answer you when you ask, for example, for neural networks
implementation in prolog (ref. this newsgroup 23/10/2006 16:14)"...
So, perhaps mine are stupid questions... neural networks in prolog??? one
should say... what the f**k are you asking for?

However, dear v2hack (if this is your real name), consider that your
expression is:
a) out of the context, for prolog is not a functional language, say, as ML.
If you expect that prolog answer 15, think to read some prolog manual;
b) exactly equivalent to ( 3 * ( 4 + 1 ) ) except for the real names of the
operators.
So, the following will work:

:- op(400, yfx, mul).

:- arithmetic_function(mul/2).

Result is A+B.

mul(A, B, Result) :-
Result is A*B.

?- X is ( 3 mul ( 4 add 1 ) ).
X = 15
yes

Regards,
Mauro

<v2hack@gmail.com> ha scritto nel messaggio
>i want to write program in Prolog to evaluate this expression so any
> body can Guide me how to proced
>
> For example:
>
> ( 3 mul ( 4 add 1 ) )
>
> is a valid expression, whose value is 15.
>

3. Re: Expression Evaluate

Thanks for helping me, I am new to prolog, i am getting error message

| ?- X is ( 3 mul ( 4 add 1 ) ).

! Syntax error
! ) or operator expected
! in line 9
! X is ( 3
! <<here>>
! mul ( 4 add 1 ) ) .

Help will be really appreciated.

Pratik

Mauro Di Nuzzo wrote:
> Hi,
> this is the kind of reply I want to give in order to say myself "dont worry
> if nobody answer you when you ask, for example, for neural networks
> implementation in prolog (ref. this newsgroup 23/10/2006 16:14)"...
> So, perhaps mine are stupid questions... neural networks in prolog??? one
> should say... what the f**k are you asking for?
>
> However, dear v2hack (if this is your real name), consider that your
> expression is:
> a) out of the context, for prolog is not a functional language, say, as ML.
> If you expect that prolog answer 15, think to read some prolog manual;
> b) exactly equivalent to ( 3 * ( 4 + 1 ) ) except for the real names of the
> operators.
> So, the following will work:
>
> :- op(400, yfx, mul).
>
> :- arithmetic_function(mul/2).
>
> Result is A+B.
>
> mul(A, B, Result) :-
> Result is A*B.
>
>
>
> ?- X is ( 3 mul ( 4 add 1 ) ).
> X = 15
> yes
>
> Regards,
> Mauro
>
>
> <v2hack@gmail.com> ha scritto nel messaggio