Documentation
PfsProgs25
.
Unit10
.
Half
Search
return to top
source
Imports
Init
Mathlib
Imported by
Half
instReprHalf
half?
OneAndAHalf
quarter
quarterWithProof
half?'
half!
source
structure
Half
(n :
ℕ
)
:
Type
val :
ℕ
isHalf :
self
.val
+
self
.val
=
n
Instances For
source
instance
instReprHalf
{n✝ :
ℕ
}
:
Repr
(
Half
n✝
)
Equations
instReprHalf
=
{
reprPrec
:=
reprHalf✝
}
source
def
half?
(n :
ℕ
)
:
Option
(
Half
n
)
Equations
half?
0
=
some
{
val
:=
0
,
isHalf
:=
half?.proof_3
}
half?
1
=
none
half?
k
.succ
.succ
=
Option.map
(fun (
x
:
Half
k
) =>
match
x
with |
{
val
:=
m
,
isHalf
:=
p
}
=>
{
val
:=
m
+
1
,
isHalf
:=
⋯
}
)
(
half?
k
)
Instances For
Option is a monad. We can use do notation to simplify the code.
source
def
OneAndAHalf
(n :
ℕ
)
:
Option
ℕ
Equations
OneAndAHalf
n
=
do let
__discr
←
half?
n
match
__discr
with |
{
val
:=
m
,
isHalf
:=
isHalf
}
=>
pure
(
3
*
m
)
Instances For
source
def
quarter
(n :
ℕ
)
:
Option
ℕ
Equations
One or more equations did not get rendered due to their size.
Instances For
source
def
quarterWithProof
(n :
ℕ
)
:
Option
{
k
:
ℕ
//
k
+
k
+
k
+
k
=
n
}
Equations
One or more equations did not get rendered due to their size.
Instances For
source
def
half?'
(n? :
Option
ℕ
)
:
Option
ℕ
Equations
half?'
n?
=
do let
n
←
n?
let
__discr
←
half?
n
match
__discr
with |
{
val
:=
m
,
isHalf
:=
isHalf
}
=>
pure
m
Instances For
source
def
half!
(n :
ℕ
)
:
ℕ
Equations
half!
0
=
0
half!
1
=
panicWithPosWithDecl
"PfsProgs25.Unit10.Half"
"half!"
81
9
"odd number"
half!
k
.succ
.succ
=
half!
k
+
1
Instances For