Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:12:40+00:00 2026-06-14T10:12:40+00:00

I’m trying to figure out how I would draw a syntax tree for the

  • 0

I’m trying to figure out how I would draw a syntax tree for the expression below. First, how exactly is this behaving? It looks like it takes 1 and 2 as parameters, and if n is 0, it will just return m.

<code>Add</code> definition

Also, could someone point a start off to parse tree, or an example? I haven’t been able to find one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:12:41+00:00Added an answer on June 14, 2026 at 10:12 am

    Once the function is defined, you do applications of the arguments on the function itself, returning, thus, new functions, resultants of the applied args.

    I’m not sure which language you used to wirte that code, but the application would result in something like:

    \f.\n.\m.if isZero n then m else f (pred n) (succ m)
    

    Since \f is the definition of the function, you can write the above as:

    add = (\n.\m.if (isZero n) then m else add (pred n) (succ m))
    

    And the applications:

    add = (\n.\m.if (isZero n) then m else add (pred n) (succ m))
    add 1 2
    (\n.\m.if (isZero n) then m else add (pred n) (succ m)) 1 2
    

    Replacing the outermost variable with the innermost argument (in this case, n by 1):

    ((**\n**.\m.if (isZero n) then m else f (pred **n**) (succ m)) **1**) 2
    (\m.if (isZero 1) then m else add (pred 1) (succ m)) 2
    

    Resolving it a bit:

    (\m.if (isZero 1) then m else add **(pred 1)** (succ m)) 2
    (\m.if (isZero 1) then m else add 0 (succ m)) 2
    

    Applying the second argument, and resolving:

    (**\m**.if (isZero 1) then **m** else add 0 (succ **m**)) **2**
    (if (isZero 1) then 2 else add 0 (succ 2))
    (if (isZero 1) then 2 else add 0 **(succ 2)**)
    (if (isZero 1) then 2 else add 0 3)
    

    We know (isZero 1) is false; so, we solve the above expression and have the resulting:

    (if **(isZero 1)** then 2 else add 0 3)
    (if False then 2 else add 0 3)
    add 0 3
    

    Which is the same as of applying 0 to function f, and then, 3 to the result.
    The above expression may be read as: “f” is: 0 applied to “f”, and 3 applied to the result of the former application.

    But f’s been defined formerly as:

    (\f.\n.\m.if (isZero n) then m else f (pred n) (succ m))
    

    So, in this case, you’d have:

    add = (\f.\n.\m.if (isZero n) then m else f (pred n) (succ m))
    
    add 0 3 = \n.\m.if (isZero n) then m else add (pred n) (succ m)) 0 3
        = **\n**.\m.if (isZero **n**) then m else add (pred **n**) (succ m)) **0** 3
        = \m.if (isZero 0) then m else add (pred 0) (succ m)) 3
        = **\m**.if (isZero 0) then **m** else add (pred 0) (succ **m**)) **3**
        = if (isZero 0) then 3 else add (pred 0) (succ 3))
        = if **(isZero 0)** then 3 else add (pred 0) (succ 3))
        = if True then 3 else add (pred 0) (succ 3))
        = 3
    

    In the syntax tree you would simply show the expansions, reaching the result 3.

    As a more straightforward example of the application process, considering the function “sum”, defined as (\x.\y.x + y), the result of (sum 3 2) would be:

    (sum 3 2)
    ((sum 3) 2)
    (((sum) 3) 2)
    (((\x.\y.x + y) 3) 2)
    ((\y.3 + y) 2)
    (3 + 2)
    5
    

    There’s no restraint on the order one solves the expressions; lambda calculus is proved to have the same result what ever may be the order of the reductions used.
    See ref.

    As pointed out by Giorgio, Y is a fixed point combinator, that allows you to stop iterating at a certain point, if you’re applications return to the same expression.

    Since the application requires a finite number of iterations, the solution would be the same, simply noting the fixed pointer combination mark:

    Y = (\f.\n.\m.if (isZero n) then m else f (pred n) (succ m))
    Y add = (\f.\n.\m.if (isZero n) then m else f (pred n) (succ m)) add
    Y add = (**\f**.\n.\m.if (isZero n) then m else **f** (pred n) (succ m)) **add**
    Y add = \n.\m.if (isZero n) then m else add (pred n) (succ m)
    
    Y add 0 3 = \n.\m.if (isZero n) then m else add (pred n) (succ m)) 0 3
        = **\n**.\m.if (isZero **n**) then m else add (pred **n**) (succ m)) **0** 3
        = \m.if (isZero 0) then m else add (pred 0) (succ m)) 3
        = **\m**.if (isZero 0) then **m** else add (pred 0) (succ **m**)) **3**
        = if (isZero 0) then 3 else add (pred 0) (succ 3))
        = if **(isZero 0)** then 3 else add (pred 0) (succ 3))
        = if True then 3 else add (pred 0) (succ 3))
        = 3
    

    Reference to fixed point combinator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.