leanprover / leanprover/lean4

add mul and div to time units

Open
#10,198 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

would be cool to add something like this to each of time units

--- a/src/Std/Time/Time/Unit/Millisecond.lean
+++ b/src/Std/Time/Time/Unit/Millisecond.lean
@@ -80,6 +80,34 @@ Creates an `Offset` from an integer.
 def ofInt (data : Int) : Offset :=
   UnitVal.ofInt data

+/--
+Multiplies the `Offset` by an `Int`.
+-/
+@[inline]
+def mulFactor (offset : Offset) (factor : Int) : Offset :=
+  Offset.ofInt (offset.val * factor)
+
+/--
+Divides the `Offset` by an `Int`, using the E-rounding convention (euclidean division).
+-/
+@[inline]
+def edivFactor (offset : Offset) (divisor : Int) : Offset :=
+  Offset.ofInt (offset.val.ediv divisor)
+
+/--
+Divides the `Offset` by an `Int`, using the "T-rounding" (truncation rounding) convention.
+-/
+@[inline]
+def tdivFactor (offset : Offset) (divisor : Int) : Offset :=
+  Offset.ofInt (offset.val.tdiv divisor)
+
+/--
+Divides the `Offset` by an `Int` (default = truncation rounding).
+-/
+@[inline]
+def divFactor (offset : Offset) (divisor : Int) : Offset :=
+  Offset.ofInt (offset.val.tdiv divisor)
+
 end Offset
 namespace Ordinal

N.B. why not just def mul (offset : Offset) (factor : Int) : Offset? bc it would break src/Std/Time/Time/Unit/Basic.lean

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/Std/Time/Time/Unit/Millisecond.lean and inspect src/Std/Time/Time/Unit/Basic.lean to understand how the unit definitions interact. Add the requested multiplication and division operations to each time unit, then verify the standard library still compiles without breaking Basic.lean.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.