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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
-- Programmed by Jedidiah Barber
-- Licensed under the Sunset License v1.0
-- See license.txt for further details
with
Ada.Text_IO,
Kompsos.Math,
Kompsos.Pretty_Print;
procedure Multo is
package TIO renames Ada.Text_IO;
package InKomp is new Kompsos (Integer);
use InKomp;
package Math is new InKomp.Math (0, 1);
package Printer is new InKomp.Pretty_Print (Integer'Image);
function B
(Item : in Natural)
return Term
renames Math.Build;
function P
(Item : in Integer)
return String
renames Printer.Image;
function PV
(Item : in Term)
return String is
begin
return P (Math.Value (Item));
exception
when others =>
return Printer.Image (Item);
end PV;
procedure Test
(Multiplier, Multiplicand : in Natural)
is
Relation : Goal := Empty_Goal;
Product : constant Term := Relation.Fresh;
Result : State;
begin
Math.Multiply (Relation, B (Multiplier) & B (Multiplicand) & Product);
Result := Relation.Run;
TIO.Put_Line (P (Multiplier) & " * " & P (Multiplicand) &
" = " & PV (Product.Resolve (Result)));
end Test;
begin
TIO.Put_Line ("Multiplication");
Test (0, 1);
Test (2, 0);
Test (1, 3);
Test (5, 1);
Test (2, 7);
Test (4, 4);
Test (3, 3);
Test (10, 2);
Test (11, 4);
Test (8, 7);
Test (3, 5);
Test (6, 3);
Test (3, 6);
Test (20, 2);
Test (3, 7);
Test (14, 4);
Test (5, 8);
Test (16, 7);
Test (5, 3);
Test (6, 5);
Test (5, 6);
Test (12, 3);
Test (3, 9);
Test (6, 6);
Test (3, 12);
Test (40, 2);
Test (3, 11);
Test (6, 7);
Test (7, 6);
Test (28, 4);
Test (3, 13);
Test (10, 8);
Test (5, 16);
end Multo;
|