chore: update
This commit is contained in:
parent
4776edc9db
commit
416d97c513
25 changed files with 1653 additions and 283 deletions
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
let dt = 0.001
|
||||
let dt = 0.01
|
||||
let g = 9.81
|
||||
|
||||
let node f_integr (x0, x') = x where
|
||||
17
exm/ball/dune
Normal file
17
exm/ball/dune
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(env
|
||||
(dev
|
||||
(flags
|
||||
(:standard -w -a))))
|
||||
|
||||
(rule
|
||||
(targets exm_ball.ml ball.ml ball.zci)
|
||||
(deps
|
||||
(:zl ball.zls)
|
||||
(package zelus))
|
||||
(action
|
||||
(run zeluc -s main -o exm_ball %{zl})))
|
||||
|
||||
(executable
|
||||
(name exm_ball)
|
||||
(public_name exm_ball)
|
||||
(libraries zelus))
|
||||
18
exm/ballc/ball.zls
Normal file
18
exm/ballc/ball.zls
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
let g = 9.81
|
||||
let p0 = 5.0
|
||||
let v0 = 0.0
|
||||
|
||||
let hybrid ball () = (p, z) where
|
||||
rec der p = v init p0 reset z -> 0.0
|
||||
and der v = -. g init v0 reset z -> -0.8 *. (last v)
|
||||
and z = up (-. p)
|
||||
|
||||
let hybrid main () =
|
||||
let der t = 1.0 init 0.0 in
|
||||
let rec der p = 1.0 init -0.01 reset q -> -0.01
|
||||
and q = up (last p) in
|
||||
let (b, z) = ball () in
|
||||
present q | z -> (
|
||||
print_float t; print_string "\t";
|
||||
print_float b; print_newline ()
|
||||
); ()
|
||||
16
exm/ballc/dune
Normal file
16
exm/ballc/dune
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
(env
|
||||
(dev
|
||||
(flags
|
||||
(:standard -w -a))))
|
||||
|
||||
(rule
|
||||
(targets ball.ml main.ml ball.zci)
|
||||
(deps
|
||||
(:zl ball.zls))
|
||||
(action
|
||||
(run zeluc -s main %{zl})))
|
||||
|
||||
(executable
|
||||
(public_name ballc.exe)
|
||||
(name main)
|
||||
(libraries hsim))
|
||||
10
exm/ballc/ztypes.ml
Normal file
10
exm/ballc/ztypes.ml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
include Hsim
|
||||
include Ztypes
|
||||
|
||||
module type IGNORE = sig end
|
||||
module Defaultsolver : IGNORE = struct end
|
||||
|
||||
module Zlsrun = struct
|
||||
module Make (S : IGNORE) = Runtime
|
||||
end
|
||||
17
exm/dune
17
exm/dune
|
|
@ -1,17 +0,0 @@
|
|||
(env
|
||||
(dev
|
||||
(flags
|
||||
(:standard -w -a))))
|
||||
|
||||
(rule
|
||||
(targets exm_ball_discrete.ml ball_discrete.ml ball_discrete.zci)
|
||||
(deps
|
||||
(:zl ball_discrete.zls)
|
||||
(package zelus))
|
||||
(action
|
||||
(run zeluc -s main -o exm_ball_discrete %{zl})))
|
||||
|
||||
(executable
|
||||
(name exm_ball_discrete)
|
||||
(public_name exm_ball_discrete)
|
||||
(libraries zelus))
|
||||
17
exm/fib/dune
Normal file
17
exm/fib/dune
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(env
|
||||
(dev
|
||||
(flags
|
||||
(:standard -w -a))))
|
||||
|
||||
(rule
|
||||
(targets exm_fib.ml fib.ml fib.zci)
|
||||
(deps
|
||||
(:zl fib.zls)
|
||||
(package zelus))
|
||||
(action
|
||||
(run zeluc -s main -o exm_fib %{zl})))
|
||||
|
||||
(executable
|
||||
(name exm_fib)
|
||||
(public_name exm_fib)
|
||||
(libraries zelus))
|
||||
7
exm/fib/fib.zls
Normal file
7
exm/fib/fib.zls
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
let node fib () = n where
|
||||
rec n = 0 -> pre (1 -> (pre n) + n)
|
||||
|
||||
let node main () =
|
||||
let f = fib () in
|
||||
print_int f; print_newline ()
|
||||
130
exm/main.zls
130
exm/main.zls
|
|
@ -1,9 +1,26 @@
|
|||
|
||||
|
||||
|
||||
(** Zélus
|
||||
|
||||
Synchronous language kernel _à la_ Lustre:
|
||||
|
||||
|
||||
(** Zélus: Hybrid system programming language
|
||||
|
||||
- Model discrete systems and their continuous environment
|
||||
- Research language, design space for hybrid system modelers
|
||||
- Compilation to OCaml, execution with an off-the-shelf ODE solver
|
||||
- Developed by the Inria PARKAS team *)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(** Synchronous language kernel _à la_ Lustre:
|
||||
- programs are Mealy machines (outputs on each transition)
|
||||
- variables represent streams of values in time *)
|
||||
|
||||
|
|
@ -18,21 +35,22 @@ let node incr x = y where
|
|||
|
||||
|
||||
|
||||
|
||||
(** - we can use values of the previous instants (using [pre]) and
|
||||
initialize streams (using [->]) *)
|
||||
(** - we can use values of the previous instants with [pre] and
|
||||
initialize streams with [->] *)
|
||||
|
||||
let node accumulate x = z where
|
||||
rec w = pre x
|
||||
and y = 0 -> pre x
|
||||
and z = x -> (pre z) + x
|
||||
rec z = x -> (pre z) + x
|
||||
|
||||
(* x │ 1 2 5 2 5 3 …
|
||||
───┼─────────────────────
|
||||
w │ 1 2 5 2 5 …
|
||||
y │ 0 1 2 5 2 5 …
|
||||
z │ 1 3 8 10 15 18 … *)
|
||||
(* x │ 1 2 5 2 5 3 …
|
||||
──────────────┼─────────────────────
|
||||
pre x │ 1 2 5 2 5 …
|
||||
0 -> x │ 0 2 5 2 5 3 …
|
||||
accumulate x │ 1 3 8 10 15 18 … *)
|
||||
|
||||
let node fib () = n where
|
||||
rec n = 0 -> pre (1 -> pre(n) + n)
|
||||
|
||||
(** - causality loops are forbidden ([rec x = x]) *)
|
||||
|
||||
|
||||
(** - we can reset streams at will *)
|
||||
|
|
@ -53,12 +71,32 @@ let node loop x = y where
|
|||
loop x │ 0 1 2 0 1 2 … *)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(** Math/physics reminder!
|
||||
|
||||
- Ordinary differential equations (ODEs), initial value problems
|
||||
- Zero-crossing event basics
|
||||
- Background on solvers *)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(** Already able to model physical behaviours! *)
|
||||
|
||||
let dt = 0.001 (* Integration step *)
|
||||
let dt = 0.01 (* Integration step *)
|
||||
let g = 9.81 (* Gravitational constant *)
|
||||
let node f_integr (x0, x') = x where (* Forward Euler integrator *)
|
||||
rec x = x0 -> pre (x +. x' *. dt)
|
||||
|
||||
let node b_integr (x0, x') = x where (* Backward Euler integrator *)
|
||||
rec x = x0 -> (pre x) +. x' *. dt
|
||||
|
||||
|
|
@ -68,7 +106,21 @@ let node bouncing_ball (p0, v0) = p where
|
|||
and q = p0 -> 0.0 and w = v0 -> -0.8 *. (pre v)
|
||||
and z = false -> (pre p) < 0.0
|
||||
|
||||
(** Quite cumbersome. *)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(** Cumbersome, and error-prone! *)
|
||||
|
||||
let node sincos () = (sin, cos) where
|
||||
rec sin = f_integr(0.0, cos)
|
||||
and cos = f_integr(1.0, -. sin)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -81,6 +133,9 @@ let node bouncing_ball (p0, v0) = p where
|
|||
let hybrid integr (x0, x') = x where
|
||||
der x = x' init x0
|
||||
|
||||
let hybrid time () = t where
|
||||
der t = 1.0 init 0.0
|
||||
|
||||
let hybrid position (p0, v0, a) = p where
|
||||
rec der p = v init p0
|
||||
and der v = a init v0
|
||||
|
|
@ -89,33 +144,28 @@ let hybrid position (p0, v0, a) = p where
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(** We can intermingle discrete and continuous behaviours: *)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(** We can now express physical systems much more precisely: *)
|
||||
(** - mix discrete and continuous code with [up], [present], [reset]
|
||||
and [last] *)
|
||||
|
||||
let hybrid bouncing_ball (p0, v0) = p where
|
||||
rec der p = v init p0 reset z -> 0.0
|
||||
and der v = -. g init v0 reset z -> -0.8 *. last v
|
||||
and z = up(-. p)
|
||||
|
||||
let hybrid time_bounces (p0, v0) = (p, b) where
|
||||
rec p = bouncing_ball (p0, v0)
|
||||
and der t = 1.0 init 0.0
|
||||
and init b = 0.0
|
||||
and present up(-. p) -> do
|
||||
b = t -. last b
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(** - w FIXME e can mix discrete and continuous behaviours *)
|
||||
|
|
|
|||
17
exm/sincos/dune
Normal file
17
exm/sincos/dune
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(env
|
||||
(dev
|
||||
(flags
|
||||
(:standard -w -a))))
|
||||
|
||||
(rule
|
||||
(targets exm_sincos.ml sincos.ml sincos.zci)
|
||||
(deps
|
||||
(:zl sincos.zls)
|
||||
(package zelus))
|
||||
(action
|
||||
(run zeluc -s main -o exm_sincos %{zl})))
|
||||
|
||||
(executable
|
||||
(name exm_sincos)
|
||||
(public_name exm_sincos)
|
||||
(libraries zelus))
|
||||
21
exm/sincos/sincos.zls
Normal file
21
exm/sincos/sincos.zls
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
let dt = 0.001 (* Integration step *)
|
||||
|
||||
let node f_integr (x0, x') = x where (* Forward Euler integrator *)
|
||||
rec x = x0 -> pre (x +. x' *. dt)
|
||||
let node b_integr (x0, x') = x where (* Backward Euler integrator *)
|
||||
rec x = x0 -> (pre x) +. x' *. dt
|
||||
|
||||
let node sincos () = (sin, cos) where
|
||||
rec sin = f_integr(0.0, cos)
|
||||
and cos = b_integr(1.0, -. sin)
|
||||
|
||||
let node main () =
|
||||
let rec t = 0.0 -> pre t +. dt in
|
||||
let (sin, cos) = sincos () in
|
||||
match t <= 500.0 with
|
||||
| true ->
|
||||
(print_float t; print_string "\t";
|
||||
print_float sin; print_string "\t";
|
||||
print_float cos; print_newline ())
|
||||
| false -> ()
|
||||
Loading…
Add table
Add a link
Reference in a new issue