-
-
Notifications
You must be signed in to change notification settings - Fork 11
📝 Notice about subtleties of inversion semantics of ForStatement
#545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TooMuchDakka
wants to merge
4
commits into
munich-quantum-toolkit:main
Choose a base branch
from
TooMuchDakka:loop_stmt_invr_notice
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ce39a85
Added notice about potentially unexpected index-out-of-range-errors d…
TooMuchDakka 987e2e5
Fixed small typos and updated module names in examples of newly added…
TooMuchDakka 3772bb2
Fixed library documentation that still used snake_casing instead of P…
TooMuchDakka 3b5e69e
Renamed Parser.rst to Program.rst for consistency between the documen…
TooMuchDakka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -275,6 +275,39 @@ The parser will not report an overlap in the assignment due to the index of the | |
|
|
||
| - The value of the step size of a ForStatement cannot be defined as or evaluate to 0 to prevent an infinite loop. | ||
|
|
||
| ````{warning} | ||
|
|
||
| Uncalling modules containing a _ForStatement_ could lead to unexpected index-out-of-range errors if one is not familiar with the semantics of how a _ForStatement_ or more specifically its value range is inverted, with the inversion semantics being inherited by SyReC from its reversible programming language predecessor Janus {cite:p}`yokoyama2007janus`. | ||
|
|
||
| A loop (_ForStatement_) defined as {math}`for \ e_1 \ to \ e_2 \ step \ s \ do \ s_1, s_2, \dots, s_n \ rof` | ||
| is inverted by inverting not only the sequence of statements in its loop body but also by inverting its value range thus the inversion of the given loop is equal to | ||
| {math}`for \ e_2 \ to \ e_1 \ step \ s \ do \ {s_n}^{-1}, \dots, {s_2}^{-1}, {s_1}^{-1} \ rof`. | ||
|
|
||
| The inversion result of the _ForStatement_ as well as its enclosing module `basicBitwiseIncr` is equal to the module `invrBasicBitwiseIncr` with both modules being shown in the example below: | ||
|
|
||
| ```text | ||
| module basicBitwiseIncr(inout a(4), inout b(4)) | ||
| for $i = 0 to #a do | ||
| ++= a.$i; | ||
| --= b.$i | ||
| rof | ||
|
|
||
| // Inversion of basicBitwiseIncr equal to "uncall basicBitwiseIncr(a, b)" | ||
| module invrBasicBitwiseIncr(inout a(4), inout b(4)) | ||
| for $i = #a to 0 do | ||
| ++= b.$i; | ||
| --= a.$i | ||
| rof | ||
|
|
||
| module main(inout a(4), inout b(4)) | ||
| // An index-out-of-range error would be reported here due to the value range of the ForStatement of the uncalled module | ||
| // being inverted with the loop variable $i being initialized with #a instead of 0 in the inverted ForStatement thus the assignments | ||
| // ++= b.$i and --= a.$i would both result in an index-out-of-range error. | ||
| uncall basicBitwiseIncr(a, b) | ||
| ``` | ||
|
Comment on lines
+280
to
+307
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really true? This seems like more of a bug to me. |
||
|
|
||
| ```` | ||
|
|
||
| ### IfStatement | ||
|
|
||
| - The components of an IfStatement will be referred to as _if <GUARD_CONDITION> then <TRUE_BRANCH> else <FALSE_BRANCH> fi <CLOSING_GUARD_CONDITION_. To be able to identify the matching guard condition for a closing guard condition, the expressions used to define both of these components must consist of the same characters (with an expression evaluating to the same value while consisting of different or additional characters not being considered equal). An example of an IfStatement violating this rule is the following: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TooMuchDakka This seems to cause Markdown formatting issues:
(At least it doesn't render correctly here on GitHub.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see any markdown formatting issues (see screenshot below) when performing a local build of the docs via
nox -s docs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is fine and typical nesting syntax