Zulip Chat Archive
Stream: lean4
Topic: Idiomatic way to compute things on types
Jihoon Hyun (Aug 06 2025 at 17:57):
There are cases where I should compute on definition of types, like {n : Nat} -> Fin (2 * n). In such cases when n is given some value, for example n = 0, Fin (2 * 0) is not considered the same as Fin 0. What is the most idiomatic way to deal with this?
Aaron Liu (Aug 06 2025 at 17:59):
Fin (2 * 0) is considered the same as Fin 0
Kyle Miller (Aug 06 2025 at 18:04):
docs#Fin.cast is usually what you would insert, when it's necessary
Kenny Lau (Aug 06 2025 at 18:05):
so usually you will have some sort of cast functions for types that look like F x
Kenny Lau (Aug 06 2025 at 18:05):
where x is a term that is not a type
Kyle Miller (Aug 06 2025 at 18:07):
(Sometimes there are other functions for casting when types are involved, like List has docs#List.map)
Jihoon Hyun (Aug 06 2025 at 18:17):
Kyle Miller 말함:
docs#Fin.cast is usually what you would insert, when it's necessary
Yes, I would insert X.cast in such scenarios for any reasonable X, but...
Aaron Liu 말함:
Fin (2 * 0)is considered the same asFin 0
Then why does lean fail to convert from Fin (2 * 0) to Fin 0 in place? This makes some confusion when looking at the infoview.
Robin Arnez (Aug 06 2025 at 18:22):
Hmm I'm not sure where exactly you have errors but:
example (x : Fin (2 * 0)) : Fin 0 := x
works. If it's part of a function application this might be different though show Fin 0 from x (where x : Fin (2 * 0)) should still work then
Kyle Miller (Aug 06 2025 at 18:23):
Fin (2 * 0) and Fin 0 are definitionally equal, but that doesn't mean that Lean will reduce the types in the Infoview.
In this case you could use dsimp at x (maybe simp only at x) to simplify the type temporarily, to help understand what you need to do next.
Kyle Miller (Aug 06 2025 at 18:26):
(It wouldn't be impossible for Lean to reduce some simple arithmetic when computing types of things, but there are times when you don't want that, so it's not clear that it should be done.)
Max Nowak 🐉 (Aug 15 2025 at 06:21):
I have stumbled on an issue where dsimp at h works, but dsimp at * doesn't. Given h : T ⟨a, b⟩.fst. Is there a reason why this is?
Aaron Liu (Aug 15 2025 at 12:41):
This could be an instance of lean4#8300 or lean4#8696
Last updated: Dec 20 2025 at 21:32 UTC