Module Qcert.NNRSimp.Lang.NNRSimpSize
Require
Import
String
.
Require
Import
Lia
.
Require
Import
EquivDec
.
Require
Import
Decidable
.
Require
Import
Utils
.
Require
Import
DataRuntime
.
Require
Import
NNRSimp
.
Section
NNRSimpSize
.
Context
{
fruntime
:
foreign_runtime
}.
Fixpoint
nnrs_imp_expr_size
(
n
:
nnrs_imp_expr
) :
nat
:=
match
n
with
|
NNRSimpGetConstant
v
=> 1
|
NNRSimpVar
v
=> 1
|
NNRSimpConst
d
=> 1
|
NNRSimpBinop
op
n
₁
n
₂ =>
S
(
nnrs_imp_expr_size
n
₁ +
nnrs_imp_expr_size
n
₂)
|
NNRSimpUnop
op
n
₁ =>
S
(
nnrs_imp_expr_size
n
₁)
|
NNRSimpGroupBy
g
sl
e
=>
S
(
nnrs_imp_expr_size
e
)
end
.
Fixpoint
nnrs_imp_stmt_size
(
n
:
nnrs_imp_stmt
) :
nat
:=
match
n
with
|
NNRSimpSkip
=> 1
|
NNRSimpSeq
s
₁
s
₂ =>
S
(
nnrs_imp_stmt_size
s
₁ +
nnrs_imp_stmt_size
s
₂)
|
NNRSimpAssign
_
e
=>
S
(
nnrs_imp_expr_size
e
)
|
NNRSimpLet
v
None
s
=>
S
(
nnrs_imp_stmt_size
s
)
|
NNRSimpLet
v
(
Some
e
)
s
=>
S
(
nnrs_imp_expr_size
e
+
nnrs_imp_stmt_size
s
)
|
NNRSimpFor
v
n
₁
n
₂ =>
S
(
nnrs_imp_expr_size
n
₁ +
nnrs_imp_stmt_size
n
₂)
|
NNRSimpIf
n
₁
n
₂
n
₃ =>
S
(
nnrs_imp_expr_size
n
₁ +
nnrs_imp_stmt_size
n
₂ +
nnrs_imp_stmt_size
n
₃)
|
NNRSimpEither
nd
vl
nl
vr
nr
=>
S
(
nnrs_imp_expr_size
nd
+
nnrs_imp_stmt_size
nl
+
nnrs_imp_stmt_size
nr
)
end
.
Definition
nnrs_imp_size
(
q
:
nnrs_imp
) :
nat
:=
let
(
n
,
v
) :=
q
in
nnrs_imp_stmt_size
n
.
Lemma
nnrs_imp_expr_size_nzero
(
n
:
nnrs_imp_expr
) :
nnrs_imp_expr_size
n
<> 0.
Proof.
induction
n
;
simpl
;
lia
.
Qed.
Lemma
nnrs_imp_stmt_size_nzero
(
n
:
nnrs_imp_stmt
) :
nnrs_imp_stmt_size
n
<> 0.
Proof.
induction
n
;
simpl
;
try
destruct
o
;
try
lia
.
Qed.
Corollary
nnrs_imp_size_nzero
(
q
:
nnrs_imp
) :
nnrs_imp_size
q
<> 0.
Proof.
destruct
q
.
apply
nnrs_imp_stmt_size_nzero
.
Qed.
Section
Core
.
Program
Definition
nnrs_imp_core_size
(
q
:
nnrs_imp_core
) :
nat
:=
nnrs_imp_size
q
.
Lemma
nnrs_imp_core_size_nzero
(
q
:
nnrs_imp_core
) :
nnrs_imp_core_size
q
<> 0.
Proof.
apply
nnrs_imp_size_nzero
.
Qed.
End
Core
.
End
NNRSimpSize
.