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
0e2fc169
Commit
0e2fc169
authored
May 08, 2020
by
AVANZINI Martin
Browse files
parameterized trader
parent
a50ffcd4
Changes
19
Hide whitespace changes
Inline
Side-by-side
examples/oopsla/bridge.imp
View file @
0e2fc169
# variation of random walk
def bridge():
var a, b, n
while a < x and x < b:
tick 1
prob(1,1):
x = x - 1
else:
x = x + 1
var a, b, x
while a < x and x < b:
tick 1
prob(1,1):
x = x - 1
else:
x = x + 1
examples/oopsla/coupons-10.imp
0 → 100644
View file @
0e2fc169
# Coupon Collector's Problem
# Upper Bound: O(n*ln n)
def collector():
var coupons, draw
coupons = 0
draw = 0
while 0 <= coupons and coupons < 10:
tick 1
draw = unif(0,10)
if draw > coupons:
coupons = coupons + 1
examples/oopsla/coupons-100.imp
0 → 100644
View file @
0e2fc169
# Coupon Collector's Problem
# Upper Bound: O(n*ln n)
def collector():
var coupons, draw
coupons = 0
draw = 0
while 0 <= coupons and coupons < 100:
tick 1
draw = unif(0,100)
if draw > coupons:
coupons = coupons + 1
examples/oopsla/coupons-50.imp
0 → 100644
View file @
0e2fc169
# Coupon Collector's Problem
# Upper Bound: O(n*ln n)
def collector():
var coupons, draw
coupons = 0
draw = 0
while 0 <= coupons and coupons < 50:
tick 1
draw = unif(0,50)
if draw > coupons:
coupons = coupons + 1
examples/oopsla/coupons-N.pwhile
0 → 100644
View file @
0e2fc169
# Coupon Collector's Problem
# Upper Bound: O(n*ln n)
def collector():
var coupons, draw, N
coupons = 0
while 0 <= coupons and coupons < N:
tick 1
# draw = unif(0,N-1)
draw = rand(N)
draw = draw + 1
if draw > coupons:
coupons = coupons + 1
examples/oopsla/coupons.imp
deleted
100644 → 0
View file @
a50ffcd4
# Coupon Collector's Problem
# Upper Bound: O(n*ln n)
def collector():
var coupons, draw, N
coupons = 0
while 0 <= coupons and coupons < N:
tick 1
# draw = unif(0,N-1)
draw = rand(N)
draw = draw + 1
if draw > coupons:
coupons = coupons + 1
examples/oopsla/trader-10.absynth
0 → 100644
View file @
0e2fc169
# Variation of linear/trader.imp
def trader():
var price, min, nShares, tick_z
while price > min and min >= 0:
prob (1,3):
price = price + 1
else:
price = price - 1
nShares = unif(0,10)
while nShares > 0:
nShares = nShares - 1
tick_z = tick_z + price
examples/oopsla/trader-10.
imp
→
examples/oopsla/trader-10.
pwhile
View file @
0e2fc169
File moved
examples/oopsla/trader-100.absynth
0 → 100644
View file @
0e2fc169
# Variation of linear/trader.imp
def trader():
var price, min, nShares, tick_z
while price > min and min >= 0:
prob (1,3):
price = price + 1
else:
price = price - 1
nShares = unif(0,100)
while nShares > 0:
nShares = nShares - 1
tick_z = tick_z + price
examples/oopsla/trader-100.
imp
→
examples/oopsla/trader-100.
pwhile
View file @
0e2fc169
File moved
examples/oopsla/trader-1000.absynth
0 → 100644
View file @
0e2fc169
# Variation of linear/trader.imp
def trader():
var price, min, nShares, tick_z
while price > min and min >= 0:
prob (1,3):
price = price + 1
else:
price = price - 1
nShares = unif(0,500)
while nShares > 0:
nShares = nShares - 1
tick_z = tick_z + price
examples/oopsla/trader-1000.
imp
→
examples/oopsla/trader-1000.
pwhile
View file @
0e2fc169
File moved
examples/oopsla/trader-50.absynth
0 → 100644
View file @
0e2fc169
# Variation of linear/trader.imp
def trader():
var price, min, nShares, tick_z
while price > min and min >= 0:
prob (1,3):
price = price + 1
else:
price = price - 1
nShares = unif(0,50)
while nShares > 0:
nShares = nShares - 1
tick_z = tick_z + price
examples/oopsla/trader-
10000.imp
→
examples/oopsla/trader-
50.pwhile
View file @
0e2fc169
...
...
@@ -8,7 +8,7 @@ def trader():
else:
price = price - 1
nShares = unif(0,
1000
0)
nShares = unif(0,
5
0)
while nShares > 0:
nShares = nShares - 1
...
...
examples/oopsla/trader-500.absynth
0 → 100644
View file @
0e2fc169
# Variation of linear/trader.imp
def trader():
var price, min, nShares, tick_z
while price > min and min >= 0:
prob (1,3):
price = price + 1
else:
price = price - 1
nShares = unif(0,500)
while nShares > 0:
nShares = nShares - 1
tick_z = tick_z + price
examples/oopsla/trader-
100000.imp
→
examples/oopsla/trader-
500.pwhile
View file @
0e2fc169
...
...
@@ -8,7 +8,7 @@ def trader():
else:
price = price - 1
nShares = unif(0,
1000
00)
nShares = unif(0,
5
00)
while nShares > 0:
nShares = nShares - 1
...
...
examples/oopsla/trader-N.pwhile
0 → 100644
View file @
0e2fc169
# Variation of linear/trader.imp
def trader():
var price, min, nShares, maxShares
while price > min and min >= 0:
prob (1,3):
price = price + 1
else:
price = price - 1
nShares = rand(maxShares)
while nShares > 0:
nShares = nShares - 1
tick price
pwhile.cabal
View file @
0e2fc169
...
...
@@ -14,8 +14,8 @@ extra-source-files:
Flag Debug
Description: Enable debug support
Manual:
Fals
e
Default:
Fals
e
Manual:
Tru
e
Default:
Tru
e
library
hs-source-dirs: src
...
...
src/Data/PWhile/CostExpression.hs
View file @
0e2fc169
...
...
@@ -231,15 +231,15 @@ norms c = S.fromList [n | GNorm _ _ n <- gNorms c]
-- pretty printers
instance
PP
.
Pretty
Norm
where
pretty
(
Norm
_
e
)
=
PP
.
underline
(
PP
.
pretty
e
)
pretty
(
Norm
_
e
)
=
PP
.
text
"<"
PP
.<>
PP
.
pretty
e
PP
.<>
PP
.
text
">"
-- pretty (Norm g e) = PP.brackets (PP.hang 0 (PP.pretty e PP.</> PP.text "|" PP.<+> PP.pretty g))
instance
(
PP
.
Pretty
c
,
Eq
c
,
Num
c
)
=>
PP
.
Pretty
(
CExp
c
)
where
pretty
=
pp
id
where
pp
_
(
N
0
_
)
=
PP
.
text
"0"
pp
par
(
N
1
n
)
=
par
(
ppNorm
n
)
pp
_
(
N
1
n
)
=
PP
.
pretty
n
pp
_
(
N
k
(
Norm
_
1
))
=
PP
.
pretty
k
pp
_
(
N
k
n
)
=
PP
.
pretty
k
PP
.<>
PP
.
text
"·"
PP
.<>
PP
.
p
a
re
ns
(
ppNorm
n
)
pp
_
(
N
k
n
)
=
PP
.
pretty
k
PP
.<>
PP
.
text
"·"
PP
.<>
PP
.
pre
tty
n
pp
par
(
Div
c
e
)
=
par
(
infx
(
pp
id
c
)
"/"
(
PP
.
pretty
e
))
pp
par
(
Plus
c
d
)
=
par
(
infx
(
pp
id
c
)
"+"
(
pp
id
d
))
pp
_
(
Sup
c
d
)
=
ppFun
"sup"
[
PP
.
pretty
c
,
PP
.
pretty
d
]
...
...
@@ -248,7 +248,6 @@ instance (PP.Pretty c, Eq c, Num c) => PP.Pretty (CExp c) where
|
otherwise
=
PP
.
text
"ite"
PP
.<>
PP
.
tupled
[
PP
.
pretty
g
,
pp
id
c
,
pp
id
d
]
ppFun
f
ls
=
PP
.
text
f
PP
.<>
PP
.
tupled
ls
infx
l
s
r
=
PP
.
hang
1
(
l
PP
.</>
PP
.
text
s
PP
.<+>
r
)
ppNorm
(
Norm
_
e
)
=
PP
.
pretty
e
instance
(
PP
.
Pretty
c
,
Eq
c
,
Ord
c
,
Num
c
)
=>
PP
.
Pretty
(
GNorm
c
)
where
...
...
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