summaryrefslogtreecommitdiff
path: root/src/polytest.ml
blob: c378279ef08d32a6502de1c7b06a2162351fb017 (plain)
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


(* Programmed by Jedidiah Barber *)
(* Licensed under the Sunset License v1.0 *)


let _ =
  let p1 = Poly.of_list Z.( [(~$1,~$2);(~$7,~$1);(~$3,~$0)] ) in
  print_string "dividend: "; Poly.print p1; print_newline ();

  let p2 = Poly.of_list Z.( [(~$1,~$1);(~$(-1),~$0)] ) in
  print_string "divisor: "; Poly.print p2; print_newline ();

  let (p3,p4) = Poly.div_rem p1 p2 in
  print_string "quotient: "; Poly.print p3; print_newline ();
  print_string "remainder: "; Poly.print p4; print_newline ();

  let p5 = Poly.add (Poly.mul p3 p2) p4 in
  print_string "reconstituted: "; Poly.print p5; print_newline ();

  print_newline ();

  let p6 = Poly.of_list Z.( [(~$(-3),~$2);(~$7,~$0)] ) in
  print_string "dividend: "; Poly.print p6; print_newline ();

  let p7 = Poly.of_list Z.( [(~$2,~$1);(~$2,~$0)] ) in
  print_string "divisor: "; Poly.print p7; print_newline ();

  let (p8,p9) = Poly.div_rem p6 p7 in
  print_string "quotient: "; Poly.print p8; print_newline ();
  print_string "remainder: "; Poly.print p9; print_newline ();

  let p10 = Poly.add (Poly.mul p8 p7) p9 in
  print_string "reconstituted: "; Poly.print p10; print_newline ();

  print_newline ();

  let p11 = Poly.of_list Z.( [(~$1,~$8);(~$(-1),~$0)] ) in
  print_string "dividend: "; Poly.print p11; print_newline ();

  let p12 = Poly.of_list Z.( [(~$1,~$1);(~$(-1),~$0)] ) in
  print_string "divisor: "; Poly.print p12; print_newline ();

  let (p13,p14) = Poly.div_rem p11 p12 in
  print_string "quotient: "; Poly.print p13; print_newline ();
  print_string "remainder: "; Poly.print p14; print_newline ();

  let p15 = Poly.add (Poly.mul p13 p12) p14 in
  print_string "reconstituted: "; Poly.print p15; print_newline ();