Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
use linear_combination with exponent
Browse files Browse the repository at this point in the history
  • Loading branch information
robertylewis committed Jul 16, 2022
1 parent 4fa0a2c commit f6893ac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion scripts/polyrith_sage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def create_query(type: str, n_vars: int, eq_list, goal_type):
raise e
n = naive_power_search(p, I)
coeffs = (p^n).lift(I)
print(json.dumps({{'exponent': n, "coeffs": [polynomial_to_string(c) for c in coeffs]}}))
print(json.dumps({{'exponent': int(n), "coeffs": [polynomial_to_string(c) for c in coeffs]}}))
'''
return query

Expand Down
13 changes: 4 additions & 9 deletions src/tactic/polyrith.lean
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ remember to force recompilation of any files that call `polyrith`.

open tactic native

lemma pow_eq_zero' {M : Type*} [monoid_with_zero M] [no_zero_divisors M] {x : M} (n : ℕ) :
x ^ n = 0 → x = 0 :=
pow_eq_zero

namespace polyrith

/-! # Poly Datatype -/
Expand Down Expand Up @@ -471,18 +467,17 @@ meta def process_output (eq_names : list expr) (m : list expr) (R : expr) (sage_
tactic format := do
some (exp, coeffs_as_poly) ← convert_sage_output sage_out
| fail!"internal error: No output available",
when (exp ≠ 1) $ refine ``(pow_eq_zero' %%`(exp) _),
coeffs_as_pexpr ← coeffs_as_poly.mmap (poly.to_pexpr m),
let eq_names_pexpr := eq_names.map to_pexpr,
coeffs_as_expr ← coeffs_as_pexpr.mmap $ λ e, to_expr ``(%%e : %%R),
linear_combo.linear_combination eq_names_pexpr coeffs_as_pexpr,
linear_combo.linear_combination eq_names_pexpr coeffs_as_pexpr
(if exp ≠ 1 then some exp else none),
let components := (eq_names.zip coeffs_as_expr).filter
$ λ pr, bnot $ pr.2.is_app_of `has_zero.zero,
expr_string ← components_to_lc_format components,
let refn : format :=
if exp ≠ 1 then format!"refine pow_eq_zero' {exp} _;" ++ format.line else "",
let lc : format := "linear_combination " ++ format.group expr_string,
return $ format.nest 2 $ refn ++ lc
let lc := if exp ≠ 1 then lc ++ format!" with exponent {exp}" else lc,
return $ format.nest 2 lc

/-- Tactic for the special case when no hypotheses are available. -/
meta def no_hypotheses_case : tactic (option format) :=
Expand Down

0 comments on commit f6893ac

Please sign in to comment.