Skip to content

Commit

Permalink
Shorten the Lutin example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erwan Jahier authored and pyrmont committed Aug 2, 2019
1 parent 8eaae46 commit 837ed67
Showing 1 changed file with 4 additions and 59 deletions.
63 changes: 4 additions & 59 deletions lib/rouge/demos/lutin
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
-- The examples provided in [SIES'13] "Engineering Functional
-- Some of the examples provided in [SIES'13] "Engineering Functional
-- Requirements of Reactive Systems using Synchronous Languages"

node gen_x_v1() returns (x:real) = loop 0.0<x and x<42.0

node gen_x_v2() returns (x:real) =
loop { 0.0<x and x<42.0 fby loop [20] x = pre x }

node gen_x_v3() returns (target:real; x:real=0.0) =
run target := gen_x_v2() in
loop { x = (pre x + target) / 2.0 }

let inertia=0.6
node gen_x_v2() returns (x:real) = loop { 0.0<x and x<42.0 fby loop [20] x = pre x }

node gen_x_v4() returns (target:real; x:real=0.0) =
run target := gen_x_v2() in
Expand All @@ -20,65 +12,18 @@ node gen_x_v4() returns (target:real; x:real=0.0) =
x = (px+target) / 2.0+inertia*(px-ppx)
}

let Between(x, min, max : real) : bool = ((min < x) and (x < max))
node between (min, max : real) returns (x:real) =
loop ((min < x) and (x < max))

-- saw-tooth curves
let Between(x, min, max : real) : bool = ((min < x) and (x < max))

node up(init, delta:real) returns( x : real) =
x = init fby loop { Between(x, pre x, pre x + delta) }

node down(init, delta:real) returns( x : real) =
x = init fby loop { Between(x, pre x - delta, pre x) }

node up_and_down1(min, max, delta : real) returns (x : real) =
node up_and_down(min, max, delta : real) returns (x : real) =
Between(x, min, max)
fby
loop {
| run x := up(pre x, delta) in loop { x < max }
| run x := down(pre x, delta) in loop { x > min }
}

-- Similar to up and down, except that the min, max, and delta are
-- chosen randomly at each round
node up_and_down2_old(min, max, delta : real) returns (x : real) =
Between(x, min, max)
fby
loop
exist lmin, lmax,ldelta : real in
run lmin := between(min, pre x) in
run lmax := between(pre x, max) in
run ldelta := between(0., delta) in
{
| run x := up(pre x, ldelta) in loop { x < lmax }
| run x := down(pre x, ldelta) in loop { x > lmin }
}
node up_down(min, max, delta : real) returns (x : real) =
Between(x, min, max)
fby
loop
exist lmin, lmax,ldelta : real in
run lmin := between(min, pre x) in
run lmax := between(pre x, max) in
run ldelta := between(0., delta) in
run x := up_and_down1(lmin, lmax, ldelta)

node up_and_down(min, max, delta:real) returns (x:real) =
Between(x, min, max)
fby
loop
exist lmin, lmax, ldelta : real in
run lmin := between(min, pre x) in
run lmax := between(pre x, max) in
run ldelta := between(0., delta) in
{
| run x := up(pre x, ldelta) in loop { x < lmax }
| run x := down(pre x, ldelta) in loop { x > lmin }
}






0 comments on commit 837ed67

Please sign in to comment.