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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
#+title: RPN calculator for multi-precision finite arithmetic
* Task[fn:1]
Create a calculator for multi-precision finite arithmetic <Z_i; +, *>
(8 digits) for four operations (+, -, *, ÷) based on single-precision
finite arithmetic, where the "+1" rule is defined and the properties
of commutativity (+, *), associativity (+, *), and distributivity of *
over + are satisfied; an additive identity "a" and a multiplicative
identity "b" are defined; and the following property holds: for (∀x)
x*a=a. Additionally, you can implement exponentiation, as well as the
search for GCD and LCM for two numbers.
#+caption: The "+1" rule
#+attr_html: :style margin: auto;
| x | = | a | b | c | d | e | f | g | h |
| x + b | = | b | d | h | c | f | a | e | g |
* Documentation
The exported report can be found at [[https://git.michalec.dev/uni/term-03/discrete-math/coursework/report.pdf][this link]].
* Showcase
#+begin_src text
> jsadh
[-] ERROR: input doesn't match regexp `^\s*([+-][a-h]{1,8}|nop|dup|del|clr|swp|neg|add|mul|sub|div|mod|inc|dec|pow|gcd|lcm)\s*$'
> nop
> +f
f
>
f
f
> dup
f
f
f
> add
f
be
> sub
-f
> neg
f
> -a
f
a
> div
[*] INFO: division by zero
[*] INFO: operation resulted in empty set
> +a
a
>
a
a
> div
[*] INFO: dividing zero by zero
[*] INFO: operation result is a range: [-ffffffff; ffffffff]
> +ffffffff
ffffffff
>
ffffffff
ffffffff
> mul
[-] ERROR: operation has overflown
> +ghf
ghf
> -fe
ghf
-fe
> mod
eb
> +ghf
eb
ghf
> -fe
eb
ghf
-fe
> div
eb
-g
> -fe
eb
-g
-fe
> mul
eb
hee
> add
ghf
> inc
gga
>
ggb
>
ggd
>
ggc
> dec
ggd
>
ggb
>
gga
> del
>
[*] INFO: stack is already empty
> clr
[*] INFO: stack is already empty
> +d
d
> +h
d
h
> pow
da
> del
> +e
e
> +h
e
h
> gcd
d
> +c
d
c
> lcm
e
> +f
e
f
> swp
f
e
> clr
> ^Cinterrupt
#+end_src
* Unlicense
#+include: UNLICENSE verse
* Footnotes
[fn:1] Original text:
#+html: <i>
#+begin_quote
Сформировать калькулятор «большой» конечной арифметики <Z_i; +, *> (8
разрядов) для четырех действий (+, -, *, ÷)= на основе «малой»
конечной арифметики, где задано правило «+1» и выполняются свойства
коммутативности (+, *), ассоциативности (+, *), дистрибутивности *
относительно +, заданы аддитивная единица «a» и мультипликативная
единица «b», а также выполняется свойство: для (∀х) х*a=a.
Дополнительно можно реализовать возведение в степень, поиск НОД и НОК
для двух чисел.
#+caption: Правило «+1»:
#+attr_html: :style margin: auto;
| x | = | a | b | c | d | e | f | g | h |
| x + b | = | b | d | h | c | f | a | e | g |
#+end_quote
#+html: </i>
|