aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / scripts / allen / science / math-admit.om
| 1 | note Pure Omega mathematical-expression admission, protocol v1. |
| 2 | note stdin at most 4096 bytes; stdout untouched; exit 0 admit, 2 refuse, 3 IO. |
| 3 | note Every name and quoted unit is allowlisted. No context/assignment/escape/effect symbols. |
| 4 | note Native host IO only. Bounded lexical gate; aien-math owns expression grammar. |
| 5 | text 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|" |
| 6 | text 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|" |
| 7 | text dist "\\[Distributed]" |
| 8 | global inp uchar 4097 |
| 9 | global stk uchar 32 |
| 10 | global total ulong 1 |
| 11 | global level ulong 1 |
| 12 | |
| 13 | fn alpha c uchar to bool |
| 14 | ret or and ge c 65 le c 90 and ge c 97 le c 122 |
| 15 | end |
| 16 | |
| 17 | fn insym start ulong size ulong to bool |
| 18 | p = ulong 0 |
| 19 | matched = ulong 0 |
| 20 | while lt p len symbols bound 4096 |
| 21 | c = get symbols p |
| 22 | if eq c 124 |
| 23 | if eq matched size |
| 24 | ret true |
| 25 | end |
| 26 | matched = 0 |
| 27 | else |
| 28 | if lt matched size |
| 29 | if eq c get inp add start matched |
| 30 | matched = add matched 1 |
| 31 | else |
| 32 | matched = 4096 |
| 33 | end |
| 34 | else |
| 35 | matched = 4096 |
| 36 | end |
| 37 | end |
| 38 | p = add p 1 |
| 39 | end |
| 40 | ret false |
| 41 | end |
| 42 | |
| 43 | fn inunit start ulong size ulong to bool |
| 44 | p = ulong 0 |
| 45 | matched = ulong 0 |
| 46 | while lt p len units bound 4096 |
| 47 | c = get units p |
| 48 | if eq c 124 |
| 49 | if eq matched size |
| 50 | ret true |
| 51 | end |
| 52 | matched = 0 |
| 53 | else |
| 54 | if lt matched size |
| 55 | if eq c get inp add start matched |
| 56 | matched = add matched 1 |
| 57 | else |
| 58 | matched = 4096 |
| 59 | end |
| 60 | else |
| 61 | matched = 4096 |
| 62 | end |
| 63 | end |
| 64 | p = add p 1 |
| 65 | end |
| 66 | ret false |
| 67 | end |
| 68 | |
| 69 | fn pairat p ulong a uchar b uchar to bool |
| 70 | if ge add p 1 get total 0 |
| 71 | ret false |
| 72 | end |
| 73 | ret and eq get inp p a eq get inp add p 1 b |
| 74 | end |
| 75 | |
| 76 | fn brackets c uchar to bool |
| 77 | n = get level 0 |
| 78 | if or eq c 91 or eq c 123 eq c 40 |
| 79 | if ge n 32 |
| 80 | ret false |
| 81 | end |
| 82 | put stk n c |
| 83 | put level 0 add n 1 |
| 84 | ret true |
| 85 | end |
| 86 | if or eq c 93 or eq c 125 eq c 41 |
| 87 | if eq n 0 |
| 88 | ret false |
| 89 | end |
| 90 | n = sub n 1 |
| 91 | want = uchar 40 |
| 92 | if eq c 93 |
| 93 | want = 91 |
| 94 | end |
| 95 | if eq c 125 |
| 96 | want = 123 |
| 97 | end |
| 98 | if ne get stk n want |
| 99 | ret false |
| 100 | end |
| 101 | put level 0 n |
| 102 | end |
| 103 | ret true |
| 104 | end |
| 105 | |
| 106 | fn safechr p ulong to bool |
| 107 | c = get inp p |
| 108 | if or eq c 32 or eq c 9 or eq c 10 eq c 13 |
| 109 | ret true |
| 110 | end |
| 111 | if and ge c 48 le c 57 |
| 112 | ret true |
| 113 | end |
| 114 | if eq c 61 |
| 115 | if pairat p 61 61 |
| 116 | ret true |
| 117 | end |
| 118 | if gt p 0 |
| 119 | prev = get inp sub p 1 |
| 120 | if or eq prev 61 or eq prev 60 eq prev 62 |
| 121 | ret true |
| 122 | end |
| 123 | end |
| 124 | ret false |
| 125 | end |
| 126 | if or pairat p 47 47 or pairat p 47 42 or pairat p 42 47 or pairat p 40 42 pairat p 42 41 |
| 127 | ret false |
| 128 | end |
| 129 | if eq c 44 |
| 130 | if eq get level 0 0 |
| 131 | ret false |
| 132 | end |
| 133 | end |
| 134 | if or pairat p 43 43 pairat p 45 45 |
| 135 | ret false |
| 136 | end |
| 137 | if or eq c 91 or eq c 93 or eq c 123 or eq c 125 or eq c 40 eq c 41 |
| 138 | ret brackets c |
| 139 | end |
| 140 | if or eq c 43 or eq c 45 or eq c 42 eq c 47 |
| 141 | ret true |
| 142 | end |
| 143 | if or eq c 94 or eq c 46 eq c 44 |
| 144 | ret true |
| 145 | end |
| 146 | ret or eq c 60 or eq c 62 eq c 39 |
| 147 | end |
| 148 | |
| 149 | fn scan to bool |
| 150 | p = ulong 0 |
| 151 | seen = false |
| 152 | while lt p get total 0 bound 4096 |
| 153 | c = get inp p |
| 154 | if alpha c |
| 155 | start = p |
| 156 | while lt p get total 0 bound 4096 |
| 157 | if not alpha get inp p |
| 158 | break |
| 159 | end |
| 160 | p = add p 1 |
| 161 | end |
| 162 | if not insym start sub p start |
| 163 | ret false |
| 164 | end |
| 165 | seen = true |
| 166 | else |
| 167 | if eq c 34 |
| 168 | p = add p 1 |
| 169 | start = p |
| 170 | while lt p get total 0 bound 4096 |
| 171 | if not alpha get inp p |
| 172 | break |
| 173 | end |
| 174 | p = add p 1 |
| 175 | end |
| 176 | if ge p get total 0 |
| 177 | ret false |
| 178 | end |
| 179 | if ne get inp p 34 |
| 180 | ret false |
| 181 | end |
| 182 | if not inunit start sub p start |
| 183 | ret false |
| 184 | end |
| 185 | p = add p 1 |
| 186 | seen = true |
| 187 | else |
| 188 | if eq c 92 |
| 189 | if gt len dist sub get total 0 p |
| 190 | ret false |
| 191 | end |
| 192 | for i ulong len dist |
| 193 | if ne get inp add p i get dist i |
| 194 | ret false |
| 195 | end |
| 196 | end |
| 197 | p = add p len dist |
| 198 | seen = true |
| 199 | else |
| 200 | if not safechr p |
| 201 | ret false |
| 202 | end |
| 203 | if and ge c 48 le c 57 |
| 204 | seen = true |
| 205 | end |
| 206 | p = add p 1 |
| 207 | end |
| 208 | end |
| 209 | end |
| 210 | end |
| 211 | ret and seen eq get level 0 0 |
| 212 | end |
| 213 | |
| 214 | fn main to int |
| 215 | n = ulong 0 |
| 216 | while lt n len inp bound 4097 |
| 217 | r = read 0 inp n sub len inp n |
| 218 | if lt r 0 |
| 219 | ret 3 |
| 220 | end |
| 221 | if eq r 0 |
| 222 | break |
| 223 | end |
| 224 | n = add n ulong r |
| 225 | end |
| 226 | if or eq n 0 gt n 4096 |
| 227 | ret 2 |
| 228 | end |
| 229 | put total 0 n |
| 230 | if scan |
| 231 | ret 0 |
| 232 | end |
| 233 | ret 2 |
| 234 | end |