Module Qcert.Data.OperatorsTyping.TGroupBy
Require Import String.
Require Import List.
Require Import ZArith.
Require Import Compare_dec.
Require Import Utils.
Require Import Types.
Require Import DataModel.
Require Import ForeignData.
Require Import ForeignOperators.
Require Import ForeignDataTyping.
Require Import Operators.
Require Import TData.
Require Import TUtil.
Require Import GroupBy.
Section TGroupBy.
Context {
fdata:
foreign_data}.
Context {
ftype:
foreign_type}.
Context {
fdtyping:
foreign_data_typing}.
Context {
m:
brand_model}.
Import ListNotations.
Definition GroupBy_type
(
g :
string)
(
sl :
list string)
(
k :
record_kind)
(τ
l :
list (
string *
rtype))
(
pf :
is_list_sorted ODT_lt_dec (
domain τ
l) =
true)
:
rtype
:=
Coll
(
Rec Closed
(
rec_concat_sort
(
rproject τ
l sl) [(
g,
Coll (
Rec k τ
l pf))])
rec_sort_pf).
Lemma typed_group_to_partitions_yields_typed_data
{
key:
data} {
values:
list data} {τ
keys pf τ
values} :
key ▹
Rec Closed τ
keys pf ->
Forall (
fun v =>
v ▹ τ
values)
values ->
forall g,
exists d' :
data,
group_to_partitions g (
key,
values) =
Some d'
/\
d' ▹
Rec Closed (
rec_concat_sort τ
keys [(
g,
Coll τ
values)])
rec_sort_pf.
Proof.
Lemma typed_to_partitions_yields_typed_data
{
g:
string}
(
l:
list (
data*
list data))
{τ
keys pf τ
values} :
Forall (
fun kv =>
(
fst kv) ▹
Rec Closed τ
keys pf /\
Forall (
fun v =>
v ▹ τ
values) (
snd kv))
l ->
exists dl' :
list data,
to_partitions g l =
Some dl'
/\
Forall (
fun d' =>
d' ▹
Rec Closed (
rec_concat_sort τ
keys [(
g,
Coll τ
values)])
rec_sort_pf)
dl'.
Proof.
Lemma typed_group_of_key_yields_typed_data eval_key k l τ :
Forall (
fun d =>
d ▹ τ)
l ->
Forall (
fun d =>
exists y,
eval_key d =
Some y)
l ->
exists dl' :
list data,
group_of_key eval_key k l =
Some dl'
/\
Forall (
fun d' =>
d' ▹ τ)
dl'.
Proof.
Lemma typed_group_by_nested_eval_yields_typed_data eval_key l τ τ' :
Forall (
fun d =>
d ▹ τ)
l ->
Forall (
fun d =>
exists y,
eval_key d =
Some y /\
y ▹ τ')
l ->
exists dl' :
list (
data*
list data),
group_by_nested_eval eval_key l =
Some dl'
/\
Forall (
fun d'
dl' => (
fst d'
dl') ▹ τ' /\
Forall (
fun d =>
d▹ τ) (
snd d'
dl'))
dl'.
Proof.
Lemma typed_group_by_nested_eval_keys_partition_yields_typed_data g eval_key l τ τ
keys pf :
Forall (
fun d =>
d ▹ τ)
l ->
Forall (
fun d =>
exists y,
eval_key d =
Some y /\
y ▹
Rec Closed τ
keys pf)
l ->
exists dl' :
list data,
group_by_nested_eval_keys_partition g eval_key l =
Some dl'
/\
Forall (
fun d' =>
d' ▹
Rec Closed (
rec_concat_sort τ
keys [(
g,
Coll τ)])
rec_sort_pf)
dl'.
Proof.
Lemma typed_group_by_nested_eval_table_yields_typed_data {
d k τ
l pf} :
dcoll d ▹
Coll (
Rec k τ
l pf) ->
forall g sl,
sublist sl (
domain τ
l) ->
exists d' :
data,
lift dcoll (
group_by_nested_eval_table g sl d) =
Some d'
/\
d' ▹
GroupBy_type g sl k τ
l pf .
Proof.
End TGroupBy.