Editing 2453: Excel Lambda

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 10: Line 10:
 
[[Cueball]] is computing and [[Ponytail]] criticizes him in a way that is reminiscent of the [[:Category:Code Quality|Code Quality series]], although not as harsh. Cueball has lots of strange [[:Category:Cueball Computer Problems|computer problems]], and this will most likely result in another one.
 
[[Cueball]] is computing and [[Ponytail]] criticizes him in a way that is reminiscent of the [[:Category:Code Quality|Code Quality series]], although not as harsh. Cueball has lots of strange [[:Category:Cueball Computer Problems|computer problems]], and this will most likely result in another one.
  
βˆ’
The comic begins with Ponytail finding out that {{w|Microsoft Excel}} is adding a {{w|Anonymous_function|lambda function}} to their function library. This was [https://techcommunity.microsoft.com/t5/excel-blog/announcing-lambda-turn-excel-formulas-into-custom-functions/ba-p/1925546 announced by Microsoft] for Beta users in December of 2020. A lambda function is a fundamental mathematical structure that can be used to define all possible computations, in what is known as {{w|lambda calculus}}. They are commonly found in programming languages such as {{w|Lisp}}, {{w|Python}}, and many others. A lambda function is also called an {{w|anonymous function}} because in most languages it can be passed to other functions (including another lambda function) without needing to be given any formal name.
+
The comic begins with Ponytail finding out that {{w|Microsoft Excel}} is adding a {{w|Anonymous_function|lambda function}} to their function library. This was [https://techcommunity.microsoft.com/t5/excel-blog/announcing-lambda-turn-excel-formulas-into-custom-functions/ba-p/1925546 announced by Microsoft] for Beta users in December of 2020, but perhaps Ponytail has only discovered this recently. A lambda function is a fundamental mathematical structure that can (alternatively) be used to completely define all possible computations from the ground up, in what is known as {{w|lambda calculus}}, other than using for-loops, pointers and effect-ful functions that bear little resemblance to mathematical functions. They are commonly found in programming languages such as {{w|Lisp}}, {{w|Python}}, and many others. A lambda function is also called an {{w|anonymous function}} because in most languages it can be passed to other functions (including another lambda function) without needing to be given any formal name during coding, or given {{w|Closure_(computer_programming)|'clo1sure'}} under whatever name(s) its calling procedures desire.
  
 
Finding that Excel is adding a lambda function pleases Ponytail. Cueball claims that the lambda function is unnecessary, as when he needs arbitrary computation he just adds a block of columns to the side of his sheet and has a {{w|Turing machine}} process it. This would technically work as lambda calculus is formally equivalent to Turing machines. People have created [https://www.felienne.com/archives/2974 Turing machines in Excel], although not for practical purposes.
 
Finding that Excel is adding a lambda function pleases Ponytail. Cueball claims that the lambda function is unnecessary, as when he needs arbitrary computation he just adds a block of columns to the side of his sheet and has a {{w|Turing machine}} process it. This would technically work as lambda calculus is formally equivalent to Turing machines. People have created [https://www.felienne.com/archives/2974 Turing machines in Excel], although not for practical purposes.
Line 20: Line 20:
 
Ponytail then says that Turing would change his mind if he saw Cueball's spreadsheet, presumably because of the extreme complexity of Cueball's code in the spreadsheet. Cueball's final statement is that Turing could ask him to stop, but would not be able to prove if he actually will stop.  
 
Ponytail then says that Turing would change his mind if he saw Cueball's spreadsheet, presumably because of the extreme complexity of Cueball's code in the spreadsheet. Cueball's final statement is that Turing could ask him to stop, but would not be able to prove if he actually will stop.  
  
βˆ’
Cueball's final statement is a reference to the {{w|halting problem}} mentioned in the title text. It is the problem of determining whether a given Turing machine will halt. The problem has been shown to be undecidable, i.e., it is impossible to build an algorithm that computes whether any arbitrary Turing machine will halt or not. Because of the way Cueball has behaved, he has been specifically mentioned in Turing's later formulations of the halting problem. Cueball finds this very rude. This is of course a joke, since Turing has been dead since 1954, presumably long before Cueball was born. But it would be crazy indeed if a scientist became so mad at a person that they would mention this person by name in their formulation of a serious problem.
+
Cueball's final statement is a reference to the {{w|halting problem}} mentioned in the title text. It is the problem of determining whether a given Turing machine will halt. The problem has been shown to be undecidable, i.e., it is impossible to build an algorithm that computes whether any arbitrary Turing machine will halt or not. Because of the way Cueball has behaved, he has been specifically mentioned in Turing's later formulations of the halting problem. Cueball finds this very rude. This is of course a joke,{{citation needed}} since Turing has been dead since 1954, presumably long before Cueball was born. But it would be crazy{{citation needed}} indeed if a scientist became so mad at a person that he would mention this person by name in his formulation of a serious problem.
  
 
Over-complicated spreadsheets were also mentioned in [[2180: Spreadsheets]].
 
Over-complicated spreadsheets were also mentioned in [[2180: Spreadsheets]].
 +
 +
While conditional loops with the ability to interact with the loop variable, and functions reading and altering parameters ''not'' passed to it, can be (ab)used creatively to great effect, the fact a same structure may have been vastly different control schemes puts burden on anyone reading preexisting code. Functional programming abstracts computation differently, and uses distinct constructs for plain iterating over a list ('''map''' and co., the inner function is forbidden to interact with the accumulator by semantics) and recursion and iteration with side-effects or implicit input (modeled as various flavors of monads). Constructs like '''map''' take functions as parameter, but giving every tidbit of code a name and hiding it 100+ lines away nullifies the readability. Lambda function is thus a much needed piece for a functional style of expression.
 +
 +
In the Excel example though, the point is you can finally create custom functions in the original '''formula''' language, not some too-powerful-not-to-be-abused-by-hackers macro language that any security-aware person would strip out before opening an Excel spreadsheet. Excel formulas take only explicit input (cells) and have explicit and controlled output (cells or function return value), fitting the Lambda notion nicely. Combine this with proper recursion support and you have a language that becomes Turing-complete without relying on evaluator abuse ([https://chandoo.org/wp/timestamps-excel-formula-help/ circular reference and F7 for next iteration]) or a [https://www.felienne.com/archives/2974 ''wall'' of Turing machine states]. Now one can '''express''' (pseudo-code follows) CellValue=iterate(recursive-function, num-of-steps) properly, with num-of-steps as an input not *number of F7 presses* or *starting value of a cell which get decremented to zero as recursion proceeds* or *row number from wall of states*. Excel probably still tracks the iteration with a variable in calculating the final value, but that implementation detail is decoupled from the language itself.
 +
 +
An example of a lambda function in Python that takes a parameter named '''a''' and computes the value '''a'''-squared minus 1:
 +
 +
    lambda a: (a ** 2) - 1
 +
 +
Lambda values are often used as parameters to other functions, such as '''map''' which applies a function to each item of an "iterable" such as this list of the numbers 1, 2, and 3:
 +
 +
    map(lambda a: (a ** 2) - 1, [1, 2, 3])  ''# will generate the values 0, 3, and 8''
 +
You can copy/paste this statement into a Python interpreter (such as [https://www.tutorialspoint.com/execute_python_online.php TutorialsPoint]) to see it work (do not copy the leading spaces; that's a wiki thing):
 +
    print(list(map(lambda a: (a ** 2) - 1, [1, 2, 3])))
 +
 +
In the above example, '''map''' takes each element of the list containing the values 1, 2, and 3 in turn, sending each value to the lambda function (as the parameter "a") and so generating the sequence of values: 0, 3, and 8. These are then reconstructed into a '''list''' to '''print''' the complete result: '''[0, 3, 8]'''.
 +
 +
A recursive lambda might be:
 +
 +
  def pointless_recursion(v):
 +
      # If current value (x) is evenly divisible by 4, return the source (v) * current (x)
 +
      # Otherwise, print current, and then try the process again with the current value of x + 3
 +
      r = lambda x: x * v if x % 4 == 0 else print(x) or r(x + 3)
 +
      return r(v)
 +
 
 +
  pointless_recursion(12)  # returns 144 (i.e., 12*12)
 +
  pointless_recursion(11)  # prints 11, 14, 17 then returns 220 (i.e., 20*11)
 +
 +
In this instance, the function is given the name 'r', and features a (conditional) call back to this self-same 'r' within it. The 'x' is whatever value is the latest passed to 'r', while 'v' is that which was first passed to the container function.
 +
 +
Ideally, such techniques should be used to ''reduce'' {{w|Spaghetti code}}, not increase it. But this isn't a foregone conclusion, especially in Cueball's hands.
  
 
==Transcript==
 
==Transcript==

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)