(ai) add custom functions

This commit is contained in:
mcDandy
2026-01-19 17:22:23 +01:00
parent a4b9abfc61
commit 8e0b1c65f5
13 changed files with 1598 additions and 1853 deletions
+1
View File
@@ -21,6 +21,7 @@ You can also get the node from comfy manager under the name of More math.
- Conversion between INT and FLOAT; AUDIO and IMAGE (red - real - strenght of cosine of frequency; blue - imaginary - strenght of sine of frequency; green - log1p of amplitude - just so it looks good to humans)
- Nodes for FLOAT, CONDITIONING, LATENT, IMAGE, MASK, NOISE, AUDIO, VIDEO, MODEL, CLIP, VAE and SIGMAS
- Vector Math: Support for List literals `[v1, v2, ...]` and operations between lists/scalars/tensors
- Custom functions `funcname(variable,variable,...)->expression;` they can be used in any later defined custom function or in expression. Shadowing inbuilt functions do not work.
## Operators
+14 -2
View File
@@ -1,6 +1,13 @@
grammar MathExpr;
// Top-level expression, with operator precedence (lowest to highest)
// Top-level entry point
start: funcDef* expr EOF;
funcDef:
VARIABLE LPAREN paramList? RPAREN ARROW expr SEMICOLON # FunctionDef;
paramList: VARIABLE (COMMA VARIABLE)*;
expr: atom | compExpr;
compExpr:
@@ -46,7 +53,10 @@ atom:
| CONSTANT # ConstantExp
| LPAREN expr RPAREN # ParenExp
| PIPE expr PIPE # AbsExp
| LBRACKET expr (COMMA expr)* RBRACKET # ListExp;
| LBRACKET expr (COMMA expr)* RBRACKET # ListExp
| VARIABLE LPAREN exprList? RPAREN # CallExp;
exprList: expr (COMMA expr)*;
// Single-argument functions
func1:
@@ -217,6 +227,8 @@ PIPE: '|';
LPAREN: '(';
RPAREN: ')';
COMMA: ',';
SEMICOLON: ';';
ARROW: '->';
LBRACKET: '[';
RBRACKET: ']';
File diff suppressed because one or more lines are too long
+12 -8
View File
@@ -81,12 +81,14 @@ PIPE=80
LPAREN=81
RPAREN=82
COMMA=83
LBRACKET=84
RBRACKET=85
CONSTANT=86
NUMBER=87
VARIABLE=88
WS=89
SEMICOLON=84
ARROW=85
LBRACKET=86
RBRACKET=87
CONSTANT=88
NUMBER=89
VARIABLE=90
WS=91
'sin'=1
'cos'=2
'tan'=3
@@ -163,5 +165,7 @@ WS=89
'('=81
')'=82
','=83
'['=84
']'=85
';'=84
'->'=85
'['=86
']'=87
File diff suppressed because one or more lines are too long
+248 -241
View File
@@ -10,7 +10,7 @@ else:
def serializedATN():
return [
4,0,89,684,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
4,0,91,693,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,
13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,
19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,
@@ -23,235 +23,238 @@ def serializedATN():
65,7,65,2,66,7,66,2,67,7,67,2,68,7,68,2,69,7,69,2,70,7,70,2,71,7,
71,2,72,7,72,2,73,7,73,2,74,7,74,2,75,7,75,2,76,7,76,2,77,7,77,2,
78,7,78,2,79,7,79,2,80,7,80,2,81,7,81,2,82,7,82,2,83,7,83,2,84,7,
84,2,85,7,85,2,86,7,86,2,87,7,87,2,88,7,88,1,0,1,0,1,0,1,0,1,1,1,
1,1,1,1,1,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3,1,3,1,4,1,4,1,4,1,4,1,
4,1,5,1,5,1,5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,
7,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,
10,1,10,1,11,1,11,1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,
12,1,13,1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,14,1,15,1,15,1,15,1,
16,1,16,1,16,1,16,1,17,1,17,1,17,1,17,1,18,1,18,1,18,1,18,1,18,1,
19,1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,20,1,21,1,21,1,21,1,
21,1,21,1,22,1,22,1,22,1,22,1,22,1,22,1,23,1,23,1,23,1,23,1,23,1,
23,1,24,1,24,1,24,1,24,1,24,1,24,1,25,1,25,1,25,1,25,1,25,1,26,1,
26,1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,28,1,28,1,
28,1,28,1,29,1,29,1,29,1,29,1,29,1,30,1,30,1,30,1,30,1,30,1,30,1,
31,1,31,1,31,1,31,1,32,1,32,1,32,1,32,1,32,1,33,1,33,1,33,1,33,1,
33,1,33,1,34,1,34,1,34,1,34,1,34,1,34,1,35,1,35,1,35,1,35,1,35,1,
35,1,35,1,35,1,35,1,35,1,35,1,35,1,35,1,35,1,35,3,35,372,8,35,1,
36,1,36,1,36,1,36,1,36,1,37,1,37,1,37,1,37,1,37,1,38,1,38,1,38,1,
38,1,38,1,38,1,38,1,38,1,38,1,38,1,38,1,39,1,39,1,39,1,39,1,39,1,
39,1,40,1,40,1,40,1,40,1,40,1,41,1,41,1,41,1,41,1,41,1,41,1,41,1,
41,1,41,1,42,1,42,1,42,1,42,1,42,1,43,1,43,1,43,1,43,1,43,1,44,1,
44,1,44,1,44,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,
45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,3,45,448,8,45,1,46,1,
46,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,
46,3,46,465,8,46,1,47,1,47,1,47,1,47,1,47,1,48,1,48,1,48,1,48,1,
48,1,48,1,48,1,48,1,48,1,48,1,48,3,48,483,8,48,1,49,1,49,1,49,1,
49,1,49,1,49,1,49,1,49,1,49,1,49,1,49,3,49,496,8,49,1,50,1,50,1,
50,1,50,1,50,1,50,1,51,1,51,1,51,1,51,1,51,1,52,1,52,1,52,1,52,1,
52,1,53,1,53,1,53,1,53,1,53,1,54,1,54,1,54,1,54,1,55,1,55,1,55,1,
55,1,55,1,56,1,56,1,56,1,56,1,57,1,57,1,57,1,57,1,58,1,58,1,58,1,
58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,3,58,551,
8,58,1,59,1,59,1,59,1,59,1,59,1,59,1,59,1,59,1,59,1,59,1,59,1,59,
1,59,1,59,1,59,3,59,568,8,59,1,60,1,60,1,60,1,60,1,60,1,60,1,60,
1,60,1,60,1,61,1,61,1,61,1,61,1,62,1,62,1,62,1,62,1,62,1,62,1,62,
1,63,1,63,1,63,1,63,1,63,1,63,1,63,1,64,1,64,1,64,1,64,1,64,1,65,
1,65,1,65,1,65,1,66,1,66,1,66,1,66,1,66,1,67,1,67,1,68,1,68,1,69,
1,69,1,70,1,70,1,71,1,71,1,72,1,72,1,73,1,73,1,73,1,74,1,74,1,75,
1,75,1,75,1,76,1,76,1,77,1,77,1,77,1,78,1,78,1,78,1,79,1,79,1,80,
1,80,1,81,1,81,1,82,1,82,1,83,1,83,1,84,1,84,1,85,1,85,1,85,1,85,
1,85,3,85,656,8,85,1,86,4,86,659,8,86,11,86,12,86,660,1,86,1,86,
4,86,665,8,86,11,86,12,86,666,3,86,669,8,86,1,87,1,87,5,87,673,8,
87,10,87,12,87,676,9,87,1,88,4,88,679,8,88,11,88,12,88,680,1,88,
1,88,0,0,89,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,
23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,
45,23,47,24,49,25,51,26,53,27,55,28,57,29,59,30,61,31,63,32,65,33,
67,34,69,35,71,36,73,37,75,38,77,39,79,40,81,41,83,42,85,43,87,44,
89,45,91,46,93,47,95,48,97,49,99,50,101,51,103,52,105,53,107,54,
109,55,111,56,113,57,115,58,117,59,119,60,121,61,123,62,125,63,127,
64,129,65,131,66,133,67,135,68,137,69,139,70,141,71,143,72,145,73,
147,74,149,75,151,76,153,77,155,78,157,79,159,80,161,81,163,82,165,
83,167,84,169,85,171,86,173,87,175,88,177,89,1,0,5,2,0,69,69,101,
101,1,0,48,57,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,
3,0,9,10,13,13,32,32,697,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,
1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,
1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,
1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,
1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,
1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,57,
1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,67,
1,0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,77,
1,0,0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,87,
1,0,0,0,0,89,1,0,0,0,0,91,1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,
1,0,0,0,0,99,1,0,0,0,0,101,1,0,0,0,0,103,1,0,0,0,0,105,1,0,0,0,0,
107,1,0,0,0,0,109,1,0,0,0,0,111,1,0,0,0,0,113,1,0,0,0,0,115,1,0,
0,0,0,117,1,0,0,0,0,119,1,0,0,0,0,121,1,0,0,0,0,123,1,0,0,0,0,125,
1,0,0,0,0,127,1,0,0,0,0,129,1,0,0,0,0,131,1,0,0,0,0,133,1,0,0,0,
0,135,1,0,0,0,0,137,1,0,0,0,0,139,1,0,0,0,0,141,1,0,0,0,0,143,1,
0,0,0,0,145,1,0,0,0,0,147,1,0,0,0,0,149,1,0,0,0,0,151,1,0,0,0,0,
153,1,0,0,0,0,155,1,0,0,0,0,157,1,0,0,0,0,159,1,0,0,0,0,161,1,0,
0,0,0,163,1,0,0,0,0,165,1,0,0,0,0,167,1,0,0,0,0,169,1,0,0,0,0,171,
1,0,0,0,0,173,1,0,0,0,0,175,1,0,0,0,0,177,1,0,0,0,1,179,1,0,0,0,
3,183,1,0,0,0,5,187,1,0,0,0,7,191,1,0,0,0,9,196,1,0,0,0,11,201,1,
0,0,0,13,206,1,0,0,0,15,212,1,0,0,0,17,217,1,0,0,0,19,222,1,0,0,
0,21,227,1,0,0,0,23,233,1,0,0,0,25,239,1,0,0,0,27,245,1,0,0,0,29,
249,1,0,0,0,31,254,1,0,0,0,33,257,1,0,0,0,35,261,1,0,0,0,37,265,
1,0,0,0,39,270,1,0,0,0,41,275,1,0,0,0,43,280,1,0,0,0,45,285,1,0,
0,0,47,291,1,0,0,0,49,297,1,0,0,0,51,303,1,0,0,0,53,308,1,0,0,0,
55,314,1,0,0,0,57,320,1,0,0,0,59,324,1,0,0,0,61,329,1,0,0,0,63,335,
1,0,0,0,65,339,1,0,0,0,67,344,1,0,0,0,69,350,1,0,0,0,71,371,1,0,
0,0,73,373,1,0,0,0,75,378,1,0,0,0,77,383,1,0,0,0,79,394,1,0,0,0,
81,400,1,0,0,0,83,405,1,0,0,0,85,414,1,0,0,0,87,419,1,0,0,0,89,424,
1,0,0,0,91,447,1,0,0,0,93,464,1,0,0,0,95,466,1,0,0,0,97,482,1,0,
0,0,99,495,1,0,0,0,101,497,1,0,0,0,103,503,1,0,0,0,105,508,1,0,0,
0,107,513,1,0,0,0,109,518,1,0,0,0,111,522,1,0,0,0,113,527,1,0,0,
0,115,531,1,0,0,0,117,550,1,0,0,0,119,567,1,0,0,0,121,569,1,0,0,
0,123,578,1,0,0,0,125,582,1,0,0,0,127,589,1,0,0,0,129,596,1,0,0,
0,131,601,1,0,0,0,133,605,1,0,0,0,135,610,1,0,0,0,137,612,1,0,0,
0,139,614,1,0,0,0,141,616,1,0,0,0,143,618,1,0,0,0,145,620,1,0,0,
0,147,622,1,0,0,0,149,625,1,0,0,0,151,627,1,0,0,0,153,630,1,0,0,
0,155,632,1,0,0,0,157,635,1,0,0,0,159,638,1,0,0,0,161,640,1,0,0,
0,163,642,1,0,0,0,165,644,1,0,0,0,167,646,1,0,0,0,169,648,1,0,0,
0,171,655,1,0,0,0,173,658,1,0,0,0,175,670,1,0,0,0,177,678,1,0,0,
0,179,180,5,115,0,0,180,181,5,105,0,0,181,182,5,110,0,0,182,2,1,
0,0,0,183,184,5,99,0,0,184,185,5,111,0,0,185,186,5,115,0,0,186,4,
1,0,0,0,187,188,5,116,0,0,188,189,5,97,0,0,189,190,5,110,0,0,190,
6,1,0,0,0,191,192,5,97,0,0,192,193,5,115,0,0,193,194,5,105,0,0,194,
195,5,110,0,0,195,8,1,0,0,0,196,197,5,97,0,0,197,198,5,99,0,0,198,
199,5,111,0,0,199,200,5,115,0,0,200,10,1,0,0,0,201,202,5,97,0,0,
202,203,5,116,0,0,203,204,5,97,0,0,204,205,5,110,0,0,205,12,1,0,
0,0,206,207,5,97,0,0,207,208,5,116,0,0,208,209,5,97,0,0,209,210,
5,110,0,0,210,211,5,50,0,0,211,14,1,0,0,0,212,213,5,115,0,0,213,
214,5,105,0,0,214,215,5,110,0,0,215,216,5,104,0,0,216,16,1,0,0,0,
217,218,5,99,0,0,218,219,5,111,0,0,219,220,5,115,0,0,220,221,5,104,
0,0,221,18,1,0,0,0,222,223,5,116,0,0,223,224,5,97,0,0,224,225,5,
110,0,0,225,226,5,104,0,0,226,20,1,0,0,0,227,228,5,97,0,0,228,229,
5,115,0,0,229,230,5,105,0,0,230,231,5,110,0,0,231,232,5,104,0,0,
232,22,1,0,0,0,233,234,5,97,0,0,234,235,5,99,0,0,235,236,5,111,0,
0,236,237,5,115,0,0,237,238,5,104,0,0,238,24,1,0,0,0,239,240,5,97,
0,0,240,241,5,116,0,0,241,242,5,97,0,0,242,243,5,110,0,0,243,244,
5,104,0,0,244,26,1,0,0,0,245,246,5,97,0,0,246,247,5,98,0,0,247,248,
5,115,0,0,248,28,1,0,0,0,249,250,5,115,0,0,250,251,5,113,0,0,251,
252,5,114,0,0,252,253,5,116,0,0,253,30,1,0,0,0,254,255,5,108,0,0,
255,256,5,110,0,0,256,32,1,0,0,0,257,258,5,108,0,0,258,259,5,111,
0,0,259,260,5,103,0,0,260,34,1,0,0,0,261,262,5,101,0,0,262,263,5,
120,0,0,263,264,5,112,0,0,264,36,1,0,0,0,265,266,5,115,0,0,266,267,
5,109,0,0,267,268,5,105,0,0,268,269,5,110,0,0,269,38,1,0,0,0,270,
271,5,115,0,0,271,272,5,109,0,0,272,273,5,97,0,0,273,274,5,120,0,
0,274,40,1,0,0,0,275,276,5,116,0,0,276,277,5,109,0,0,277,278,5,105,
0,0,278,279,5,110,0,0,279,42,1,0,0,0,280,281,5,116,0,0,281,282,5,
109,0,0,282,283,5,97,0,0,283,284,5,120,0,0,284,44,1,0,0,0,285,286,
5,116,0,0,286,287,5,110,0,0,287,288,5,111,0,0,288,289,5,114,0,0,
289,290,5,109,0,0,290,46,1,0,0,0,291,292,5,115,0,0,292,293,5,110,
0,0,293,294,5,111,0,0,294,295,5,114,0,0,295,296,5,109,0,0,296,48,
1,0,0,0,297,298,5,102,0,0,298,299,5,108,0,0,299,300,5,111,0,0,300,
301,5,111,0,0,301,302,5,114,0,0,302,50,1,0,0,0,303,304,5,99,0,0,
304,305,5,101,0,0,305,306,5,105,0,0,306,307,5,108,0,0,307,52,1,0,
0,0,308,309,5,114,0,0,309,310,5,111,0,0,310,311,5,117,0,0,311,312,
5,110,0,0,312,313,5,100,0,0,313,54,1,0,0,0,314,315,5,103,0,0,315,
316,5,97,0,0,316,317,5,109,0,0,317,318,5,109,0,0,318,319,5,97,0,
0,319,56,1,0,0,0,320,321,5,112,0,0,321,322,5,111,0,0,322,323,5,119,
0,0,323,58,1,0,0,0,324,325,5,115,0,0,325,326,5,105,0,0,326,327,5,
103,0,0,327,328,5,109,0,0,328,60,1,0,0,0,329,330,5,99,0,0,330,331,
5,108,0,0,331,332,5,97,0,0,332,333,5,109,0,0,333,334,5,112,0,0,334,
62,1,0,0,0,335,336,5,102,0,0,336,337,5,102,0,0,337,338,5,116,0,0,
338,64,1,0,0,0,339,340,5,105,0,0,340,341,5,102,0,0,341,342,5,102,
0,0,342,343,5,116,0,0,343,66,1,0,0,0,344,345,5,97,0,0,345,346,5,
110,0,0,346,347,5,103,0,0,347,348,5,108,0,0,348,349,5,101,0,0,349,
68,1,0,0,0,350,351,5,112,0,0,351,352,5,114,0,0,352,353,5,105,0,0,
353,354,5,110,0,0,354,355,5,116,0,0,355,70,1,0,0,0,356,357,5,112,
0,0,357,358,5,114,0,0,358,359,5,105,0,0,359,360,5,110,0,0,360,361,
5,116,0,0,361,362,5,95,0,0,362,363,5,115,0,0,363,364,5,104,0,0,364,
365,5,97,0,0,365,366,5,112,0,0,366,372,5,101,0,0,367,368,5,112,0,
0,368,369,5,115,0,0,369,370,5,104,0,0,370,372,5,112,0,0,371,356,
1,0,0,0,371,367,1,0,0,0,372,72,1,0,0,0,373,374,5,108,0,0,374,375,
5,101,0,0,375,376,5,114,0,0,376,377,5,112,0,0,377,74,1,0,0,0,378,
379,5,115,0,0,379,380,5,116,0,0,380,381,5,101,0,0,381,382,5,112,
0,0,382,76,1,0,0,0,383,384,5,115,0,0,384,385,5,109,0,0,385,386,5,
111,0,0,386,387,5,111,0,0,387,388,5,116,0,0,388,389,5,104,0,0,389,
390,5,115,0,0,390,391,5,116,0,0,391,392,5,101,0,0,392,393,5,112,
0,0,393,78,1,0,0,0,394,395,5,102,0,0,395,396,5,114,0,0,396,397,5,
97,0,0,397,398,5,99,0,0,398,399,5,116,0,0,399,80,1,0,0,0,400,401,
5,114,0,0,401,402,5,101,0,0,402,403,5,108,0,0,403,404,5,117,0,0,
404,82,1,0,0,0,405,406,5,115,0,0,406,407,5,111,0,0,407,408,5,102,
0,0,408,409,5,116,0,0,409,410,5,112,0,0,410,411,5,108,0,0,411,412,
5,117,0,0,412,413,5,115,0,0,413,84,1,0,0,0,414,415,5,103,0,0,415,
416,5,101,0,0,416,417,5,108,0,0,417,418,5,117,0,0,418,86,1,0,0,0,
419,420,5,115,0,0,420,421,5,105,0,0,421,422,5,103,0,0,422,423,5,
110,0,0,423,88,1,0,0,0,424,425,5,109,0,0,425,426,5,97,0,0,426,427,
5,112,0,0,427,90,1,0,0,0,428,429,5,101,0,0,429,430,5,122,0,0,430,
431,5,99,0,0,431,432,5,111,0,0,432,433,5,110,0,0,433,434,5,118,0,
0,434,435,5,111,0,0,435,436,5,108,0,0,436,437,5,117,0,0,437,438,
5,116,0,0,438,439,5,105,0,0,439,440,5,111,0,0,440,448,5,110,0,0,
441,442,5,101,0,0,442,443,5,122,0,0,443,444,5,99,0,0,444,445,5,111,
0,0,445,446,5,110,0,0,446,448,5,118,0,0,447,428,1,0,0,0,447,441,
1,0,0,0,448,92,1,0,0,0,449,450,5,99,0,0,450,451,5,111,0,0,451,452,
5,110,0,0,452,453,5,118,0,0,453,454,5,111,0,0,454,455,5,108,0,0,
455,456,5,117,0,0,456,457,5,116,0,0,457,458,5,105,0,0,458,459,5,
111,0,0,459,465,5,110,0,0,460,461,5,99,0,0,461,462,5,111,0,0,462,
463,5,110,0,0,463,465,5,118,0,0,464,449,1,0,0,0,464,460,1,0,0,0,
465,94,1,0,0,0,466,467,5,115,0,0,467,468,5,119,0,0,468,469,5,97,
0,0,469,470,5,112,0,0,470,96,1,0,0,0,471,472,5,112,0,0,472,473,5,
101,0,0,473,474,5,114,0,0,474,475,5,109,0,0,475,476,5,117,0,0,476,
477,5,116,0,0,477,483,5,101,0,0,478,479,5,112,0,0,479,480,5,101,
0,0,480,481,5,114,0,0,481,483,5,109,0,0,482,471,1,0,0,0,482,478,
1,0,0,0,483,98,1,0,0,0,484,485,5,114,0,0,485,486,5,101,0,0,486,487,
5,115,0,0,487,488,5,104,0,0,488,489,5,97,0,0,489,490,5,112,0,0,490,
496,5,101,0,0,491,492,5,114,0,0,492,493,5,115,0,0,493,494,5,104,
0,0,494,496,5,112,0,0,495,484,1,0,0,0,495,491,1,0,0,0,496,100,1,
0,0,0,497,498,5,114,0,0,498,499,5,97,0,0,499,500,5,110,0,0,500,501,
5,103,0,0,501,502,5,101,0,0,502,102,1,0,0,0,503,504,5,116,0,0,504,
505,5,111,0,0,505,506,5,112,0,0,506,507,5,107,0,0,507,104,1,0,0,
0,508,509,5,98,0,0,509,510,5,111,0,0,510,511,5,116,0,0,511,512,5,
107,0,0,512,106,1,0,0,0,513,514,5,112,0,0,514,515,5,105,0,0,515,
516,5,110,0,0,516,517,5,118,0,0,517,108,1,0,0,0,518,519,5,115,0,
0,519,520,5,117,0,0,520,521,5,109,0,0,521,110,1,0,0,0,522,523,5,
109,0,0,523,524,5,101,0,0,524,525,5,97,0,0,525,526,5,110,0,0,526,
112,1,0,0,0,527,528,5,115,0,0,528,529,5,116,0,0,529,530,5,100,0,
0,530,114,1,0,0,0,531,532,5,118,0,0,532,533,5,97,0,0,533,534,5,114,
0,0,534,116,1,0,0,0,535,536,5,113,0,0,536,537,5,117,0,0,537,538,
5,97,0,0,538,539,5,114,0,0,539,540,5,116,0,0,540,541,5,105,0,0,541,
542,5,108,0,0,542,551,5,101,0,0,543,544,5,113,0,0,544,545,5,117,
0,0,545,546,5,97,0,0,546,547,5,114,0,0,547,548,5,116,0,0,548,549,
5,105,0,0,549,551,5,108,0,0,550,535,1,0,0,0,550,543,1,0,0,0,551,
118,1,0,0,0,552,553,5,112,0,0,553,554,5,101,0,0,554,555,5,114,0,
0,555,556,5,99,0,0,556,557,5,101,0,0,557,558,5,110,0,0,558,559,5,
116,0,0,559,560,5,105,0,0,560,561,5,108,0,0,561,568,5,101,0,0,562,
563,5,112,0,0,563,564,5,114,0,0,564,565,5,99,0,0,565,566,5,110,0,
0,566,568,5,116,0,0,567,552,1,0,0,0,567,562,1,0,0,0,568,120,1,0,
0,0,569,570,5,113,0,0,570,571,5,117,0,0,571,572,5,97,0,0,572,573,
5,110,0,0,573,574,5,116,0,0,574,575,5,105,0,0,575,576,5,108,0,0,
576,577,5,101,0,0,577,122,1,0,0,0,578,579,5,100,0,0,579,580,5,111,
0,0,580,581,5,116,0,0,581,124,1,0,0,0,582,583,5,109,0,0,583,584,
5,111,0,0,584,585,5,109,0,0,585,586,5,101,0,0,586,587,5,110,0,0,
587,588,5,116,0,0,588,126,1,0,0,0,589,590,5,99,0,0,590,591,5,111,
0,0,591,592,5,115,0,0,592,593,5,115,0,0,593,594,5,105,0,0,594,595,
5,109,0,0,595,128,1,0,0,0,596,597,5,102,0,0,597,598,5,108,0,0,598,
599,5,105,0,0,599,600,5,112,0,0,600,130,1,0,0,0,601,602,5,99,0,0,
602,603,5,111,0,0,603,604,5,118,0,0,604,132,1,0,0,0,605,606,5,115,
0,0,606,607,5,111,0,0,607,608,5,114,0,0,608,609,5,116,0,0,609,134,
1,0,0,0,610,611,5,43,0,0,611,136,1,0,0,0,612,613,5,45,0,0,613,138,
1,0,0,0,614,615,5,42,0,0,615,140,1,0,0,0,616,617,5,47,0,0,617,142,
1,0,0,0,618,619,5,37,0,0,619,144,1,0,0,0,620,621,5,94,0,0,621,146,
1,0,0,0,622,623,5,62,0,0,623,624,5,61,0,0,624,148,1,0,0,0,625,626,
5,62,0,0,626,150,1,0,0,0,627,628,5,60,0,0,628,629,5,61,0,0,629,152,
1,0,0,0,630,631,5,60,0,0,631,154,1,0,0,0,632,633,5,61,0,0,633,634,
5,61,0,0,634,156,1,0,0,0,635,636,5,33,0,0,636,637,5,61,0,0,637,158,
1,0,0,0,638,639,5,124,0,0,639,160,1,0,0,0,640,641,5,40,0,0,641,162,
1,0,0,0,642,643,5,41,0,0,643,164,1,0,0,0,644,645,5,44,0,0,645,166,
1,0,0,0,646,647,5,91,0,0,647,168,1,0,0,0,648,649,5,93,0,0,649,170,
1,0,0,0,650,651,5,112,0,0,651,656,5,105,0,0,652,653,5,80,0,0,653,
656,5,73,0,0,654,656,7,0,0,0,655,650,1,0,0,0,655,652,1,0,0,0,655,
654,1,0,0,0,656,172,1,0,0,0,657,659,7,1,0,0,658,657,1,0,0,0,659,
660,1,0,0,0,660,658,1,0,0,0,660,661,1,0,0,0,661,668,1,0,0,0,662,
664,5,46,0,0,663,665,7,1,0,0,664,663,1,0,0,0,665,666,1,0,0,0,666,
664,1,0,0,0,666,667,1,0,0,0,667,669,1,0,0,0,668,662,1,0,0,0,668,
669,1,0,0,0,669,174,1,0,0,0,670,674,7,2,0,0,671,673,7,3,0,0,672,
671,1,0,0,0,673,676,1,0,0,0,674,672,1,0,0,0,674,675,1,0,0,0,675,
176,1,0,0,0,676,674,1,0,0,0,677,679,7,4,0,0,678,677,1,0,0,0,679,
680,1,0,0,0,680,678,1,0,0,0,680,681,1,0,0,0,681,682,1,0,0,0,682,
683,6,88,0,0,683,178,1,0,0,0,14,0,371,447,464,482,495,550,567,655,
660,666,668,674,680,1,6,0,0
84,2,85,7,85,2,86,7,86,2,87,7,87,2,88,7,88,2,89,7,89,2,90,7,90,1,
0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3,1,
3,1,4,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,
6,1,7,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,
10,1,10,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,11,1,11,1,11,1,12,1,
12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,
14,1,15,1,15,1,15,1,16,1,16,1,16,1,16,1,17,1,17,1,17,1,17,1,18,1,
18,1,18,1,18,1,18,1,19,1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,
20,1,21,1,21,1,21,1,21,1,21,1,22,1,22,1,22,1,22,1,22,1,22,1,23,1,
23,1,23,1,23,1,23,1,23,1,24,1,24,1,24,1,24,1,24,1,24,1,25,1,25,1,
25,1,25,1,25,1,26,1,26,1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,27,1,
27,1,27,1,28,1,28,1,28,1,28,1,29,1,29,1,29,1,29,1,29,1,30,1,30,1,
30,1,30,1,30,1,30,1,31,1,31,1,31,1,31,1,32,1,32,1,32,1,32,1,32,1,
33,1,33,1,33,1,33,1,33,1,33,1,34,1,34,1,34,1,34,1,34,1,34,1,35,1,
35,1,35,1,35,1,35,1,35,1,35,1,35,1,35,1,35,1,35,1,35,1,35,1,35,1,
35,3,35,376,8,35,1,36,1,36,1,36,1,36,1,36,1,37,1,37,1,37,1,37,1,
37,1,38,1,38,1,38,1,38,1,38,1,38,1,38,1,38,1,38,1,38,1,38,1,39,1,
39,1,39,1,39,1,39,1,39,1,40,1,40,1,40,1,40,1,40,1,41,1,41,1,41,1,
41,1,41,1,41,1,41,1,41,1,41,1,42,1,42,1,42,1,42,1,42,1,43,1,43,1,
43,1,43,1,43,1,44,1,44,1,44,1,44,1,45,1,45,1,45,1,45,1,45,1,45,1,
45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,1,45,3,
45,452,8,45,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,
46,1,46,1,46,1,46,1,46,3,46,469,8,46,1,47,1,47,1,47,1,47,1,47,1,
48,1,48,1,48,1,48,1,48,1,48,1,48,1,48,1,48,1,48,1,48,3,48,487,8,
48,1,49,1,49,1,49,1,49,1,49,1,49,1,49,1,49,1,49,1,49,1,49,3,49,500,
8,49,1,50,1,50,1,50,1,50,1,50,1,50,1,51,1,51,1,51,1,51,1,51,1,52,
1,52,1,52,1,52,1,52,1,53,1,53,1,53,1,53,1,53,1,54,1,54,1,54,1,54,
1,55,1,55,1,55,1,55,1,55,1,56,1,56,1,56,1,56,1,57,1,57,1,57,1,57,
1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,1,58,
1,58,1,58,3,58,555,8,58,1,59,1,59,1,59,1,59,1,59,1,59,1,59,1,59,
1,59,1,59,1,59,1,59,1,59,1,59,1,59,3,59,572,8,59,1,60,1,60,1,60,
1,60,1,60,1,60,1,60,1,60,1,60,1,61,1,61,1,61,1,61,1,62,1,62,1,62,
1,62,1,62,1,62,1,62,1,63,1,63,1,63,1,63,1,63,1,63,1,63,1,64,1,64,
1,64,1,64,1,64,1,65,1,65,1,65,1,65,1,66,1,66,1,66,1,66,1,66,1,67,
1,67,1,68,1,68,1,69,1,69,1,70,1,70,1,71,1,71,1,72,1,72,1,73,1,73,
1,73,1,74,1,74,1,75,1,75,1,75,1,76,1,76,1,77,1,77,1,77,1,78,1,78,
1,78,1,79,1,79,1,80,1,80,1,81,1,81,1,82,1,82,1,83,1,83,1,84,1,84,
1,84,1,85,1,85,1,86,1,86,1,87,1,87,1,87,1,87,1,87,3,87,665,8,87,
1,88,4,88,668,8,88,11,88,12,88,669,1,88,1,88,4,88,674,8,88,11,88,
12,88,675,3,88,678,8,88,1,89,1,89,5,89,682,8,89,10,89,12,89,685,
9,89,1,90,4,90,688,8,90,11,90,12,90,689,1,90,1,90,0,0,91,1,1,3,2,
5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,
15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,
26,53,27,55,28,57,29,59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,
37,75,38,77,39,79,40,81,41,83,42,85,43,87,44,89,45,91,46,93,47,95,
48,97,49,99,50,101,51,103,52,105,53,107,54,109,55,111,56,113,57,
115,58,117,59,119,60,121,61,123,62,125,63,127,64,129,65,131,66,133,
67,135,68,137,69,139,70,141,71,143,72,145,73,147,74,149,75,151,76,
153,77,155,78,157,79,159,80,161,81,163,82,165,83,167,84,169,85,171,
86,173,87,175,88,177,89,179,90,181,91,1,0,5,2,0,69,69,101,101,1,
0,48,57,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,3,0,
9,10,13,13,32,32,706,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,
0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,
0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,
0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,
0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,1,0,
0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,57,1,0,
0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,67,1,0,
0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,77,1,0,
0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,87,1,0,
0,0,0,89,1,0,0,0,0,91,1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,1,0,
0,0,0,99,1,0,0,0,0,101,1,0,0,0,0,103,1,0,0,0,0,105,1,0,0,0,0,107,
1,0,0,0,0,109,1,0,0,0,0,111,1,0,0,0,0,113,1,0,0,0,0,115,1,0,0,0,
0,117,1,0,0,0,0,119,1,0,0,0,0,121,1,0,0,0,0,123,1,0,0,0,0,125,1,
0,0,0,0,127,1,0,0,0,0,129,1,0,0,0,0,131,1,0,0,0,0,133,1,0,0,0,0,
135,1,0,0,0,0,137,1,0,0,0,0,139,1,0,0,0,0,141,1,0,0,0,0,143,1,0,
0,0,0,145,1,0,0,0,0,147,1,0,0,0,0,149,1,0,0,0,0,151,1,0,0,0,0,153,
1,0,0,0,0,155,1,0,0,0,0,157,1,0,0,0,0,159,1,0,0,0,0,161,1,0,0,0,
0,163,1,0,0,0,0,165,1,0,0,0,0,167,1,0,0,0,0,169,1,0,0,0,0,171,1,
0,0,0,0,173,1,0,0,0,0,175,1,0,0,0,0,177,1,0,0,0,0,179,1,0,0,0,0,
181,1,0,0,0,1,183,1,0,0,0,3,187,1,0,0,0,5,191,1,0,0,0,7,195,1,0,
0,0,9,200,1,0,0,0,11,205,1,0,0,0,13,210,1,0,0,0,15,216,1,0,0,0,17,
221,1,0,0,0,19,226,1,0,0,0,21,231,1,0,0,0,23,237,1,0,0,0,25,243,
1,0,0,0,27,249,1,0,0,0,29,253,1,0,0,0,31,258,1,0,0,0,33,261,1,0,
0,0,35,265,1,0,0,0,37,269,1,0,0,0,39,274,1,0,0,0,41,279,1,0,0,0,
43,284,1,0,0,0,45,289,1,0,0,0,47,295,1,0,0,0,49,301,1,0,0,0,51,307,
1,0,0,0,53,312,1,0,0,0,55,318,1,0,0,0,57,324,1,0,0,0,59,328,1,0,
0,0,61,333,1,0,0,0,63,339,1,0,0,0,65,343,1,0,0,0,67,348,1,0,0,0,
69,354,1,0,0,0,71,375,1,0,0,0,73,377,1,0,0,0,75,382,1,0,0,0,77,387,
1,0,0,0,79,398,1,0,0,0,81,404,1,0,0,0,83,409,1,0,0,0,85,418,1,0,
0,0,87,423,1,0,0,0,89,428,1,0,0,0,91,451,1,0,0,0,93,468,1,0,0,0,
95,470,1,0,0,0,97,486,1,0,0,0,99,499,1,0,0,0,101,501,1,0,0,0,103,
507,1,0,0,0,105,512,1,0,0,0,107,517,1,0,0,0,109,522,1,0,0,0,111,
526,1,0,0,0,113,531,1,0,0,0,115,535,1,0,0,0,117,554,1,0,0,0,119,
571,1,0,0,0,121,573,1,0,0,0,123,582,1,0,0,0,125,586,1,0,0,0,127,
593,1,0,0,0,129,600,1,0,0,0,131,605,1,0,0,0,133,609,1,0,0,0,135,
614,1,0,0,0,137,616,1,0,0,0,139,618,1,0,0,0,141,620,1,0,0,0,143,
622,1,0,0,0,145,624,1,0,0,0,147,626,1,0,0,0,149,629,1,0,0,0,151,
631,1,0,0,0,153,634,1,0,0,0,155,636,1,0,0,0,157,639,1,0,0,0,159,
642,1,0,0,0,161,644,1,0,0,0,163,646,1,0,0,0,165,648,1,0,0,0,167,
650,1,0,0,0,169,652,1,0,0,0,171,655,1,0,0,0,173,657,1,0,0,0,175,
664,1,0,0,0,177,667,1,0,0,0,179,679,1,0,0,0,181,687,1,0,0,0,183,
184,5,115,0,0,184,185,5,105,0,0,185,186,5,110,0,0,186,2,1,0,0,0,
187,188,5,99,0,0,188,189,5,111,0,0,189,190,5,115,0,0,190,4,1,0,0,
0,191,192,5,116,0,0,192,193,5,97,0,0,193,194,5,110,0,0,194,6,1,0,
0,0,195,196,5,97,0,0,196,197,5,115,0,0,197,198,5,105,0,0,198,199,
5,110,0,0,199,8,1,0,0,0,200,201,5,97,0,0,201,202,5,99,0,0,202,203,
5,111,0,0,203,204,5,115,0,0,204,10,1,0,0,0,205,206,5,97,0,0,206,
207,5,116,0,0,207,208,5,97,0,0,208,209,5,110,0,0,209,12,1,0,0,0,
210,211,5,97,0,0,211,212,5,116,0,0,212,213,5,97,0,0,213,214,5,110,
0,0,214,215,5,50,0,0,215,14,1,0,0,0,216,217,5,115,0,0,217,218,5,
105,0,0,218,219,5,110,0,0,219,220,5,104,0,0,220,16,1,0,0,0,221,222,
5,99,0,0,222,223,5,111,0,0,223,224,5,115,0,0,224,225,5,104,0,0,225,
18,1,0,0,0,226,227,5,116,0,0,227,228,5,97,0,0,228,229,5,110,0,0,
229,230,5,104,0,0,230,20,1,0,0,0,231,232,5,97,0,0,232,233,5,115,
0,0,233,234,5,105,0,0,234,235,5,110,0,0,235,236,5,104,0,0,236,22,
1,0,0,0,237,238,5,97,0,0,238,239,5,99,0,0,239,240,5,111,0,0,240,
241,5,115,0,0,241,242,5,104,0,0,242,24,1,0,0,0,243,244,5,97,0,0,
244,245,5,116,0,0,245,246,5,97,0,0,246,247,5,110,0,0,247,248,5,104,
0,0,248,26,1,0,0,0,249,250,5,97,0,0,250,251,5,98,0,0,251,252,5,115,
0,0,252,28,1,0,0,0,253,254,5,115,0,0,254,255,5,113,0,0,255,256,5,
114,0,0,256,257,5,116,0,0,257,30,1,0,0,0,258,259,5,108,0,0,259,260,
5,110,0,0,260,32,1,0,0,0,261,262,5,108,0,0,262,263,5,111,0,0,263,
264,5,103,0,0,264,34,1,0,0,0,265,266,5,101,0,0,266,267,5,120,0,0,
267,268,5,112,0,0,268,36,1,0,0,0,269,270,5,115,0,0,270,271,5,109,
0,0,271,272,5,105,0,0,272,273,5,110,0,0,273,38,1,0,0,0,274,275,5,
115,0,0,275,276,5,109,0,0,276,277,5,97,0,0,277,278,5,120,0,0,278,
40,1,0,0,0,279,280,5,116,0,0,280,281,5,109,0,0,281,282,5,105,0,0,
282,283,5,110,0,0,283,42,1,0,0,0,284,285,5,116,0,0,285,286,5,109,
0,0,286,287,5,97,0,0,287,288,5,120,0,0,288,44,1,0,0,0,289,290,5,
116,0,0,290,291,5,110,0,0,291,292,5,111,0,0,292,293,5,114,0,0,293,
294,5,109,0,0,294,46,1,0,0,0,295,296,5,115,0,0,296,297,5,110,0,0,
297,298,5,111,0,0,298,299,5,114,0,0,299,300,5,109,0,0,300,48,1,0,
0,0,301,302,5,102,0,0,302,303,5,108,0,0,303,304,5,111,0,0,304,305,
5,111,0,0,305,306,5,114,0,0,306,50,1,0,0,0,307,308,5,99,0,0,308,
309,5,101,0,0,309,310,5,105,0,0,310,311,5,108,0,0,311,52,1,0,0,0,
312,313,5,114,0,0,313,314,5,111,0,0,314,315,5,117,0,0,315,316,5,
110,0,0,316,317,5,100,0,0,317,54,1,0,0,0,318,319,5,103,0,0,319,320,
5,97,0,0,320,321,5,109,0,0,321,322,5,109,0,0,322,323,5,97,0,0,323,
56,1,0,0,0,324,325,5,112,0,0,325,326,5,111,0,0,326,327,5,119,0,0,
327,58,1,0,0,0,328,329,5,115,0,0,329,330,5,105,0,0,330,331,5,103,
0,0,331,332,5,109,0,0,332,60,1,0,0,0,333,334,5,99,0,0,334,335,5,
108,0,0,335,336,5,97,0,0,336,337,5,109,0,0,337,338,5,112,0,0,338,
62,1,0,0,0,339,340,5,102,0,0,340,341,5,102,0,0,341,342,5,116,0,0,
342,64,1,0,0,0,343,344,5,105,0,0,344,345,5,102,0,0,345,346,5,102,
0,0,346,347,5,116,0,0,347,66,1,0,0,0,348,349,5,97,0,0,349,350,5,
110,0,0,350,351,5,103,0,0,351,352,5,108,0,0,352,353,5,101,0,0,353,
68,1,0,0,0,354,355,5,112,0,0,355,356,5,114,0,0,356,357,5,105,0,0,
357,358,5,110,0,0,358,359,5,116,0,0,359,70,1,0,0,0,360,361,5,112,
0,0,361,362,5,114,0,0,362,363,5,105,0,0,363,364,5,110,0,0,364,365,
5,116,0,0,365,366,5,95,0,0,366,367,5,115,0,0,367,368,5,104,0,0,368,
369,5,97,0,0,369,370,5,112,0,0,370,376,5,101,0,0,371,372,5,112,0,
0,372,373,5,115,0,0,373,374,5,104,0,0,374,376,5,112,0,0,375,360,
1,0,0,0,375,371,1,0,0,0,376,72,1,0,0,0,377,378,5,108,0,0,378,379,
5,101,0,0,379,380,5,114,0,0,380,381,5,112,0,0,381,74,1,0,0,0,382,
383,5,115,0,0,383,384,5,116,0,0,384,385,5,101,0,0,385,386,5,112,
0,0,386,76,1,0,0,0,387,388,5,115,0,0,388,389,5,109,0,0,389,390,5,
111,0,0,390,391,5,111,0,0,391,392,5,116,0,0,392,393,5,104,0,0,393,
394,5,115,0,0,394,395,5,116,0,0,395,396,5,101,0,0,396,397,5,112,
0,0,397,78,1,0,0,0,398,399,5,102,0,0,399,400,5,114,0,0,400,401,5,
97,0,0,401,402,5,99,0,0,402,403,5,116,0,0,403,80,1,0,0,0,404,405,
5,114,0,0,405,406,5,101,0,0,406,407,5,108,0,0,407,408,5,117,0,0,
408,82,1,0,0,0,409,410,5,115,0,0,410,411,5,111,0,0,411,412,5,102,
0,0,412,413,5,116,0,0,413,414,5,112,0,0,414,415,5,108,0,0,415,416,
5,117,0,0,416,417,5,115,0,0,417,84,1,0,0,0,418,419,5,103,0,0,419,
420,5,101,0,0,420,421,5,108,0,0,421,422,5,117,0,0,422,86,1,0,0,0,
423,424,5,115,0,0,424,425,5,105,0,0,425,426,5,103,0,0,426,427,5,
110,0,0,427,88,1,0,0,0,428,429,5,109,0,0,429,430,5,97,0,0,430,431,
5,112,0,0,431,90,1,0,0,0,432,433,5,101,0,0,433,434,5,122,0,0,434,
435,5,99,0,0,435,436,5,111,0,0,436,437,5,110,0,0,437,438,5,118,0,
0,438,439,5,111,0,0,439,440,5,108,0,0,440,441,5,117,0,0,441,442,
5,116,0,0,442,443,5,105,0,0,443,444,5,111,0,0,444,452,5,110,0,0,
445,446,5,101,0,0,446,447,5,122,0,0,447,448,5,99,0,0,448,449,5,111,
0,0,449,450,5,110,0,0,450,452,5,118,0,0,451,432,1,0,0,0,451,445,
1,0,0,0,452,92,1,0,0,0,453,454,5,99,0,0,454,455,5,111,0,0,455,456,
5,110,0,0,456,457,5,118,0,0,457,458,5,111,0,0,458,459,5,108,0,0,
459,460,5,117,0,0,460,461,5,116,0,0,461,462,5,105,0,0,462,463,5,
111,0,0,463,469,5,110,0,0,464,465,5,99,0,0,465,466,5,111,0,0,466,
467,5,110,0,0,467,469,5,118,0,0,468,453,1,0,0,0,468,464,1,0,0,0,
469,94,1,0,0,0,470,471,5,115,0,0,471,472,5,119,0,0,472,473,5,97,
0,0,473,474,5,112,0,0,474,96,1,0,0,0,475,476,5,112,0,0,476,477,5,
101,0,0,477,478,5,114,0,0,478,479,5,109,0,0,479,480,5,117,0,0,480,
481,5,116,0,0,481,487,5,101,0,0,482,483,5,112,0,0,483,484,5,101,
0,0,484,485,5,114,0,0,485,487,5,109,0,0,486,475,1,0,0,0,486,482,
1,0,0,0,487,98,1,0,0,0,488,489,5,114,0,0,489,490,5,101,0,0,490,491,
5,115,0,0,491,492,5,104,0,0,492,493,5,97,0,0,493,494,5,112,0,0,494,
500,5,101,0,0,495,496,5,114,0,0,496,497,5,115,0,0,497,498,5,104,
0,0,498,500,5,112,0,0,499,488,1,0,0,0,499,495,1,0,0,0,500,100,1,
0,0,0,501,502,5,114,0,0,502,503,5,97,0,0,503,504,5,110,0,0,504,505,
5,103,0,0,505,506,5,101,0,0,506,102,1,0,0,0,507,508,5,116,0,0,508,
509,5,111,0,0,509,510,5,112,0,0,510,511,5,107,0,0,511,104,1,0,0,
0,512,513,5,98,0,0,513,514,5,111,0,0,514,515,5,116,0,0,515,516,5,
107,0,0,516,106,1,0,0,0,517,518,5,112,0,0,518,519,5,105,0,0,519,
520,5,110,0,0,520,521,5,118,0,0,521,108,1,0,0,0,522,523,5,115,0,
0,523,524,5,117,0,0,524,525,5,109,0,0,525,110,1,0,0,0,526,527,5,
109,0,0,527,528,5,101,0,0,528,529,5,97,0,0,529,530,5,110,0,0,530,
112,1,0,0,0,531,532,5,115,0,0,532,533,5,116,0,0,533,534,5,100,0,
0,534,114,1,0,0,0,535,536,5,118,0,0,536,537,5,97,0,0,537,538,5,114,
0,0,538,116,1,0,0,0,539,540,5,113,0,0,540,541,5,117,0,0,541,542,
5,97,0,0,542,543,5,114,0,0,543,544,5,116,0,0,544,545,5,105,0,0,545,
546,5,108,0,0,546,555,5,101,0,0,547,548,5,113,0,0,548,549,5,117,
0,0,549,550,5,97,0,0,550,551,5,114,0,0,551,552,5,116,0,0,552,553,
5,105,0,0,553,555,5,108,0,0,554,539,1,0,0,0,554,547,1,0,0,0,555,
118,1,0,0,0,556,557,5,112,0,0,557,558,5,101,0,0,558,559,5,114,0,
0,559,560,5,99,0,0,560,561,5,101,0,0,561,562,5,110,0,0,562,563,5,
116,0,0,563,564,5,105,0,0,564,565,5,108,0,0,565,572,5,101,0,0,566,
567,5,112,0,0,567,568,5,114,0,0,568,569,5,99,0,0,569,570,5,110,0,
0,570,572,5,116,0,0,571,556,1,0,0,0,571,566,1,0,0,0,572,120,1,0,
0,0,573,574,5,113,0,0,574,575,5,117,0,0,575,576,5,97,0,0,576,577,
5,110,0,0,577,578,5,116,0,0,578,579,5,105,0,0,579,580,5,108,0,0,
580,581,5,101,0,0,581,122,1,0,0,0,582,583,5,100,0,0,583,584,5,111,
0,0,584,585,5,116,0,0,585,124,1,0,0,0,586,587,5,109,0,0,587,588,
5,111,0,0,588,589,5,109,0,0,589,590,5,101,0,0,590,591,5,110,0,0,
591,592,5,116,0,0,592,126,1,0,0,0,593,594,5,99,0,0,594,595,5,111,
0,0,595,596,5,115,0,0,596,597,5,115,0,0,597,598,5,105,0,0,598,599,
5,109,0,0,599,128,1,0,0,0,600,601,5,102,0,0,601,602,5,108,0,0,602,
603,5,105,0,0,603,604,5,112,0,0,604,130,1,0,0,0,605,606,5,99,0,0,
606,607,5,111,0,0,607,608,5,118,0,0,608,132,1,0,0,0,609,610,5,115,
0,0,610,611,5,111,0,0,611,612,5,114,0,0,612,613,5,116,0,0,613,134,
1,0,0,0,614,615,5,43,0,0,615,136,1,0,0,0,616,617,5,45,0,0,617,138,
1,0,0,0,618,619,5,42,0,0,619,140,1,0,0,0,620,621,5,47,0,0,621,142,
1,0,0,0,622,623,5,37,0,0,623,144,1,0,0,0,624,625,5,94,0,0,625,146,
1,0,0,0,626,627,5,62,0,0,627,628,5,61,0,0,628,148,1,0,0,0,629,630,
5,62,0,0,630,150,1,0,0,0,631,632,5,60,0,0,632,633,5,61,0,0,633,152,
1,0,0,0,634,635,5,60,0,0,635,154,1,0,0,0,636,637,5,61,0,0,637,638,
5,61,0,0,638,156,1,0,0,0,639,640,5,33,0,0,640,641,5,61,0,0,641,158,
1,0,0,0,642,643,5,124,0,0,643,160,1,0,0,0,644,645,5,40,0,0,645,162,
1,0,0,0,646,647,5,41,0,0,647,164,1,0,0,0,648,649,5,44,0,0,649,166,
1,0,0,0,650,651,5,59,0,0,651,168,1,0,0,0,652,653,5,45,0,0,653,654,
5,62,0,0,654,170,1,0,0,0,655,656,5,91,0,0,656,172,1,0,0,0,657,658,
5,93,0,0,658,174,1,0,0,0,659,660,5,112,0,0,660,665,5,105,0,0,661,
662,5,80,0,0,662,665,5,73,0,0,663,665,7,0,0,0,664,659,1,0,0,0,664,
661,1,0,0,0,664,663,1,0,0,0,665,176,1,0,0,0,666,668,7,1,0,0,667,
666,1,0,0,0,668,669,1,0,0,0,669,667,1,0,0,0,669,670,1,0,0,0,670,
677,1,0,0,0,671,673,5,46,0,0,672,674,7,1,0,0,673,672,1,0,0,0,674,
675,1,0,0,0,675,673,1,0,0,0,675,676,1,0,0,0,676,678,1,0,0,0,677,
671,1,0,0,0,677,678,1,0,0,0,678,178,1,0,0,0,679,683,7,2,0,0,680,
682,7,3,0,0,681,680,1,0,0,0,682,685,1,0,0,0,683,681,1,0,0,0,683,
684,1,0,0,0,684,180,1,0,0,0,685,683,1,0,0,0,686,688,7,4,0,0,687,
686,1,0,0,0,688,689,1,0,0,0,689,687,1,0,0,0,689,690,1,0,0,0,690,
691,1,0,0,0,691,692,6,90,0,0,692,182,1,0,0,0,14,0,375,451,468,486,
499,554,571,664,669,675,677,683,689,1,6,0,0
]
class MathExprLexer(Lexer):
@@ -343,12 +346,14 @@ class MathExprLexer(Lexer):
LPAREN = 81
RPAREN = 82
COMMA = 83
LBRACKET = 84
RBRACKET = 85
CONSTANT = 86
NUMBER = 87
VARIABLE = 88
WS = 89
SEMICOLON = 84
ARROW = 85
LBRACKET = 86
RBRACKET = 87
CONSTANT = 88
NUMBER = 89
VARIABLE = 90
WS = 91
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
@@ -366,7 +371,7 @@ class MathExprLexer(Lexer):
"'mean'", "'std'", "'var'", "'quantile'", "'dot'", "'moment'",
"'cossim'", "'flip'", "'cov'", "'sort'", "'+'", "'-'", "'*'",
"'/'", "'%'", "'^'", "'>='", "'>'", "'<='", "'<'", "'=='", "'!='",
"'|'", "'('", "')'", "','", "'['", "']'" ]
"'|'", "'('", "')'", "','", "';'", "'->'", "'['", "']'" ]
symbolicNames = [ "<INVALID>",
"SIN", "COS", "TAN", "ASIN", "ACOS", "ATAN", "ATAN2", "SINH",
@@ -379,8 +384,9 @@ class MathExprLexer(Lexer):
"BOTK", "PINV", "SUM", "MEAN", "STD", "VAR", "QUARTILE", "PERCENTILE",
"QUANTILE", "DOT", "MOMENT", "COSSIM", "FLIP", "COV", "SORT",
"PLUS", "MINUS", "MULT", "DIV", "MOD", "POW", "GE", "GT", "LE",
"LT", "EQ", "NE", "PIPE", "LPAREN", "RPAREN", "COMMA", "LBRACKET",
"RBRACKET", "CONSTANT", "NUMBER", "VARIABLE", "WS" ]
"LT", "EQ", "NE", "PIPE", "LPAREN", "RPAREN", "COMMA", "SEMICOLON",
"ARROW", "LBRACKET", "RBRACKET", "CONSTANT", "NUMBER", "VARIABLE",
"WS" ]
ruleNames = [ "SIN", "COS", "TAN", "ASIN", "ACOS", "ATAN", "ATAN2",
"SINH", "COSH", "TANH", "ASINH", "ACOSH", "ATANH", "ABS",
@@ -393,8 +399,9 @@ class MathExprLexer(Lexer):
"STD", "VAR", "QUARTILE", "PERCENTILE", "QUANTILE", "DOT",
"MOMENT", "COSSIM", "FLIP", "COV", "SORT", "PLUS", "MINUS",
"MULT", "DIV", "MOD", "POW", "GE", "GT", "LE", "LT", "EQ",
"NE", "PIPE", "LPAREN", "RPAREN", "COMMA", "LBRACKET",
"RBRACKET", "CONSTANT", "NUMBER", "VARIABLE", "WS" ]
"NE", "PIPE", "LPAREN", "RPAREN", "COMMA", "SEMICOLON",
"ARROW", "LBRACKET", "RBRACKET", "CONSTANT", "NUMBER",
"VARIABLE", "WS" ]
grammarFileName = "MathExpr.g4"
+12 -8
View File
@@ -81,12 +81,14 @@ PIPE=80
LPAREN=81
RPAREN=82
COMMA=83
LBRACKET=84
RBRACKET=85
CONSTANT=86
NUMBER=87
VARIABLE=88
WS=89
SEMICOLON=84
ARROW=85
LBRACKET=86
RBRACKET=87
CONSTANT=88
NUMBER=89
VARIABLE=90
WS=91
'sin'=1
'cos'=2
'tan'=3
@@ -163,5 +165,7 @@ WS=89
'('=81
')'=82
','=83
'['=84
']'=85
';'=84
'->'=85
'['=86
']'=87
+45
View File
@@ -8,6 +8,33 @@ else:
# This class defines a complete listener for a parse tree produced by MathExprParser.
class MathExprListener(ParseTreeListener):
# Enter a parse tree produced by MathExprParser#start.
def enterStart(self, ctx:MathExprParser.StartContext):
pass
# Exit a parse tree produced by MathExprParser#start.
def exitStart(self, ctx:MathExprParser.StartContext):
pass
# Enter a parse tree produced by MathExprParser#FunctionDef.
def enterFunctionDef(self, ctx:MathExprParser.FunctionDefContext):
pass
# Exit a parse tree produced by MathExprParser#FunctionDef.
def exitFunctionDef(self, ctx:MathExprParser.FunctionDefContext):
pass
# Enter a parse tree produced by MathExprParser#paramList.
def enterParamList(self, ctx:MathExprParser.ParamListContext):
pass
# Exit a parse tree produced by MathExprParser#paramList.
def exitParamList(self, ctx:MathExprParser.ParamListContext):
pass
# Enter a parse tree produced by MathExprParser#expr.
def enterExpr(self, ctx:MathExprParser.ExprContext):
pass
@@ -305,6 +332,24 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#CallExp.
def enterCallExp(self, ctx:MathExprParser.CallExpContext):
pass
# Exit a parse tree produced by MathExprParser#CallExp.
def exitCallExp(self, ctx:MathExprParser.CallExpContext):
pass
# Enter a parse tree produced by MathExprParser#exprList.
def enterExprList(self, ctx:MathExprParser.ExprListContext):
pass
# Exit a parse tree produced by MathExprParser#exprList.
def exitExprList(self, ctx:MathExprParser.ExprListContext):
pass
# Enter a parse tree produced by MathExprParser#SinFunc.
def enterSinFunc(self, ctx:MathExprParser.SinFuncContext):
pass
File diff suppressed because it is too large Load Diff
+25
View File
@@ -9,6 +9,21 @@ else:
class MathExprVisitor(ParseTreeVisitor):
# Visit a parse tree produced by MathExprParser#start.
def visitStart(self, ctx:MathExprParser.StartContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#FunctionDef.
def visitFunctionDef(self, ctx:MathExprParser.FunctionDefContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#paramList.
def visitParamList(self, ctx:MathExprParser.ParamListContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#expr.
def visitExpr(self, ctx:MathExprParser.ExprContext):
return self.visitChildren(ctx)
@@ -174,6 +189,16 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#CallExp.
def visitCallExp(self, ctx:MathExprParser.CallExpContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#exprList.
def visitExprList(self, ctx:MathExprParser.ExprListContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#SinFunc.
def visitSinFunc(self, ctx:MathExprParser.SinFuncContext):
return self.visitChildren(ctx)
+50 -1
View File
@@ -6,7 +6,7 @@ from ..helper_functions import generate_dim_variables
class UnifiedMathVisitor(MathExprVisitor):
def __init__(self, variables, shape=None, device=None):
def __init__(self, variables, shape=None, device=None, functions=None):
self.variables = variables
self.spatial_variables = variables.copy()
self.shape = shape if shape is not None else ()
@@ -14,6 +14,7 @@ class UnifiedMathVisitor(MathExprVisitor):
self.device = next((v.device for v in variables.values() if isinstance(v, torch.Tensor)), torch.device("cpu"))
else:
self.device = device
self.functions = functions if functions is not None else {}
def _is_tensor(self, val):
return isinstance(val, torch.Tensor)
@@ -1041,3 +1042,51 @@ class UnifiedMathVisitor(MathExprVisitor):
result = self._apply_conv_internal(conv_input, kernel_val, kernel_sizes, spatial_dims_count)
return result.reshape(*batch_shape, in_channels, *spatial_shape)
def visitStart(self, ctx):
# Visit all statements (function definitions)
if ctx.funcDef():
for i in range(len(ctx.funcDef())):
self.visit(ctx.funcDef(i))
return self.visit(ctx.expr())
def visitFunctionDef(self, ctx):
func_name = ctx.VARIABLE().getText()
params = []
if ctx.paramList():
params = [node.getText() for node in ctx.paramList().VARIABLE()]
self.functions[func_name] = {
"params": params,
"body": ctx.expr()
}
return None
def visitCallExp(self, ctx):
func_name = ctx.VARIABLE().getText()
# Check if it is a user-defined function
if func_name in self.functions:
func_def = self.functions[func_name]
params = func_def["params"]
# Evaluate arguments
args = []
if ctx.exprList():
args = [self.visit(e) for e in ctx.exprList().expr()]
if len(args) != len(params):
raise ValueError(f"Function '{func_name}' expects {len(params)} arguments, got {len(args)}")
# Create a new scope for function execution
new_vars = self.variables.copy()
for param, arg in zip(params, args):
new_vars[param] = arg
# Create a new visitor to execute the function body in the new scope - easier than managing stack of variables and call stack
visitor = UnifiedMathVisitor(new_vars, self.shape, self.device, self.functions)
return visitor.visit(func_def["body"])
raise ValueError(f"Unknown function: {func_name}")
+1 -1
View File
@@ -29,7 +29,7 @@ def parse_expr(expr: str):
stream = CommonTokenStream(lexer)
parser = MathExprParser(stream)
parser.addErrorListener(ThrowingErrorListener())
return parser.expr()
return parser.start()
def getIndexTensorAlongDim(tensor, dim):
+33 -1
View File
@@ -21,7 +21,7 @@ def parse_and_visit(expr_str, variables):
lexer = MathExprLexer(InputStream(expr_str))
stream = CommonTokenStream(lexer)
parser = MathExprParser(stream)
tree = parser.expr()
tree = parser.start()
# We might need to pass shape/device if UnifiedMathVisitor requires it for tensor creation
# For now assuming it can infer or defaults.
@@ -291,6 +291,36 @@ def test_percentile():
assert parse_and_visit("prcnt(l, 50)", vars) == 5.0
def test_custom_functions():
vars = {}
# 1. Simple function definition and call
# f(x) -> x + 1; f(10)
expr1 = "f(x) -> x + 1; f(10)"
assert parse_and_visit(expr1, vars) == 11.0
# 2. Multi-arg function
# add(a, b) -> a + b; add(3, 4)
expr2 = "add(a, b) -> a + b; add(3, 4)"
assert parse_and_visit(expr2, vars) == 7.0
# 3. Function reusing other functions (simulated by defining in same block)
# sq(x) -> x * x; sumsq(a, b) -> sq(a) + sq(b); sumsq(3, 4)
expr3 = "sq(x) -> x * x; sumsq(a, b) -> sq(a) + sq(b); sumsq(3, 4)"
assert parse_and_visit(expr3, vars) == 25.0
# 4. Global variable access & Shadowing
# x = 10 (global)
# f(x) -> x * 2; f(5) -> should be 10, not 20
vars = {"x": 10.0}
expr4 = "f(x) -> x * 2; f(5)"
assert parse_and_visit(expr4, vars) == 10.0
# f(y) -> x + y; f(5) -> global x(10) + param y(5) = 15
expr5 = "f(y) -> x + y; f(5)"
assert parse_and_visit(expr5, vars) == 15.0
if __name__ == "__main__":
try:
test_scalar_ops()
@@ -305,7 +335,9 @@ if __name__ == "__main__":
test_topk()
test_botk()
test_pinv()
test_pinv()
test_quartil()
test_custom_functions()
print("All UnifiedMathVisitor tests passed!")
except Exception:
import traceback