Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AVANZINI Martin
ecoimp
Commits
e5de6acc
Commit
e5de6acc
authored
May 07, 2020
by
AVANZINI Martin
Browse files
oopsla testbed
parent
32c49299
Changes
135
Hide whitespace changes
Inline
Side-by-side
app/RunTestbed.hs
View file @
e5de6acc
...
...
@@ -203,7 +203,7 @@ pldi = unsafePerformIO $ Benchmark "pldi" <$> do
{-# NOINLINE oopsla #-}
oopsla
::
Benchmark
oopsla
=
unsafePerformIO
$
Benchmark
"oopsla"
<$>
do
fps
<-
sort
.
lines
<$>
readCreateProcess
(
shell
"find examples/oopsla -type f"
)
mempty
fps
<-
sort
.
lines
<$>
readCreateProcess
(
shell
"find examples/oopsla -type f
-name '*.imp' -o -name '*.pwhile'
"
)
mempty
forM
fps
$
\
fp
->
Problem
fp
<$>
fromFile'
fp
...
...
examples/absynth/complex.imp
deleted
100644 → 0
View file @
32c49299
# A complex expected polynomial bound program.
# It involves sequential and nested loops,
# different types of probabilistic commands,
# and multiplication
def f():
var x, y, w, N, M, z
assume M >= 0 and y >= 0:
x = 0
while x < N:
z = unif(0,3)
x = x + (z - 1)
y = y + 3*M
# y = y + bin(3,1,2)
while y > 0:
while w > 0:
w = w - 1
tick 1
prob(2,1):
y = y - 1
else:
y = y + 1
tick 1
examples/absynth/linear/2drwalk.imp
deleted
100644 → 0
View file @
32c49299
# 2-d random walk
# d = |x| + |y|
def f():
var x, y, d, n, z
while d < n:
if x > 0:
if y > 0:
prob(1,3):
x = x + 2
d = d + 2
else:
prob(1,2):
y = y + 2
d = d + 2
else:
prob(1,1):
x = x - 1
d = d - 1
else:
y = y - 1
d = d - 1
else:
if y < 0:
prob(1,3):
x = x + 2
d = d + 2
else:
prob(1,2):
y = y + 1
d = d - 1
else:
prob(1,1):
x = x - 1
d = d - 1
else:
y = y - 2
d = d + 2
else:
prob(1,3):
x = x + 2
d = d + 2
else:
prob(1,2):
y = y + 1
d = d + 1
else:
prob(1,1):
x = x - 1
d = d - 1
else:
y = y - 1
d = d + 1
else:
if x < 0:
if y > 0:
prob(1,3):
x = x + 1
d = d - 1
else:
prob(1,2):
y = y + 2
d = d + 2
else:
prob(1,1):
x = x - 2
d = d + 2
else:
y = y - 1
d = d - 1
else:
if y < 0:
prob(1,3):
x = x + 1
d = d - 1
else:
prob(1,2):
y = y + 1
d = d - 1
else:
prob(1,1):
x = x - 2
d = d + 2
else:
y = y - 2
d = d + 2
else:
prob(1,3):
x = x + 1
d = d - 1
else:
prob(1,2):
y = y + 1
d = d + 1
else:
prob(1,1):
x = x - 2
d = d + 2
else:
y = y - 1
d = d + 1
else:
if y > 0:
prob(1,3):
x = x + 1
d = d + 1
else:
prob(1,2):
y = y + 2
d = d + 2
else:
prob(1,1):
x = x - 1
d = d + 1
else:
y = y - 1
d = d - 1
else:
if y < 0:
prob(1,3):
x = x + 1
d = d + 1
else:
prob(1,2):
y = y + 1
d = d - 1
else:
prob(1,1):
x = x - 1
d = d + 1
else:
y = y - 2
d = d + 2
else:
prob(1,3):
x = x + 1
d = d + 1
else:
prob(1,2):
y = y + 1
d = d + 1
else:
prob(1,1):
x = x - 1
d = d + 1
else:
y = y - 1
d = d + 1
tick 1
examples/absynth/linear/C4B_t09.imp
deleted
100644 → 0
View file @
32c49299
# t09 in C4B figure 8
def f():
var i, j, x, z
i = 1
j = 0
while j < x:
j = j + 1
if i >= 4:
i = 1
tick 40
else:
z = unif(1,3)
i = i + z
tick 1
examples/absynth/linear/C4B_t13.imp
deleted
100644 → 0
View file @
32c49299
# t13 in C4B figure 8
def f():
var x, y, t, z
assume y >= 0:
while x > 0:
x = x - 1
prob(1, 3):
y = y + 1
else:
while y > 0:
y = y - 1
tick 1
tick 1
examples/absynth/linear/C4B_t15.imp
deleted
100644 → 0
View file @
32c49299
# t15 in C4B figure 8
def f():
var x, y, t, z
assume y >= 0:
while x > y:
x = x - y
x = x - 1
t = y
while t > 0:
z = unif(1,2)
t = t - z
tick 1
tick 1
examples/absynth/linear/C4B_t15_2.imp
deleted
100644 → 0
View file @
32c49299
# t15 in C4B figure 8
def f():
var x, y, t, z
assume y >= 0:
while [x >= 0 and y >= 0] x > y:
x = x - y
x = x - 1
t = y
while t > 0:
z = unif(1,2)
t = t - z
tick 1
tick 1
examples/absynth/linear/C4B_t19.imp
deleted
100644 → 0
View file @
32c49299
# t19 in C4B figure 8
def f():
var i, k, z
while i > 100:
prob(1,1):
i = i - 1
else:
i = i - 0
tick 1
i = i + k
i = i + 50
while i >= 0:
i = i - 1
tick 1
examples/absynth/linear/C4B_t30.imp
deleted
100644 → 0
View file @
32c49299
# t30 in C4B figure 8
def f():
var x, y, t, z
while x > 0:
z = unif(1,2)
x = x - z
t = x
x = y
y = t
tick 1
examples/absynth/linear/C4B_t30_2.imp
deleted
100644 → 0
View file @
32c49299
# t30 in C4B figure 8
def f():
var x, y, t, z
while [y >= -1] x > 0:
z = unif(1,2)
x = x - z
t = x
x = y
y = t
tick 1
examples/absynth/linear/C4B_t61.imp
deleted
100644 → 0
View file @
32c49299
# tick N = 10
def f():
var l, z
while l >= 8:
z = unif(6,8)
l = l - z
tick 10
while l > 0:
l = l - 1
tick 1
examples/absynth/linear/bayesian_network.imp
deleted
100644 → 0
View file @
32c49299
# Example of Bayesian Network
# Perform n iterations over the network with 5 nodes
def f():
var i, d, s, l, g, z
while n > 0:
i = ber(3,10)
z = z + 1
d = ber(2,5)
tick 1
if i < 1 and d < 1:
g = ber(7,10)
tick 1
else:
if i < 1 and d > 0:
g = ber(19,20)
tick 1
else:
if i > 0 and d < 1:
g = ber(1,10)
tick 1
else:
g = ber(1,2)
tick 1
if i < 1:
s = ber(1,20)
tick 1
else:
s = ber(4,5)
tick 1
if g < 1:
l = ber(1,10)
tick 1
else:
l = ber(3,5)
tick 1
n = n - 1
examples/absynth/linear/ber.imp
deleted
100644 → 0
View file @
32c49299
def f():
var x, n, z
while x < n:
z = ber(1,2)
x = x + z
tick 1
examples/absynth/linear/condand.imp
deleted
100644 → 0
View file @
32c49299
# conjunction conditional loop
def f():
var n, m, z
while n > 0 and m > 0:
prob(1,1):
n = n - 1
else:
m = m - 1
tick 1
examples/absynth/linear/coupon.imp
deleted
100644 → 0
View file @
32c49299
# Coupon with N = 5
def f():
var i, z
i = 0
while i < 5:
if i >= 0 and 0 >= i:
i = i + 1
else:
if i >= 1 and 1 >= i:
prob(1,4):
i = 1
else:
i = i + 1
else:
if i >= 2 and 2 >= i:
prob(2,3):
i = 2
else:
i = i + 1
else:
if i >= 3 and 3 >= i:
prob(3,2):
i = 3
else:
i = i + 1
else:
prob(4,1):
i = 4
else:
i = i + 1
tick 1
examples/absynth/linear/cowboy_duel.imp
deleted
100644 → 0
View file @
32c49299
# The duel cowboys
# The probability A hits B is p_a = 3/4
# The probability B hits A is p_b = 1/3
# The duel ends when one hits the other
# A shoots first
# Compute the expected number of turns that the duel will end
# Exact answer, it is geometric distribution with p = 5/6, E(1_Head) = 6/5 = 1.2
# 1.(3/4 + 1/4.1/3) + 2.(1/4.2/3.3/4 + 1/4.2/3.1/4.1/3) ....
# = 1.5/6 + 2.(5/6^2) + 3.(5/6^3) + ... + n.(5/6^n)
# Arithmetic-geometric sequence a = 1, b = 5/6, d = 1, r = 1/6
# t_n = [1 + (n-1).1].5/6.(1/6)^(n-1)
# lim Sn = 5/6(6/5 + 6/25) = 1 + 1/5 = 1.2
# flag : 0: one is hit, otherwise 1
def f():
var flag, z
flag = 1
while flag > 0:
prob(3,1):
flag = 0
else:
prob(1,2):
flag = 0
else:
flag = 1
tick 1
examples/absynth/linear/filling_vol.imp
deleted
100644 → 0
View file @
32c49299
# filling containers
def f():
var volToFill, fast, medium, slow, vol, volMeasured, z
fast = 10
medium = 3
slow = 1
volMeasured = 0
z = unif(0,1)
volMeasured = volMeasured + z
while volMeasured <= volToFill:
if volToFill < (volMeasured + fast):
z = unif(9,10)
volMeasured = volMeasured + z
else:
if volToFill < (volMeasured + medium):
z = unif(2,4)
volMeasured = volMeasured + z
else:
z = unif(0,2)
volMeasured = volMeasured + z
z = unif(0,1)
volMeasured = volMeasured + z
tick 1
examples/absynth/linear/geo.imp
deleted
100644 → 0
View file @
32c49299
# Truncated geometric distribution
def f():
var c, z
c = 1
while c > 0:
prob(1, 1):
c = 0
tick 1
else:
c = 1
tick 1
tick 2
tick 1
examples/absynth/linear/linear01.imp
deleted
100644 → 0
View file @
32c49299
def f():
var x, z
while x >= 2:
prob(1,2):
x = x - 1
else:
x = x - 2
tick 1
examples/absynth/linear/no_loop.imp
deleted
100644 → 0
View file @
32c49299
# this is a simple probabilistic program without loops.
# 3, 5, and 7 resource units are consumed with the same probability 1/3.
# Thus the expected resource usage is 1/3*3 + 1/3*5 + 1/3*7 = 5
def f():
var flag, z
prob(1,2):
flag = 0
tick 3
else:
prob(1,1):
flag = 1
tick 5
else:
flag = 1
tick 7
Prev
1
2
3
4
5
…
7
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment