-
Notifications
You must be signed in to change notification settings - Fork 64
feat: named ring/field instances for ring/field structure selection
#1067
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
Merged
Merged
Changes from all commits
Commits
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
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
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
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
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
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
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
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| (* Selecting a named `field` structure when a carrier has several instances. | ||
| Mirrors ring-multi-instance.ec for the `field` tactic: two field structures | ||
| are registered on `real', each named at declaration and picked with | ||
| `field [<name>]'. *) | ||
| require import Real. | ||
|
|
||
| (* ------------------------------------------------------------------ *) | ||
| (* Structure A, registered under the name `A'. *) | ||
| op zeroA : real = 0%r. | ||
| op oneA : real = 1%r. | ||
| op addA (x y : real) : real = x + y. | ||
| op oppA (x : real) : real = -x. | ||
| op mulA (x y : real) : real = x * y. | ||
| op invA (x : real) : real = inv x. | ||
| op exprA (x : real) (n : int) : real = RField.exp x n. | ||
| op ofintA (n : int) : real = n%r. | ||
|
|
||
| instance field [A] with real | ||
| op rzero = zeroA op rone = oneA op add = addA op opp = oppA | ||
| op mul = mulA op expr = exprA op ofint = ofintA op inv = invA | ||
|
|
||
| proof oner_neq0 by smt() proof addr0 by smt() proof addrA by smt() | ||
| proof addrC by smt() proof addrN by smt() proof mulr1 by smt() | ||
| proof mulrA by smt() proof mulrC by smt() proof mulrDl by smt() | ||
| proof mulrV by smt() | ||
| proof expr0 by smt(RField.expr0 RField.exprS RField.exprN) | ||
| proof exprS by smt(RField.expr0 RField.exprS RField.exprN) | ||
| proof exprN by smt(RField.expr0 RField.exprS RField.exprN) | ||
| proof ofint0 by smt() proof ofint1 by smt() | ||
| proof ofintS by smt() proof ofintN by smt(). | ||
|
|
||
| (* ------------------------------------------------------------------ *) | ||
| (* Structure B, registered under the name `B'. *) | ||
| op zeroB : real = 0%r. | ||
| op oneB : real = 1%r. | ||
| op addB (x y : real) : real = x + y. | ||
| op oppB (x : real) : real = -x. | ||
| op mulB (x y : real) : real = x * y. | ||
| op invB (x : real) : real = inv x. | ||
| op exprB (x : real) (n : int) : real = RField.exp x n. | ||
| op ofintB (n : int) : real = n%r. | ||
|
|
||
| instance field [B] with real | ||
| op rzero = zeroB op rone = oneB op add = addB op opp = oppB | ||
| op mul = mulB op expr = exprB op ofint = ofintB op inv = invB | ||
|
|
||
| proof oner_neq0 by smt() proof addr0 by smt() proof addrA by smt() | ||
| proof addrC by smt() proof addrN by smt() proof mulr1 by smt() | ||
| proof mulrA by smt() proof mulrC by smt() proof mulrDl by smt() | ||
| proof mulrV by smt() | ||
| proof expr0 by smt(RField.expr0 RField.exprS RField.exprN) | ||
| proof exprS by smt(RField.expr0 RField.exprS RField.exprN) | ||
| proof exprN by smt(RField.expr0 RField.exprS RField.exprN) | ||
| proof ofint0 by smt() proof ofint1 by smt() | ||
| proof ofintS by smt() proof ofintN by smt(). | ||
|
|
||
| (* Each selector routes to its own structure. The trailing `smt()' discharges | ||
| the `x <> 0' side condition that `field' emits for the inverse. *) | ||
| lemma fA (x : real) : | ||
| x <> zeroA => mulA (addA x oneA) (invA x) = addA oneA (invA x). | ||
| proof. move=> h; field [A]; smt(). qed. | ||
|
|
||
| lemma fB (x : real) : | ||
| x <> zeroB => mulB (addB x oneB) (invB x) = addB oneB (invB x). | ||
| proof. move=> h; field [B]; smt(). qed. |
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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| (* Selecting a named `ring` structure when a carrier has several instances. | ||
| Two ring structures are registered on `int`; each is given a name at | ||
| declaration, and the `ring` tactic is directed at one of them with | ||
| `ring [<name>]`. Bare `ring` keeps resolving the sole/first instance. *) | ||
| require import Int. | ||
| require (*--*) Ring. | ||
|
|
||
| (* ------------------------------------------------------------------ *) | ||
| (* Structure A, registered under the name `A'. *) | ||
| op zeroA : int = 0. | ||
| op oneA : int = 1. | ||
| op addA (x y : int) : int = x + y. | ||
| op oppA (x : int) : int = -x. | ||
| op mulA (x y : int) : int = x * y. | ||
| op exprA (x : int) (n : int) : int = Ring.IntID.exp x n. | ||
|
|
||
| instance ring [A] with int | ||
| op rzero = zeroA op rone = oneA op add = addA | ||
| op opp = oppA op mul = mulA op expr = exprA | ||
|
|
||
| proof oner_neq0 by smt() proof addr0 by smt() proof addrA by smt() | ||
| proof addrC by smt() proof addrN by smt() proof mulr1 by smt() | ||
| proof mulrA by smt() proof mulrC by smt() proof mulrDl by smt() | ||
| proof expr0 by smt(Ring.IntID.expr0) proof exprS by smt(Ring.IntID.exprS). | ||
|
|
||
| (* Only one instance exists here, so bare `ring` resolves it (this is the | ||
| backwards-compatible, single-structure case). *) | ||
| lemma bare (x y : int) : addA x (mulA y oneA) = addA (mulA oneA y) x. | ||
| proof. ring. qed. | ||
|
|
||
| lemma useA1 (x y : int) : addA x (mulA y oneA) = addA (mulA oneA y) x. | ||
| proof. ring [A]. qed. | ||
|
|
||
| (* ------------------------------------------------------------------ *) | ||
| (* Structure B, registered under the name `B'. Same underlying maths, but | ||
| distinct operator paths, so it is a genuinely separate instance on the | ||
| same carrier `int'. *) | ||
| op zeroB : int = 0. | ||
| op oneB : int = 1. | ||
| op addB (x y : int) : int = x + y. | ||
| op oppB (x : int) : int = -x. | ||
| op mulB (x y : int) : int = x * y. | ||
| op exprB (x : int) (n : int) : int = Ring.IntID.exp x n. | ||
|
|
||
| instance ring [B] with int | ||
| op rzero = zeroB op rone = oneB op add = addB | ||
| op opp = oppB op mul = mulB op expr = exprB | ||
|
|
||
| proof oner_neq0 by smt() proof addr0 by smt() proof addrA by smt() | ||
| proof addrC by smt() proof addrN by smt() proof mulr1 by smt() | ||
| proof mulrA by smt() proof mulrC by smt() proof mulrDl by smt() | ||
| proof expr0 by smt(Ring.IntID.expr0) proof exprS by smt(Ring.IntID.exprS). | ||
|
|
||
| (* Two instances are now registered on `int'. Each selector routes to its own | ||
| structure: the operators of the other structure are opaque to it, so a goal | ||
| phrased with A's operators is a ring identity only for structure A (and dually | ||
| for B). These lemmas being accepted is exactly what shows the selector picks | ||
| the intended structure rather than the first-registered one. *) | ||
| lemma useA2 (x y : int) : addA x (mulA y oneA) = addA (mulA oneA y) x. | ||
| proof. ring [A]. qed. | ||
|
|
||
| lemma useB (x y : int) : addB x (mulB y oneB) = addB (mulB oneB y) x. | ||
| proof. ring [B]. qed. |
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.