let rec v_add v1 v2 = match v1 with
|Vec (size1, vec1) ->
(
match v2 with
|Vec (size2, vec2) ->
if size1 = size2 then
make_vector size1 (fun i -> v_add (vec1 i) (vec2 i))
else raise (Value_operation "vector size not matched.")
|Zero -> v1
|_ -> raise (Value_operation "Vector_Scalar vec1 +~ sca2")
)
|N i1 ->
(
match v2 with
|N i2 -> normalize (return_N (i1 + i2))
|R f2 -> normalize (return_R ((float_of_int i1) +. f2))
|Vec (size2, vec2) -> raise (Value_operation "Vector_Scalar i1 +~ vec2")
|Zero -> v1
|W -> fail
)
|R f1 ->
(
match v2 with
|N i2 -> normalize (return_R (f1 +. (float_of_int i2)))
|R f2 -> normalize (return_R (f1 +. f2))
|Vec (size2, vec2) -> raise (Value_operation "Vector_Scalar f1 +~ vec2")
|Zero -> v1
|W -> fail
)
|Zero -> v2
|W ->
(
match v2 with
|N i2 -> fail
|R f2 -> fail
|Vec (size2, vec2) -> raise (Value_operation "Vector_Scalar W +~ vec2")
|Zero -> v1
|W -> fail
)