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....

+ Reply to Thread
Results 1 to 3 of 3

Expression Evaluate

  1. Default 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. Default 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(500, yfx, add).
    :- op(400, yfx, mul).

    :- arithmetic_function(add/2).
    :- arithmetic_function(mul/2).

    add(A, B, Result) :-
    Result is A+B.

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


    Now you can ask:

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

    Regards,
    Mauro


    <v2hack@gmail.com> ha scritto nel messaggio
    news:1163054729.890006.282270@m73g2000cwd.googlegroups.com...
    >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. Default 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(500, yfx, add).
    > :- op(400, yfx, mul).
    >
    > :- arithmetic_function(add/2).
    > :- arithmetic_function(mul/2).
    >
    > add(A, B, Result) :-
    > Result is A+B.
    >
    > mul(A, B, Result) :-
    > Result is A*B.
    >
    >
    > Now you can ask:
    >
    > ?- X is ( 3 mul ( 4 add 1 ) ).
    > X = 15
    > yes
    >
    > Regards,
    > Mauro
    >
    >
    > <v2hack@gmail.com> ha scritto nel messaggio
    > news:1163054729.890006.282270@m73g2000cwd.googlegroups.com...
    > >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.
    > >



+ Reply to Thread

Similar Threads

  1. Can I evaluate an expression with the Eclipse debugger?
    By Application Development in forum Java
    Replies: 1
    Last Post: 12-13-2007, 12:38 PM
  2. Need to evaluate simple arithmetic expression
    By Application Development in forum C
    Replies: 6
    Last Post: 11-20-2007, 05:12 PM
  3. Expression must evaluate to a node-set
    By Application Development in forum XML SOAP
    Replies: 2
    Last Post: 03-02-2007, 05:40 PM
  4. How to evaluate in C# a string of expression
    By Application Development in forum Javascript
    Replies: 12
    Last Post: 02-09-2005, 10:25 AM