Skip to content

[question] how to see the formula that gets sent to the solver? #2259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jwaldmann opened this issue Jan 25, 2024 · 4 comments
Closed

[question] how to see the formula that gets sent to the solver? #2259

jwaldmann opened this issue Jan 25, 2024 · 4 comments

Comments

@jwaldmann
Copy link

I want to show liquid Haskell as an application of constraint programming. You are using QF_UFLRA?

Is there an easy way to see the actual formula that gets sent to the backend solver? (and the answer). I guess I could put a fake z3 executable in my PATH that does some extra printing but I was hoping there is something more direct.

@ranjitjhala
Copy link
Member

Hi @jwaldmann -- yes, there is an easy way:

  • if you run LH on some source file path/to/file.hs
  • then LH generates the SMT queries in path/to/.liquid/file.hs.smt2

So you can see the generated SMT queries in the latter file.

I should say though, that the latter is not terribly readable, owing to the various intermediate layers of abstractions introduced by GHC, the liquid type checking and the SMT translation!

If you like you may be interested in this stripped down version of LH

https://github.com/ranjitjhala/sprite-lang

which uses many of the same ideas, but where you can look at the constraints more easily, both as

  1. The "Horn Constraints" generated by refinement type checking, and
  2. The "SMTLIB" queries generated to solve the horn constraints (1).

@jwaldmann
Copy link
Author

interesting! yes I only need small examples, readability is good. I can build and run "sprite".

@facundominguez
Copy link
Collaborator

@jwaldmann, is this issue good to close?

@jwaldmann
Copy link
Author

jwaldmann commented Feb 6, 2024

Yeah it's fine. I just copy here a code snippet buried in another issue #2261 (comment) that shows how to call the constraint solver directly:

cat tests/neg/.liquid/Fail.hs.smt2 |sed -e 's/Str/String/g' -e 's/strLen/str.len/g' | z3 /dev/stdin 
unsat
sat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants