My Popper page
Here is a collection of my Popper encodings.
Popper is an inductive logic programming (ILP) system. For more about Popper, see github.com/logic-and-learning-lab/Popper and the paper Learning programs by learning from failures by Andrew Cropper and Rolf Morel.
My Popper encodings
Many of these encoding are ports from Metagol, Progol, the old Popper version, etc. Note that some of them might not be of general interest. My Popper page at Github: github.com/hakank/hakank/tree/master/popper.
Most programs are run like this:
$ popper3 popper.py --timeout 999999 problem_directory
The links below are to a directory which contains three files (all are needed to run Popper):
-
exs.pl
: File including the positive and negative examples of the predicate.
-
bk.pl
: File including the background knowledge (BK), i.e. the Prolog predicates that can be used.
-
bias.pl
: Includes the bias, such as
- maximum number of variables, body predicates, and clauses. This file includes some info about the problem.
- if predicate invention should be used (
enable_pi
)
- which predicates to use in the head and body
- type of the arguments of the predicates (not needed but might boost performance)
- direction (in/out) of the predicates (not needed but might boost performance)
f(A,B) :- last(A,C),cons(C,A,B).
adjacent_to_red
Program found in 0.25s:
target(A) :- edge(A,B),colour(B,C),red(C).
append
Program found in 18s:
target(A,B,C):- eq(B,C),empty(A).
target(A,B,C):- tail(C,D),target(D,B,A).
arch
Program found in 0.2s:
arch(A,B,C) :- supports(B,A),not_touches(B,C).
book2
Program found in 0.2s:
book(A,B,C,D) :- editor(A,D),author(A,B),title(A,C).
book3
Program found in 0.3s:
book(A,B):- list3(B,E,D,C),editor(A,C),title(A,D),author(A,E).
clpfd_test Testing SWI-Prolog's clpfd
package to find (global)
constraints given some examples. This program usees my SWI Prolog utils module
hakank_utils.pl
Program found in 0.7s:
target(A,B,C):- exactly(A,B,C).
constants1_b using "named constants"
Program found in 0.2s:
p(A,B) :- const(B),const1(A).
p(A,B) :- const2(A),const2(B).
p(A,B) :- const(B),const4(A).
cyclic
Program found in 0.9s:
cyclic(A) :- arc(A,B,C),path(A,C,B).
cyclic-pi (Testing `enable_pi` but another non-PI solution is found.)
Program found in 0.5s:
cyclic(A) :- arc(A,B,C),arc(A,C,B).
cyclic(A) :- arc(A,B,C),arc(A,D,B),arc(A,C,D).
droplast
Program found in 1.3s:
f(A,B) :- tail(A,B).
f(A,B) :- head(A,D),tail(A,E),f(E,C),cons(D,C,B).
even
Program found in 0.2s:
f(A) :- zero(A).
f(A) :- succ(B,A),succ(C,B),f(C).
evs
Program found in 2.8s:
evs(A) :- empty(A).
evs(A) :- head(A,B),even(B),tail(A,D),tail(D,E),head(D,C),odd(C),evs(E).
facebook_puzzle
Solving this puzzle:
1 + 4 = 5
2 + 5 = 12
3 + 6 = 21
5 + 8 = ??
Program found in 1.7s:
f(A,B,C):- mult(A,B,D),plus(A,D,C).
facebook_puzzle2
Solving this puzzle (alternative version):
1 + 4 = 5
2 + 5 = 12
3 + 6 = 21
5 + 8 = ??
Program found in 1.0s:
f(A,B,C,D,E,F):-plus(E,D,G),plus(C,G,F).
find_duplicates
Program found in 1.3s:
f(A,B) :- tail(A,C),head(A,B),element(C,B).
f(A,B) :- tail(A,C),f(C,B).
find_last
Program found in 0.2s:
find_last(A,B) :- my_head(A,B),my_tail(A,C),empty(C).
find_last(A,B) :- my_tail(A,C),find_last(C,B).
float_test Just a simple test of using floats
Program found in 0.2s:
target(A,B,C):- times(A,B,C).
grammar1
Program found in 13.0s:
s(A,B) :- np(D,B),np(A,C),vp(C,D).
graph_coloring
Program found in 0.25s:
target(A) :- edge(A,B),colour(B,C),colour(A,C)
graph_connectedness
Program found in 0.2s:
target(A) :- edge(A,B),colour(A,C),colour(B,C).
graph_reachability
Program found in 0.2s:
p(A,B) :- edge(A,B).
p(A,B) :- edge(A,C),p(C,B).
last
Program found in 7.8s:
last(A,B) :- head(B,A),not_empty(B).
last(A,B) :- tail(B,C),last(A,C).
leap_year
Program found in 1.5s:
leapyear(A) :- divisible(A,B),known_divider400(B).
leapyear(A) :- divisible(A,C),known_divider4(C),not_divisible(A,B),known_divider100(B).
length
Program found in 1.1s:
f(A,B) :- empty(A),zero(B).
f(A,B) :- tail(A,D),f(D,C),succ(C,B).
less_than
Program found in 1.3s:
target(A,B) :- succ(A,B).
target(A,B) :- succ(A,C),target(C,B).
member
Program found in 0.5s:
mem(A,B) :- head(B,A).
mem(A,B) :- tail(B,C),mem(A,C).
mutual_recursion
Program found in 1.6s:
even(A):- zero(A).
even(A):- s(A,B),s(B,C),even(C).
nextto
Program found in 0.3s:
nextto(A,B,C):- tail(C,D),head(C,A),head(D,B).
nextto(A,B,C):- tail(C,D),nextto(A,B,D).
nextto2
Program found in 0.3s:
nexttox(A,B,C):- diff1(D,E),nth1x(D,C,A),nth1x(E,C,B).
Alternative variant (using diff/3
instead of code1
):
Program found in 0.9s:
nexttox(A,B,C):- const1(D),diff(D,E,F),nth1x(F,C,A),nth1x(E,C,B).
nim
Program found in 0.3s:
won(A,B,C) :- move(B,C),divisible(C,D),num4(D),side(A).
predecessor
Program found in 0.2s:
target(A,B) :- succ(A,B).
primorial (Kind of OK)
Program found in 0.7s:
primorial(A):- const2(A).
primorial(A):- div3(A),div2(A).
relatedness Note: inv1
is an invented predicate
Program found in 4.0s:
target(A,B) :- inv1(B,C),inv1(A,C).
inv1(A,B) :- parent(A,B).
inv1(A,B) :- parent(C,A),inv1(C,B).
son
Program found in 0.2s:
target(A,B) :- father(B,C),brother(A,C).
strings1
Program found in 43.9s:
f(A,B):- copy1(B,A).
f(A,B):- copy1(A,C),f(B,C).
f(A,B):- skip1(A,C),f(B,C).
sum
Program found in 0.3s:
f(A,B) :- empty(A),zero(B).
f(A,B) :- cons(D,C,A),f(C,E),sum(D,E,B).
trains
Program found in 0.3s:
e(A) :- has_car(A,B),closed(B),short(B).
undirected_edge
Program found in 0.2s:
target(A,B) :- edge(B,A).
target(A,B) :- edge(A,B).
truthtable1
Program found in 0.5s:
f(A,B):-pand(C,A).
f(A,B):-pfalse(B).
truthtable2
Program found in 0.6s:
f(A,B,C):-ptrue(A).
f(A,B,C):-pnot(C),por(C,B).
number_puzzle1
Solving this puzzle:
2 3 10
7 2 63
6 5 66
8 4 96
9 7 ?
Program found in 1.1s:
f(A,B,C):- plus(B,A,D),mult(D,A,C).
pickover_puzzle1_cp
Puzzle from Pickover https://twitter.com/pickover/status/1504602497280786435:
What number should replaced the question mark?
3 9 8
44 32 75
8 4 7 2 7 ?
Program found in 2.1s:
f(A,B,C,D):- plus(B,A,E),mult(E,D,C).
boyles_law
Finding Boyle's law: PV = P*V
Since it's float variables, we use approximate variants of add,minus,mult,div.
Program found in 0.3s:
f(A,B,C):- approx_div(C,B,A).
equation
Solving this puzzle:
11x11=4
22x22=16
33x33=?
Program found in 12.0s (i.e. E = 36)
f(A,B,C,D,E):- plus(A,B,G),plus(D,C,F),mult(G,F,E).
equation2
Solving this puzzle:
11x11=4
22x22=16
33x33=?
But we disallow the found solution in `equation`
Program found in 3.5s (i.e. E = 64)
f(A,B,C,D,E):- const4(F),pow(F,A,E).
MagicPopper
MagicPopper is an extension of Popper which can handle "magic constants" . The plan is probably to integrate MagicPopper into Popper.
Here are some problems encoded in MagicPopper:
p(1,B):- num(B).
p(4,4):- num(4).
p(2,2):- num(2).
leap_year
Program found in 5.9s
leapyear(A):- divisible(A,16).
leapyear(A):- not_divisible(A,25),divisible(A,4).
nim
Program found in 0.4s
won(A,B,C):- side(A),move(B,C),divisible(C,4).
sequence_induction
Program found in 2.5s
f(A,B):- num(C),num(B),minus(C,B,A),plus(C,A,7).
strings2
Program found in 7.6s
f(A,B):- write1(A,B,d),empty(B).
f(A,B):- copy1(A,D),skip1(D,C),f(C,B).
Back to my homepage
Created by Hakan Kjellerstrand (hakank@gmail.com)