Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Y-Combinator in PHP

Y-Combinator in PHP

This talk is about Y-Combinator and implementation in PHP

Article associated to this talk

https://blog.darkwood.fr/article/y-combinator-en-php

Video associated to this talk

https://www.youtube.com/watch?v=QSS_ZcO8Q1g

Mathieu Ledru

April 25, 2023
Tweet

More Decks by Mathieu Ledru

Other Decks in Programming

Transcript

  1. ⾠ I’m not an expert ⾠ I will speak with

    my own words @matyo91 @matyo91 25-04-2023
  2. Objectives : Go back up to theoretical concepts that solve

    an issue How I discovered Y-Combinator and why I do need them ? Why Y-Combinator ? Introduction to Lambda Calculus Exemples of basic Lambda Calculus and equivalent in PHP Y-Combinator in PHP (for me and others github repositories) Plan @matyo91 25-04-2023 @matyo91
  3. Do recursion in a language that do not have any

    recursion mechanism at all “ @matyo91 25-04-2023
  4. A Y-combinator is a "functional" (a function that operates on

    other functions) that enables recursion, when you can't refer to the function from within itself. In computer-science theory, it generalises recursion, abstracting its implementation, and thereby separating it from the actual work of the function in question. This is applicable in languages that support Lambda-Calculus functions Y-Combinator @matyo91 25-04-2023 @matyo91
  5. Alonzo Church ( 1903 - 1995 ) Inventor of Lambda

    Calculus @matyo91 @matyo91 25-04-2023
  6. λ x . x + 1 ( λ x .

    x + 1 ) ( 5 ) = 5 + 1 = 6 @matyo91 @matyo91 25-04-2023 X X + 1
  7. λ x . λ y . x+y 
 
 (

    λ x . λ y . x+y ) ( 5 , 6 ) = 5 + 6 = 11 @matyo91 @matyo91 25-04-2023 X X + Y Y
  8. There are variables. We got a way to build functions.

    We can apply functions to each others by providing elements of the language itself. All derivatives of lambda calculus language is something defined in terms of this definition. Lambda Calculus @matyo91 25-04-2023 @matyo91
  9. True = λ x . λ y . x False

    = λ x . λ y . y @matyo91 @matyo91 25-04-2023 X X Y True X Y Y False
  10. True = λ x . λ y . x @matyo91

    @matyo91 25-04-2023 False = λ x . λ y . y
  11. Not = λ b . b False True @matyo91 @matyo91

    25-04-2023 b False True b Not
  12. Not = ( λ b . b False True )

    ( True ) = True False True = ( λ x . λ y . x ) ( False True ) = False @matyo91 @matyo91 25-04-2023
  13. Y ( f ) = f ( Y ( f

    ) ) = f ( f ( Y ( f ) ) ) = f ( f ( f ( f ( ... ) ) ) ) @matyo91 @matyo91 25-04-2023
  14. Fac (n) = if n == 1 then 1 else

    n * Fac (n - 1) 
 Fac (3) = 3 * Fac (2) = 3 * 2 * Fac (1) = 3 * 2 * 1 = 6 @matyo91 @matyo91 25-04-2023 YCombinator in Lambda Calculus
  15. Fac = Y ( ? ) = Y ( λ

    f . λ n . ? ) = Y ( λ f . λ n . max( n , 1 ) * Fac ( n - 1 ) ) @matyo91 @matyo91 25-04-2023 YCombinator in Lambda Calculus
  16. Loop = ( λ x . x . x )

    ( λ x . x . x ) @matyo91 @matyo91 25-04-2023 YCombinator in Lambda Calculus
  17. Loop = ( λ x . x . x )

    ( λ x . x . x ) @matyo91 @matyo91 25-04-2023 YCombinator in Lambda Calculus
  18. Loop = ( λ x . x . x )

    ( λ x . x . x ) Loop = ( λ x . ( λ x . x . x ) . ( λ x . x . x ) ) @matyo91 @matyo91 25-04-2023 YCombinator in Lambda Calculus
  19. Loop = ( λ x . x . x )

    ( λ x . x . x ) Loop = ( λ x . ( λ x . x . x ) . ( λ x . x . x ) ) Loop = ( λ x . x . x ) ( λ x . x . x ) @matyo91 @matyo91 25-04-2023 YCombinator in Lambda Calculus
  20. Loop = Y ( λ x . x . x

    ) = ( λ x . x . x ) ( Y ( λ x . x . x ) ) = ( λ x . x . x ) ( λ x . x . x ) ( Y ( λ x . x . x ) ) @matyo91 @matyo91 25-04-2023 YCombinator in Lambda Calculus
  21. Y ( f ) = λ f ( λ x

    . f ( x x ) ) ( λ x . f ( x x ) ) @matyo91 @matyo91 25-04-2023 YCombinator in Lambda Calculus
  22. Hello! I Am Mathieu Ledru You can contact me at

    @matyo91 25-04-2023 @matyo91 Thanks! Any questions?