TorchLean API

NN.Tensor.Internal.Syntax.Parser.Expression.State

Expression token state #

This module owns duplicate detection, group state, token decoding, and the canonicalization invariants preserved by each state transition.

Duplicate-detection identity for a named axis or the single ellipsis marker.

  • named (name : String) : AxisKey

    Duplicate-detection key for a user-named axis.

  • ellipsis : AxisKey

    Duplicate-detection key shared by all ellipsis occurrences.

Instances For

    Accumulated grouping and duplicate-detection state for one expression.

    Instances For

      Normalize decimal words to their canonical natural-number spelling while leaving structural tokens unchanged.

      Instances For

        Canonicalizing decimal words does not change whether a token is an arrow.

        Canonicalizing decimal words preserves and reflects comma tokens.

        theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.findArrow_eq_none_of_canonical (policy : IdentifierPolicy) (sourceTokens targetTokens : List Token) (hTokens : List.map Located.value targetTokens = List.map (fun (token : Token) => canonicalTokenKind policy token.value) sourceTokens) (hFind : List.find? (fun (token : Token) => token.value == TokenKind.arrow) sourceTokens = none) :
        List.find? (fun (token : Token) => token.value == TokenKind.arrow) targetTokens = none

        Canonical token replacement cannot introduce an arrow into an arrow-free stream.

        Construct a source-located duplicate-axis diagnostic.

        Instances For

          Record one named axis or ellipsis while enforcing the expression's duplicate policy.

          Instances For
            theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.registerKey_eq_ok_at_span (config : ExpressionConfig) (key : AxisKey) (sourceSpan targetSpan : Span) (seen nextSeen : List AxisKey) (hRegister : registerKey config key sourceSpan seen = Except.ok nextSeen) :
            registerKey config key targetSpan seen = Except.ok nextSeen

            Successful duplicate registration is independent of the diagnostic source span.

            Enforce einops underscore placement while permitting the wildcard _.

            Instances For

              Interpret one word token as a named, anonymous, or unit axis and update duplicate tracking.

              Instances For

                Decode and register a bare ellipsis token.

                Instances For

                  Append an axis to the open group or as a new top-level physical axis.

                  Instances For

                    Render the parser state's completed axes and any currently open group.

                    Instances For

                      Appending an axis to parser state appends its token kind to the rendered state.

                      Relate parser states that differ only in source spans and canonical decimal spelling.

                      Instances For
                        theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.ExpressionState.canonicalEq_pushAxis (leftAxis rightAxis : Located Axis) (leftState rightState : ExpressionState) (hState : leftState.CanonicalEq rightState) (hAxis : leftAxis.value.tokenKind = rightAxis.value.tokenKind) :
                        (pushAxis leftAxis leftState).CanonicalEq (pushAxis rightAxis rightState)

                        Pushing canonically equal axes preserves canonical parser-state equivalence.

                        theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.ExpressionState.canonicalEq_setSeen (leftState rightState : ExpressionState) (leftSeen rightSeen : List AxisKey) (hState : leftState.CanonicalEq rightState) (hSeen : leftSeen = rightSeen) :
                        { seen := leftSeen, group := leftState.group, axesRev := leftState.axesRev }.CanonicalEq { seen := rightSeen, group := rightState.group, axesRev := rightState.axesRev }

                        Replacing equal duplicate-tracking lists preserves canonical state equivalence.

                        theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.ExpressionState.canonicalEq_openGroup (leftState rightState : ExpressionState) (leftSpan rightSpan : Span) (hState : leftState.CanonicalEq rightState) (hLeftGroup : leftState.group = none) (hRightGroup : rightState.group = none) :
                        { seen := leftState.seen, group := some (leftSpan, []), axesRev := leftState.axesRev }.CanonicalEq { seen := rightState.seen, group := some (rightSpan, []), axesRev := rightState.axesRev }

                        Opening corresponding empty groups preserves canonical state equivalence.

                        theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.ExpressionState.canonicalEq_closeGroup (leftState rightState : ExpressionState) (leftOpenSpan rightOpenSpan leftCloseSpan rightCloseSpan : Span) (leftAxesRev rightAxesRev : List (Located Axis)) (hState : leftState.CanonicalEq rightState) (hLeftGroup : leftState.group = some (leftOpenSpan, leftAxesRev)) (hRightGroup : rightState.group = some (rightOpenSpan, rightAxesRev)) :
                        { seen := leftState.seen, axesRev := { axes := leftAxesRev.reverse, parenthesized := true, span := leftOpenSpan.join leftCloseSpan } :: leftState.axesRev }.CanonicalEq { seen := rightState.seen, axesRev := { axes := rightAxesRev.reverse, parenthesized := true, span := rightOpenSpan.join rightCloseSpan } :: rightState.axesRev }

                        Closing corresponding groups preserves canonical token structure despite span changes.

                        theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.tokenKinds_pushAxis_decodeWord (policy : IdentifierPolicy) (config : ExpressionConfig) (token : Token) (state : ExpressionState) (axis : Located Axis) (nextState : ExpressionState) (hDecode : decodeWord policy config token state = Except.ok (axis, nextState)) :
                        (pushAxis axis nextState).tokenKinds = state.tokenKinds ++ [canonicalTokenKind policy token.value]

                        Successful word decoding appends the token's canonical kind to parser state.

                        theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.decodeWord_canonical (config : ExpressionConfig) (sourceToken targetToken : Token) (sourceState targetState : ExpressionState) (sourceAxis : Located Axis) (sourceNextState : ExpressionState) (hValue : targetToken.value = canonicalTokenKind IdentifierPolicy.pythonUnicode sourceToken.value) (hState : sourceState.CanonicalEq targetState) (hDecode : decodeWord IdentifierPolicy.pythonUnicode config sourceToken sourceState = Except.ok (sourceAxis, sourceNextState)) :
                        (targetAxis : Located Axis), (targetNextState : ExpressionState), decodeWord IdentifierPolicy.pythonUnicode config targetToken targetState = Except.ok (targetAxis, targetNextState) (pushAxis sourceAxis sourceNextState).CanonicalEq (pushAxis targetAxis targetNextState)

                        Decoding a canonical word spelling succeeds with an equivalent next parser state.

                        theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.tokenKinds_pushAxis_decodeEllipsis (config : ExpressionConfig) (token : Token) (state : ExpressionState) (axis : Located Axis) (nextState : ExpressionState) (hDecode : decodeEllipsis config token state = Except.ok (axis, nextState)) :

                        Successful ellipsis decoding appends exactly one ellipsis token kind.

                        theorem TorchLean.Tensor.Internal.Syntax.Parser.Impl.decodeEllipsis_canonical (config : ExpressionConfig) (sourceToken targetToken : Token) (sourceState targetState : ExpressionState) (sourceAxis : Located Axis) (sourceNextState : ExpressionState) (hState : sourceState.CanonicalEq targetState) (hDecode : decodeEllipsis config sourceToken sourceState = Except.ok (sourceAxis, sourceNextState)) :
                        (targetAxis : Located Axis), (targetNextState : ExpressionState), decodeEllipsis config targetToken targetState = Except.ok (targetAxis, targetNextState) (pushAxis sourceAxis sourceNextState).CanonicalEq (pushAxis targetAxis targetNextState)

                        Re-decoding an ellipsis at a new span preserves canonical parser state.