提交信息
题目#6. 模同余相关性质和中国剩余定理证明
提交者jkjkmxmx
状态Compile Error
分数0
提交时间2026/02/13 20:48:38
源代码
import Mathlib.Data.Int.GCD
import Mathlib.Tactic.Convert
import Mathlib.Tactic.Ring

local notation " ( " a " ≡ " b " mod " n " ) " => n ∣ a - b

theorem modulo_tran (a b c n : ℤ) (hab : (a ≡ b mod n)) (hbc : (b ≡ c mod n)) : (a ≡ c mod n) := by
  convert Int.dvd_add hab hbc using 1
  ring

theorem modulo_mult_subst (a b c n : ℤ) (hab : (a ≡ b mod n)) : (a * c ≡ b * c mod n) := by
  convert Int.dvd_mul_of_dvd_left hab (c := c) using 1
  ring

theorem modulo_inv (m n : ℤ) (p : m.gcd n = 1) : ∃ x : ℤ, (m * x ≡ 1 mod n) := by
  refine ⟨m.gcdA n, ?_⟩
  have h := m.gcd_eq_gcd_ab n
  rw [p, Nat.cast_one] at h
  rw [h]
  simp

theorem SimpleChineseRemainder (m n : ℤ) (p : m.gcd n = 1) (a b : ℤ) : ∃ x : ℤ, (x ≡ a mod m) ∧ (x ≡ b mod n) := by
  refine ⟨m * m.gcdA n * b + n * m.gcdB n * a, ?_, ?_⟩
  · refine modulo_tran _ (m * m.gcdA n * a + n * m.gcdB n * a) _ m ?_ ?_
    · ring
      apply Int.dvd_sub <;> simp [Int.mul_assoc]
    · rw [← Int.add_mul, ← m.gcd_eq_gcd_ab n, p]
      simp
  · refine modulo_tran _ (m * m.gcdA n * b + n * m.gcdB n * b) _ n ?_ ?_
    · ring
      apply Int.dvd_add
      · simp
        rw [Int.mul_right_comm]
        simp
      · simp [Int.mul_assoc]
    · rw [← Int.add_mul, ← m.gcd_eq_gcd_ab n, p]
      simp

theorem P₅₀₅ :
  (∀ (a b c n : ℤ), (a ≡ b mod n) → (b ≡ c mod n) → (a ≡ c mod n)) ∧
  (∀ (a b c n : ℤ), (a ≡ b mod n) → (a * c ≡ b * c mod n)) ∧
  (∀ (m n : ℤ), m.gcd n = 1 → ∃ x : ℤ, (m * x ≡ 1 mod n)) ∧
  (∀ (m n : ℤ), m.gcd n = 1 → ∀ (a b : ℤ), ∃ x : ℤ, (x ≡ a mod m) ∧ (x ≡ b mod n)) :=
  ⟨modulo_tran, modulo_mult_subst, modulo_inv, SimpleChineseRemainder⟩
评测详情
compilecompile_problem
787 ms1090 MBOK
Built: problem
输出 (stdout / stderr)
[lean -o] /work/problem.lean:11:4: warning: declaration uses 'sorry'
/work/problem.lean:20:4: warning: declaration uses 'sorry'
/work/problem.lean:28:8: warning: declaration uses 'sorry'
/work/problem.lean:33:8: warning: declaration uses 'sorry'

[lean -c] /work/problem.lean:11:4: warning: declaration uses 'sorry'
/work/problem.lean:20:4: warning: declaration uses 'sorry'
/work/problem.lean:28:8: warning: declaration uses 'sorry'
/work/problem.lean:33:8: warning: declaration uses 'sorry'
compilecompile_usersol
590 ms1370 MBFailed
Compile failed: UserSol
/work/UserSol.lean:12:10: error(lean.unknownIdentifier): Unknown constant `Int.dvd_mul_of_dvd_left`
/work/UserSol.lean:13:2: error: No goals to be solved
Try this: ring_nf
Try this: ring_nf
输出 (stdout / stderr)
[lean -o] /work/UserSol.lean:12:10: error(lean.unknownIdentifier): Unknown constant `Int.dvd_mul_of_dvd_left`
/work/UserSol.lean:13:2: error: No goals to be solved
Try this: ring_nf
Try this: ring_nf