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
8f806526
Commit
8f806526
authored
May 07, 2020
by
AVANZINI Martin
Browse files
more examples
parent
e5de6acc
Changes
40
Hide whitespace changes
Inline
Side-by-side
app/RunTestbed.hs
View file @
8f806526
...
...
@@ -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 -name '*.imp' -o -name '*.pwhile'"
)
mempty
fps
<-
sort
.
lines
<$>
readCreateProcess
(
shell
"find examples/oopsla -type f -name '*.imp' -o -name '*.pwhile'
| sort
"
)
mempty
forM
fps
$
\
fp
->
Problem
fp
<$>
fromFile'
fp
...
...
examples/oopsla/absynth/linear/2drwalk.imp
0 → 100644
View file @
8f806526
# 2-d random walk
# d = |x| + |y|
def f():
var x, y, d, n
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/oopsla/absynth/linear/C4B_t09.imp
0 → 100644
View file @
8f806526
# t09 in C4B figure 8
def f():
var i, j, x, r
i = 1
j = 0
while j < x:
j = j + 1
if i >= 10:
i = 1
tick 40
else:
r = unif(1,3)
i = i + r
tick 1
examples/oopsla/absynth/linear/C4B_t13.imp
0 → 100644
View file @
8f806526
# t13 in C4B figure 8
def f():
var x, y, t
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/oopsla/absynth/linear/C4B_t15.imp
0 → 100644
View file @
8f806526
# t15 in C4B figure 8
def f():
var x, y, t, r
assume y >= 0
while x > y:
x = x - y
x = x - 1
t = y
while t > 0:
r = unif(0,1)
t = t - r
tick 1
tick 1
examples/oopsla/absynth/linear/C4B_t15_2.imp
0 → 100644
View file @
8f806526
# t15 in C4B figure 8
def f():
var x, y, t, r
assume y >= 0
while [y >= 0] x > y:
x = x - y
x = x - 1
t = y
while t > 0:
r = unif(0,1)
t = t - r
tick 1
tick 1
examples/oopsla/absynth/linear/C4B_t19.imp
0 → 100644
View file @
8f806526
# t19 in C4B figure 8
def f():
var i, k
while i > 100:
prob(1,1):
i = i - 1
else:
i = i - 0
tick 1
i = i + k + 50
while i >= 0:
i = i - 1
tick 1
examples/oopsla/absynth/linear/C4B_t30.imp
0 → 100644
View file @
8f806526
# t30 in C4B figure 8
def f():
var x, y, t, r
while x > 0:
r = unif(1, 3)
x = x - r
t = x
x = y
y = t
tick 1
examples/oopsla/absynth/linear/C4B_t30_2.imp
0 → 100644
View file @
8f806526
# t30 in C4B figure 8
def f():
var x, y, t, r
while [y >= -1] x > 0:
r = unif(1, 3)
x = x - r
t = x
x = y
y = t
tick 1
examples/oopsla/absynth/linear/C4B_t61.imp
0 → 100644
View file @
8f806526
# tick N = 10
def f():
var l
while l >= 8:
prob(95,5):
l = l - 8
tick 8
while l > 0:
l = l - 1
tick 1
examples/oopsla/absynth/linear/bayesian_network.imp
0 → 100644
View file @
8f806526
# Example of Bayesian Network
# Perform n iterations over the network with 5 nodes
def f():
var i, d, s, l, g
while n > 0:
i = ber(3,10)
tick 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
\ No newline at end of file
examples/oopsla/absynth/linear/ber.imp
0 → 100644
View file @
8f806526
def f():
var x, n, r
while x < n:
r = ber(1,2)
x = x + r
tick 1
examples/oopsla/absynth/linear/bin.imp
0 → 100644
View file @
8f806526
def f():
var x, n, r
x = 0
while x < n:
r = bin(10,1,2)
x = x + r
tick 1
examples/oopsla/absynth/linear/condand.imp
0 → 100644
View file @
8f806526
# mix of conjunction and disjunction conditional loop
def f():
var n, m
while n > 0 and m > 0:
prob(1,1):
n = n - 1
else:
m = m - 1
tick 1
examples/oopsla/absynth/linear/coupon.imp
0 → 100644
View file @
8f806526
# Coupon with N = 5
def f():
var i
i = 0
while i < 5:
if i = 0:
i = i + 1
else:
if i = 1:
prob(1,4):
i = 1
else:
i = i + 1
else:
if i = 2:
prob(2,3):
i = 2
else:
i = i + 1
else:
if i = 3:
prob(3,2):
i = 3
else:
i = i + 1
else:
prob(4,1):
i = 4
else:
i = i + 1
tick 1
examples/oopsla/absynth/linear/cowboy_duel.imp
0 → 100644
View file @
8f806526
# 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 a geometric distribution with p = (3/4 + 1/4*1/3) = 5/6, E(1_Head) = 6/5 = 1.2
# Alternatively, 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)
# limit of Sn = 5/6(6/5 + 6/25) = 1 + 1/5 = 1.2
# flag : 0: one is hit, otherwise 1
def f():
var flag
flag = 1
while flag > 0:
prob(3,1):
flag = 0
else:
prob(1,2):
flag = 0
else:
flag = 1
tick 1
\ No newline at end of file
examples/oopsla/absynth/linear/filling_vol.absynth
View file @
8f806526
# filling containers
def f():
var volToFill, fast, medium, slow, vol, volMeasured
, r
var volToFill, fast, medium, slow, vol, volMeasured
fast = 10
medium = 3
slow = 1
...
...
@@ -10,16 +10,12 @@ def f():
while volMeasured <= volToFill:
if volToFill < (volMeasured + fast):
r = unif(9,10)
volMeasured = volMeasured + r
volMeasured = volMeasured + unif(9,10)
else:
if volToFill < (volMeasured + medium):
r = unif(2,4)
volMeasured = volMeasured + r
volMeasured = volMeasured + unif(2,4)
else:
r = unif(0,2)
volMeasured = volMeasured + r
volMeasured = volMeasured + unif(0,2)
r = unif(0,1)
volMeasured = volMeasured + r
volMeasured = volMeasured + unif(0,1)
tick 1
examples/oopsla/absynth/linear/linear01.imp
0 → 100644
View file @
8f806526
def f():
var x
while x >= 2:
prob(1,2):
x = x - 1
else:
x = x - 2
tick 1
examples/oopsla/absynth/linear/prspeed.imp
0 → 100644
View file @
8f806526
def f():
var x, y, m, n
while x + 3 <= n:
if y < m:
prob(1,1):
y = y + 1
else:
y = y + 0
else:
prob(1,3):
x = x + 0
else:
prob(1,2):
x = x + 1
else:
prob(1,1):
x = x + 2
else:
x = x + 3
tick 1
examples/oopsla/absynth/linear/rdseql.imp
0 → 100644
View file @
8f806526
# simulate the randomization of pushing one and always popping many
def f():
var x, y
assume y >= 0
while x > 0:
x = x - 1
prob(1,3):
y = y + 1
while y > 0:
y = y - 1
tick 1
tick 2
Prev
1
2
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