1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
type grid =
{rows: int; columns: int}
type mat_expr =
| Mat of grid
| MatUnary of (grid -> grid option) * mat_expr
| MatBinary of (grid -> grid -> grid option) * mat_expr * mat_expr
let mat_id g = Some g (* négation, puissance, scalaire *)
let mat_trans g = Some {rows=g.columns;columns=g.rows}
let mat_sum g1 g2 = if g1 = g2 then Some g1 else None
let mat_product g1 g2 = Some {rows=g1.rows;columns=g2.columns}
let mat_tensorial g1 g2 = Some g1
let rec mat_size mat_expr =
match mat_expr with
| Mat g ->
Some g
| MatUnary(f,m) ->
( match mat_size m with
| Some g -> f g
| None -> None )
| MatBinary(f,m1,m2) ->
( match mat_size m1,mat_size m2 with
| Some g1,Some g2 -> f g1 g2
| None,_ -> None
| _,None -> None ) |