UHC Ruler getting started - haskell

I have just read about UHC's Ruler and would like to use it in my own project.
However, trying to compile examples from paper about it gives me a bunch of syntax error messages.
Is there any examples of rule files (which can be compiled with version from hackage - 0.4.0.0) to start with?

There are example ruler files in the demo and test folders of the github repository.
The full text of the tst4 file looks like a good minimal case:
scheme Y =
hole [ a: A, b: B | | ]
judgeshape tex a `=` b
rules y scheme Y "" =
rule y =
judge Y = a `=` b
-
judge Y = b `=` a

Related

Minizinc lazyfd solution ignores constraint

The problem is to find a schedule for some people to play golf (or whatever) in groups of a fixed size.
We have to guarantee that every player is only in one group at a time.
Here is my code:
int: gr; % number of groups
int: sz; % size of groups
int: we; % number of weeks
int: n=gr*sz; % number of players
set of int: G=1..gr; % set of group indices
set of int: P=1..n; % set of players
set of int: W=1..we; % set of weeks
% test instance
gr = 2;
sz = 2;
we = 2;
array[G,W] of var set of P: X;
%X[g,w] is the set of people that form group with index g in week w
% forall group x, |x| = sz
constraint forall (g in G, w in W)
(card (X[g,w]) = sz);
% one person cannot play in two groups simultaneously
constraint forall (g in G, w in W, p in X[g,w], g2 in (g+1..gr))
(not(p in X[g2,w]));
solve satisfy;
My problem now is that if I use the G12 lazyfd solver, i.e.
$ minizinc -b lazy this.mzn
I get
X = array2d(1..2 ,1..2 ,[1..2, 1..2, 1..2, 1..2]);
----------
which seems to ignore my second constraint.
On the other hand, using G12 without the lazy option, i.e.
$ minizinc this.mzn
yields
X = array2d(1..2 ,1..2 ,[1..2, 1..2, 3..4, 3..4]);
----------
which is correct.
G12 MIP and Gecode also give a correct result.
How is this possible? And how can I use the lazy solver such that I can rely on it? Or is it just my installation that is messed up somehow?
G12/lazyFD is known to be broken in various places. The problem is that the G12 solvers are no longer being developed and will most likely be removed from the distributions soon.
I would offer Chuffed as an alternative. Chuffed is FD solver written in C++ with lazy clause generation. It should be correct and will perform better then the G12 solver (at least when the solutions are correct).
Chuffed and other MiniZinc solvers can be found on the software page of the MiniZinc website.

How can I replace some variables in a BDD by CUDD package?

Suppose DdManager has four variables: x, y, x', y' and I have a BDD built by x and y.
Now I want to change x to x', y to y', namely, get an identical BDD built by x' and y'.
How can I get this using the CUDD package? I encountered this problem when I wanted to implement a model checking algorithm. I want to know how to implement this operation or whether I misunderstand the symbolic model checking algorithm?
Thank you very much!
You do this with the function Cudd_bddSwapVariables. It gets the following parameters:
A BDD Manager
The BDD where you want to replace variables by others.
The first array of variables (represented by the BDD nodes that also Cudd_bddNewVar would return)
The second array of variables
The number of variables being swapped.
You will need to allocate and free the arrays yourself.
Example of variable substitution using the Cython bindings to CUDD that are included in the package dd:
from dd import cudd
bdd = cudd.BDD() # instantiate a shared BDD manager
bdd.declare("x", "y", "x'", "y'")
u = bdd.add_expr(r"x \/ y") # create the BDD for the disjunction of x and y
rename = dict(x="x'", y="y'")
v = bdd.let(rename, u) # substitution of x' for x and y' for y
s = bdd.to_expr(v)
print(s) # outputs: "ite(x', TRUE, y')"
# another way to confirm that the result is as expected
v_ = bdd.add_expr(r"x' \/ y'")
assert v == v_

How can I convert PCFG in CNF for this grammar?

Given the following probabilistic context-free grammar -
1.NP -> ADJ N [0.6]
2.NP -> N [0.4]
3.N -> cat [0.2]
4.N -> dog [0.8]
what will be the CNF??
Given PCFG in CNF is given below.
1.NP -> ADJ N [0.6]
2.NP -> cat [0.08]
3.NP -> dog [0.32]
Because you need to get the same probability for the result by applying both the original and the converted set of rules (in CNF).
Be careful! You need to add keep the original rules 3 and 4 with the same probabilities in order for rule 1 to be productive

displaying trees on graphviz

I was wondering how to display my python code onto a software called graphviz. I wanted to display a binary tree which looked like this on graphviz.
1
/ \
29 4
/ \
25 2
/
5
This is the code I wrote to create the tree, I just want to know how to display this into graphviz using Dot Language.
def print_tree(tree):
if tree is not None:
print_tree(tree.get_left_subtree())
print(tree.get_value())
print_tree(tree.get_right_subtree())
dot is able to draw a graph just for edges. You can print all of your edges (it will depend of your tree implementation) and let dot do the rest.
Edit: A dot file is just like that
Graph {
a -- b -- c;
d -- e;
}
So you can use python to do:
print("Graph {")
for e in g.edges():
print(e[0], " -- ", e[1])
print("}")

Develop a context-sensitive grammar that generates the language

Can some one explain how to create a context-sensitive grammar that generates the language
L={i^n j^n k^m l^m | n,m ≥ 1}?
This is what i got so far:(I'm not sure that it's right)
S → IJ
I → iIX | iX;
J → jJl | jYl;
Xj → jX;
XY → Yk;
Y→ε.
I will appreciate if you will explain step by step, how to do it correctly or any path how to check the answer. Because I feel completely lost how to solve these problems even after reading about CFG (CSG) from the book.
Thank you.
The language definition L={i^n j^n k^m l^m | n,m ≥ 1} means a non-zero number of is followed by the same number of js as there are is, followed by a different non-zero number of ks followed by the same number of ls as there are ks.
So, start with a starting rule to generate the two independent parts of teh language:
1. S → XY
Add rules for generating 1 ij and 1 kl:
2. iXj → ij
3. kYl → kl
Add rules for generating multiple 'nested' sets:
4. X → iXj
5. Y → kYl
For example, a generation chain for iijjkkklll is:
→1 XY
→4 iXjY
→4 iiXjjY
→2 iijjY
→5 iijjkYl
→5 iijjkkYll
→5 iijjkkkYlll
→3 iijjkkklll

Resources