"Monad transformers more powerful than effects" - Examples? - functional-programming

The paper "Programming and reasoning with algebraic effects and dependent types" by Edwin C. Brady on effects in Idris contains the (unreferenced) claim that:
Although [effects and monad transformers] are not equivalent in power — monads and monad transformers can express more concepts — many common effectful computations are captured.
What examples are there that can be modelled by monad transformers but not effects?

Continuations can be modelled as monads, using CPS, but they are not algebraic effects as they cannot be modelled using Lawvere theories. See Martin Hyland and John Power, 2007, The Category Theoretic Understanding of Universal Algebra: Lawvere Theories and Monads (pdf), ENTCS 172:437-458.

Related

Isabelle/HOL with HOL-Z and ZETA

I have seen some papers that describe how to use the Z notation with Isabelle/HOL using the tools HOL-Z and ZETA. I was not able to find these tools, have they ever been published? Are there other ways to use Isabelle with the Z notation?
If you are prepared to substitute Isabelle/HOL for one of the HOL theorem provers (which also adopt the LCF approach to soundness) then you should consider ProofPower, which also embeds the Z notation in HOL. ProofPower-Z has been used on large industrial examples for many years, in particular to discharge verification conditions to show the correctness of Ada source code.

Math for computer science [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have read several answers on this topic , but I still have questions..
There are plenty of math courses, and I don't know which one to take first.
Which math classes should every computer scientist take? And what class should be first one and why?
Very good and important question! A good understanding of math is essential for every computer scientist, and the math requirement is starting to become more diverse.
Discrete Math is the most important and basic class for computer science, and for this reason it is usually offered in CS departments instead of math departments. This class will underpin your intro to algorithms to class and teach you how to prove things mathematically and give you the fundamentals for analyzing data structures and algorithms.
Calculus, while not directly used in intro-level computer science classes, is generally a sequence of courses offered by your university to buff up your math skills. As you start getting into things like numerical programming and machine learning, though, it will prove immensely useful. It's also a requirement for advanced probability/statistics courses.
Probability is usually covered in some extent in your discrete math class, but you'll want to take a class on continuous probability distributions and statistical inference, probably in the math and statistics department. This will give you a better understanding of how to do numerical computation and simulation, and is fundamentally necessary for machine learning, one of the most important applications of computer science.
Linear Algebra is a class that you will find primarily useful for machine learning and (advanced) algorithms classes, but its importance in computer vision, computer graphics, machine learning, and other quantitative sub-disciplines is paramount.
That said, if an intro to machine learning class is available, they will probably cover enough linear algebra and other stuff that you can get by with a basic probability class. However, for graduate study in computer science, a good understanding of all areas of math above is essential.
Beyond undergraduate math, higher-level math courses are useful for certain theoretical areas of computer science (e.g. algorithmic game theory, which intersects with economics) and especially in going beyond being a machine learning practitioner to developing new algorithms. These courses include:
Real analysis, including measure theory where you'll find that if you study probability and calculus for long enough, they converge again. Analysis is generally a useful thing to know when you start working with algorithms involving numbers.
Optimization, including linear optimization, convex optimization, gradient descent, and so on. In many cases, "learning" a machine learning model basically boils down to optimizing an objective function, and properties of this function such as whether it is convex have a big impact on how easy it is to optimize.
Numerical methods: some wouldn't consider this a math class per se, but in translating algorithms and theory into the imperfect representation of floating-point math, there are many practical problems to be solved. For example, the log-sum-exp trick.
For those who will be in "data science" and related fields, advanced statistics and especially causal inference are very important. There are a lot of things to know, mostly because having access to a lot of data tempts this problem for the uninitiated.
Combinatorics, numerical analysis, discrete mathematics, mathematical statistics, probability theory, information theory, linear algebra, lambda calculus, mathematical logic, category theory, process calculus etc.
Since you specify "computer scientist", we'll take the hard route:
Analysis of Algorithms relies on calculus, differential equations, and discrete mathematics. (Many view analysis of algorithms as the primary differentiator between computer science and software engineering programs).
Computer graphics/scientific visualization requires an engineering analysis sort of background: numerical methods, linear algebra, etc.
Computational geometry
Function approximation
Set theory, logic/first-order calculus
Probability / Statistics
the list goes on :)

What is `wholemeal` in functional programming?

Can anybody give a clear explanation? What is a wholemeal programming in functional programming area. All I've found is that wholemeal is a
focusing on entire data structures rather than their elements
but how can it be archived?
(Code examples in such languages as Scala or Ocaml are very desirable.)
"Functional languages excel at wholemeal programming, a term coined by
Geraint Jones. Wholemeal programming means to think big: work with an
entire list, rather than a sequence of elements; develop a solution
space, rather than an individual solution; imagine a graph, rather
than a single path. The wholemeal approach often offers new insights
or provides new perspectives on a given problem. It is nicely
complemented by the idea of projective programming: first solve a more
general problem, then extract the interesting bits and pieces by
transforming the general program into more specialised ones."
I also found this
it helps prevent a disease called "indexitis" and encourages lawful
program construction (from "Pearls of Functional Algorithm Design",
Richard Bird, 2010)
See also (http://www.comlab.ox.ac.uk/ralf.hinze/publications/ICFP09.pdf)
I always found the Hutton/Bird Sudoku solver a good example of wholemeal programming: http://www.cs.nott.ac.uk/~gmh/sudoku.lhs
A fair number of functional pearls (both that in Bird's excellent book that Code Monkey cites and those available here: http://www.haskell.org/haskellwiki/Research_papers/Functional_pearls) will probably also be instructive.

Representing code algebraically

I have a number of small algorithms that I would like to write up in a paper. They are relatively short, and concise. However, instead of writing them in pseudo-code (à la Cormen or even Knuth), I would like to write an algebraic representation of them (more linear and better LaTeX rendering) . However, I cannot find resources as to the best notation for this, if there is anything: e.g. how do I represent a loop? If? The addition of a tuple to a list?
Has any of you encountered this problem, and somehow solved it?
Thanks.
EDIT: Thanks, people. I think I did a poor job at phrasing the question. Here goes again, hoping I make it clearer: what is the common notation for talking about loops and if-then clauses in a mathematical notation? For instance, I can use $acc \leftarrow acc \cup \langle i,i+1 \rangle$ to represent the "add" method of a list.
Don't do this. You are deviating from what people expect to see when they read a paper about algorithms. You should follow expected practices; your ideas are more likely to get the attention that they deserve. When in Rome, do as the Romans do.
Formatting code (or pseudocode as it may be) in a LaTeXed paper is very easy. See, for example, Formatting code in LaTeX.
I see if-expressions in mathematical notation fairly often. The usual thing for a loop is a recurrence relation, or equivalently, a function defined recursively.
Here's how the Ackermann function is defined on Wikipedia, for instance:
This picture is nice because it feels mathematical in flavor and yet you could clearly type it in almost exactly as written and have an implementation. It is not always possible to achieve that.
Other mathematical notations that correspond to loops include ∑-notation for summation and set-builder notation.
I hope this answers your question! But if your aim is to describe how something is done and have someone understand, I think it is probably a mistake to assume that mathematicians would prefer to see equations. I don't think they're interchangeable tools (despite Turing equivalence). If your algorithm involves mutable data structures, procedural code is probably going to be better than equations for explaining it.
I'd copy Knuth. Few know how to communicate better than him in a computer science setting.
A symbol for general loops does not exist; usually you will use the summation operator. "if" is represented using implications, and to "add a tuple to a list" you would use union.
However, in general, a bit of verbosity is not necessarily a bad thing - sometimes, especially for complex algorithms, it is best to spell it out in plain English, using examples and diagrams. This is doubly-true for non-coders.
Think about it: when you read a math text-book on Euclid's algorithm for GCD, or the sieve of Eratosthenes, how is it written? Usually, the algorithm itself is in prose, while the proof of the algorithm is where the mathematical symbols lie.
You might take a look at Haskell. Haskell formats well in latex, has a nice algebraic syntax, and you can even compile a latex file with Haskell in it, provided the code is wrapped in \begin{code} and \end{code}. See here: http://www.haskell.org/haskellwiki/Literate_programming. There are probably literate programming tools for other languages.
Lisp started out as a mathematical notation of a computing model so that the lecturer would have a better tool than turing machines. By accident, it turns out that it can be implemented in assembly - thus lisp, the programming language was born.
But I don't think this is really what you are looking for since the computing model that lisp describes doesn't have loops: recursion is used instead. The syntax derives from algebra where braces denote evaluate-this-and-substitute-the-result. Indeed, lisp's model of computing is basically substitution - what algebra essentially is.
Indeed, most functional languages like Lisp, Haskell and Erlang are derived from mathematics. Haskell is actually a result of proving that lambda calculus can be used to implement type systems. So Haskell, like Lisp was born out of pure mathematics. But again, the syntax is not what you would probably be used to.
You can certainly explain Lisp and Haskell syntax to mathematicians and they would treat it as a "game". Language constructs like loops, recursion and conditionals can be proven out of the rules of the game rather than blindly implemented like in other languages. This would lead you into the realms of combinatronics, another branch of mathematics. Indeed, in combinatronics, even the concept of numbers can be constructed out of the rules of the game rather than being a native part of the language (google Church Numerals).
So have a look at Lisp/Scheme, Erlang and Haskell if you want. Erlang especially has syntax close to what you want:
add(a,b) -> a + b
But my recommendation is to write in C-like pseudocode. It's sort of the lowest common denominator in programming languages. Has a syntax that is fairly easy to understand and clean. And the function syntax even derives from functions in mathematics. Remember f(x)?
As a plus, mathematicians are used to writing C, statisticians are used to writing C (though generally they prefer R), physicists are used to writing C, programmers are used to at least looking at C (I know a few who've never touched C).
Actually, scratch that. You mention that your target audience are statisticians. Write in R
Something like this website describes?
APL? The only problem is that few people can read it.

Advanced Formal logic / Automata Theory textbook

I know this is more a Math/Formal Language/Automata/Computer science question than an a programming one, but I hope I can get some advice on a comprehensible textbook (not an indecipherable monograph) on formal logic beyond Propositional and Predicate Calculus. I’m especially interested in monadic second order logic and Büchi Automata.
For now, I’ve only found Automata theory and its applications by Bakhadyr Khoussainov, Anil Nerode. Automata, logics, and infinite games By Erich Grädel, Thomas Wilke (eds). And Formal Models of Communicating Systems: Languages, Automata, and Monadic Second-Order Logic Benedikt Bollig....Way over my head.
So this is the best curriculum I can come with :
For Beginners in Logic :
Peter J. Cameron, Sets, Logic and Categories, Springer, Springer Undergraduate Mathematics Series, 1999, URL.
James L. Hein, Discrete Structures, Logic, and Computability, Jones & Bartlett Publishers, 2009 (3th ed) URL.
Logic for the computer scientist.
For Beginners in Automata and Formal Langugage :
Michael Sipser, Introduction to the Theory of Computation, Course Technology, 2005 (2nd), URL.
and
Alan P. Parkes, Introduction to Languages, Machines, and Logic, Springer, 2002.
and
Peter Linz, An introduction to formal languages and automata, Jones & Bartlett Publishers, 2000 (3 ed) URL.
and
John E. Hopcroft and Jeffrey D. Ullman, Introduction to Automata Theory, Languages and Computation, Addison Wesley , 1979, (1st ed), ISBN : 0-201-02988-X; URL.
Intermediate level Logic (undergraduate):
D. Ebbinghaus , Mathematical Logic, Springer, URL.
or
Elliott Mendelson, Introduction to Mathematical Logic, URL
Advanced level (Graduate):
Wolfgang Thomas, Languages, Automata and Logic, 1996.
Leoni Libkin, Elements of Finite Model Theory, Springer, 2004, URL, TOC.
For Research
Benedikt Bolli, Formal models of communicating systems, Springer, 2006, URL.
Grädel, Erich; Thomas, Wolfgang; Wilke, Thomas (Eds.), Automata, logics, and infinite games, Springer, 2002, URL,
I've heard good things about Michael Sipser's Introduction to the Theory of Computation. I actually have it right in front of me, although I haven't started reading it yet.
You seem to have specific topic you want from a book, so I looked into the index of some books in Amazon. Although I've never read this one, Theory of Computation by Dexter C. Kozen might interest you.
Büchi automation, 155, 159, 161, 283, 298, 343
determinization, 167-170
monadic second-order theory
of n successors, 154
of successor, 154-159
The covered pages are in Lecture 25 Automata on Infinite Strings and S1S, the first page is available for preview from the link.
Theory of Computation http://ecx.images-amazon.com/images/I/51JKHJGWBRL._BO2,204,203,35,-76_AA240_SH20_OU01_.jpg
This may not be quite what you're looking for, but I learned a great deal from Blackburn et al's Modal Logic, and I learned what I know of automata from Jurafsky and Martin's Speech and Language Processing, esp. Chapter 2. If nothing else, both provide excellent groundwork for further research.
I remember reading about Büchi Automata in Principles of Model Checking, which seems like a pretty good book. Of course, the focus is on the application to model checking, but model checking is mostly logic anyway.
You're going to be a little surprised, but I think the book you're looking for is Foundations of Databases by Abiteboul, Hull and Vianu (also known as the "Alice book", because Alice is painted on its cover and stars in chapter-introduction dialogs with the authors). It's not a book about SQL, but about the theory of databases -- logic and its implementation in programs and functions -- so it spends quite a lot on issues of complexity and computability of query languages; and the authors make a great effort to be friendly and communicative.

Resources