Zulip Chat Archive

Stream: new members

Topic: Working with rationals


Nathan (Oct 04 2025 at 06:13):

How do I work with rationals? I don't know how to do something as simple as:

example : (1+3:) = (4:) := by
  refine Rat.ext ?_ ?_
  · sorry
  · sorry

Nathan (Oct 04 2025 at 06:13):

simp doesn't work

Ruben Van de Velde (Oct 04 2025 at 06:18):

norm_num should work

Nathan (Oct 04 2025 at 06:24):

aha, thanks :pray:

Nathan (Oct 04 2025 at 06:57):

what about this? example (a b : ℚ) : a*b/a = b := sorry

Ruben Van de Velde (Oct 04 2025 at 07:48):

It's not true! (If a is zero)

Ruben Van de Velde (Oct 04 2025 at 07:49):

But I'd hope that by apply? finds something useful

Nathan (Oct 04 2025 at 14:05):

oh yeah true, if i add the hypothesis then maybe that will help apply? out

Alfredo Moreira-Rosa (Oct 04 2025 at 15:59):

yes, try this:

import Batteries.Data.Rat
import Mathlib.Data.Rat.Lemmas
import Mathlib.Tactic

example (a b : ) (h:a  0) : a * b / a = b := by field_simp

Alfredo Moreira-Rosa (Oct 04 2025 at 16:01):

or using exact?, you get :

example (a b : ) (h:a  0) : a * b / a = b := by exact mul_div_cancel_left₀ b h

Nathan (Oct 04 2025 at 17:05):

oh field_simp is great, thanks

Alfredo Moreira-Rosa (Oct 04 2025 at 17:23):

in the same vein of field_simp, you have ring, noncomm_ring, module, abel, group depending on your use case.

Alfredo Moreira-Rosa (Oct 04 2025 at 17:29):

to find which one solves your goal, you can use hint or try?. try? will come up with more complex tactics than hint in my experience

Nathan (Oct 04 2025 at 23:00):

i feel like i'm starting to get the hang of this

Nathan (Oct 05 2025 at 02:41):

maybe i'll just post here rather than open a new topic...

is there any way to convert a sum over a Fin into a sum over a Finset? I wrote half my code one way, and half the other. now i need to connect them...

example (k : ℕ) (f : ℕ → ℚ) : ∑ i ∈ Finset.Ico 0 k, f i = ∑ i : Fin k, f i := sorry

Aaron Liu (Oct 05 2025 at 02:44):

Nathan said:

maybe i'll just post here rather than open a new topic...

is there any way to convert a sum over a Fin into a sum over a Finset? I wrote half my code one way, and half the other. now i need to connect them...

example (k : ℕ) (f : ℕ → ℚ) : ∑ i ∈ Finset.Ico 0 k, f i = ∑ i : Fin k, f i := sorry

docs#Finset.sum_range and docs#Finset.range_eq_Ico

Nathan (Oct 05 2025 at 02:47):

oh wow, thanks :pray: thought i would have to rewrite it so everything was in Finsets :sweat_smile: probably should anyway, but i just want to get it working first

Nathan (Oct 05 2025 at 02:51):

why might i get Unknown identifier 'range'? i'm importing all of Mathlib

Nathan (Oct 05 2025 at 02:54):

oh duh i just need Finset.range


Last updated: Dec 20 2025 at 21:32 UTC