Skip to content

Commit 922505f

Browse files
committed
docs: define PET 2.0 operator semantics
1 parent 8b20677 commit 922505f

2 files changed

Lines changed: 246 additions & 0 deletions

File tree

docs/foundations/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ For live research notes, read `../research/README.md`.
4040
- `pet-peg-2.0-core-pillars.md` — PET/PEG 2.0 core pillars and boundary
4141
- `pet-peg-2.0-root-base-recursion.md` — PET/PEG 2.0 exact and partial root-base recursion semantics
4242
- `pet-peg-2.0-structural-addresses.md` — PET/PEG 2.0 structural address, identity, and address-outcome semantics
43+
- `pet-peg-2.0-operator-semantics.md` — PET/PEG 2.0 NEW/DROP/INC/DEC target and value-level application semantics
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# PET/PEG 2.0 Operator Semantics
2+
3+
This note defines the first PET/PEG 2.0 operator semantics over recursive
4+
`PETObject` values.
5+
6+
This layer defines target validity and value-level application for:
7+
8+
- `NEW`
9+
- `DROP`
10+
- `INC`
11+
- `DEC`
12+
13+
It does not define routing policy, graph traversal policy, anchor selection, or
14+
factorization-performance behavior.
15+
16+
## Operator axes
17+
18+
PET/PEG 2.0 currently defines two executable operator axes in the core object
19+
model.
20+
21+
| Axis | Operators | Target kind |
22+
| --- | --- | --- |
23+
| X | `NEW`, `DROP` | parent-support |
24+
| Y | `INC`, `DEC` | selected-root |
25+
26+
## X-axis operators
27+
28+
X-axis operators mutate support at an addressed parent PET object.
29+
30+
### NEW(parent_address, q)
31+
32+
`NEW` adds a fresh prime label `q` to the support of the parent object selected
33+
by `parent_address`.
34+
35+
Target validity:
36+
37+
- `parent_address` must resolve to a valid PET object
38+
- selected parent must be composite
39+
- `q` must be prime
40+
- `q` must not already exist in the selected parent support
41+
42+
Example on `60 = 2^2 * 3 * 5`:
43+
44+
NEW((), 7)
45+
46+
is valid and produces:
47+
48+
60 -> 420
49+
50+
Nested example:
51+
52+
NEW((2,), 3)
53+
54+
enters the exponent-object of the selected root `2`.
55+
56+
For:
57+
58+
60 = 2^2 * 3 * 5
59+
60+
the selected child at `(2,)` has exponent object `2`.
61+
62+
Adding `3` inside that exponent object changes:
63+
64+
2 -> 2 * 3 = 6
65+
66+
so:
67+
68+
2^2 * 3 * 5 -> 2^6 * 3 * 5 = 960
69+
70+
### DROP(parent_address, p)
71+
72+
`DROP` removes an existing prime label `p` from the support of the parent object
73+
selected by `parent_address`.
74+
75+
Target validity:
76+
77+
- `parent_address` must resolve to a valid PET object
78+
- selected parent must be composite
79+
- `p` must be prime
80+
- `p` must exist in the selected parent support
81+
82+
Example on `60 = 2^2 * 3 * 5`:
83+
84+
DROP((), 5)
85+
86+
is valid and produces:
87+
88+
60 -> 12
89+
90+
## Y-axis operators
91+
92+
Y-axis operators mutate the exponent of a selected root.
93+
94+
### INC(address)
95+
96+
`INC` increments the exponent of the root selected by `address`.
97+
98+
Target validity:
99+
100+
- `address` must be non-empty
101+
- `address` must resolve to a valid selected root
102+
- atomic and composite selected roots are both valid targets
103+
104+
Example on `60 = 2^2 * 3 * 5`:
105+
106+
INC((2,))
107+
108+
increments the exponent of `2`:
109+
110+
2^2 -> 2^3
111+
112+
so:
113+
114+
60 -> 120
115+
116+
Nested example:
117+
118+
INC((2, 2))
119+
120+
increments inside the exponent-object of root `2`.
121+
122+
For:
123+
124+
60 = 2^2 * 3 * 5
125+
126+
the exponent object of `2` is `2`. Incrementing that inner `2` changes the
127+
outer exponent:
128+
129+
2 -> 3
130+
131+
so:
132+
133+
2^2 * 3 * 5 -> 2^3 * 3 * 5 = 120
134+
135+
When applied through the current value-level implementation, recursive exponent
136+
rewriting is rebuilt through represented integer value.
137+
138+
### DEC(address)
139+
140+
`DEC` decrements the exponent of the root selected by `address`.
141+
142+
Target validity:
143+
144+
- `address` must be non-empty
145+
- `address` must resolve to a valid selected root
146+
- selected root must be composite
147+
- selected atomic leaf is invalid because exponent `1` has no predecessor in
148+
this semantics
149+
150+
Example on `60 = 2^2 * 3 * 5`:
151+
152+
DEC((2,))
153+
154+
decrements the exponent of `2`:
155+
156+
2^2 -> 2^1
157+
158+
so:
159+
160+
60 -> 30
161+
162+
`DEC((3,))` is invalid because `(3,)` selects an atomic leaf.
163+
164+
## Target semantics
165+
166+
Current implementation resolves operator targets without mutation.
167+
168+
Implementation:
169+
170+
- `PETOperatorTarget`
171+
- `new_target(obj, parent_address, q)`
172+
- `drop_target(obj, parent_address, p)`
173+
- `inc_target(obj, address)`
174+
- `dec_target(obj, address)`
175+
- `resolve_operator_target(obj, op, address, argument=None)`
176+
177+
Target examples on `PETObject(60)`:
178+
179+
| Invocation | Valid | Reason |
180+
| --- | --- | --- |
181+
| `NEW((), 7)` | yes | `new-target-valid` |
182+
| `NEW((), 3)` | no | `q-already-in-target-baseline` |
183+
| `DROP((), 5)` | yes | `drop-target-valid` |
184+
| `DROP((), 7)` | no | `p-not-in-target-baseline` |
185+
| `INC((2,))` | yes | `inc-target-valid` |
186+
| `INC((3, 2))` | no | `address-blocked-at-leaf` |
187+
| `DEC((2,))` | yes | `dec-target-valid` |
188+
| `DEC((3,))` | no | `selected-object-is-atomic-leaf` |
189+
190+
## Value-level application
191+
192+
Current implementation applies valid operators by represented integer value and
193+
then rebuilds a new `PETObject`.
194+
195+
Implementation:
196+
197+
- `PETOperatorApplication`
198+
- `apply_operator_by_value(obj, op, address, argument=None)`
199+
200+
This is intentionally value-level application.
201+
202+
It is not yet manual structural rewriting of existing object internals.
203+
204+
Application examples on `PETObject(60)`:
205+
206+
| Invocation | Result |
207+
| --- | --- |
208+
| `NEW((), 7)` | `60 -> 420` |
209+
| `DROP((), 5)` | `60 -> 12` |
210+
| `INC((2,))` | `60 -> 120` |
211+
| `DEC((2,))` | `60 -> 30` |
212+
| `INC((2, 2))` | `60 -> 240` |
213+
| `NEW((2,), 3)` | `60 -> 960` |
214+
215+
Invalid operators return an invalid `PETOperatorApplication` without producing
216+
an `after_object`.
217+
218+
## Current implementation
219+
220+
Current implementation:
221+
222+
- `src/pet/operators.py`
223+
- `PETOperatorTarget`
224+
- `PETOperatorApplication`
225+
- `new_target`
226+
- `drop_target`
227+
- `inc_target`
228+
- `dec_target`
229+
- `resolve_operator_target`
230+
- `apply_operator_by_value`
231+
232+
Current tests:
233+
234+
- `tests/test_operators.py`
235+
236+
## Boundary
237+
238+
This semantics does not claim:
239+
240+
- routing policy
241+
- graph traversal policy
242+
- anchor selection
243+
- factorization performance
244+
- stable CLI behavior changes
245+
- manual structural rewrite semantics

0 commit comments

Comments
 (0)