-
Notifications
You must be signed in to change notification settings - Fork 5
A simplification tactic for Z-module equations, specific to Z #17
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
pi8027
wants to merge
1
commit into
main
Choose a base branch
from
ac-simplifier-Z
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,10 @@ From elpi Require Import elpi. | |
From AC Require Import AC. | ||
|
||
(******************************************************************************) | ||
(* The Z_zmodule tactic *) | ||
(* Tactics specific to Z *) | ||
(******************************************************************************) | ||
|
||
Ltac Z_zmodule_reflection VM ZE1 ZE2 := | ||
apply (@ZM_correct_Z VM ZE1 ZE2); [vm_compute; reflexivity]. | ||
|
||
Elpi Tactic Z_zmodule. | ||
Elpi Accumulate lp:{{ | ||
|
||
pred mem o:list term, o:term, o:term. | ||
mem [X|_] X {{ O }} :- !. | ||
mem [_|XS] X {{ S lp:N }} :- !, mem XS X N. | ||
Elpi Db Z_reify lp:{{ | ||
|
||
pred quote i:term, o:term, o:list term. | ||
quote {{ Z0 }} {{ AGO }} _ :- !. | ||
|
@@ -23,10 +15,25 @@ quote {{ Z.add lp:In1 lp:In2 }} {{ AGAdd lp:Out1 lp:Out2 }} VM :- !, | |
quote In1 Out1 VM, quote In2 Out2 VM. | ||
quote In {{ AGX lp:N }} VM :- !, mem VM In N. | ||
|
||
pred mem o:list term, o:term, o:term. | ||
mem [X|_] X {{ O }} :- !. | ||
mem [_|XS] X {{ S lp:N }} :- !, mem XS X N. | ||
|
||
pred list-constant o:term, o:list term, o:term. | ||
list-constant T [] {{ @nil lp:T }} :- !. | ||
list-constant T [X|XS] {{ @cons lp:T lp:X lp:XS' }} :- list-constant T XS XS'. | ||
|
||
}}. | ||
|
||
(* The Z_zmodule tactic *) | ||
|
||
Ltac Z_zmodule_reflection VM ZE1 ZE2 := | ||
apply (@ZM_correct_Z VM ZE1 ZE2); [vm_compute; reflexivity]. | ||
|
||
Elpi Tactic Z_zmodule. | ||
Elpi Accumulate Db Z_reify. | ||
Elpi Accumulate lp:{{ | ||
|
||
pred solve i:goal, o:list sealed-goal. | ||
solve (goal _ _ {{ @eq Z lp:T1 lp:T2 }} _ _ as Goal) GS :- !, | ||
quote T1 ZE1 VM, !, | ||
|
@@ -45,3 +52,48 @@ zmod-reflection _ _ _ _ _ :- | |
Elpi Typecheck. | ||
|
||
Tactic Notation "Z_zmodule" := (elpi Z_zmodule). | ||
|
||
(* The Z_zmodule_simplify tactic *) | ||
|
||
Ltac Z_zmodule_simplify_reflection VM ZE1 ZE2 := | ||
let zero := fresh "zero" in | ||
let add := fresh "add" in | ||
let vm := fresh "vm" in | ||
let zeroE := fresh "zeroE" in | ||
let addE := fresh "addE" in | ||
let vmE := fresh "vmE" in | ||
let norm := fresh "norm" in | ||
apply (@ZMsimpl_correct_Z VM ZE1 ZE2); | ||
intros zero add vm zeroE addE vmE norm; | ||
vm_compute in norm; compute; | ||
rewrite zeroE, addE, vmE; clear zero add vm zeroE addE vmE norm. | ||
Comment on lines
+67
to
+69
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. And this is the normalization of the proof obligation. |
||
|
||
Elpi Tactic Z_zmodule_simplify. | ||
Elpi Accumulate Db Z_reify. | ||
Elpi Accumulate lp:{{ | ||
|
||
pred solve i:goal, o:list sealed-goal. | ||
solve (goal _ _ {{ @eq Z lp:T1 lp:T2 }} _ _ as Goal) GS :- !, | ||
quote T1 ZE1 VM, !, | ||
quote T2 ZE2 VM, !, | ||
list-constant {{ Z }} VM VM', !, | ||
zmod-simpl-reflection VM' ZE1 ZE2 Goal GS. | ||
solve _ _ :- coq.ltac.fail 0 "The goal is not an equation". | ||
|
||
pred zmod-simpl-reflection i:term, i:term, i:term, i:goal, o:list sealed-goal. | ||
zmod-simpl-reflection VM ZE1 ZE2 G GS :- | ||
coq.ltac.call "Z_zmodule_simplify_reflection" [trm VM, trm ZE1, trm ZE2] G GS. | ||
zmod-simpl-reflection _ _ _ _ _ :- | ||
coq.ltac.fail 0 "Reflection failed". | ||
|
||
}}. | ||
Elpi Typecheck. | ||
|
||
Tactic Notation "Z_zmodule_simplify" := (elpi Z_zmodule_simplify). | ||
|
||
Goal forall x y y' z, y = y' -> (x + y + - z + y = x + - z + y + y')%Z. | ||
Proof. | ||
intros x y y' z Hy. | ||
Z_zmodule_simplify. | ||
exact Hy. | ||
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
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.
This is the proof obligation of the
Z_zmodule_simplify
tactic:zero
,add
, andvm'
are abstracted out to make sure that they will not be reduced. I thought thatnorm
should be reduced byvm_compute
, and the other part should be reduced bylazy
orcompute
because its readback seems to be costly.It is quite intricate, so should be documented in detail.