Zulip Chat Archive
Stream: Is there code for X?
Topic: get the denominator and numerator from a rational number
Huajian Xin (Aug 10 2023 at 16:22):
Is there any direct method to get the denominator and numerator from a rational number? For example, how to solve the tactic state
m: ℚ
h: m = 1 / 4
⊢ m.num = 1
```?
Kevin Buzzard (Aug 10 2023 at 16:27):
You don't get this completely for free because somewhere you'll need that 1/4 is in lowest terms. For example m is also 2/8 but the numerator isn't 2.
I would try subst h
and then either rfl
or norm_num
or simp
.
Kalle Kytölä (Aug 10 2023 at 16:36):
import Mathlib.Data.Rat.Basic
example (q : ℚ) (h : q = -773 / 28601) :
q.den = 37 := by
rw [h]
rfl
Huajian Xin (Aug 11 2023 at 01:23):
Thanks! But it seems that the rat defined in Lean 3 mathlib forces the denominator and numerator should be coprime, and these tactic seems fail. :smiling_face_with_tear:
Huajian Xin (Aug 11 2023 at 01:23):
Kevin Buzzard said:
You don't get this completely for free because somewhere you'll need that 1/4 is in lowest terms. For example m is also 2/8 but the numerator isn't 2.
I would try
subst h
and then eitherrfl
ornorm_num
orsimp
.
Huajian Xin (Aug 11 2023 at 01:25):
Kalle Kytölä said:
import Mathlib.Data.Rat.Basic example (q : ℚ) (h : q = -773 / 28601) : q.den = 37 := by rw [h] rfl
Thanks! I apology for my unclear that I'm using Lean 3, and could you please provide a Lean 3 code? I seems that rfl in Lean 3 cannot fix this.
Scott Morrison (Aug 11 2023 at 04:27):
Is there something blocking you from upgrading to Lean 4? We're hoping everyone is able to switch soon! :-)
Last updated: Dec 20 2023 at 11:08 UTC