4

I was working on an abstract algebra library for Python, when I realized that a lot of the dirty work was just constructing loops to correspond to logical expressions with quantifiers. I then realized, while it might be hard to implement a function for logical quantification in Python, it would be easier in Haskell or another language.

Right now I have quantifiers that work as long as the property only involves one variable that is being quantified over, and only if the relation you are quantifying over has three variables, getting over these barriers seems to be the difficult part.

For example, the statement ∀x ∃y (x < y) causes problems, but ∀x (x = 2) ∃y (y < 3) is fine.

Are there any existing Haskell libraries that implement value-level logical quantifiers like this? It's difficult to search, because whenever I search something along the lines of "logical quantifiers Haskell" I get lots of things about type quantifiers, which isn't what I want.

The only thing I could find is a forAll in Test.QuickCheck, and this does not come with an "exists".

Bakuriu
  • 98,325
  • 22
  • 197
  • 231
Nathan BeDell
  • 2,263
  • 1
  • 14
  • 25
  • 2
    Interesting. Could you add a little detail about what you want to do with these constructions? I'm unclear whether you want to prove them, manipulate them, assert them, test them or some other thing. – AndrewC Aug 16 '14 at 14:26
  • what are you trying to do exactly? Do you want to *loop* over a certain value range and search for *examples* or check all values? (like Foldables all and any: http://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Foldable.html#v:all)? – Random Dev Aug 16 '14 at 14:28
  • Ultimately it should produce a Boolean value, and short-curcuit evaluation would be ideal. It should also be able to chain universal and existential operators so they work like they do mathematically, I don't know if `all` and `any` work like that. All and any work with unary predicates, but I want to be able to specify two separate variables for an `all` and `any`, then chain them together to produce a function that takes a binary predicate, and in general chain n different quantifier functions to produce one that takes an n-ary predicate. – Nathan BeDell Aug 16 '14 at 14:44
  • This is what my code looks like now, it works with relations with three variables, and uses an `Int` argument to represent which variable is being quantified over. What I *can't* do is compose quantifiers to allow n-ary predicates like `(forAll x) .* (exists y) (x < y)`, imagining `.*` to be an operator that composes two quantifiers with variable specified of arites n and m, and produces a quantifier that takes a predicate function of arity n+m. https://gist.github.com/Sintrastes/692e0dedf42373fec10a#file-gistfile1-txt – Nathan BeDell Aug 16 '14 at 14:50
  • 1
    What are the domains you are quantifying over? If you have your values in a list then `all` and `any` will work fine (nested as well). – augustss Aug 16 '14 at 17:50
  • I am quantifying over relations, which I represent as a list of tuples, for example, with two variables and using Ints for the values: [(Int,Int)], where the first part of the tuple is x, and the second part is y, how would I express "for all x there exists a y such that x > y"? – Nathan BeDell Aug 16 '14 at 18:01
  • Have you tried the `smallcheck` library? – Gabriella Gonzalez Aug 17 '14 at 05:05
  • 1
    I'm not exactly sure what features you're looking for, but if the domains are (practically) finite, a [constraint](http://labix.org/python-constraint) [programming](http://hackage.haskell.org/package/monadiccp) library might suit your needs. – phipsgabler Aug 17 '14 at 08:32

1 Answers1

0

You can write expressions of this sort and generate counterexamples using an SMT solver. Haskell has great, natural bindings to smt solvers (https://hackage.haskell.org/package/sbv for example), that let you write normal looking expressions and evaluate them under this special discipline.

That is one nice way to get what you're looking for.

sclv
  • 38,665
  • 7
  • 99
  • 204