-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmath.rock
386 lines (297 loc) · 10.7 KB
/
math.rock
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
(Pi constant)
Put 3.1415926535897932 into the pi
Put 2.7182818284590452 into the e
Put the pi times 2 into the tau
(Convert degrees to radians)
DegToRad takes the degrees
Give back the degrees times the tau over 360
(Convert radians to degrees)
RadToDeg takes the radian
Give back the radian times 360 over the tau
(Factorial: n!)
Factorial takes the number
Put 0 into the zero
If the number is the zero
Give back 1
If the number is less than the zero
Give back -1
Put 1 into the iterator
Put 1 into the answer
While the iterator is as little as the number
Put the iterator of the answer into the answer
Build the iterator up
Give back the answer
(Abs value)
Absolute Value takes The number
If The number is less than 0
Put The number times -1 into The number
Give back The number
Give back The number
(Is-close)
Is Close takes the a and the b
Put 0.0000000001 into the relativetolerance (to be changed to an optional argument)
Put 0 into the absolutetolerance (to be changed to an optional argument)
Put Absolute Value taking the a into the largest
If Absolute Value taking the b is greater than the largest
Put Absolute Value taking the b into the largest
Put the relativetolerance times the largest into the scalefactor
If the absolutetolerance is greater than the scalefactor
Put the absolutetolerance into the threshold
Else
Put the scalefactor into the threshold
Put the a minus the b into the difference
Put Absolute Value taking the difference into the difference
If the difference is as little as the threshold
Give back true
Else
Give back false
(Mod: a % m)
Mod takes the number and the modulo
If the number is greater than 0
While the number is as great as the modulo
Put the number minus the modulo into the number
Give back the number
If the number is less than 0
While the number is less than 0
Put the number plus the modulo into the number
Give back the number
Give back the number
(Gcd)
Gcd takes the x and the y
If Mod taking the x, 1 is not 0 or Mod taking the y, 1 is not 0
Give back "Error: the input must be two integer numbers"
Put Absolute Value taking the x into the x
Put Absolute Value taking the y into the y
If the x is 0
Give back the y
If the y is 0
Give back the x
While the x is not the y
If the x is greater than the y
Put the x minus the y into the x
Else
Put the y minus the x into the y
Give back the x
(Floor)
Floor takes the number
Put the number minus Mod taking the number, 1 into the number
Give back the number
(Ceil)
Ceil takes the number
Put -1 times the number into the number
Put -1 times Floor taking the number into the number
Give back the number
(Power: a^x)
Power takes the base and the exponent
If the exponent is less than 0
Put -1 times the exponent into the newexponent
Give back 1 over Power taking the base, the newexponent
If the exponent is 0
Give back 1
If the base is 0
Give back 0
If Mod taking the exponent, 1 is 0
Give back PowerIntegerExponent taking the base, the exponent
Else
Give back PowerRealExponent taking the base, the exponent
(PowerIntegerExponent: should rather be named PowerPositiveIntegerExponent)
PowerIntegerExponent takes the base and the exponent
Put 0 into the iterator
Put the 1 into the answer
While the iterator is smaller than the exponent (Probably can also use divide and conquer exponentiation -> e^n + e^m + ....)
Put the base times the answer into the answer
Build the iterator up
Give back the answer
(PowerRealExponent)
PowerRealExponent takes the base and the exponent
Put the exponent times LN taking the base into the argument
Give back Exp taking the argument
(Exp)
Exp takes the x
Put 666 into the prevanswer
Put 1 into the nextanswer
Put 1 into the iterator
While the iterator is less than 2000 and Is Close taking the prevanswer, the nextanswer is false
Put the nextanswer into the prevanswer
Put Power taking the x, the iterator into the numerator
Put Factorial taking the iterator into the denominator
Put the numerator over the denominator into the term
Put the prevanswer plus the term into the nextanswer
Build the iterator up
Give back the nextanswer
(Natural Logarithm, always base e)
LN takes the number
Put the number minus 1 into the top
Put the number plus 1 into the bottom
Put the top over the bottom into the x
Put 1 into the iterator
Put 0 into the answer
While the iterator is less than 10 (get reasonable starting point for Halley's method)
Put Power taking the x, the iterator into the term
Put the term over the iterator into the term
Put the answer plus the term into the answer
Build the iterator up
Build the iterator up
Put the answer times 2 into the nextanswer (end power expansion, start Halley's cubic convergence)
Put 666 into the prevanswer
Put 0 into the iterator
While the iterator is less than 2000 and Is Close taking the prevanswer, the nextanswer is false
Put the nextanswer into the prevanswer
Put the number minus Exp taking the prevanswer into the numerator
Put the number plus Exp taking the prevanswer into the denominator
Put 2 times the numerator over the denominator into the term
Put the prevanswer plus the term into the nextanswer
Build the iterator up
Give back the nextanswer
(Log with number and base)
LOG takes the number and the base
Put LN taking the number into the top
Put LN taking the base into the bottom
Give back the top over the bottom
(Square Root Function)
Square Root takes the number
Put 666 into the prevanswer
Put 0.5 times the number into the nextanswer
Put 1 into the iterator
Put 1.0 times the number into the number
While the iterator is less than 2000 and Is Close taking the prevanswer, the nextanswer is false
Put the nextanswer into the prevanswer
Put the number over the prevanswer plus the prevanswer into the term
Put 0.5 times the term into the nextanswer
Build the iterator up
Give back the nextanswer
(Sine)
Sine takes the radian
Put 1 into the iterator
Put 666 into the prevanswer
Put 0 into the nextanswer
Put 1 into the sign
While the iterator is less than 2000 and Is Close taking the prevanswer, the nextanswer is false
Put the nextanswer into the prevanswer
Put Power taking the radian, the iterator over Factorial taking the iterator into the term
Put the term times the sign into the term
Put the prevanswer plus the term into the nextanswer
Build the iterator up
Build the iterator up
Put the sign times -1 into the sign
Give back the nextanswer
(Cos)
Cos takes the radian
Put 0 into the iterator
Put 666 into the prevanswer
Put 0 into the nextanswer
Put 1 into the sign
While the iterator is less than 2000 and Is Close taking the prevanswer, the nextanswer is false
Put the nextanswer into the prevanswer
Put Power taking the radian, the iterator over Factorial taking the iterator into the term
Put the term times the sign into the term
Put the prevanswer plus the term into the nextanswer
Build the iterator up
Build the iterator up
Put the sign times -1 into the sign
Give back the nextanswer
(Tan)
Tan takes the radian
Put Sine taking the radian into the numerator
Put Cos taking the radian into the denominator
Give back the numerator over the denominator
(Arctan)
Arctan takes the number
Put 1 into the iterator
Put 666 into the prevanswer
Put 0 into the nextanswer
Put 1 into the sign
While the iterator is less than 2000 and Is Close taking the prevanswer, the nextanswer is false
Put the nextanswer into the prevanswer
Put Power taking the number, the iterator over the iterator into the term
Put the term times the sign into the term
Put the prevanswer plus the term into the nextanswer
Build the iterator up
Build the iterator up
Put the sign times -1 into the sign
Give back the nextanswer
(Arcsin)
Arcsin takes the number
Put 0 into the iterator
Put 666 into the prevanswer
Put 0 into the nextanswer
While the iterator is less than 2000 and Is Close taking the prevanswer, the nextanswer is false
Put the nextanswer into the prevanswer
Put 2 times the iterator into the placeholder
Put Factorial taking the placeholder into the numerator
Put 2 times the iterator plus 1 into the exponent
Put the numerator times Power taking the number, the exponent into the numerator
Put Power taking 4, the iterator into the firstdenominator
Put Factorial taking the iterator into the placeholder
Put Power taking the placeholder, 2 into the seconddenominator
Put 2 times the iterator plus 1 into the thirddenominator
Put the firstdenominator times the seconddenominator times the thirddenominator into the denominator
Put the numerator over the denominator into the term
Put the prevanswer plus the term into the nextanswer
Build the iterator up
Give back the nextanswer
(Arccos)
Arccos takes the number
Put the pi over 2 into the answer
Put the answer minus Arcsin taking the number into the answer
Give back the answer
(Sinh)
Sinh takes the number
Put 1 into the iterator
Put 666 into the prevanswer
Put 0 into the nextanswer
While the iterator is less than 2000 and Is Close taking the prevanswer, the nextanswer is false
Put the nextanswer into the prevanswer
Put Power taking the number, the iterator over Factorial taking the iterator into the term
Put the prevanswer plus the term into the nextanswer
Build the iterator up
Build the iterator up
Give back the nextanswer
(Cosh)
Cosh takes the number
Put 0 into the iterator
Put 666 into the prevanswer
Put 0 into the nextanswer
While the iterator is less than 2000 and Is Close taking the prevanswer, the nextanswer is false
Put the nextanswer into the prevanswer
Put Power taking the number, the iterator over Factorial taking the iterator into the term
Put the prevanswer plus the term into the nextanswer
Build the iterator up
Build the iterator up
Give back the nextanswer
(Tanh)
Tanh takes the number
Put Sinh taking the number into the numerator
Put Cosh taking the number into the denominator
Give back the numerator over the denominator
(Arcsinh)
Arcsinh takes the number
Put Power taking the number, 2 into the term
Put the term plus 1 into the term
Put the number plus Square Root taking the term into the argument
Give back LN taking the argument
(Arccosh)
Arccosh takes the number
Put Power taking the number, 2 into the term
Put the term minus 1 into the term
Put the number plus Square Root taking the term into the argument
Give back LN taking the argument
(Arctanh)
Arctanh takes the number
Put 1 plus the number into the numerator
Put 1 minus the number into the denominator
Put the numerator over the denominator into the argument
Give back LN taking the argument over 2
(Get binary from decimal)
DecToBin takes the number
If the number is as little as 1
If the number is 0
Give back "0"
Give back "1"
Put Mod taking the number, 2 into the temp
If the temp is 0
Put "0" into the temp
Else
Put "1" into the temp
Put the number over 2 into the number
Give back the temp plus DecToBin taking the number (doesn't work until we have integer division)