Zulip Chat Archive

Stream: Is there code for X?

Topic: IsCoprime_num_den


Moritz Firsching (Mar 08 2024 at 15:59):

Is there code for the following:

import Mathlib
example (q : ) : Int.gcd q.num q.den = 1 := by sorry

or

example (q : ) : IsCoprime q.num q.den := by sorry

I searched a bit, but only found docs#RatFunc.isCoprime_num_denom.

Gareth Ma (Mar 08 2024 at 16:12):

If you look at the definition of Rat, you will see that there is a field

reduced : num.natAbs.Coprime den := by decide

So you can use that to derive the exact statement you want :)

Daniel Weber (Mar 08 2024 at 16:12):

One of docs#Rat 's field seems to be reduced which is what you want

Gareth Ma (Mar 08 2024 at 16:13):

example (q : ) : IsCoprime q.num q.den := by
  have := q.reduced /- Introduce this into the scope -/
  exact? /- Let the tactics do its magic -/

Last updated: May 02 2025 at 03:31 UTC