INTERFACE PZSymbol;

(* Small signed integers coded into characters. *)
(* Last edited on 1999-09-04 12:43:30 by hcgl *)

FROM PZTypes IMPORT LONG, INT, BOOL;

TYPE
  T = CHAR;
    (*
      Encoding: 'A'..'Z' = +1..+26, 'a'..'z' = -1..-26, '0' = 0. *)
      
CONST
  Valid = SET OF CHAR { 'a' .. 'z', '0', 'A'..'Z' } ;

PROCEDURE ToInt(ch: T): INT;
  (*
    The numeric value of "ch". *)
          
PROCEDURE FromInt(i: INT): T;
  (*
    The coded representation of value "i". *)
          
PROCEDURE Encode(x: LONG; sigma: LONG): T;
  (*
    Compresses, quantizes, and encodes the curvature "x" which is
    assumed to have Gaussian distribution with standard deviation 
    "sigma". *)

PROCEDURE Decode(c: T; sigma: LONG): LONG;
  (*
    Inverse of "Encode" - decodes a quantized and encoded curvature. *)

TYPE
  Table = ARRAY T OF LONG; 

PROCEDURE ErrorVar(c: T; sigma: LONG): LONG;
  (*
    Returns the estimated variance of the quantization error for 
    the given encoded value. *)

PROCEDURE MakeDecodeTable(sigma: LONG): REF Table;
  (*
    Creates a table "tb" that maps "T" symbols to real values,
    i.e. "tb[c] = Decode(c, sigma)". *)

PROCEDURE MakeErrorVarTable(sigma: LONG): REF Table;
  (*
    Creates a table "tb" that maps "T" symbols to quant. error variance,
    i.e. "tb[c] = ErrorVar(c, sigma)". *)

PROCEDURE Complement(ch: T): T;
  (*
    Negates the numeric value of "ch" *)

PROCEDURE DistSqr(
    a, b: T; 
    complement: BOOL; 
    READONLY decode, errorVar: Table;
  ): LONG;
  (*
    A discrepancy measure, squared, between "a" and "b": basically,
    the square of the difference "d = decode[a] - decode[b]", plus
    "errorVar[a] + errorVar[b]".
    
    If "complement=TRUE", uses "Complement(b)" instead of "b".
  *)
          
PROCEDURE IntgDistSqr(
    a1, a2, b1, b2: T;
    complement: BOOL; 
    READONLY decode, errorVar: Table;
  ): LONG;
  (*
    The integral of "DistSqr(a(t), b(t), complement, de)" where "a(t)" 
    interpolates linearly between "a1" and "a2" 
    as "t" goes from 0 to 1; and similarly for "b(t)". *)
          
END PZSymbol.
(*
  Copyright © 2001 Universidade Estadual de Campinas (UNICAMP).
  Authors: Helena C. G. Leitão and Jorge Stolfi.
  
  This file can be freely distributed, used, and modified, provided
  that this copyright and authorship notice is preserved, and that any
  modified versions are clearly marked as such.
  
  This software has NO WARRANTY of correctness or applicability for
  any purpose. Neither the authors nor their employers chall be held
  responsible for any losses or damages that may result from its use.
*)