octalgo.octalgo.static


Require Import fintrees.
Require Import syntax.
Require Import occurrences.
Require Import subs.
Require Import pmatch.
Require Import bSemantics.
Require Import tSemantics.
Require Import monotonicity.
Require Import soundness.
Require Import norec_sem.


Require Import bigop_aux.
Require Import utils.
Require Import finseqs.

Set Implicit Arguments.

Static analysis of a Datalog program

Section analysis.

program to analyze
Variable p : program.

default term and variable for the nth function
Variable dt : term.
Variable dv : 'I_n.

The actual analysis

Section rules.

Definition bigcup_tup {m} {A : finType} (t : m.-tuple {set A}) : {set A} :=
  \bigcup_(x <- tval t) x.

Definition bigcup_cart {m} {A : finType} (s : {set m.-tuple {set A}}) : {set {set A}} :=
  [set bigcup_tup y | y : m.-tuple {set A} in s].

prev is the set of tocs already visited v is the analyzed variable count is the fuel, used for termination The analysis is returned as a DNF, encoded as a set of set of uniq_seqs of toccs. The "outer set" represents the disjunction, whereas the "inner sets" are the conjunctions
Fixpoint analyze_var_prev (prev : (tocs p)) (v : 'I_n) (count : nat) : {set {set (dbranch p)}} :=
  match count with | 0 ⇒ set0 | count.+1
    
    let occs := occsInProgram p v :\: prev in
    let analyze_pi (prev : tocs p) (o : t_occ p) :=
        
        match p_at o with
           
         | Noneset0
         | Some f
            match predtype f with
              | Edb[set [set unil]]
Idblet arec := [set (analyze_var_prev prev (get_cl_var dt dv cl (t_ind o))) count | cl in p & hsym_cl cl == f]
                        in \bigcup_(x in arec) x
          end
        end
    in
      let all_add_o (dt : {set {set (dbranch p)}}) (o : t_occ p) : {set {set (dbranch p)}}:=
        [set [set pucons o br | br in pred_of_set ct] | ct in dt]
      in
      let arec := [seq all_add_o (analyze_pi (occ |: prev) occ) occ | occ <- enum occs]
    in bigcup_cart (gen_cart_prod arec) end.

Definition analyze_var (v : 'I_n) (count : nat) :=
  analyze_var_prev set0 v count.

End rules.

Completeness results on the analysis

Section completeness.

default t_occ for the nth function (should not be necessary with tnth_map)
Variable docc : t_occ p.

the content of any sequence in the result of an analysis is disjoint

from the given set of previously visited toccs
Lemma analyze_disj (prev : (tocs p)) (v : 'I_n) (count : nat) :
  [ ct in analyze_var_prev (prev : (tocs p)) (v : 'I_n) (count : nat),
    [ br in pred_of_set ct,
      [disjoint [set x | x \in (useq br)] & prev]]].

The analysis is monotonous wrt. its fuel

default ground atom and predicate for the nth function
Variable gat_def : gatom.
Variable df : symtype.

Core result: any no recursion trace is captured by the analysis

Any no recursion trace is captured in by the analysis with bounded fuel

and empty prev