Julian Gamble ([@juliansgamble][] on Twitter) gave his first FP-Syd talk with an introduction to simulation testing using [Datomic][].

[@juliansgamble]: http://twitter.com/juliansgamble [Datomic]: http://www.datomic.com

Plug: He’s writing a book called Clojure Recipes which is due out in January 2014.

Simulant – the subject of the talk – is a framework for Datomic database. It’s for *simulation testing*.

Many types of testing (in something resembling order of popularity):

- Unit testing
- User acceptance testing
- Performance testing
- Simulation testing

Simulation testing uses modeling and simulation to “test” systems which are too complex for linear models like unit testing. Generations of simulations:

High school solving maths problems

Stock analysts modelling and analysing companies

Analytics driven audits simulating systems for comparison.

Business scenarios predicting responses to, e.g., market crashes.

Most of these can be done on a piece of paper or on a single machine, but systems which aren’t amenable to such approaches are becoming more common.

Chris Okasaki’s book Purely Functional Data Structures popularised the use of purely functional approaches to data structures through sharing.

Datomic is “a database as a value”. Or, put another way, a database as a persistent data structure. This makes state management easier for, e.g., reproducing problems for bug fixing.

Built on pluggable storage system. Uses a Java-native store locally, can use Amazon Dynamo DB. Writing is done through a single transactor process with querying done directly from the data store.

Simulant is a framework which uses Datomic to help to distribute and scale simulation testing. Assumes that you’ll be modelling *agents* and *actions* – which are stored in the Simulant schema – and additonal model details stored in your own schema. Uses git too, to keep track of version of the simulation changing over time.

Develop a Datomic schema for your model. This will be used to record the generic details of the simulation – the actions performed by the agents – and the domain specific details.

Set the model parameters (stocks/prices, etc. or ants/food/world size)

Make statistical assertions about the system. These will be verified against the data recorded during the simulation.

There are more details to this, but they flew past and I couldn’t get them down.

Being persistent (in the “persistent data structures” sense), Datomic makes it far easier to review old data from older simulations, add additional statistical assertions, etc. without having to jump through the many and varied hoops you’d need for, e.g., a relational database.

I’m not sure how true a comparison this is, given that Datomic forces all writes to the database through the single transactor. A similar architecture with a relational database could quite easily use a single transactor to enforce timestamp consistency on data being recorded. I must be missing something.

Non-trivial system with multiple agents.

Datomic’s database as value, thing.

Where you have statistical assertions to be evaluated.

Works on the web animations specification for the W3C. Unifies SVG and CSS animations on the web.

The web animations specification defines a Javascript API which looks something like this:

```
new Animation(
document.getElementById('hello'),
[ {"left" : "200px"},
{"left" : "400px", "height" : "100px"}],
1
);
```

This talk isn’t about “generating a functional API for web animations” but he thought it was two weeks ago. He tried to generate bindings, but failed. Instead, it’s a discussion about the attempt and the result.

I think there might be animations of yak shaving involved.

There are quite a few functional languages which target Javascript and they all, in Shane’s opinion, hate the web.

The UHC Javascript backend has little documentation, claims to “compile most of Hackage” and provides an FFI to interact with “native” Javascript code.

The barrier between Haskell and Javascript is the problem. Everything on the web “platform” is exposed with APIs in Javascript. Having a UHC-JS generate a blob of HTML and CSS and Javascript stuff is pretty hard to compose with other web-ish things.

There’s a big impedance mismatch between Haskell and Javascript.

Elm is a functional reactive programming language which compiles to Javascript. Lots of documentation, an online editor, and it already has animations.

But Elm is another “replace the world” abstraction.

Roy has a much saner approach, largely just syntactice sugar around Javascript:

- Javascript functions are available
- Roy types are almost Javascript “types”

But no ADTs, etc. Because JS is pretty shitty with no recursion, etc.

So with no “good” existing languages he started his own language called krazy.

The current implementation is a PEG parser and interpreter in Javascript.

Functional types are Javascript types (lists, for example, really are Javascript arrays).

Supports ADTs, HOFs, pattern matching, etc.

JS interop “constrained” by type assertions.

Will probably add record with optional, structural typing.

Back to the web animations API.

The web animations specification has side-effect free constructors for animations, effects, timing groups, etc.

This could be exposed to library authors and used as an interface or to generate an interface automatically? I’m not sure.

Survey: who can name an NP-complete problem?

NP-complete problems can be solved by a non-deterministic machine but the solutions can be checked by a deterministic machine. In essence, they are very hard to solve but easy to check.

Circuit satisfiability can be encoded in SAT.

The SAT problem attempts to assign values to logical variables in a formula in conjunctive normal form and produces either a set of assignments (if the formula is satisfiable) or “no” (if there is no assignment).

The DPLL algorithm is pretty naive and does lots of backtracking.

The CDCL algorithm – discovered in the 90s – increased the size of viable problems to millions of variables. Instead of having to “re-learn” the same pieces of information repeatedly when backtracking, the Conflict Driven Clause Learning algorithm tracks the “cause” of a clause you learn and, when a contradiction is derived, it learns the inverse of it’s parent.

E.g.

If we reach contratiction, and the parents are \(x_{1}\), \(\neg x_{2}\), \(x_{12}\). Then we need to learn \(\neg x_{1} \vee x_{2} \vee \neg x_{12}\) as at least one of the assumptions are false, so the negation of their disjunction must hold.

Competitions - progress

Fast propagation - a modern SAT solver needs a very efficient implementation of the propagation algorithm.

Locality - solvers make decisions “near” previous decisions. Need a heuristic to find “nearby” variables for choice.

Phases - alternate between phases focussed on SAT and un-SAT phases.

Pruning - prune the database of clauses periodically to speed propagation.

Glue - Not sure what this means?

Rewriting - preprocessing the problem into an equisatisfiable problem. Make the problem “better”, works well as a first step. Useful on problems like CPUs problems.

Lots of problems have nice and/or useful SAT encodings.

NP-complete problems were, in the not too distant past, primarily useful as a polite “no” for managers. (You can’t have your cake and eat it too.)

Some solvers produce a resolution proof.

Reverse Unit Propagation of a proof is a services of clauses that can be learned by unit propagation only. The conflict clauses of a CDCL solver in the order they are learned form a RUP proof.

DRUP adds clause deletion, to speed up unit propagation.

Having useful proofs with rewriting is complex. Checking that a SAT proof for a rewritten problem is tricky; dealing with the rewriting (incorporating it into the proof and validating the rewriting is often as complex as the SAT problem itself, etc.)

Have some SMT proofs and would love to check them in HOL4 or Isabelle/HOL. Satisfiability Modulo Theories (SMT) incorporates SAT as part of it. HOL4 and Isabelle/HOL are highly trusted but very slow. Using SMT/SAT to solve a problem quickly and Isabelle/HOL to replay and verify the result should result in a fast, trusted proof.

There are SAT replay tools that do this sort of thing, but they were all pretty or extremely slow. Turns out millions of variables are hard in more traditional tools.

]]>`Int`

for example, but I don’t have any sort of intuitive understanding of what this actually means. This is probably because I haven’t done much with intuitionistic logics.
I think that I’ll start trying to get a better understanding of intuitionistic logics by reading Eleanor Donovan’s honours thesis: “Automated Proof Search in Bi-Intuitionistic Logic Using Sequent Calculi”.

]]>On the “reading” front, I purchased my copy of Advanced Topics in Types and Programming Languages (companion and somewhat successor to TAPL) this morning. I’ve had a bit of a flick through it and it looks really, *really* interesting. Hopefully having spent almost $200 on the two books will provide an added incentive to not only start, but finish, reading them and hopefully even work through the problems.

I’ve been thinking about typography and book design lately which has suggested, amongst other things, that I see if it’d be possible to get my copy of ATTAPL rebound with some extra pages. It would be nice, for example, to insert the extended version of chapter 10 - the essence of ML type inference and to “fix” any errata with updated pages. I imagine, though I haven’t bothered to investigate at all, that this’d be quite a difficult and expensive thing to do for a single copy, so it’ll probably be a long while before I do it, if ever.

Before that though, I’ve been focussed on getting through Logic by Greg Restall. I’m almost half way through and while I’d have preferred a slightly difference syntax (I prefer `∧`

as conjunction, rather than `&`

), it’s easy to read and is much more accessible than most other books I’ve seen with titles like “Logic”.

I happened to spot Logic: An Introduction on the shelf and needed to buy it. Hence, now that I’ve got a bit of money to spare, I have bought it. I expect it will be brilliant.

I’ve already read one volume from Routledge’s *Thinking In Action* series and, as previously noted I really liked it. Hopefully On The Public will be just as good.

I’ve liked some of the other books in Penguin’s *Great Ideas* series, so I hope that Conspicuous Consumption will be just as interesting.

A short survey of 30 important logicians, philosophers and mathematicians and their ‘great moments’ in logic. Well written and very accessible, anyone interested in philosophy, logic, mathematics or their history will find it worth reading.

]]>- written a parser for my logic definition language;
- solved the problem I was having with polymorphism;
- designed, in the large, my data structures; and
- thought about name for the project.

We’ve now entered the mid-year holiday between the two semesters and I am hoping to get a large amount of my implementation done during the break. On my list of things to do are:

define a state monad (to model the saturation of a branch);

define a backtracking monad (to model the branching of non-deterministic choices);

find a way to compose them (perhaps by deriving a monad transformer);

finalise the structure of the logic modules;

write a realistic (perhaps even production) parser and code generator for the logics;

learn to use hs-plugins to write dynamically loadable modules (and find a way to make logic modules dynamically loadable); and

implement some representative test logics (propositional calculus, K, intuitionistic logic, something with transitive frames, etc).

I’ve got a lot of work ahead of me, but the next few weeks are going to be fun. At the end of it, I will (I hope) have a running system to extend and improve and a much greater knowledge of Haskell.

]]>I’ve been reading Rajeev Gore’s chapter on tableau methods for modal logics for the last few days. I think I’m starting to understand the unlabelled tableau systems now, though I still don’t see why one would want to use an unlabelled tableau calculus over a labelled one, especially for mechanisation. This new-found semi-understanding makes me think that I’m going to have to re-read the Matsumoto and Mouri papers I looked at last week.

I’ve still not encountered anything about counter-model extraction in Goré yet, perhaps it was only meant to introduce me to the basics. I’m not yet sure, but since I’ve started reading these papers, I’ve developed a bit of a sinking feeling: perhaps counter-model extraction won’t be as challenging as we expect. I’d really rather not have implementation issues of the user interface aspect dominating my thesis, if at all possible. Perhaps I’ll be able to take a detour through one of the more unusual logics to demonstrate the counter-model extraction…

What ever happens, I’ve got a lot of work (and reading) ahead of me. I won’t know if it’ll all be worth it until I get my first class [finger crossed] Honours at the end of the year, but here’s hoping.

]]>This sounds like an interesting book. I’ll have to see if I can get a hold of it some how, as I don’t really want to spend $130 on a book without at least looking at it first. On the other hand, if I spend $130 on a book, perhaps I’ll bother to read it which will be an improvement.

Normally I buy books, and put them on my bookshelf, occasionally after having read a chapter or two.

]]>If anyone spots any glaring mistakes or omissions in the below, I would very much appreciate having them pointed out in the comments (as though anyone will read this).

**et alia wrote:**

Believe it or not, there’s a work of contemporary philosophy devoted to this topic: Saul Kripke’s Naming and Necessity. Anyone else here know it? If I remember correctly and follow his arguments from that work (two big ifs), it’d be girl with the same name that Daria should talk to.

Argh!–just realized this: since the hypothesis of the story is that Daria analogue opens the open, then n world Daria should open the door, i.e., the girl who looks like Quinn, etc, but is named Daria. There’s potential for “who’s on first” dialogue:

**My reply:**

The issue of trans-world identity is quite interesting philosophically and is one in which there are a lot of points of view.

I, personally, like the counterpart theory (due to Lewis), in which there are no objects that are the same from world to world. What we mean when we speak of Daria from world n is the thing that is most similar to the actual Daria (i.e. the one we thing is “real”). All the “Daria”s are equally real, and completely unrelated, except through the counterpart relation.

There are alternative views in which the Darias are all part of one trans-world object, a kind of Uber-Daria. This is called mereology (IIRC) and the various Darias are just world indexed parts of the trans-world Daria. This view is somewhat related to the idea of temporal identity ( i.e. am ‘I’ the same thing that sat here yesterday and browsed this forum?). The temporal variant is pretty much the same (just replace “world” with “time”), but also a lot stronger as a person has some form of spacial continuity between instants (i.e. I’m pretty close to where I was from one instant to the next), whereas there is no continuity between objects at different worlds.

Another view which might be taken into account is haecceity (literally, “this-ness”) in which there is some ineffable thing (a je ne sais quoi if you’ll forgive the pretension) that makes Daria-n identical to Daria-m, even if one is a person and the other a cement block. This is, needless to say, a little weird, but the whole concept of trans-world identity is a bit strange anyway.

If anyone cares to read more, I can post some references, or you can just look for books on modal logic (if you like formalisms) or the attendant philosophy of possibility (and lots of other stuff) in your local library.

**My follow-up by PM:**

First of all, I’m no expert, so you’ll have to take what I’ve said, and will say with a grain of salt. Additionally, I’m more interested in the formalisms of modal logic than the attendant philosophical issues, so I don’t pay as much attention to them than I might otherwise. I’m writing this the better part of three months after the end of my unit on modal logic. Needless to say, I’ll probably make a few mistakes.

If you’re familiar with formal logic, you might be familiar with the concept of an interpretation which assigns values to logical formulae. In propositional calculus, or PC, (ordinary two-valued logic with ‘and’, ‘or’, ‘not’, ‘implies’ and ‘equals’ and an alphabet of propositional parameters ‘p’, ‘q’, … which stand for propositions). An interpretation of PC is simply a function v [the Greek letter nu, if you can type it :-)], which is a function from logical formulae to true or false.

PC is normal everyday logic. It is simple, obvious, and to most people fairly intuitive. It also doesn’t really match the way we speak or think about a lot of things. Things like possibility and necessity (“Surely it is possible that I be Prime Minister.”), temporality (“Tomorrow, we will try to take over the world!”), belief (“If Jill knows that John is drunk, she’ll …”) and a whole bunch of other things that we talk about can’t really be encoded into PC without causing problems.

Modal logic is one approach concerned with reasoning formally about these concepts. In general, modal logic is concerned with reasoning about relational structures, like possible worlds, or instants in time, or any set of things that can be represented as a graph (or network).

The most basic interpretation of modal logic is \(<W,R,V>\), a set of Worlds, a Relation between them, and an interpretation function that is a little more complex than that for PC.

I’ll skip the whole great big raft of crap on modal operators and more than one modality here, as there are plenty of books on the subject and I wouldn’t be able to write a passingly good blurb, never mind a book.

Another form of logic for reasoning about relational structures is quantification theory (QT). The main difference between modal logic and QT, is their perspective. In modal logic, one examines the structure from the inside (e.g. from the “world n”, or “time t”, etc) whereas with QT one has a gods eye perspective (e.g. you can see all the objects, not just the ones you can reach from here).

With plain modal logic, \(W\) (the set of worlds, times, whatevers) contains the “things” with which the logic is concerned and the most we can do regarding things IN the worlds (or times, etc) is say “the cat is green” is true or not. Combining QT with modal logic however we can say things like: it is possible that, for all objects x, if x is a cat, then it is green (which would be something like:

`◇(∀x. isACat(x) -> isGreen(x))`

where the

`◇`

is a diamond modal operator and the`∀`

stands for “forall”.

This then leads to a number of logics, one of which has the interpretation

, a Domain of all objects (all the objects in all the worlds), a set of Worlds (times, etc), an accessibility relation between the members of W, and v (the truth function). Then all the mess comes in about objects being present in two worlds (if there is me in world n and me in world m, then are they two different objects in D? Are they the same object in D? If they’re the same object, how can they be in two worlds at the same time?, etc). There is LOTs of stuff about this, Lewis is a good start (a search for Lewis and modal logic will probably get you heaps), Meinongianism is an interesting perspective where there are non-existent objects like the proverbial pigs-with-wings (Routley Exploring Meinong’s Jungle and Beyond). On the other hand, modal logic is not a give and does have detractors. The only one that springs to mind is W. V. Quine. Merging QT and K (the basic modal logic) as above leads us to questions about identity between objects in different worlds. Is the Daria in canon the same person as the Daria in John? There are four approaches to this that I’m familiar with. The first is to say that there is no identity between worlds, that canon-Daria and John-dating-Daria are completely different entities. This is called extreme essentialism and one proponent is Chisholm.

The second is the counterpart theory proposed by David Lewis and explained, however briefly, in my post on the message board.

The third is haecceitism, also covered above. It is also something of a cop-out to say that “canon-Daria and John-dating-Daria are identical because they are” (in my opinion at least).

The fourth is mereology. This holds that canon-Daria and John-dating-Daria are parts of Uber-Daria, a trans-world “whole” composed of all the Darias in all the worlds. This is similar to an approach to temporal identity, as I explained previously. An interpretation of a mereological modal logic might be

where the Domain is a set of parts (the things in worlds) and the members of the set of Worlds (times, etc) are linked by a Relation. There is also a set of Functions which, given a world, return a part from D. The members of D then, are the things that exist in worlds, and the functions in F are “individuals”. That is, f (a member of F) represents Daria. At the world canon, f returns canon-Daria, which is the thing that is “Daria” at the world canon. At the world John, it returns John-dating-Daria, which is the thing that is “Daria” at the world John. There are a few philosophical approaches that result in a semantically equivalent logics, but I can’t really remember them. If you’re interested, I’d recommend seeing if your local University offers a course about modal logic, and see if you can go along. There are also a wealth of fairly good books on modal logic. If you like formalisms ( i.e. mathematical proofs, etc) “Modal Logic” a volume in the Tracts in Theoretical Computer Science series from Cambridge University Press is good as well as detailing the true generality of modal logic (the modal operators and multiple modalities mentioned above). Finally, there are a large number of resources on the web. There are lots of ’blogs by students of logic, and you should be able to find a lot of paper, most of which won’t make much sense.

Once again if anyone has any pointers to interesting material, comments or criticisms of my explanations above, please feel free (I’d like to say obliged, but you aren’t) to post comments.

Additionally, this post wouldn’t have been possible without the efforts of Dr. James Chase to endow a class of undergraduates with some little (in my case at least) understanding of modal logic during HPA292 - Logic and Philosophy.

]]>That is not to say, however, that the more theoretical approach is better or more suitable than teaching “by example”. In a course without prerequisites in mathematical reasoning, teaching modal logic by focusing on examples of its use is the most obvious, and quite probably the best, course. Without the opportunity to study modal logic in such a course, it would probably not have caught my attention and I would be in no position to be reading this book.

]]>