This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 295
feat(data/rat/floor): add norm_num support for int.{floor,ceil,fract}
#16502
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -149,4 +149,46 @@ begin | |
rwa [q_inv_eq, this.left, this.right, q_num_abs_eq_q_num, mul_comm] at q_inv_num_denom_ineq | ||
end | ||
|
||
namespace norm_num | ||
open tactic | ||
|
||
/-- A norm_num extension for `int.floor`, `int.ceil`, and `int.fract`. -/ | ||
@[norm_num] meta def eval_floor_ceil : expr → tactic (expr × expr) | ||
| e@`(@int.floor %%R %%inst_1 %%inst_2 %%x) := do | ||
q ← x.to_rat, | ||
let z := int.floor q, | ||
let ze := `(z), | ||
t ← to_expr ``(%%e = %%ze), | ||
((), p) ← tactic.solve_aux t (do | ||
tactic.mk_mapp `int.floor_eq_iff [some R, some inst_1, some inst_2] >>= tactic.rewrite_target, | ||
tactic.interactive.norm_num [] (interactive.loc.ns [none])), | ||
p ← instantiate_mvars p, | ||
pure (ze, p) | ||
| e@`(@int.ceil %%R %%inst_1 %%inst_2 %%x) := do | ||
q ← x.to_rat, | ||
let z := int.ceil q, | ||
let ze := `(z), | ||
t ← to_expr ``(%%e = %%ze), | ||
((), p) ← tactic.solve_aux t (do | ||
tactic.mk_mapp `int.ceil_eq_iff [some R, some inst_1, some inst_2] >>= tactic.rewrite_target, | ||
`[norm_num]), | ||
Comment on lines
+172
to
+174
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. Should the tactic input to (Most of my comments are also for my own understanding!) |
||
p ← instantiate_mvars p, | ||
pure (ze, p) | ||
| e@`(@int.fract %%R %%inst_1 %%inst_2 %%x) := do | ||
q ← x.to_rat, | ||
ic ← mk_instance_cache R, | ||
let q' := int.fract q, | ||
(ic, q'e) ← ic.of_rat q', | ||
let z := int.floor q, | ||
let ze := `(z), | ||
t ← to_expr ``(%%e = %%q'e), | ||
((), p) ← tactic.solve_aux t (do | ||
`[rw int.fract_eq_iff; norm_num], | ||
tactic.refine ``(⟨%%ze, _⟩), | ||
`[norm_num]), | ||
p ← instantiate_mvars p, | ||
pure (q'e, p) | ||
| _ := failed | ||
|
||
end norm_num | ||
end rat |
This file contains 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 | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ import algebra.big_operators.norm_num | |||||
import data.nat.squarefree | ||||||
import data.int.gcd | ||||||
import data.nat.fib | ||||||
import data.rat.floor | ||||||
import data.nat.prime | ||||||
import data.nat.sqrt_norm_num | ||||||
import analysis.special_functions.pow | ||||||
|
@@ -301,3 +302,17 @@ example : ∏ i in {1, 4, 9, 16}, nat.sqrt i = 24 := by norm_num | |||||
example : ∑ i : fin 2, ∑ j : fin 2, ![![0, 1], ![2, 3]] i j = 6 := by norm_num | ||||||
|
||||||
end big_operators | ||||||
|
||||||
section floor | ||||||
|
||||||
variables (R : Type*) [linear_ordered_field R] [floor_ring R] | ||||||
|
||||||
example : int.floor (15 / 16 : R) + 1 = 1 := by norm_num | ||||||
example : int.ceil (15 / 16 : R) + 1 = 2 := by norm_num | ||||||
example : int.fract (17 / 16 : R) + 1 = 17 / 16 := by norm_num | ||||||
|
||||||
example : int.floor (-15 / 16 : R) + 1 = 0 := by norm_num | ||||||
example : int.ceil (-15 / 16 : R) + 1 = 1 := by norm_num | ||||||
example : int.fract (-17 / 16 : R) - 1 = -1 / 16 := by norm_num | ||||||
|
||||||
end | ||||||
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.
Suggested change
to please the linter |
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.
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.
maybe, since it deals with
int.fract
as well.