We compare typical definitions of the left and right fold functions, with their mathematical definitions in Sergei Winitzkiβs upcoming book: The Science of Functional Programming.
Errata:
Slide 13: "The way πππππ does it is by associating to the right" - should, of course ,end in "to the left".
βgo-toβ general-purpose sequential collections -from Java To ScalaPhilip Schwarz
Β
The simple idea of this slide deck is that it collects in a single place quite a bit of information that can be used to gain a basic understanding of some key differences between the βgotoβ sequential collections of Java and Scala.
Errata:
* the twitter handle of Daniel Westheide is @kaffeecoder and not @cafeecoder
* on slide 35, the numbers 215, 220, 225 and 230, should be 2^15, 2^20, 2^25 and 2^30 respectively
* on slide 54, the bottom left node should be green rather than black
Arriving at monads by going from pure-function composition to effectful-funct...Philip Schwarz
Β
download for better quality - Arrive at monads by going from pure-function composition to effectful-function composition - I made some summary/overview slides of Rob Norris' (https://twitter.com/tpolecat) very interesting talk: "Functional Programming with Effects" https://www.youtube.com/watch?v=po3wmq4S15
He starts from pure function composition and uses math to derive Kleisli composition and Monad.
The Functional Programming Triad of Map, Filter and FoldPhilip Schwarz
Β
This slide deck is my homage to SICP, the book which first introduced me to the Functional Programming triad of map, filter and fold.
It was during my Computer Science degree that a fellow student gave me a copy of the first edition, not long after the book came out.
I have not yet come across a better introduction to these three functions.
The upcoming slides are closely based on the second edition of the book, a free online copy of which can be found here:
https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book.html.
Download for original image quality.
Errata:
slide 20: the Clojure map function is in fact the Scheme one repeated - see code below for correction.
Scheme code: https://github.com/philipschwarz/the-fp-triad-of-map-filter-and-fold-scheme
Clojure code: https://github.com/philipschwarz/the-fp-triad-of-map-filter-and-fold-clojure
Download for better quality - Learn about the composition of effectful functions through the work of Bartosz Milewski, Rob Norris, RΓΊnar Bjarnason and Debasish Ghosh.
βgo-toβ general-purpose sequential collections -from Java To ScalaPhilip Schwarz
Β
The simple idea of this slide deck is that it collects in a single place quite a bit of information that can be used to gain a basic understanding of some key differences between the βgotoβ sequential collections of Java and Scala.
Errata:
* the twitter handle of Daniel Westheide is @kaffeecoder and not @cafeecoder
* on slide 35, the numbers 215, 220, 225 and 230, should be 2^15, 2^20, 2^25 and 2^30 respectively
* on slide 54, the bottom left node should be green rather than black
Arriving at monads by going from pure-function composition to effectful-funct...Philip Schwarz
Β
download for better quality - Arrive at monads by going from pure-function composition to effectful-function composition - I made some summary/overview slides of Rob Norris' (https://twitter.com/tpolecat) very interesting talk: "Functional Programming with Effects" https://www.youtube.com/watch?v=po3wmq4S15
He starts from pure function composition and uses math to derive Kleisli composition and Monad.
The Functional Programming Triad of Map, Filter and FoldPhilip Schwarz
Β
This slide deck is my homage to SICP, the book which first introduced me to the Functional Programming triad of map, filter and fold.
It was during my Computer Science degree that a fellow student gave me a copy of the first edition, not long after the book came out.
I have not yet come across a better introduction to these three functions.
The upcoming slides are closely based on the second edition of the book, a free online copy of which can be found here:
https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book.html.
Download for original image quality.
Errata:
slide 20: the Clojure map function is in fact the Scheme one repeated - see code below for correction.
Scheme code: https://github.com/philipschwarz/the-fp-triad-of-map-filter-and-fold-scheme
Clojure code: https://github.com/philipschwarz/the-fp-triad-of-map-filter-and-fold-clojure
Download for better quality - Learn about the composition of effectful functions through the work of Bartosz Milewski, Rob Norris, RΓΊnar Bjarnason and Debasish Ghosh.
download for better quality - Learn how to use an Applicative Functor to handle multiple independent effectful values β¨through the work of Sergei Winitzki, Runar Bjarnason, Paul Chiusano, Debasish Ghosh and Adelbert Chang
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Philip Schwarz
Β
(download for best quality slides) Gain a deeper understanding of why right folds over very large and infinite lists are sometimes possible in Haskell.
See how lazy evaluation and function strictness affect left and right folds in Haskell.
Learn when an ordinary left fold results in a space leak and how to avoid it using a strict left fold.
This version eliminates some minor imperfections and corrects the following two errors:
slide 15: "as sharing is required" should be "as sharing is not required"
slide 43: ν ννννν (β) ν should be ν ννννν (β) ν
Refactoring: A First Example - Martin Fowlerβs First Example of Refactoring, ...Philip Schwarz
Β
Follow in the footsteps of refactoring guru Martin Fowler as he improves the design of a program in a simple yet instructive refactoring example whose JavaScript code and associated refactoring is herein adapted to Scala.
Based on the second edition of βtheβ Refactoring book.
Here is a github repository with the whole refactoring, from start to finish, following the steps seen in the slides https://github.com/philipschwarz/refactoring-a-first-example-scala
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit β Haskell and...Philip Schwarz
Β
First see the problem solved using the List monad and a Scala for comprehension.
Then see the Scala program translated into Haskell, both using a do expressions and using a List comprehension.
Understand how the Scala for comprehension is desugared, and what role the withFilter function plays.
Also understand how the Haskell do expressions and List comprehension are desugared, and what role the guard function plays.
Scala code for Part 1: https://github.com/philipschwarz/n-queens-combinatorial-problem-scala-part-1
Errata: on slide 30, the resulting lists should be Haskell ones rather than Scala ones.
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Philip Schwarz
Β
(download for perfect quality) - See how recursive functions and structural induction relate to recursive datatypes.
Follow along as the fold abstraction is introduced and explained.
Watch as folding is used to simplify the definition of recursive functions over recursive datatypes
Part 1 - through the work of Richard Bird and Graham Hutton.
This version corrects the following issues:
slide 7, 11 fib(0) is 0,rather than 1
slide 23: was supposed to be followed by 2-3 slides recapitulating definitions of factorial and fibonacci with and without foldr, plus translation to scala
slide 36: concat not invoked in concat example
slides 48 and 49: unwanted 'm' in definition of sum
throughout: a couple of typographical errors
throughout: several aesthetic imperfections (wrong font, wrong font colour)
Nat, List and Option Monoids -from scratch -Combining and Folding -an examplePhilip Schwarz
Β
Nat, List and Option Monoids, from scratch. Combining and Folding: an example.
Code: https://github.com/philipschwarz/nat-list-and-option-monoids-from-scratch-combining-and-folding-an-example
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1Philip Schwarz
Β
slides can look grainy and/or out of focus when seen on slideshare - download for flawless quality - Based on Scott Wlaschinβs great book 'Domain Modeling Made Functional' and on Martin Odersky's talk 'A Tour of Scala 3'.
download for better quality - Learn about the sequence and traverse functions
through the work of Runar Bjarnason and Paul Chiusano, authors of Functional Programming in Scala https://www.manning.com/books/functional-programming-in-scala
Understand the expression problem
See Haskell and Scala code illustrating the problem
Learn how FP typeclasses can be used to solve the problem
See the Haskell solution to the problem and a translation into Scala
Part 2
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaPhilip Schwarz
Β
Take the very first baby steps on the path to doing graphics in Haskell and Scala.
Learn about a simple yet educational recursive algorithm producing images that are pleasing to the eye.
Learn how functional programs deal with the side effects required to draw images.
See how libraries like Gloss and Doodle make drawing Sierpinskiβs triangle a doddle.
Code for this slide deck:
https://github.com/philipschwarz/sierpinski-triangle-haskell-gloss
https://github.com/philipschwarz/sierpinski-triangle-scala-cats-io
https://github.com/philipschwarz/sierpinski-triangle-scala-awt-and-doodle
Errata:
1. the title 'Sierpinski Triangle' on the front slide could be improved by replacing it with 'Sierpinski's Triangle'.
2. a couple of typos on two slides
3. the triangles drawn using Doodle are not equilateral, as intended but isosceles.
(UPDATE 2021-06-15 I opened PR https://github.com/creativescala/doodle/pull/99 and as a result, an equilateral triangle has now been added to Doodle: https://github.com/creativescala/doodle/commit/30d20efebcc2016942e9cdbae85fefca5b95fa3c).
Here is a corrected version of the deck: https://www.slideshare.net/pjschwarz/sierpinski-triangle-polyglot-fp-for-fun-and-profit-haskell-and-scala-with-minor-corrections
How to successfully manage a ZIO fiberβs lifecycle - Functional Scala 2021Natan Silnitsky
Β
Fibers are the backbone of the highly performant, asynchronous and concurrent abilities of ZIO. They are lightweight βgreen threadsβ implemented by the ZIO runtime system.
In this lightening talk you will learn about:
* How to handle fiber dying due to unexpected failure
* How to guarantee a ZIO fiber is interrupted
* How to set up fiber tracking and executing a fiberDump for increased debuggability
In this slide deck we are going to see some examples of how the effort required to read an understand the Sieve of Eratosthenes varies greatly depending on the programming paradigm used to implement the algorithm.
We'll see code in Java, Scheme, Haskell and Scala.
Errata:
slide 10: "points asserts" should be "asserts"
slide 22,23,25: "// larger than that root.private static int" should be "// larger than that root"
slide 29: "three slides" should be "two slides"
slide 45,46,48,49: List.range(m,n + 1) should be List.range(2,maxValue + 1)
Here I link up up some very useful material by Robert Norris (@tpolecat) and Martin Odersky (@odersky) to introduce Monad laws and reinforce the importance of checking the laws. E.g. while Option satisfies the laws, Try is not a lawful Monad: it trades the left identity law for the bullet-proof principle.
* ERRATA *
1) on the first slide the Kleisli composition signature appears three times, but one of the occurrences is incorrect in that it is (>=>)::(a->mb)->(b->mb)->(a->mc) whereas is should be (>=>)::(a->mb)->(b->mc)->(a->mc) - thank you Jules Ivanic.
Blazing Fast, Pure Effects without Monads β LambdaConf 2018John De Goes
Β
Effect monads like IO are the way functional programmers interact with the real world. Yet, monadic effects in programming languages like Scala often perform poorly compared to their Haskell counterpartsβas much as 10x slower in some benchmarks. In this presentation, John A. De Goes, author of the Scalaz 8 effect system, dredges up an old paper to cast new light on the question of how to model effects, and comes to the surprising conclusion that in Scala, monads may not be the fastest way to model purely functional effects. Join John as he shows a new model of effects that offers performance improvements without sacrificing the wonderful purity that functional programmers rely on to reason about their software.
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Philip Schwarz
Β
Quicksort - a whistle-stop tour of the algorithm in five languages and four paradigms.
Programming Paradigms: Functional, Logic, Imperative, Imperative Functional
Languages: Haskell, Scala, Java, Clojure, Prolog
Computer Graphics in Java and Scala - Part 1Philip Schwarz
Β
Computer Graphics in Java and Scala - Part 1.
Continuous (Logical) and Discrete (Device) Coordinates,
with a simple yet pleasing example involving concentric triangles.
Scala code: https://github.com/philipschwarz/computer-graphics-50-triangles-scala
Errata:
1. Scala classes TrianglesPanel and Triangles need not be classes, they could just be objects.
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mappinginventionjournals
Β
In this paper we define the generalized Cesaro sequence spaces ννν (ν, ν, ν ). We prove the space ννν (ν, ν, ν ) is a complete paranorm space. In section-2 we determine its Kothe-Toeplitz dual. In section-3 we establish necessary and sufficient conditions for a matrix A to map ννν ν, ν, ν to νβ and ννν (ν, ν, ν ) to c, where νβ is the space of all bounded sequences and c is the space of all convergent sequences. We also get some known and unknown results as remarks.
download for better quality - Learn how to use an Applicative Functor to handle multiple independent effectful values β¨through the work of Sergei Winitzki, Runar Bjarnason, Paul Chiusano, Debasish Ghosh and Adelbert Chang
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Philip Schwarz
Β
(download for best quality slides) Gain a deeper understanding of why right folds over very large and infinite lists are sometimes possible in Haskell.
See how lazy evaluation and function strictness affect left and right folds in Haskell.
Learn when an ordinary left fold results in a space leak and how to avoid it using a strict left fold.
This version eliminates some minor imperfections and corrects the following two errors:
slide 15: "as sharing is required" should be "as sharing is not required"
slide 43: ν ννννν (β) ν should be ν ννννν (β) ν
Refactoring: A First Example - Martin Fowlerβs First Example of Refactoring, ...Philip Schwarz
Β
Follow in the footsteps of refactoring guru Martin Fowler as he improves the design of a program in a simple yet instructive refactoring example whose JavaScript code and associated refactoring is herein adapted to Scala.
Based on the second edition of βtheβ Refactoring book.
Here is a github repository with the whole refactoring, from start to finish, following the steps seen in the slides https://github.com/philipschwarz/refactoring-a-first-example-scala
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit β Haskell and...Philip Schwarz
Β
First see the problem solved using the List monad and a Scala for comprehension.
Then see the Scala program translated into Haskell, both using a do expressions and using a List comprehension.
Understand how the Scala for comprehension is desugared, and what role the withFilter function plays.
Also understand how the Haskell do expressions and List comprehension are desugared, and what role the guard function plays.
Scala code for Part 1: https://github.com/philipschwarz/n-queens-combinatorial-problem-scala-part-1
Errata: on slide 30, the resulting lists should be Haskell ones rather than Scala ones.
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Philip Schwarz
Β
(download for perfect quality) - See how recursive functions and structural induction relate to recursive datatypes.
Follow along as the fold abstraction is introduced and explained.
Watch as folding is used to simplify the definition of recursive functions over recursive datatypes
Part 1 - through the work of Richard Bird and Graham Hutton.
This version corrects the following issues:
slide 7, 11 fib(0) is 0,rather than 1
slide 23: was supposed to be followed by 2-3 slides recapitulating definitions of factorial and fibonacci with and without foldr, plus translation to scala
slide 36: concat not invoked in concat example
slides 48 and 49: unwanted 'm' in definition of sum
throughout: a couple of typographical errors
throughout: several aesthetic imperfections (wrong font, wrong font colour)
Nat, List and Option Monoids -from scratch -Combining and Folding -an examplePhilip Schwarz
Β
Nat, List and Option Monoids, from scratch. Combining and Folding: an example.
Code: https://github.com/philipschwarz/nat-list-and-option-monoids-from-scratch-combining-and-folding-an-example
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1Philip Schwarz
Β
slides can look grainy and/or out of focus when seen on slideshare - download for flawless quality - Based on Scott Wlaschinβs great book 'Domain Modeling Made Functional' and on Martin Odersky's talk 'A Tour of Scala 3'.
download for better quality - Learn about the sequence and traverse functions
through the work of Runar Bjarnason and Paul Chiusano, authors of Functional Programming in Scala https://www.manning.com/books/functional-programming-in-scala
Understand the expression problem
See Haskell and Scala code illustrating the problem
Learn how FP typeclasses can be used to solve the problem
See the Haskell solution to the problem and a translation into Scala
Part 2
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaPhilip Schwarz
Β
Take the very first baby steps on the path to doing graphics in Haskell and Scala.
Learn about a simple yet educational recursive algorithm producing images that are pleasing to the eye.
Learn how functional programs deal with the side effects required to draw images.
See how libraries like Gloss and Doodle make drawing Sierpinskiβs triangle a doddle.
Code for this slide deck:
https://github.com/philipschwarz/sierpinski-triangle-haskell-gloss
https://github.com/philipschwarz/sierpinski-triangle-scala-cats-io
https://github.com/philipschwarz/sierpinski-triangle-scala-awt-and-doodle
Errata:
1. the title 'Sierpinski Triangle' on the front slide could be improved by replacing it with 'Sierpinski's Triangle'.
2. a couple of typos on two slides
3. the triangles drawn using Doodle are not equilateral, as intended but isosceles.
(UPDATE 2021-06-15 I opened PR https://github.com/creativescala/doodle/pull/99 and as a result, an equilateral triangle has now been added to Doodle: https://github.com/creativescala/doodle/commit/30d20efebcc2016942e9cdbae85fefca5b95fa3c).
Here is a corrected version of the deck: https://www.slideshare.net/pjschwarz/sierpinski-triangle-polyglot-fp-for-fun-and-profit-haskell-and-scala-with-minor-corrections
How to successfully manage a ZIO fiberβs lifecycle - Functional Scala 2021Natan Silnitsky
Β
Fibers are the backbone of the highly performant, asynchronous and concurrent abilities of ZIO. They are lightweight βgreen threadsβ implemented by the ZIO runtime system.
In this lightening talk you will learn about:
* How to handle fiber dying due to unexpected failure
* How to guarantee a ZIO fiber is interrupted
* How to set up fiber tracking and executing a fiberDump for increased debuggability
In this slide deck we are going to see some examples of how the effort required to read an understand the Sieve of Eratosthenes varies greatly depending on the programming paradigm used to implement the algorithm.
We'll see code in Java, Scheme, Haskell and Scala.
Errata:
slide 10: "points asserts" should be "asserts"
slide 22,23,25: "// larger than that root.private static int" should be "// larger than that root"
slide 29: "three slides" should be "two slides"
slide 45,46,48,49: List.range(m,n + 1) should be List.range(2,maxValue + 1)
Here I link up up some very useful material by Robert Norris (@tpolecat) and Martin Odersky (@odersky) to introduce Monad laws and reinforce the importance of checking the laws. E.g. while Option satisfies the laws, Try is not a lawful Monad: it trades the left identity law for the bullet-proof principle.
* ERRATA *
1) on the first slide the Kleisli composition signature appears three times, but one of the occurrences is incorrect in that it is (>=>)::(a->mb)->(b->mb)->(a->mc) whereas is should be (>=>)::(a->mb)->(b->mc)->(a->mc) - thank you Jules Ivanic.
Blazing Fast, Pure Effects without Monads β LambdaConf 2018John De Goes
Β
Effect monads like IO are the way functional programmers interact with the real world. Yet, monadic effects in programming languages like Scala often perform poorly compared to their Haskell counterpartsβas much as 10x slower in some benchmarks. In this presentation, John A. De Goes, author of the Scalaz 8 effect system, dredges up an old paper to cast new light on the question of how to model effects, and comes to the surprising conclusion that in Scala, monads may not be the fastest way to model purely functional effects. Join John as he shows a new model of effects that offers performance improvements without sacrificing the wonderful purity that functional programmers rely on to reason about their software.
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Philip Schwarz
Β
Quicksort - a whistle-stop tour of the algorithm in five languages and four paradigms.
Programming Paradigms: Functional, Logic, Imperative, Imperative Functional
Languages: Haskell, Scala, Java, Clojure, Prolog
Computer Graphics in Java and Scala - Part 1Philip Schwarz
Β
Computer Graphics in Java and Scala - Part 1.
Continuous (Logical) and Discrete (Device) Coordinates,
with a simple yet pleasing example involving concentric triangles.
Scala code: https://github.com/philipschwarz/computer-graphics-50-triangles-scala
Errata:
1. Scala classes TrianglesPanel and Triangles need not be classes, they could just be objects.
Dual Spaces of Generalized Cesaro Sequence Space and Related Matrix Mappinginventionjournals
Β
In this paper we define the generalized Cesaro sequence spaces ννν (ν, ν, ν ). We prove the space ννν (ν, ν, ν ) is a complete paranorm space. In section-2 we determine its Kothe-Toeplitz dual. In section-3 we establish necessary and sufficient conditions for a matrix A to map ννν ν, ν, ν to νβ and ννν (ν, ν, ν ) to c, where νβ is the space of all bounded sequences and c is the space of all convergent sequences. We also get some known and unknown results as remarks.
On ranges and null spaces of a special type of operator named π β πππππππ. β ...IJMER
Β
In this article, π β ππππ‘πππ has been introduced which is a generalization of trijection
operator as introduced in P.Chandraβs Ph. D. thesis titled βInvestigation into the theory of operators
and linear spacesβ (Patna University,1977). We obtain relation between ranges and null spaces of two
given π β ππππ‘ππππ under suitable conditions.
IOSR Journal of Mathematics(IOSR-JM) is an open access international journal that provides rapid publication (within a month) of articles in all areas of mathemetics and its applications. The journal welcomes publications of high quality papers on theoretical developments and practical applications in mathematics. Original research papers, state-of-the-art reviews, and high quality technical notes are invited for publications.
Matrix Transformations on Some Difference Sequence SpacesIOSR Journals
Β
The sequence spaces πβ(π’,π£,Ξ), π0(π’,π£,Ξ) and π(π’,π£,Ξ) were recently introduced. The matrix classes (π π’,π£,Ξ :π) and (π π’,π£,Ξ :πβ) were characterized. The object of this paper is to further determine the necessary and sufficient conditions on an infinite matrix to characterize the matrix classes (π π’,π£,Ξ βΆππ ) and (π π’,π£,Ξ βΆ ππ). It is observed that the later characterizations are additions to the existing ones
Recurrence relation of Bessel's and Legendre's functionPartho Ghosh
Β
This presentation tells about use recurrence relation in finding the solution of ordinary differential equations, with special emphasis on Bessel's and Legendre's Function.
Further Results On The Basis Of Cauchyβs Proper Bound for the Zeros of Entire...IJMER
Β
International Journal of Modern Engineering Research (IJMER) is Peer reviewed, online Journal. It serves as an international archival forum of scholarly research related to engineering and science education.
International Journal of Modern Engineering Research (IJMER) covers all the fields of engineering and science: Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Computer Engineering, Agricultural Engineering, Aerospace Engineering, Thermodynamics, Structural Engineering, Control Engineering, Robotics, Mechatronics, Fluid Mechanics, Nanotechnology, Simulators, Web-based Learning, Remote Laboratories, Engineering Design Methods, Education Research, Students' Satisfaction and Motivation, Global Projects, and Assessmentβ¦. And many more.
Generalized Laplace - Mellin Integral TransformationIJERA Editor
Β
The main propose of this paper is to generalized Laplace-Mellin Integral Transformation in between the positive regions of real axis. We have derived some new properties and theorems .And give selected tables for Laplace-Mellin Integral Transformation.
Theory of Relativity
Maybe travelling in time is an interesting topic. Also the idea of the flow of time at high speeds is a difficult idea to understand. But did you know that in 1905, someone dared to think differently. He is Albert Einstein. Questions such as, what will you see if you are moving at the speed of light? Well, it is argued that light speed is the maximum speed that is available in the entire universe. The speed of light was calculated by Maxwell using the equations of Electromagnetic wave.
c=β(1/(Ξ΅_o ΞΌ_o ))
We were able to understand that anything that has speed travels a certain distance in space in amount of time.
Einstein argued that measurements done on physically observable quantity must be uniform in all inertial reference frame. The problem is there is no such as universal reference frame. This gives rise to the assumption that everyone is moving relative to one another. This would give rise to another claim that is, βmeasurements taken from one reference frame, will be different from measurements taken from other frame of referenceβ. This argument is absurd because it will mean that laws of physics were different for different reference frames. The theory of relativity holds to the fact that the laws of physics were the same for all inertial reference frames.
This will be eminent when we apply the concept of the Doppler Effect to sound. We know that whenever the source of the sound moves with a velocity V_s, with respect to the observer there will be a change in the measured frequency. Furthermore there will be more measurements that can be made depending on the observer. So how do we determine the real frequency of the sound emitted by the source?
Another instance is when we are on board a plane with some velocity Vplane and we fire a bullet the relative velocity of the bullet on an stationary observer will be;
V=Vbullet+Vplane
Which is correct in Galilean transformation. Now what if we turn on the headlight of a plane? Would it mean that the speed of light will be the velocity of the plane + the speed of light? (v=c) ?. Absolutely not, because this will violate the premise that, βthe speed of light is constant in a vacuumβ.
Clearly from the two instances there must be a different formula that will unify measurements made on different reference frame. This method is called transformation.
So let us create two equation that will unify measurements in these two instances. The first instance is at the plane, the observer at the plane will have (x,y,z,t). and the observer from the earth will us the coordinates (x^',y^',z^',t^'). So which is it the spaceship is moving away from the earth or the earth is moving away from the spaceship. To fix this, we assume that the origin O and O^'coincide and are parallel to one another at all times. Further more we let t and t^' be equal that is t= t^'.
and more....
Similar to Left and Right Folds- Comparison of a mathematical definition and a programmatic one- Polyglot FP for Fun and Profit - Haskell and Scala (20)
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidPhilip Schwarz
Β
The subject of this deck is the small Print[A] program in the following blog post by Noel Welsh: https://www.inner-product.com/posts/direct-style-effects/.
Keywords: "direct-style", "context function", "context functions", "algebraic effect", "algebraic effects", "scala", "effect system", "effect systems", "effect", "side effect", "composition", "fp", "functional programming"
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
Β
For functions that can be defined both as an instance of a right fold and as an instance of a left fold, one may be more efficient than the other.
Let's look at the example of a function 'decimal' that converts a list of digits into the corresponding decimal number.
Erratum: it has been pointed out that it is possible to define the zip function using a right fold (see slide 5).
Tagless Final Encoding - Algebras and Interpreters and also ProgramsPhilip Schwarz
Β
Tagless Final Encoding - Algebras and Interpreters and also Programs - An introduction, through the work of Gabriel Volpe.
Slide deck home: http://fpilluminated.com/assets/tagless-final-encoding-algebras-interpreters-and-programs.html
A sighting of traverseFilter and foldMap in Practical FP in ScalaPhilip Schwarz
Β
Slide deck home: http://fpilluminated.com/assets/sighting-of-scala-cats-traverseFilter-and-foldMap-in-practical-fp-in-scala.html.
Download PDF for perfect image quality.
A sighting of sequence function in Practical FP in ScalaPhilip Schwarz
Β
Slide deck home: http://fpilluminated.com/assets/sighting-of-scala-cats-sequence-function-in-practical-fp-in-scala.html.
Download PDF for perfect image quality.
This talk was presented on Aug 3rd 2023 during the Scala in the City event a ITV in London https://www.meetup.com/scala-in-the-city/events/292844968/
Visit the following for a description, slideshow, all slides with transcript, pdf, github repo, and eventually a video recording: http://fpilluminated.com/assets/n-queens-combinatorial-puzzle-meets-cats.html
At the centre of this talk is the N-Queens combinatorial puzzle. The reason why this puzzle features in the Scala book and functional programming course by Martin Odersky (the languageβs creator), is that such puzzles are a particularly suitable application area of 'for comprehensions'.
Weβll start by (re)acquainting ourselves with the puzzle, and seeing the role played in it by permutations. Next, weβll see how, when wanting to visualise candidate puzzle solutions, Catsβ monoidal functions fold and foldMap are a great fit for combining images.
While we are all very familiar with the triad providing the bread, butter and jam of functional programming, i.e. map, filter and fold, not everyone knows about the corresponding functions in Catsβ monadic variant of the triad, i.e. mapM, filterM and foldM, which we are going to learn about next.
As is often the case in functional programming, the traverse function makes an appearance, and we shall grab the opportunity to point out the symmetry that exists in the interrelation of flatMap / foldMap / traverse and flatten / fold / sequence.
Armed with an understanding of foldM, we then look at how such a function can be used to implement an iterative algorithm for the N-Queens puzzle.
The talk ends by pointing out that the iterative algorithm is smarter than the recursive one, because it βremembersβ where it has already placed previous queens.
Kleisli composition, flatMap, join, map, unit - implementation and interrelat...Philip Schwarz
Β
Kleisli composition, flatMap, join, map, unit. A study/memory aid, to help learn/recall their implementation/interrelation.
Version 2, updated for Scala 3
Nat, List and Option Monoids -from scratch -Combining and Folding -an examplePhilip Schwarz
Β
Nat, List and Option Monoids, from scratch. Combining and Folding: an example.
This is a new version of the original which has some cosmetic changes and a new 7th slide which only differs from slide 6 in that it defines the fold function in terms of the foldRight function.
Code: https://github.com/philipschwarz/nat-list-and-option-monoids-from-scratch-combining-and-folding-an-example
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...Philip Schwarz
Β
When I posted the deck for Part 1 to the Scala users forum, Odd MΓΆller linked to a paper titled "The Genuine Sieve of Eratosthenes", which speaks of the Unfaithful Sieve.
Part 2 is based on that paper and on Richard Bird's faithful Haskell implementation of the Sieve, which we translate into Scala.
Scala code for Richard Bird's infinite primes Haskell program: https://github.com/philipschwarz/sieve-of-eratosthenes-part-2-scala
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...Philip Schwarz
Β
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Haskell, Scala and Java.
Inspired by the example in Scott Wlaschinβs F# book: Domain Modeling Made Functional.
Download for better results.
Java 19 Code: https://github.com/philipschwarz/fruit-salad-and-fruit-snack-ADT-example-java
Jordan Peterson - The pursuit of meaning and related ethical axiomsPhilip Schwarz
Β
I have only recently become aware of the work of Jordan Peterson. Because I am finding it so interesting, I hope that the following small collection of excerpts from some of his writings and speeches might entice any fellow latecomers to find out more about his work. See below for my own summary of some of the subjects touched upon in these slides.
Download for best results.
Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...Philip Schwarz
Β
Defining filter using
(a) recursion
(b) folding
(c) folding with S, B and I combinators
(d) folding with applicative functor and identity function.pdf
This second version adds a simpler folding definition, which I had left out in the first version.
The Sieve of Eratosthenes - Part 1 - with minor correctionsPhilip Schwarz
Β
In this slide deck we are going to see some examples of how the effort required to read an understand the Sieve of Eratosthenes varies greatly depending on the programming paradigm used to implement the algorithm.
We'll see code in Java, Scheme, Haskell and Scala.
This version of the deck contains some minor corrections (see errata section in first version for details)
Computer Graphics in Java and Scala - Part 1bPhilip Schwarz
Β
First see the Scala program from Part 1 translated into Java.
Then see the Scala program modified to produce a more intricate drawing.
Java Code: https://github.com/philipschwarz/computer-graphics-50-triangles-java
Scala Code: https://github.com/philipschwarz/computer-graphics-chessboard-with-a-great-many-squares-scala
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
Β
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
Β
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
First Steps with Globus Compute Multi-User EndpointsGlobus
Β
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
Β
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Β
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
Β
JASMIN is the UKβs high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERCβs long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Β
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. Itβs here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Β
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
Β
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our teamβs work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Β
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Β
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
Β
Keep tabs on your field staff effortlessly with Informap Technology Centre LLC. Real-time tracking, task assignment, and smart features for efficient management. Request a live demo today!
For more details, visit us : https://informapuae.com/field-staff-tracking/
Enhancing Research Orchestration Capabilities at ORNL.pdfGlobus
Β
Cross-facility research orchestration comes with ever-changing constraints regarding the availability and suitability of various compute and data resources. In short, a flexible data and processing fabric is needed to enable the dynamic redirection of data and compute tasks throughout the lifecycle of an experiment. In this talk, we illustrate how we easily leveraged Globus services to instrument the ACE research testbed at the Oak Ridge Leadership Computing Facility with flexible data and task orchestration capabilities.
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Β
Even though at surface level βjava.lang.OutOfMemoryErrorβ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
Understanding Globus Data Transfers with NetSageGlobus
Β
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
In software engineering, the right architecture is essential for robust, scalable platforms. Wix has undergone a pivotal shift from event sourcing to a CRUD-based model for its microservices. This talk will chart the course of this pivotal journey.
Event sourcing, which records state changes as immutable events, provided robust auditing and "time travel" debugging for Wix Stores' microservices. Despite its benefits, the complexity it introduced in state management slowed development. Wix responded by adopting a simpler, unified CRUD model. This talk will explore the challenges of event sourcing and the advantages of Wix's new "CRUD on steroids" approach, which streamlines API integration and domain event management while preserving data integrity and system resilience.
Participants will gain valuable insights into Wix's strategies for ensuring atomicity in database updates and event production, as well as caching, materialization, and performance optimization techniques within a distributed system.
Join us to discover how Wix has mastered the art of balancing simplicity and extensibility, and learn how the re-adoption of the modest CRUD has turbocharged their development velocity, resilience, and scalability in a high-growth environment.
Left and Right Folds- Comparison of a mathematical definition and a programmatic one- Polyglot FP for Fun and Profit - Haskell and Scala
1. Based on definitions from
Left and Right Folds
Comparison of a mathematical definition
and a programmatic one
Polyglot FP for Fun and Profit - Haskell and Scala
@philip_schwarz
slides by https://www.slideshare.net/pjschwarz
Sergei Winitzki
sergei-winitzki-11a6431
Richard Bird
http://www.cs.ox.ac.uk/people/richard.bird/
2. πππππ β· π½ β πΌ β π½ β π½ β πΌ β π½
πππππ π π = π
πππππ π π π₯ βΆ π₯π = πππππ π π π π₯ π₯π
πππππ β· πΌ β π½ β π½ β π½ β πΌ β π½
πππππ π π = π
πππππ π π π₯ βΆ π₯π = π π₯ πππππ π π π₯π
If I have to write down the definitions of a left
fold and a right fold for lists, here is what I write
While both definitions are recursive, the left fold is tail recursive, whereas the right fold isnβt.
Although I am very familiar with the above definitions, and view them as doing a good job of
explaining the two folds, I am always interested in alternative ways of explaining things, and so
I have been looking at Sergei Winitzkiβs mathematical definitions of left and right folds, in his
upcoming book: The Science of Functional Programming (SOFP).
Sergeiβs definitions of the folds are in the top two rows of the following table
Sergei Winitzki
Richard Bird
@philip_schwarz
3. test1 = TestCase (assertEqual "foldl(+) 0 []" 0 (foldl (+) 0 []))
test2 = TestCase (assertEqual "foldl(+) 0 [1,2,3,4]" 10 (foldl (+) 0 [1,2,3,4]))
test3 = TestCase (assertEqual "foldr (+) 0 []" 0 (foldr (+) 0 []))
test4 = TestCase (assertEqual "foldr (+) 0 [1,2,3,4]" 10 (foldr (+) 0 [1,2,3,4]))
Left folds and right folds do not necessarily produce the same
results. According to the first duality theorem of folding, one case
in which the results are the same, is when we fold using the unit
and associative operation of a monoid.
First duality theorem. Suppose β is associative with unit π. Then
πππππ β π π₯π = πππππ β π π₯π
For all finite lists π₯π .
test5 = TestCase (assertEqual "foldl(-) 0 []" 0 (foldl (+) 0 []))
test6 = TestCase (assertEqual "foldl(-) 0 [1,2,3,4]" (- 10) (foldl (-) 0 [1,2,3,4]))
test7 = TestCase (assertEqual "foldr (-) 0 []" 0 (foldr (-) 0 []))
test8 = TestCase (assertEqual "foldr (-) 0 [1,2,3,4]" (- 2) (foldr (-) 0 [1,2,3,4]))
Folding integers left and right using the (Int,+,0) monoid, for example, produces the same results.
But folding integers left and right using subtraction and zero, does not produce the same results, and in
fact (Int,-,0) is not a monoid, because subtraction is not associative.
4. π = π; π π₯ β§Ί π = π(π₯, π(π ))
π = π; π π β§Ί [π₯] = π(π π , π₯)
To avoid any confusion (the definitions use the same function name π), and to
align with the definitions on the right, letβs modify Sergeiβs definitions by doing
some simple renaming.
Here are Sergeiβs mathematical definitions again, on the right (the β§Ί operator
is list concatenation). Notice how neither definition is tail recursive. That is
deliberate.
As Sergei explained to me: βI'd like to avoid putting tail recursion into a
mathematical formula, because tail recursion is just a detail of how we
implement this functionβ and βThe fact that foldLeft is tail recursive for List is
an implementation detail that is specific to the List type. It will be different for
other sequence types. I do not want to put the implementation details into the
formulas.β
π β πππππ π β π π β π
πππππ = π; πππππ π₯ β§Ί π = π(π₯, πππππ(π ))
πππππ = π; πππππ π β§Ί [π₯] = π(πππππ π , π₯)
π β πππππ π β π π β π
πππππ β· π½ β πΌ β π½ β π½ β πΌ β π½
πππππ π π = π
πππππ π π π₯ βΆ π₯π = πππππ π π π π₯ π₯π
πππππ β· πΌ β π½ β π½ β π½ β πΌ β π½
πππππ π π = π
πππππ π π π₯ βΆ π₯π = π π₯ πππππ π π π₯π
π = π; π π₯ β§Ί π = π(π₯, π(π ))
π = π; π π β§Ί [π₯] = π(π π , π₯)
5. πππππ π π [ ] = π
πππππ π π π₯ β§Ί π = π π₯ (πππππ π π π )
πππππ π π = π
πππππ π π π β§Ί [π₯] = π πππππ π π π π₯
πππππ :: (π β π β π) β π β[π] β π
πππππ π π = π
πππππ π π ππ = π πππππ π π (ππππ‘ ππ ) (πππ π‘ ππ )
πππππ :: (π β π β π) β π β[π] β π
πππππ π π = π
πππππ π π ππ = π βπππ ππ πππππ π π (π‘πππ ππ )
πππππ :: (π β π β π) β π β[π] β π
πππππ π π = π
πππππ π π ππ = π π π
π€βπππ π = πππ π‘ ππ
π = πππππ π π (ππππ‘ ππ )
πππππ :: (π β π β π) β π β[π] β π
πππππ π π = π
πππππ π π ππ = π π π
π€βπππ π = βπππ ππ
π = πππππ π π (π‘πππ ππ )
πππππ = π; πππππ π₯ β§Ί π = π(π₯, πππππ(π ))
πππππ = π; πππππ π β§Ί [π₯] = π(πππππ π , π₯)
To help us understand the above two definitions, letβs first express them in Haskell,
pretending that we are able to use π β§Ί [π₯] and π₯ β§Ί π in a pattern match.
Now letβs replace π β§Ί [π₯] and π₯ β§Ί π with as, and get the functions to extract
the π and the π₯ using the βπππ, π‘πππ, πππ π‘ and ππππ‘. Letβs also add type signatures
And now letβs make it more obvious that what each fold is doing is taking an π from the list,
folding the rest of the list into a π, and then returning the result of calling π with π and π.
6. πππππ :: (π β π β π) β π β[π] β π
πππππ π π = π
πππππ π π ππ = π π π
π€βπππ π = πππ π‘ ππ
π = πππππ π π (ππππ‘ ππ )
πππππ :: (π β π β π) β π β[π] β π
πππππ π π = π
πππππ π π ππ = π π π
π€βπππ π = βπππ ππ
π = πππππ π π (π‘πππ ππ )
Since the above two functions are very similar, letβs extract their common logic into a fold function. Letβs call the function
that is used to extract an element from the list π‘πππ, and the function that is used to extract the rest of the list πππ π‘.
ππππ :: (π β π β π) β ([π] β π) β ([π] β [π]) β π β [π] β π
ππππ π π‘πππ πππ π‘ π = π
ππππ π π‘πππ πππ π‘ π ππ = π π π
π€βπππ π = π‘πππ ππ
π = ππππ π π‘πππ πππ π‘ π (πππ π‘ ππ )
We can now define left and right
folds in terms of ππππ.
πππππ :: (π β π β π) β π β[π] β π
πππππ π = ππππ π πππ π‘ ππππ‘
πππππ :: (π β π β π) β π β[π] β π
πππππ π = ππππ ππππ π βπππ π‘πππ
ππππ :: (π β π β π) β π β π β π
ππππ π π₯ π¦ = π π¦ π₯
The slightly perplexing thing is that while a left fold applies π to list elements starting with the βπππ of the list and
proceeding from left to right, the above πππππ function achieves that by navigating through list elements from right to left.
Third duality theorem. For all finite lists π₯π ,
πππππ π π π₯π = πππππ ππππ π π (πππ£πππ π π₯π )
πππππ ππππ π π₯ π¦ = π π¦ π₯
The fact that we can define πππππ and πππππ in terms of ππππ, as we
do above, seems related to the third duality theorem of folding.
Instead of our πππππ function being passed the reverse of the list
passed to πππππ, it processes the list with πππ π‘ and ππππ‘, rather than
with βπππ and π‘πππ.
@philip_schwarz
7. To summarise what we did to help understand SOFPβs mathematical definitions of left and right fold: we
turned them into code and expressed them in terms of a common function ππππ that uses a π‘πππ function
to extract an element from the list being folded, and a πππ π‘ function to extract the rest of the list.
ππππ :: (π β π β π) β ([π] β π) β ([π] β [π]) β π β [π] β π
ππππ π π‘πππ πππ π‘ π = π
ππππ π π‘πππ πππ π‘ π ππ = π π π
π€βπππ π = π‘πππ ππ
π = ππππ π π‘πππ πππ π‘ π (πππ π‘ ππ )
πππππ :: (π β π β π) β π β[π] β π
πππππ π = ππππ π πππ π‘ ππππ‘
πππππ :: (π β π β π) β π β[π] β π
πππππ π = ππππ ππππ π βπππ π‘πππ
πππππ = π; πππππ π₯ β§Ί π = π(π₯, πππππ(π ))
πππππ = π; πππππ π β§Ί [π₯] = π(πππππ π , π₯)
πππππ = π; πππππ ππ = π(βπππ(ππ ), πππππ(π‘πππ(ππ )))
πππππ = π; πππππ ππ = π(πππππ ππππ‘(ππ ) , πππ π‘(ππ ))
Letβs feed one aspect of the above back into Sergeiβs definitions. Letβs temporarily rewrite them by
replacing π β§Ί [π₯] and π₯ β§Ί π with as, and getting the definitions to extract the π and the π₯ using the
functions βπππ, π‘πππ, πππ π‘ and ππππ‘.
Notice how the flipping of π done by the πππππ function above, is reflected, in the πππππ function below,
in the fact that its π takes an π and a π, rather than a π and an π.
8. Another thing we can do to understand SOFPβs definitions of left and right folds, is to see how they work
when applied to a sample list, e.g. [π₯0, π₯1, π₯2, π₯3], when we run them manually.
In the next slide we first do this for the following definitions
πππππ = π; πππππ π β§Ί [π₯] = π(πππππ π , π₯) πππππ = π; πππππ π₯ β§Ί π = π(π₯, πππππ(π ))
πππππ β· π½ β πΌ β π½ β π½ β πΌ β π½
πππππ π π = π
πππππ π π π₯ βΆ π₯π = πππππ π π π π₯ π₯π
πππππ β· πΌ β π½ β π½ β π½ β πΌ β π½
πππππ π π = π
πππππ π π π₯ βΆ π₯π = π π₯ πππππ π π π₯π
In the slide after that, we do it for SOFPβs definitions.
13. The way πππππ applies π to π₯, π¦, z is by associating to the right.
The way πππππ does it is by associating to the right.
Thinking of π as an infix operator can help to grasp this.
πππππ π(π₯, π(π¦, π§)) π₯ β π¦ β π§
πππππ π π π₯, π¦ , π§ (π₯ β π¦) β π§
πππππ β π π₯, π¦, z = π₯ β (π¦ β π§ β π )
πππππ (+) 0 [1,2,3] = 1 + (2 + (3 + 0)) = 6
πππππ (+) 0 [1,2,3] = ((0 + 1) + 2) + 3 = 6
πππππ β 0 1,2,3 = 1 β (2 β (3 β 0)) = 2
πππππ β 0 1,2,3 = ((0 β 1) β 2) β 3 = β6
β
/
π₯ β
/
π¦ β
/
π§ π
β
/
β π§
/
β π¦
/
π π₯
πππππ β π π₯, π¦, π§ = ((π β π₯) β π¦) β π§
Addition is associative, so associating to the left and to the right yields the
same result. But subtraction isnβt associative, so associating to the left yields
a result that is different to the one yielded when associating to the right.
14. We have seen that Sergeiβs definitions of left and right folds make perfect sense.
Not only are they simple and succinct, they are also free of implementation details like tail recursion.
Thatβs all. I hope you found this slide deck useful.
By the way, in case you are interested, see below for a whole series of slide decks dedicated to folding.