目前我试图让列表的使用功能来创建:OCaml中和创建列表
0 V12 V13 V14
V21 0 V23 V24
V31 V32 0 V34
V41 V42 V43 0
的方式,我发现这样做是使用论文公式:
(2*V1 - 1)*(2*V2-1) = for spot V(1,2) in the Matrix
(2*V1 - 1)*(2*V3-1) = for spot V(1,3) in the Matrix
etc
因此到目前为止,我有:
let singleState state =
if state = 0.0 then 0.0
else
((2.0 *. state) -. 1.0);;
let rec matrixState v =
match v with
| [] -> []
| hd :: [] -> v
| hd :: (nx :: _ as tl) ->
singleState hd *. singleState nx :: matrixState tl;;
我的结果出来是:
float list = [-3.; -3.; -3.; -1.]
当他们应该列出看起来名单如下:
0 -1 1 -1
-1 0 -1 1
1 -1 0 -1
-1 1 -1 0
所以,相反,它使列表是制作只有一个名单列表。我也有麻烦搞清楚如何使对角线0
的签名应该是这样的:
val singleState : float list -> float list list = <fun>
val matrixState : float list list -> float list list = <fun>
和我得到
val singleState : float -> float = <fun>
val matrixState : float list -> float list = <fun>
任何想法?
您所使用的语言为w ritten“OCaml”,大写字母O和大写字母C. http://caml.inria.fr/ocaml/index.en.html –