interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / scripts / allen / science / math-admit.om

234 lines · 4784 bytes Raw Blame History
1note Pure Omega mathematical-expression admission, protocol v1.
2note stdin at most 4096 bytes; stdout untouched; exit 0 admit, 2 refuse, 3 IO.
3note Every name and quoted unit is allowlisted. No context/assignment/escape/effect symbols.
4note Native host IO only. Bounded lexical gate; aien-math owns expression grammar.
5text symbols "Abs|ArcCos|ArcSin|ArcTan|Cos|Sin|Tan|Cosh|Sinh|Tanh|Exp|Log|Sqrt|Power|Rational|Complex|N|D|Integrate|NIntegrate|Limit|Series|Normal|Sum|Product|Solve|Reduce|Simplify|FullSimplify|Expand|Factor|Together|Apart|Cancel|Numerator|Denominator|Coefficient|CoefficientList|Collect|Det|Inverse|Transpose|Eigenvalues|Eigenvectors|MatrixRank|RowReduce|LinearSolve|Dot|IdentityMatrix|DiagonalMatrix|Tr|EigenSystem|Eigensystem|DSolve|DSolveValue|NDSolve|Mean|Median|Variance|StandardDeviation|Covariance|Correlation|PDF|CDF|Quantile|NormalDistribution|BinomialDistribution|PoissonDistribution|Gamma|Beta|Erf|Erfc|Factorial|Binomial|GCD|LCM|Mod|Min|Max|Floor|Ceiling|Round|Sign|Re|Im|Conjugate|Chop|Length|Total|Range|Table|List|Plus|Times|Equal|Less|Greater|LessEqual|GreaterEqual|And|Or|Not|True|False|Pi|E|I|Infinity|DirectedInfinity|Assumptions|GenerateConditions|ConditionalExpression|SingularValueList|MatrixExp|First|HermiteH|C|Quantity|QuantityMagnitude|QuantityUnit|UnitConvert|UnitSimplify|Probability|Expectation|Zeta|SeriesData|Distributed|x|y|z|t|a|b|c|d|f|g|h|k|m|n|p|q|r|s|u|v|w|"
6text units "Kilograms|SpeedOfLight|Joules|GravitationalConstant|SolarMass|Kilometers|Parsecs|LightYears|ReducedPlanckConstant|Meters|Seconds|Kelvins|Celsius|Fahrenheit|Radians|Degrees|Moles|Amperes|Candelas|Newtons|Pascals|Watts|Hertz|MetersPerSecond|SIBase|"
7text dist "\\[Distributed]"
8global inp uchar 4097
9global stk uchar 32
10global total ulong 1
11global level ulong 1
12
13fn alpha c uchar to bool
14ret or and ge c 65 le c 90 and ge c 97 le c 122
15end
16
17fn insym start ulong size ulong to bool
18p = ulong 0
19matched = ulong 0
20while lt p len symbols bound 4096
21c = get symbols p
22if eq c 124
23if eq matched size
24ret true
25end
26matched = 0
27else
28if lt matched size
29if eq c get inp add start matched
30matched = add matched 1
31else
32matched = 4096
33end
34else
35matched = 4096
36end
37end
38p = add p 1
39end
40ret false
41end
42
43fn inunit start ulong size ulong to bool
44p = ulong 0
45matched = ulong 0
46while lt p len units bound 4096
47c = get units p
48if eq c 124
49if eq matched size
50ret true
51end
52matched = 0
53else
54if lt matched size
55if eq c get inp add start matched
56matched = add matched 1
57else
58matched = 4096
59end
60else
61matched = 4096
62end
63end
64p = add p 1
65end
66ret false
67end
68
69fn pairat p ulong a uchar b uchar to bool
70if ge add p 1 get total 0
71ret false
72end
73ret and eq get inp p a eq get inp add p 1 b
74end
75
76fn brackets c uchar to bool
77n = get level 0
78if or eq c 91 or eq c 123 eq c 40
79if ge n 32
80ret false
81end
82put stk n c
83put level 0 add n 1
84ret true
85end
86if or eq c 93 or eq c 125 eq c 41
87if eq n 0
88ret false
89end
90n = sub n 1
91want = uchar 40
92if eq c 93
93want = 91
94end
95if eq c 125
96want = 123
97end
98if ne get stk n want
99ret false
100end
101put level 0 n
102end
103ret true
104end
105
106fn safechr p ulong to bool
107c = get inp p
108if or eq c 32 or eq c 9 or eq c 10 eq c 13
109ret true
110end
111if and ge c 48 le c 57
112ret true
113end
114if eq c 61
115if pairat p 61 61
116ret true
117end
118if gt p 0
119prev = get inp sub p 1
120if or eq prev 61 or eq prev 60 eq prev 62
121ret true
122end
123end
124ret false
125end
126if or pairat p 47 47 or pairat p 47 42 or pairat p 42 47 or pairat p 40 42 pairat p 42 41
127ret false
128end
129if eq c 44
130if eq get level 0 0
131ret false
132end
133end
134if or pairat p 43 43 pairat p 45 45
135ret false
136end
137if or eq c 91 or eq c 93 or eq c 123 or eq c 125 or eq c 40 eq c 41
138ret brackets c
139end
140if or eq c 43 or eq c 45 or eq c 42 eq c 47
141ret true
142end
143if or eq c 94 or eq c 46 eq c 44
144ret true
145end
146ret or eq c 60 or eq c 62 eq c 39
147end
148
149fn scan to bool
150p = ulong 0
151seen = false
152while lt p get total 0 bound 4096
153c = get inp p
154if alpha c
155start = p
156while lt p get total 0 bound 4096
157if not alpha get inp p
158break
159end
160p = add p 1
161end
162if not insym start sub p start
163ret false
164end
165seen = true
166else
167if eq c 34
168p = add p 1
169start = p
170while lt p get total 0 bound 4096
171if not alpha get inp p
172break
173end
174p = add p 1
175end
176if ge p get total 0
177ret false
178end
179if ne get inp p 34
180ret false
181end
182if not inunit start sub p start
183ret false
184end
185p = add p 1
186seen = true
187else
188if eq c 92
189if gt len dist sub get total 0 p
190ret false
191end
192for i ulong len dist
193if ne get inp add p i get dist i
194ret false
195end
196end
197p = add p len dist
198seen = true
199else
200if not safechr p
201ret false
202end
203if and ge c 48 le c 57
204seen = true
205end
206p = add p 1
207end
208end
209end
210end
211ret and seen eq get level 0 0
212end
213
214fn main to int
215n = ulong 0
216while lt n len inp bound 4097
217r = read 0 inp n sub len inp n
218if lt r 0
219ret 3
220end
221if eq r 0
222break
223end
224n = add n ulong r
225end
226if or eq n 0 gt n 4096
227ret 2
228end
229put total 0 n
230if scan
231ret 0
232end
233ret 2
234end