package farith

  1. Overview
  2. Docs

Source file BinInt.ml

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 1 "extracted/BinInt.ml"

module Z =
 struct
  type t = Farith_Big.big_int

  (** val pow :
      Farith_Big.big_int -> Farith_Big.big_int -> Farith_Big.big_int **)

  let pow x y =
    Farith_Big.z_case
      (fun _ -> Farith_Big.one)
      (fun p -> Farith_Big.pow_pos x p)
      (fun _ -> Farith_Big.zero)
      y

  (** val to_nat : Farith_Big.big_int -> Farith_Big.big_int **)

  let to_nat z =
    Farith_Big.z_case
      (fun _ -> Farith_Big.zero)
      (fun p -> Farith_Big.identity p)
      (fun _ -> Farith_Big.zero)
      z

  (** val to_pos : Farith_Big.big_int -> Farith_Big.big_int **)

  let to_pos z =
    Farith_Big.z_case
      (fun _ -> Farith_Big.one)
      (fun p -> p)
      (fun _ -> Farith_Big.one)
      z

  (** val pos_div_eucl :
      Farith_Big.big_int -> Farith_Big.big_int ->
      Farith_Big.big_int * Farith_Big.big_int **)

  let rec pos_div_eucl a b =
    Farith_Big.positive_case
      (fun a' ->
      let (q, r) = pos_div_eucl a' b in
      let r' =
        Farith_Big.add (Farith_Big.mult (Farith_Big.double Farith_Big.one) r)
          Farith_Big.one
      in
      if Farith_Big.lt r' b
      then ((Farith_Big.mult (Farith_Big.double Farith_Big.one) q), r')
      else ((Farith_Big.add
              (Farith_Big.mult (Farith_Big.double Farith_Big.one) q)
              Farith_Big.one), (Farith_Big.sub r' b)))
      (fun a' ->
      let (q, r) = pos_div_eucl a' b in
      let r' = Farith_Big.mult (Farith_Big.double Farith_Big.one) r in
      if Farith_Big.lt r' b
      then ((Farith_Big.mult (Farith_Big.double Farith_Big.one) q), r')
      else ((Farith_Big.add
              (Farith_Big.mult (Farith_Big.double Farith_Big.one) q)
              Farith_Big.one), (Farith_Big.sub r' b)))
      (fun _ ->
      if Farith_Big.le (Farith_Big.double Farith_Big.one) b
      then (Farith_Big.zero, Farith_Big.one)
      else (Farith_Big.one, Farith_Big.zero))
      a

  (** val even : Farith_Big.big_int -> bool **)

  let even z =
    Farith_Big.z_case
      (fun _ -> true)
      (fun p ->
      Farith_Big.positive_case
        (fun _ -> false)
        (fun _ -> true)
        (fun _ -> false)
        p)
      (fun p ->
      Farith_Big.positive_case
        (fun _ -> false)
        (fun _ -> true)
        (fun _ -> false)
        p)
      z
 end
OCaml

Innovation. Community. Security.