December SPECIAL! For a limited time only. Get 20% discount on a LIFETIME PRO account!Want more features on Pastebin? Sign Up, it's FREE!
tweet
Guest

Untitled

By: a guest on Apr 17th, 2015  |  syntax: None  |  size: 2.74 KB  |  views: 193  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print  |  QR code  |  clone
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. We are interested in making a virus in the lambda calculi. The aim is for the virus to preserve functionality, this is, if we have a lambda-expression f such that
  2. f x => g
  3. for an infected version of f, namely f[v]
  4. f[v] x => g[v]
  5. where g[v] is the infected version of g.
  6. In 'pure' (or untyped) lambda calculus all our values are lambda-expressions of the form 'λx.[...]' so we need not worry about primitive types yet. At the end I'll peek at a way to deal with this in Scheme, a trivial task, really.
  7. Now, how do we preserve functionality while infecting a λexpr? Remember that for any expression f
  8. (λd.λx.d x) f
  9. is equivalent to just 'f'. So our first idea would be to wrap the host function in such a way and then infect it within the new expression:
  10. (λd.λx.V (d x))
  11. Here V is our (yet undefined) viral expression. when applied to a function f and an argument x it reduces to
  12. (λd.λx.V (d x)) f x
  13. => (V (f x))
  14. ==> (V g)
  15. ===> g[v]
  16. of course, we want our g[v] to have the form
  17. (λx.V (g x))
  18. where g is precisely our g expression. that way our virus should take as argument a function (the host function) and return a lambda expression that takes the argument to the function and does the application
  19. (λd.λx.V (d x))
  20. Looks familiar? Turns out this is precisely the form our viral expression V is going to adopt, for if
  21. d x => g
  22. then
  23. V g => (λx.V (g x))
  24. Thus V is of the form (λd.λx.V (d x))
  25. We can see then, that V is a recursive function that can be expressed like
  26. V = (λd.λx.V (d x))
  27. But in the lambda calculus we need to work around recursive functions due to the lack of assignment expressions. How do we make a recursive function? Remember the Y-combinator?
  28. (λf.(λx.f (x x)) (λx.f (x x)))
  29. Where a function is fed to itself, this is, it is repeated in the definition.
  30. Inspired by this idea, and with some little thinking we arrive to the following definition for our virus:
  31. V* = (λv.λd.λx.(v v) (d x))
  32. As you can see, it looks pretty much like our former definition, where we replace V with (v v), but what exactly is the 'v' we are feeding? turns out it is V* itself:
  33. (λv.λd.λx.(v v) (d x)) (λv.λd.λx.(v v) (d x))
  34. => (λf.λx.[(λv.λd.λx.(v v) (d x)) (λv.λd.λx.(v v) (d x))] (f x))
  35. The resulting expression we'll call V°. It's easy to see that (V* V*) => V° and
  36. V° = (λd.λx.(V* V*) (d x))
  37. But a closer look will reveal that V° takes an expression and returns a 'wrapped' version of it, like the first form we saw, so applied to f we have
  38. (λd.λx.(V* V*) (d x)) f
  39. => (λx.(V* V*) (f x))
  40. When applied to an argument x such that [f x => g] then we have
  41. (V* V*) g
  42. and so
  43. V° g
  44. and finally
  45. (λx.(V* V*) (g x))
  46. Thus, this is the virus we wanted, it does both preserve functionality and 'copy' itself to the new function.
clone this paste RAW Paste Data
Top