整数型模型n

发布于 2024-09-29 03:08:03 字数 127 浏览 0 评论 0原文

我正在开发一个模块,其中涉及一组自然 数字。因此,我需要对一些整数类型的 n 进行建模。我怎样才能 去做吧?

例如。从 1 开始连续递增的 i 序列的 i 之和 = n(n+1)/2

我如何在这里建模 n ?

I am working on a module which involves a set of natural
numbers. As a result I need to model some n of type integer. How can I
go about it?

Eg. sum of i for continuously increasing sequence of i starting at 1 =
n(n+1)/2

How can I model n here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窗影残 2024-10-06 03:08:03

要求是我们应该能够使用 n 作为整数。我想我明白了。

type element_i = N of nativeint | CNN of nativeint * nativeint
(* element_i can be an integer or a*n+b represented as (a,b))

let to_string_i e = 
  match e with 
  | N z   -> "%d" z 
  | CNN c -> " (%d xn + %d) " (fst c) (snd c)

let plus_i a b =
  match (a, b) with 
  | (N a1, N b1)   -> N (a1 + b1)
  | (N a1, CNN b1) -> CNN (fst b1, (snd b1) + a1)
  | (CNN a1, N b1) -> CNN (fst a1, (snd a1) + b1)

let times_i a b = 
  match (a, b) with 
  | (N a1, N b1)  -> N (a1 * b1)
  | (N a1,CNN b1) -> CNN ((fst b1) * a1, (snd b1) * a1)
  | (CNN a1,N b1) -> CNN ((fst a1) * b1, (snd a1) * b1)

The requirements are that we should be able to use n as an integer. I think I figured it out.

type element_i = N of nativeint | CNN of nativeint * nativeint
(* element_i can be an integer or a*n+b represented as (a,b))

let to_string_i e = 
  match e with 
  | N z   -> "%d" z 
  | CNN c -> " (%d xn + %d) " (fst c) (snd c)

let plus_i a b =
  match (a, b) with 
  | (N a1, N b1)   -> N (a1 + b1)
  | (N a1, CNN b1) -> CNN (fst b1, (snd b1) + a1)
  | (CNN a1, N b1) -> CNN (fst a1, (snd a1) + b1)

let times_i a b = 
  match (a, b) with 
  | (N a1, N b1)  -> N (a1 * b1)
  | (N a1,CNN b1) -> CNN ((fst b1) * a1, (snd b1) * a1)
  | (CNN a1,N b1) -> CNN ((fst a1) * b1, (snd a1) * b1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文