Zulip Chat Archive
Stream: lean4
Topic: Defining a function on the non-zero positive integers
Subhajit Bandyopadhyay (Apr 21 2024 at 18:55):
Hi all. I am new to LEAN. So please bear with me if this question is too basic. I have been able to define functions on the natural numbers. But I need to define an arithmetic function, that is, a function that acts on the non-zero positive integers and inherit all the properties of the natural numbers (addition, multiplication etc) naturally. Is there a type for positive integers? If not, how do I approach the arithmetic functions in lean?
Eric Wieser (Apr 21 2024 at 19:04):
Are you aware of docs#ArithmeticFunction ?
Yury G. Kudryashov (Apr 21 2024 at 19:11):
About positive integers: docs#PNat
Subhajit Bandyopadhyay (Apr 21 2024 at 19:29):
Eric Wieser said:
Are you aware of docs#ArithmeticFunction ?
I was not aware of this library. Thank you for pointing this out.
Subhajit Bandyopadhyay (Apr 21 2024 at 19:30):
Yury G. Kudryashov said:
About positive integers: docs#PNat
I tried to use this. But I got a "failed to synthesize instance" error in the following definition of a function.
def pow_of_two_factor (n : ℕ+) : ℕ :=
if n%2 = 1 then
0
else
1 + pow_of_two_factor (n/2)
Yury G. Kudryashov (Apr 21 2024 at 20:29):
You should try if (n : Nat) % 2 = 1
, otherwise it tries to find an instance for Mod
on PNat
and fails.
Eric Wieser (Apr 21 2024 at 23:18):
Note this function exists already, I think it's docs#Nat.log
Richard Copley (Apr 21 2024 at 23:32):
Eric Wieser (Apr 21 2024 at 23:37):
I guess we should link that to docs#Nat.floorRoot in the docs somehow, cc @Yaël Dillies
Yaël Dillies (Apr 22 2024 at 05:37):
This is not the same?
Yaël Dillies (Apr 22 2024 at 05:38):
maxPowDiv
corresponds to padicValNat
, not floorRoot
Eric Wieser (Apr 22 2024 at 12:29):
Aren't they related as log
is to nthRoot
? Or alternatively, by flipping the arguments to ^
? I guess I'm surprised to use floor
used in one name but max
in the other.
Eric Wieser (Apr 22 2024 at 12:30):
(I'm not suggesting we merge them, only make the names more similar)
Yaël Dillies (Apr 22 2024 at 13:26):
Eric Wieser said:
Aren't they related as
log
is tonthRoot
?
Yes, that's correct
Eric Wieser (Apr 25 2024 at 07:22):
What I'm suggesting then is to unify the floor/max parts of the name
Last updated: May 02 2025 at 03:31 UTC