LAProof.C.cblas.asum_model: functional model of GSL's [cblas_dasum].
Corresponds to C program C/cblas/src/dasum.c (ported from GSL cblas).
double r = 0.0;
for (i = 0; i < N; i++) { r += fabs(X[ix]); ix += incX; }
return r;
i.e., it adds |X[i]| left to right into the accumulator (BPLUS acc |x|),
starting from +0.0. The C fabs computes BABS (the result of VSTlib's
fabs_spec, whose ff_func is BABS), so the model uses BABS.
Require Import VST.floyd.proofauto.
Require Import vcfloat.VCFloat.
Require Import vcfloat.FPStdCompCert.
From vcfloat Require Import FPStdLib.
From LAProof.C Require Import floatlib.
Require Import LAProof.accuracy_proofs.sum_model.
asum_model X is the value the C loop *literally* computes: a left fold with
the accumulator as the first BPLUS operand, separate abs-then-add, starting
from +0.0. This mirrors the Clight AST in dasum.v exactly.
Definition asum_loop (l: list (ftype Tdouble)) : ftype Tdouble :=
fold_left (fun acc x ⇒ BPLUS acc (BABS x)) l (Zconst Tdouble 0).
Definition asum_model (X: list (ftype Tdouble)) : ftype Tdouble := asum_loop X.
fold_left (fun acc x ⇒ BPLUS acc (BABS x)) l (Zconst Tdouble 0).
Definition asum_model (X: list (ftype Tdouble)) : ftype Tdouble := asum_loop X.
*step*: extending the length-k prefix X[0..k-1] with the element X[k]
adds one BABS term, with the accumulator as the first BPLUS operand --
exactly the Clight statement r = r + fabs(X[k]).
Lemma asum_model_step: ∀ (X: list (ftype Tdouble)) k,
0 ≤ k < Zlength X →
asum_model (sublist 0 (k+1) X)
= BPLUS (asum_model (sublist 0 k X)) (BABS (Znth k X)).
0 ≤ k < Zlength X →
asum_model (sublist 0 (k+1) X)
= BPLUS (asum_model (sublist 0 k X)) (BABS (Znth k X)).