Menu

lambda special?

Help
arpi
2014-12-12
2014-12-16
  • arpi

    arpi - 2014-12-12

    I could not find it in the help, but is lambda the name of a function or a special variable?

    If I type mu; it is displayed, so is mu^2;
    However, landa; shows lamda, like if it was a free variable, and lambda^2; gives the error message

    ;lambda^$$$2

    * Redundant operator

    What is the reason? Thanks.

     
    • Arthur Norman

      Arthur Norman - 2014-12-16

      If you look up teh word "lambda" in the index of the PDF manual you will
      find that it is a keyword introducing syntax used in symbolic mode. It is
      used to write a "lambda expression", ie a reprsentation of a freestanding
      (anonymous) function. Theer are two main ways in which it is used - one is
      to avoid repeated evaluation of some experssion, as in the following
      example for alg/simp.red:

      symbolic procedure iroot!-ceiling(m,n);
      (lambda x; if cdr x=0 then car x else car x+1) divide(m,n);

      That lets a new lambda-bound variable called x take the value of
      divide(m,n) so that it can be used in the IF statement.

      The other is when a small function needs to be passed as an argument to
      another function as in this fragment from solve/solvealg.red
      ...
      iv! := sort(iv!,function (lambda(a,b);depends(a,b)));
      ...
      where sort takes as its second argument a function that is used to define
      the ordering it should apply, and here the lambda expression denotes a
      fucntion of two arguments. Looking at it that case could have been written
      as just
      iv! := sort(iv!,function depends);
      since depends already takes just 2 arguments, but slightlier messier cases
      also arise.

      The notation dates back to Alonzo Church in the 1930s and it was one of
      the features of Lisp that John McCarthy put in there in the late 1950s -
      it has been part of Reduce since the start.

      However lambda-expression are only supported in symbolic mode Reduce code
      but at present the parser detects, tries to process and does odd things in
      algebraic mode.

      We may look into that and see how easy it is to change. But it appears
      that at present you could do something that is a bit odd. The assignment
      greek_lambda := lambda;
      appears to be accepted, because the special syntax for "lambda" manages
      not to get triggered in the very simple RHS. Then you can write
      expressions like
      (greek_lambda + 1)^3;
      and in the gui you get nice lambda symbols visible in your result.

      I would strongly advise against trying to use lambda as the name of an
      operator or a procedure.

      I hope this explains why there is unexpected behaviour for this word,
      notes that it is documented in the manual and suggests what MAY (I have
      not tested terribly extensively) let you work around the issue if your aim
      is to get lambda symbols visible in your output so that the visible
      notation agrees with what you would have done on paper.

      I might note in passing that the word "pi" does not have special syntax,
      but could sometimes simplify in ways that are built-in (eg with trig
      functions) and even various non-greek letters like "e" and "i" can have
      predefined properties, so for instance an expression like
      (ax^4 + bx^3 + cx^2 + dx + e)
      could sometimes give a surprise if (for instance) you go "on rounded"! So
      having "lambda" reserved is not a one-off case!

             Arthur
      

      On Fri, 12 Dec 2014, arpi wrote:

      I could not find it in the help, but is lambda the name of a function or a special variable?

      If I type mu; it is displayed, so is mu^2;
      However, landa; shows lamda, like if it was a free variable, and lambda^2; gives the error message

      ;lambda^$$$2

      * Redundant operator

      What is the reason? Thanks.


      lambda special?


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/reduce-algebra/discussion/899364/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       
      • Alan Barnes

        Alan Barnes - 2014-12-16

        For those prone to labdacism (=lambdacism) the following would be an
        alternative to ACN's suggestion:

        lisp put('labda,'fancy!-special!-symbol,"\lambda");
        lisp put('labda,'unicode_character, 955);

        According to Chambers 2011 Dictionary: "lambda (or more correctly labda) is the 11th letter of the Greek alphabet ...". I also note the Shorter OED has an entry "lamda (see lambda)", though I think I agree with ACN that this is a rather horrid homophone. Websters Dictionary (as well as Chambers and OED) gives labdacism as an alternative to lambdacism.

        After this hack, "labda" in formulae will then be printed as a nice Greek
        lambda if the output device supports 'fancy-printing' or Unicode characters.

        As far as I can see there should be no problems using "labda" as the
        name of an operator etc.

        Of course, in algebraic mode

        labda := lambda;

        would also work subject to the same reservations as in ACN's post. This would involve rather less typing in formulae (as well as keeping the classicists happy!). Equally one could use the more verbose greek_lambda rather than labda in the lisp commands above.

        One might also wish to do

        lisp put('!Labda,'fancy!-special!-symbol,"\Lambda");
        lisp put('!Labda,'unicode_character, 923);

        although one can, of course, already use !Lambda if one wants an uppercase lambda.

        Alan Barnes

         

Log in to post a comment.