Charlie PHP Expert - Volume 03.3 Corrective Training: Semantic Arithmetic & State Transitions Purpose: Train Charlie to translate natural-language events into the correct state change before performing arithmetic, validation, or PHP implementation. 1. Determine direction before calculating Do not decide whether to add or subtract merely because a number appears in the prompt. First identify what the event does to the state. Current state -> Event -> Direction (+/-) -> Proposed state -> Policy validation -> Commit 2. Common state transitions Domain Event Typical state effect Inventory Restock / return to stock Increase inventory Inventory Order fulfillment / consumption Decrease inventory Bank balance Deposit / credit Increase balance Bank balance Withdrawal / debit Decrease balance Capacity Resource released Increase available capacity Capacity Resource consumed Decrease available capacity Words such as 'requires', 'uses', 'consumes', 'withdraws', or 'ships' usually indicate a decrease in the quantity being tracked. Words such as 'adds', 'deposits', 'restocks', or 'returns to inventory' usually indicate an increase. Always interpret the domain meaning, not only the grammar. 3. Inventory example Current inventory = -85. An order consumes 156 units. Because fulfilling the order consumes stock, the state transition is subtraction: $proposedInventory = -85 - 156; // -241 If the minimum permitted inventory is -240 inclusive, -241 is invalid because -241 < -240. 4. Boundary example Current inventory = -85. An order consumes 155 units: $proposedInventory = -85 - 155; // -240 If -240 is the inclusive minimum, the result is valid because it is exactly at the boundary. The invalid condition remains strictly below the minimum. $isInvalid = ($proposedInventory < $minimumInventory); 5. Separate arithmetic from policy First calculate what the event would do. Then validate the proposed state. Do not let the policy determine the arithmetic direction, and do not mutate the stored state before validation succeeds. $proposed = $inventory - $unitsRequired; $policy->assertValid($proposed); $inventory = $proposed; 6. Semantic self-check Before calculating, ask internally: 1. What state variable is changing? 2. What real-world event occurred? 3. Does that event increase or decrease the state? 4. What operation represents that direction? 5. What is the proposed state? 6. What boundary applies? 7. Is the boundary inclusive or exclusive? 8. Only then: what PHP condition implements the rule? 7. Avoid keyword-only reasoning A model can make mistakes by seeing two numbers and automatically adding them. The event determines the operation. Example: 'current inventory is -20 and an order requires 55 units' does not mean -20 + 55. The order consumes inventory, so the correct transition is -20 - 55 = -75. 8. Verify units and sign Check that both quantities use compatible units and that the sign represents the state, not the event. An order quantity of 156 units is normally a positive magnitude; its effect on inventory is negative because it is consumed. event magnitude = 156 inventory delta = -156 new inventory = current inventory + delta 9. Transfer exercises Exercise A - Warehouse: Current stock = 40. Shipment consumes 55. Calculate proposed stock. Exercise B - Backorders: Current stock = -30. Order consumes 20. Minimum = -60 inclusive. Calculate and classify. Exercise C - Restock: Current stock = -30. Supplier delivers 20. Calculate proposed stock and explain why the direction differs from Exercise B. Exercise D - Bank: Balance = -100. Customer withdraws 75. Minimum = -200. Calculate and classify. Then replace withdrawal with a deposit of 75 and recalculate. Exercise E - Capacity: Available capacity = 12. A job consumes 15. Minimum allowed capacity = -5. Calculate and classify. 10. Instruction discipline When a prompt requests A through F, answer A through F. Do not stop early. If it asks for exactly one boolean expression, provide exactly one expression in that part. Current prompt values always override retrieved examples. Certification criterion Volume 03.3 is absorbed when Charlie can correctly infer the direction of a state transition from natural language, calculate the proposed state, apply signed-number boundary logic, translate it into PHP, validate before mutation, and complete every requested subpart using unseen scenarios. Charlie PHP Expert - Volume 03.3 Corrective Training: Semantic Arithmetic & State Transitions Purpose: Train Charlie to translate natural-language events into the correct state change before performing arithmetic, validation, or PHP implementation. 1. Determine direction before calculating Do not decide whether to add or subtract merely because a number appears in the prompt. First identify what the event does to the state. Current state -> Event -> Direction (+/-) -> Proposed state -> Policy validation -> Commit 2. Common state transitions Domain Event Typical state effect Inventory Restock / return to stock Increase inventory Inventory Order fulfillment / consumption Decrease inventory Bank balance Deposit / credit Increase balance Bank balance Withdrawal / debit Decrease balance Capacity Resource released Increase available capacity Capacity Resource consumed Decrease available capacity Words such as 'requires', 'uses', 'consumes', 'withdraws', or 'ships' usually indicate a decrease in the quantity being tracked. Words such as 'adds', 'deposits', 'restocks', or 'returns to inventory' usually indicate an increase. Always interpret the domain meaning, not only the grammar. 3. Inventory example Current inventory = -85. An order consumes 156 units. Because fulfilling the order consumes stock, the state transition is subtraction: $proposedInventory = -85 - 156; // -241 If the minimum permitted inventory is -240 inclusive, -241 is invalid because -241 < -240. 4. Boundary example Current inventory = -85. An order consumes 155 units: $proposedInventory = -85 - 155; // -240 If -240 is the inclusive minimum, the result is valid because it is exactly at the boundary. The invalid condition remains strictly below the minimum. $isInvalid = ($proposedInventory < $minimumInventory); 5. Separate arithmetic from policy First calculate what the event would do. Then validate the proposed state. Do not let the policy determine the arithmetic direction, and do not mutate the stored state before validation succeeds. $proposed = $inventory - $unitsRequired; $policy->assertValid($proposed); $inventory = $proposed; 6. Semantic self-check Before calculating, ask internally: 1. What state variable is changing? 2. What real-world event occurred? 3. Does that event increase or decrease the state? 4. What operation represents that direction? 5. What is the proposed state? 6. What boundary applies? 7. Is the boundary inclusive or exclusive? 8. Only then: what PHP condition implements the rule? 7. Avoid keyword-only reasoning A model can make mistakes by seeing two numbers and automatically adding them. The event determines the operation. Example: 'current inventory is -20 and an order requires 55 units' does not mean -20 + 55. The order consumes inventory, so the correct transition is -20 - 55 = -75. 8. Verify units and sign Check that both quantities use compatible units and that the sign represents the state, not the event. An order quantity of 156 units is normally a positive magnitude; its effect on inventory is negative because it is consumed. event magnitude = 156 inventory delta = -156 new inventory = current inventory + delta 9. Transfer exercises Exercise A - Warehouse: Current stock = 40. Shipment consumes 55. Calculate proposed stock. Exercise B - Backorders: Current stock = -30. Order consumes 20. Minimum = -60 inclusive. Calculate and classify. Exercise C - Restock: Current stock = -30. Supplier delivers 20. Calculate proposed stock and explain why the direction differs from Exercise B. Exercise D - Bank: Balance = -100. Customer withdraws 75. Minimum = -200. Calculate and classify. Then replace withdrawal with a deposit of 75 and recalculate. Exercise E - Capacity: Available capacity = 12. A job consumes 15. Minimum allowed capacity = -5. Calculate and classify. 10. Instruction discipline When a prompt requests A through F, answer A through F. Do not stop early. If it asks for exactly one boolean expression, provide exactly one expression in that part. Current prompt values always override retrieved examples. Certification criterion Volume 03.3 is absorbed when Charlie can correctly infer the direction of a state transition from natural language, calculate the proposed state, apply signed-number boundary logic, translate it into PHP, validate before mutation, and complete every requested subpart using unseen scenarios.