jjinx 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- jinx/__init__.py +0 -0
- jinx/errors.py +41 -0
- jinx/execution/executor.py +60 -0
- jinx/execution/jax/__init__.py +45 -0
- jinx/execution/jax/adverbs.py +91 -0
- jinx/execution/jax/application.py +231 -0
- jinx/execution/jax/verbs.py +90 -0
- jinx/execution/numpy/__init__.py +29 -0
- jinx/execution/numpy/adverbs.py +334 -0
- jinx/execution/numpy/application.py +343 -0
- jinx/execution/numpy/conjunctions.py +437 -0
- jinx/execution/numpy/conversion.py +62 -0
- jinx/execution/numpy/helpers.py +158 -0
- jinx/execution/numpy/printing.py +179 -0
- jinx/execution/numpy/verbs.py +850 -0
- jinx/primitives.py +490 -0
- jinx/shell.py +68 -0
- jinx/vocabulary.py +181 -0
- jinx/word_evaluation.py +375 -0
- jinx/word_formation.py +229 -0
- jinx/word_spelling.py +118 -0
- jjinx-0.0.1.dist-info/METADATA +148 -0
- jjinx-0.0.1.dist-info/RECORD +27 -0
- jjinx-0.0.1.dist-info/WHEEL +5 -0
- jjinx-0.0.1.dist-info/entry_points.txt +2 -0
- jjinx-0.0.1.dist-info/licenses/LICENSE +21 -0
- jjinx-0.0.1.dist-info/top_level.txt +1 -0
jinx/word_formation.py
ADDED
@@ -0,0 +1,229 @@
|
|
1
|
+
"""Word Formation.
|
2
|
+
|
3
|
+
Given a sentence (a string of characters), form a list of its constituent words.
|
4
|
+
|
5
|
+
Based on the description from 'An Implementation of J': https://www.jsoftware.com/ioj/iojSent.htm
|
6
|
+
|
7
|
+
See also: https://code.jsoftware.com/wiki/Vocabulary/Words#WordFormation
|
8
|
+
|
9
|
+
The terse naming of states and character classes has been preserved here for the sake of consistency
|
10
|
+
with the source descriptions (except '9' is now 'NUMERIC').
|
11
|
+
|
12
|
+
"""
|
13
|
+
|
14
|
+
from enum import Enum
|
15
|
+
from typing import Mapping
|
16
|
+
|
17
|
+
from jinx.vocabulary import Word
|
18
|
+
|
19
|
+
|
20
|
+
class State(Enum):
|
21
|
+
S = "space"
|
22
|
+
X = "other"
|
23
|
+
A = "alphanumeric"
|
24
|
+
N = "N"
|
25
|
+
NB = "NB"
|
26
|
+
NUMERIC = "numeric"
|
27
|
+
Q = "quote"
|
28
|
+
QQ = "even quotes"
|
29
|
+
Z = "trailing comment"
|
30
|
+
|
31
|
+
|
32
|
+
class CharacterClass(Enum):
|
33
|
+
S = "space"
|
34
|
+
X = "other"
|
35
|
+
A = "letters excl. NB"
|
36
|
+
N = "N"
|
37
|
+
B = "B"
|
38
|
+
NUMERIC = "digits and _"
|
39
|
+
D = "."
|
40
|
+
C = ":"
|
41
|
+
Q = "'"
|
42
|
+
|
43
|
+
|
44
|
+
class Action(Enum):
|
45
|
+
I = "emit, update" # noqa: E741
|
46
|
+
N = "no emit, update"
|
47
|
+
X = "no action"
|
48
|
+
|
49
|
+
|
50
|
+
STATE_TRANSITION: Mapping[tuple[State, CharacterClass], tuple[State, Action]] = {
|
51
|
+
# "space"
|
52
|
+
(State.S, CharacterClass.X): (State.X, Action.N),
|
53
|
+
(State.S, CharacterClass.S): (State.S, Action.X),
|
54
|
+
(State.S, CharacterClass.A): (State.A, Action.N),
|
55
|
+
(State.S, CharacterClass.N): (State.N, Action.N),
|
56
|
+
(State.S, CharacterClass.B): (State.A, Action.N),
|
57
|
+
(State.S, CharacterClass.NUMERIC): (State.NUMERIC, Action.N),
|
58
|
+
(State.S, CharacterClass.D): (State.X, Action.N),
|
59
|
+
(State.S, CharacterClass.C): (State.X, Action.N),
|
60
|
+
(State.S, CharacterClass.Q): (State.Q, Action.N),
|
61
|
+
# "other"
|
62
|
+
(State.X, CharacterClass.X): (State.X, Action.I),
|
63
|
+
(State.X, CharacterClass.S): (State.S, Action.I),
|
64
|
+
(State.X, CharacterClass.A): (State.A, Action.I),
|
65
|
+
(State.X, CharacterClass.N): (State.N, Action.I),
|
66
|
+
(State.X, CharacterClass.B): (State.A, Action.I),
|
67
|
+
(State.X, CharacterClass.NUMERIC): (State.NUMERIC, Action.I),
|
68
|
+
(State.X, CharacterClass.D): (State.X, Action.X),
|
69
|
+
(State.X, CharacterClass.C): (State.X, Action.X),
|
70
|
+
(State.X, CharacterClass.Q): (State.Q, Action.I),
|
71
|
+
# "alphanumeric"
|
72
|
+
(State.A, CharacterClass.X): (State.X, Action.I),
|
73
|
+
(State.A, CharacterClass.S): (State.S, Action.I),
|
74
|
+
(State.A, CharacterClass.A): (State.A, Action.X),
|
75
|
+
(State.A, CharacterClass.N): (State.A, Action.X),
|
76
|
+
(State.A, CharacterClass.B): (State.A, Action.X),
|
77
|
+
(State.A, CharacterClass.NUMERIC): (State.A, Action.X),
|
78
|
+
(State.A, CharacterClass.D): (State.X, Action.X),
|
79
|
+
(State.A, CharacterClass.C): (State.X, Action.X),
|
80
|
+
(State.A, CharacterClass.Q): (State.Q, Action.I),
|
81
|
+
# Action.N
|
82
|
+
(State.N, CharacterClass.X): (State.X, Action.I),
|
83
|
+
(State.N, CharacterClass.S): (State.S, Action.I),
|
84
|
+
(State.N, CharacterClass.A): (State.A, Action.X),
|
85
|
+
(State.N, CharacterClass.N): (State.A, Action.X),
|
86
|
+
(State.N, CharacterClass.B): (State.NB, Action.X),
|
87
|
+
(State.N, CharacterClass.NUMERIC): (State.A, Action.X),
|
88
|
+
(State.N, CharacterClass.D): (State.X, Action.X),
|
89
|
+
(State.N, CharacterClass.C): (State.X, Action.X),
|
90
|
+
(State.N, CharacterClass.Q): (State.Q, Action.I),
|
91
|
+
# "NB"
|
92
|
+
(State.NB, CharacterClass.X): (State.X, Action.I),
|
93
|
+
(State.NB, CharacterClass.S): (State.S, Action.I),
|
94
|
+
(State.NB, CharacterClass.A): (State.A, Action.X),
|
95
|
+
(State.NB, CharacterClass.N): (State.A, Action.X),
|
96
|
+
(State.NB, CharacterClass.B): (State.A, Action.X),
|
97
|
+
(State.NB, CharacterClass.NUMERIC): (State.A, Action.X),
|
98
|
+
(State.NB, CharacterClass.D): (State.Z, Action.X),
|
99
|
+
(State.NB, CharacterClass.C): (State.X, Action.X),
|
100
|
+
(State.NB, CharacterClass.Q): (State.Q, Action.I),
|
101
|
+
# "Z"
|
102
|
+
(State.Z, CharacterClass.X): (State.Z, Action.X),
|
103
|
+
(State.Z, CharacterClass.S): (State.Z, Action.X),
|
104
|
+
(State.Z, CharacterClass.A): (State.Z, Action.X),
|
105
|
+
(State.Z, CharacterClass.N): (State.Z, Action.X),
|
106
|
+
(State.Z, CharacterClass.B): (State.Z, Action.X),
|
107
|
+
(State.Z, CharacterClass.NUMERIC): (State.Z, Action.X),
|
108
|
+
(State.Z, CharacterClass.D): (State.X, Action.X),
|
109
|
+
(State.Z, CharacterClass.C): (State.X, Action.X),
|
110
|
+
(State.Z, CharacterClass.Q): (State.Z, Action.X),
|
111
|
+
# "NINE"
|
112
|
+
(State.NUMERIC, CharacterClass.X): (State.X, Action.I),
|
113
|
+
(State.NUMERIC, CharacterClass.S): (State.S, Action.I),
|
114
|
+
(State.NUMERIC, CharacterClass.A): (State.NUMERIC, Action.X),
|
115
|
+
(State.NUMERIC, CharacterClass.N): (State.NUMERIC, Action.X),
|
116
|
+
(State.NUMERIC, CharacterClass.B): (State.NUMERIC, Action.X),
|
117
|
+
(State.NUMERIC, CharacterClass.NUMERIC): (State.NUMERIC, Action.X),
|
118
|
+
(State.NUMERIC, CharacterClass.D): (State.NUMERIC, Action.X),
|
119
|
+
(State.NUMERIC, CharacterClass.C): (State.X, Action.X),
|
120
|
+
(State.NUMERIC, CharacterClass.Q): (State.Q, Action.I),
|
121
|
+
# "Q"
|
122
|
+
(State.Q, CharacterClass.X): (State.Q, Action.X),
|
123
|
+
(State.Q, CharacterClass.S): (State.Q, Action.X),
|
124
|
+
(State.Q, CharacterClass.A): (State.Q, Action.X),
|
125
|
+
(State.Q, CharacterClass.N): (State.Q, Action.X),
|
126
|
+
(State.Q, CharacterClass.B): (State.Q, Action.X),
|
127
|
+
(State.Q, CharacterClass.NUMERIC): (State.Q, Action.X),
|
128
|
+
(State.Q, CharacterClass.D): (State.Q, Action.X),
|
129
|
+
(State.Q, CharacterClass.C): (State.Q, Action.X),
|
130
|
+
(State.Q, CharacterClass.Q): (State.QQ, Action.X),
|
131
|
+
# "QQ"
|
132
|
+
(State.QQ, CharacterClass.X): (State.X, Action.I),
|
133
|
+
(State.QQ, CharacterClass.S): (State.S, Action.I),
|
134
|
+
(State.QQ, CharacterClass.A): (State.A, Action.I),
|
135
|
+
(State.QQ, CharacterClass.N): (State.N, Action.I),
|
136
|
+
(State.QQ, CharacterClass.B): (State.A, Action.I),
|
137
|
+
(State.QQ, CharacterClass.NUMERIC): (State.NUMERIC, Action.I),
|
138
|
+
(State.QQ, CharacterClass.D): (State.X, Action.I),
|
139
|
+
(State.QQ, CharacterClass.C): (State.X, Action.I),
|
140
|
+
(State.QQ, CharacterClass.Q): (State.Q, Action.X),
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
def get_character_class(char: str) -> CharacterClass:
|
145
|
+
if char.isspace():
|
146
|
+
return CharacterClass.S
|
147
|
+
|
148
|
+
if char == "N":
|
149
|
+
return CharacterClass.N
|
150
|
+
|
151
|
+
if char == "B":
|
152
|
+
return CharacterClass.B
|
153
|
+
|
154
|
+
if char.isalpha():
|
155
|
+
return CharacterClass.A
|
156
|
+
|
157
|
+
if char.isdigit() or char == "_":
|
158
|
+
return CharacterClass.NUMERIC
|
159
|
+
|
160
|
+
if char == ".":
|
161
|
+
return CharacterClass.D
|
162
|
+
|
163
|
+
if char == ":":
|
164
|
+
return CharacterClass.C
|
165
|
+
|
166
|
+
if char == "'":
|
167
|
+
return CharacterClass.Q
|
168
|
+
|
169
|
+
return CharacterClass.X
|
170
|
+
|
171
|
+
|
172
|
+
def form_words(sentence: str) -> list[Word]:
|
173
|
+
if len(sentence) == 0:
|
174
|
+
return []
|
175
|
+
|
176
|
+
# Append whitespace EOS marker to ensure that the final word is emitted.
|
177
|
+
# This has the side effect that comments and unterminated quotes will not
|
178
|
+
# be emitted, so we handle this later in the function.
|
179
|
+
sentence += "\n"
|
180
|
+
|
181
|
+
i = j = 0
|
182
|
+
current_state: State = State.S
|
183
|
+
|
184
|
+
words: list[Word] = []
|
185
|
+
|
186
|
+
# A sequence of numbers separated by whitespace is treated as a single word in J.
|
187
|
+
# Set a flag to handle this when the current numeric word needs to be emitted.
|
188
|
+
continue_numeric = False
|
189
|
+
|
190
|
+
while i < len(sentence):
|
191
|
+
char = sentence[i]
|
192
|
+
char_class = get_character_class(char)
|
193
|
+
new_state, action = STATE_TRANSITION[(current_state, char_class)]
|
194
|
+
|
195
|
+
if (
|
196
|
+
words
|
197
|
+
and words[-1].is_numeric
|
198
|
+
and current_state == State.S
|
199
|
+
and new_state == State.NUMERIC
|
200
|
+
):
|
201
|
+
continue_numeric = True
|
202
|
+
|
203
|
+
if action == Action.I:
|
204
|
+
if continue_numeric:
|
205
|
+
prev_word = words.pop()
|
206
|
+
value = sentence[prev_word.start : i]
|
207
|
+
word = Word(value=value, is_numeric=True, start=prev_word.start, end=i)
|
208
|
+
words.append(word)
|
209
|
+
continue_numeric = False
|
210
|
+
|
211
|
+
else:
|
212
|
+
value = sentence[j:i]
|
213
|
+
is_numeric = current_state == State.NUMERIC
|
214
|
+
word = Word(value=value, is_numeric=is_numeric, start=j, end=i)
|
215
|
+
words.append(word)
|
216
|
+
|
217
|
+
j = i
|
218
|
+
|
219
|
+
elif action == Action.N:
|
220
|
+
j = i
|
221
|
+
|
222
|
+
current_state = new_state
|
223
|
+
i += 1
|
224
|
+
|
225
|
+
remaining_word = sentence[j : i - 1] # i-1 to exclude EOS marker.
|
226
|
+
if remaining_word and not remaining_word.isspace():
|
227
|
+
words.append(Word(value=remaining_word, is_numeric=False, start=j, end=i - 1))
|
228
|
+
|
229
|
+
return words
|
jinx/word_spelling.py
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
"""Word Spelling.
|
2
|
+
|
3
|
+
Given constituent words of a sentence, associate it a part of speech (noun,
|
4
|
+
verb, adverb, etc.).
|
5
|
+
|
6
|
+
Parsing of numeric constants is also done here.
|
7
|
+
|
8
|
+
If a word does not map to a recognised part of speech, raise a SpellingError.
|
9
|
+
|
10
|
+
"""
|
11
|
+
|
12
|
+
import re
|
13
|
+
|
14
|
+
from jinx.errors import SpellingError
|
15
|
+
from jinx.primitives import PRIMITIVES
|
16
|
+
from jinx.vocabulary import (
|
17
|
+
Comment,
|
18
|
+
DataType,
|
19
|
+
Name,
|
20
|
+
Noun,
|
21
|
+
PartOfSpeechT,
|
22
|
+
Punctuation,
|
23
|
+
Word,
|
24
|
+
)
|
25
|
+
|
26
|
+
|
27
|
+
def parse_integer(word: str) -> int | None:
|
28
|
+
# Integers are a sequence of digits, optionally terminated
|
29
|
+
# by a single decimal point (which can be followed by any number
|
30
|
+
# of trailing 0s), or a single 'x' (denoting extended precision)
|
31
|
+
# and ignored here as all Python integers are extended precision).
|
32
|
+
match = re.fullmatch(r"_?(\d+)(?:x|\.0*)?", word)
|
33
|
+
if not match:
|
34
|
+
return None
|
35
|
+
|
36
|
+
value = int(match.group(1))
|
37
|
+
return -value if word.startswith("_") else value
|
38
|
+
|
39
|
+
|
40
|
+
def parse_float(word: str) -> float | None:
|
41
|
+
if word == "_":
|
42
|
+
return float("inf")
|
43
|
+
if word == "__":
|
44
|
+
return float("-inf")
|
45
|
+
if not re.fullmatch(r"_?\d+\.\d*", word):
|
46
|
+
return None
|
47
|
+
if word.startswith("_"):
|
48
|
+
return -float(word[1:])
|
49
|
+
return float(word)
|
50
|
+
|
51
|
+
|
52
|
+
def spell_numeric(word: Word) -> Noun:
|
53
|
+
values = word.value.split()
|
54
|
+
numbers: list[int | float] = []
|
55
|
+
data_type = DataType.Integer
|
56
|
+
|
57
|
+
for value in values:
|
58
|
+
int_value = parse_integer(value)
|
59
|
+
if int_value is not None:
|
60
|
+
numbers.append(int_value)
|
61
|
+
continue
|
62
|
+
|
63
|
+
float_value = parse_float(value)
|
64
|
+
if float_value is not None:
|
65
|
+
numbers.append(float_value)
|
66
|
+
data_type = DataType.Float
|
67
|
+
continue
|
68
|
+
|
69
|
+
raise SpellingError(f"Ill-formed number: {value}")
|
70
|
+
|
71
|
+
return Noun(data_type=data_type, data=numbers)
|
72
|
+
|
73
|
+
|
74
|
+
def spell_quoted(word: Word) -> Noun:
|
75
|
+
data = word.value[1:-1]
|
76
|
+
return Noun(data_type=DataType.Byte, data=list(data))
|
77
|
+
|
78
|
+
|
79
|
+
PRIMITIVE_MAP = {primitive.spelling: primitive for primitive in PRIMITIVES}
|
80
|
+
|
81
|
+
PUNCTUATION_MAP = {
|
82
|
+
"(": Punctuation(spelling="(", name="LPAREN"),
|
83
|
+
")": Punctuation(spelling=")", name="RPAREN"),
|
84
|
+
"'": Punctuation(spelling="'", name="QUOTE"),
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
def spell(word: Word) -> PartOfSpeechT:
|
89
|
+
if word.value in PRIMITIVE_MAP:
|
90
|
+
return PRIMITIVE_MAP[word.value]
|
91
|
+
|
92
|
+
if word.value in PUNCTUATION_MAP:
|
93
|
+
return PUNCTUATION_MAP[word.value]
|
94
|
+
|
95
|
+
if word.is_numeric:
|
96
|
+
return spell_numeric(word)
|
97
|
+
|
98
|
+
if word.value[0] == "'" and word.value[-1] == "'":
|
99
|
+
return spell_quoted(word)
|
100
|
+
|
101
|
+
if word.value.startswith("NB."):
|
102
|
+
return Comment(spelling=word.value)
|
103
|
+
|
104
|
+
if word[0].isalpha():
|
105
|
+
# Only a restricted form of simple names are supported (alphanumeric).
|
106
|
+
# This is to avoid the complexity of parsing J's full name grammar which
|
107
|
+
# has rules for underscores to support locatives (locales / namespaces).
|
108
|
+
#
|
109
|
+
# See: https://code.jsoftware.com/wiki/Vocabulary/Locales#Locatives
|
110
|
+
if not word.value.isalnum():
|
111
|
+
raise SpellingError(f"Only alphanumeric names are supported: {word.value}")
|
112
|
+
return Name(spelling=word.value)
|
113
|
+
|
114
|
+
raise SpellingError(f"Unrecognised word: {word}")
|
115
|
+
|
116
|
+
|
117
|
+
def spell_words(words: list[Word]) -> list[PartOfSpeechT]:
|
118
|
+
return [spell(word) for word in words]
|
@@ -0,0 +1,148 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: jjinx
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: Interpreter for the J programming language.
|
5
|
+
Author: Alex Riley
|
6
|
+
License: MIT License
|
7
|
+
|
8
|
+
Copyright (c) 2025 Alex Riley
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
12
|
+
in the Software without restriction, including without limitation the rights
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
15
|
+
furnished to do so, subject to the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
18
|
+
copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
26
|
+
SOFTWARE.
|
27
|
+
|
28
|
+
Project-URL: Homepage, https://github.com/ajcr/jinx
|
29
|
+
Keywords: J,interpreter
|
30
|
+
Classifier: Development Status :: 3 - Alpha
|
31
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
32
|
+
Classifier: Topic :: Utilities
|
33
|
+
Classifier: Typing :: Typed
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
36
|
+
Classifier: Programming Language :: Python :: 3.13
|
37
|
+
Requires-Python: >=3.13
|
38
|
+
Description-Content-Type: text/markdown
|
39
|
+
License-File: LICENSE
|
40
|
+
Requires-Dist: numpy>=2.3.3
|
41
|
+
Dynamic: license-file
|
42
|
+
|
43
|
+
# Jinx
|
44
|
+
|
45
|
+

|
46
|
+
|
47
|
+
An experimental interpreter for the J programming language, built on top of [NumPy](https://numpy.org/).
|
48
|
+
|
49
|
+
Implements many of J's primitives and tacit programming capabilities, and can be extended to support execution via other frameworks too.
|
50
|
+
|
51
|
+
## Executing J
|
52
|
+
|
53
|
+
Start the interactive shell:
|
54
|
+
```sh
|
55
|
+
jinx
|
56
|
+
```
|
57
|
+
The shell prompt is four spaces, so commands appear indented. Internally, all multidimensional arrays are NumPy arrays. Verbs, conjunctions and adverbs are a mixture of Python and NumPy methods.
|
58
|
+
|
59
|
+
Here are some examples what Jinx can do so far:
|
60
|
+
|
61
|
+
- Solve the "trapping rainwater" problem (solution taken from [here](https://mmapped.blog/posts/04-square-joy-trapped-rain-water)):
|
62
|
+
```j
|
63
|
+
+/@((>./\ <. >./\.)-]) 0 1 0 2 1 0 1 3 2 1 2 1
|
64
|
+
6
|
65
|
+
```
|
66
|
+
- Compute the correlation between two arrays of numbers (taken from [here](https://stackoverflow.com/a/44845495/3923281)). This is a complex combination of different verbs, adverbs, conjunctions and trains:
|
67
|
+
```j
|
68
|
+
2 1 1 7 9 (+/@:* % *&(+/)&.:*:)&(- +/%#) 6 3 1 5 7
|
69
|
+
0.721332
|
70
|
+
```
|
71
|
+
- Create identity matrices in inventive ways (see [this essay](https://code.jsoftware.com/wiki/Essays/Identity_Matrix)):
|
72
|
+
```j
|
73
|
+
|.@~:\ @ ($&0) 3
|
74
|
+
1 0 0
|
75
|
+
0 1 0
|
76
|
+
0 0 1
|
77
|
+
|
78
|
+
(i.@,~ = >: * i.) 3
|
79
|
+
1 0 0
|
80
|
+
0 1 0
|
81
|
+
0 0 1
|
82
|
+
|
83
|
+
((={:)\ @ i.) 3
|
84
|
+
1 0 0
|
85
|
+
0 1 0
|
86
|
+
0 0 1
|
87
|
+
```
|
88
|
+
- Solve the Josephus problem (see [this essay](https://code.jsoftware.com/wiki/Essays/Josephus_Problem)). Calculate the survivor's number for a circle of people of size N. Note the use of verb obverse and the rank conjunction:
|
89
|
+
```j
|
90
|
+
(1&|.&.#:)"0 >: i. 5 10 NB. N ranges from 1 to 50 here (arranged as a table)
|
91
|
+
1 1 3 1 3 5 7 1 3 5
|
92
|
+
7 9 11 13 15 1 3 5 7 9
|
93
|
+
11 13 15 17 19 21 23 25 27 29
|
94
|
+
31 1 3 5 7 9 11 13 15 17
|
95
|
+
19 21 23 25 27 29 31 33 35 37
|
96
|
+
```
|
97
|
+
- Build nested boxes containing heterogeneous data types and print the contents:
|
98
|
+
```j
|
99
|
+
(<<'abc'),(<(<'de',.'fg'),(<<i. 5 2)),(<(<"0 ] % i. 2 2 3))
|
100
|
+
┌─────┬──────────┬────────────────────────────┐
|
101
|
+
│┌───┐│┌──┬─────┐│┌────────┬────────┬────────┐│
|
102
|
+
││abc│││df│┌───┐│││_ │1 │0.5 ││
|
103
|
+
│└───┘││eg││0 1│││├────────┼────────┼────────┤│
|
104
|
+
│ ││ ││2 3││││0.333333│0.25 │0.2 ││
|
105
|
+
│ ││ ││4 5│││└────────┴────────┴────────┘│
|
106
|
+
│ ││ ││6 7│││ │
|
107
|
+
│ ││ ││8 9│││┌────────┬────────┬────────┐│
|
108
|
+
│ ││ │└───┘│││0.166667│0.142857│0.125 ││
|
109
|
+
│ │└──┴─────┘│├────────┼────────┼────────┤│
|
110
|
+
│ │ ││0.111111│0.1 │0.090909││
|
111
|
+
│ │ │└────────┴────────┴────────┘│
|
112
|
+
└─────┴──────────┴────────────────────────────┘
|
113
|
+
```
|
114
|
+
|
115
|
+
## Easily Customisable
|
116
|
+
|
117
|
+
Everything is in Python. Adding new primitives is easy.
|
118
|
+
|
119
|
+
Update the `primitives.py` file with your new part of speech (e.g. a new verb such as `+::`). Write your implementation of this new part of speech in the relevant executor module (e.g. `verbs.py`) and then update the name-to-method mapping at the foot of that module. That's all that's needed.
|
120
|
+
|
121
|
+
## Alternative Executors
|
122
|
+
|
123
|
+
Execution of sentences is backed by NumPy by default.
|
124
|
+
|
125
|
+
However Jinx is designed so that it's possible to implement the primitives using alternative frameworks too. Python many Machine Learning and Scientific Programming libraries that could be used to execution J code.
|
126
|
+
|
127
|
+
To prove this concept, there's _highly experimental and incomplete_ support for [JAX](https://docs.jax.dev/en/latest/index.html):
|
128
|
+
```sh
|
129
|
+
jinx --executor jax
|
130
|
+
```
|
131
|
+
Primitive verbs are JIT compiled and execute on JAX arrays:
|
132
|
+
```j
|
133
|
+
mean =: +/ % #
|
134
|
+
mean 33 55 77 100 101
|
135
|
+
73.2
|
136
|
+
```
|
137
|
+
|
138
|
+
## Warning
|
139
|
+
|
140
|
+
This project is experimental. There will be bugs, missing features and performance quirks.
|
141
|
+
|
142
|
+
Many key parts of J are not currently implemented (but might be in future). These include:
|
143
|
+
- Differences in how names are interpreted and resolved at execution time.
|
144
|
+
- Locales.
|
145
|
+
- Definitions and direct definitions (using `{{ ... }}`).
|
146
|
+
- Array types other than floats, integers and and strings.
|
147
|
+
- Executing J scripts.
|
148
|
+
- Control words.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
jinx/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
jinx/errors.py,sha256=COssOTL42-Cm9qV9BsyfAxcn__kzHPzn13vI702zflU,540
|
3
|
+
jinx/primitives.py,sha256=s-f4fW4-xaPD7Wg2wjj3J6wtYM8AwtvyW3FzW0opH8E,12927
|
4
|
+
jinx/shell.py,sha256=27PQ9WjlQo6TC6E0eNuYBy9g2I9-5ykK_UXgW5EQg5M,1822
|
5
|
+
jinx/vocabulary.py,sha256=Cvpfviem13lBXN9hYoMAKTTKDtISQzJQ29dCHCEXNh8,4726
|
6
|
+
jinx/word_evaluation.py,sha256=c6xYhtooCiiztljiA7cNLX4PwuIAxaBDIEQi5ai7fWo,14359
|
7
|
+
jinx/word_formation.py,sha256=5TpE2yNQXk_J_bikOyILpXhv5dFhQCNa9NkeIxUJKSM,8185
|
8
|
+
jinx/word_spelling.py,sha256=7Ku8HIiV4FXI37V6bgAJa1WwOxHC6NU1ECAPxtKw6GA,3336
|
9
|
+
jinx/execution/executor.py,sha256=_xFu6HYJkrcFq9LljkuWaKXP3IaHREa6nUz-dRfXVWM,1917
|
10
|
+
jinx/execution/jax/__init__.py,sha256=xxDNdFZf7P0b-Mhi3_PXovameqYYCTv7X4KQ1A2frqE,1386
|
11
|
+
jinx/execution/jax/adverbs.py,sha256=EPxSXSvVkHhZvb1uD7e86MYJ7vzg7u3OYkme_8yamgM,3032
|
12
|
+
jinx/execution/jax/application.py,sha256=DYvVn4bRo3FYGVZrakchKL8zBpB0Ux_YmL-Y-dWTmj8,7458
|
13
|
+
jinx/execution/jax/verbs.py,sha256=OroFyn9oflmP-GFXNmwAhL2dGt90tnHc0lGMi0ZDFcc,2379
|
14
|
+
jinx/execution/numpy/__init__.py,sha256=ISRYr4LARvXrUmzTfMLDb2wIiIMr8Dctosetjo1cWS0,963
|
15
|
+
jinx/execution/numpy/adverbs.py,sha256=AsAPue2tTcS4kTQrbkJ0KXjFnQjwGeAoewy1LG1DsCc,11322
|
16
|
+
jinx/execution/numpy/application.py,sha256=2NNsYrdN5IaJMjGaaCTNPAZ0Gj-TwdSnL_reBkcnF3w,11254
|
17
|
+
jinx/execution/numpy/conjunctions.py,sha256=UJxWhEqvbj9G0CbjD6JoWPazg588K2gawJ9iN8xd0B8,14973
|
18
|
+
jinx/execution/numpy/conversion.py,sha256=CmMHqQ4LZVy9HrkItdGmyqGTvmlDZFuV7OH23nxsGKg,2364
|
19
|
+
jinx/execution/numpy/helpers.py,sha256=u-RqWnIVLvmyIG-K07Eo3PB1PWyN39ok6jf9uGpOYKs,4875
|
20
|
+
jinx/execution/numpy/printing.py,sha256=ksfNJ_VrXufs8NdIaFIyfTTEa92bhhKN6gd50j4T414,5306
|
21
|
+
jinx/execution/numpy/verbs.py,sha256=MxSyrmdfizhdV5K9O3uP9Ot9hG-HYxnubupqxZ35Zbs,26152
|
22
|
+
jjinx-0.0.1.dist-info/licenses/LICENSE,sha256=6aTGTYWpwS1y9Qc1yWYCL4fZiBLDOGKpmw0GegZEh98,1067
|
23
|
+
jjinx-0.0.1.dist-info/METADATA,sha256=LM0pNYqLd8PbrN1Uu5ZLp5Xg1wOHpa6tkiDSY-ylimk,6690
|
24
|
+
jjinx-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
25
|
+
jjinx-0.0.1.dist-info/entry_points.txt,sha256=pQ_2hEqrVOvVmIXehwmyDPLe-uFuPNrhHcpwipywlkU,41
|
26
|
+
jjinx-0.0.1.dist-info/top_level.txt,sha256=9RpSfRWqww0qsjO178PgxSOG5FIkU1nuzSbNgF_v9Eg,5
|
27
|
+
jjinx-0.0.1.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Alex Riley
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
jinx
|