;; -*- mode: lisp; -*- ;; Define variables and their domains ;; Households (either 1 or 2) ;; ;; HOUSEHOLD SEX AGE RACE MARITAL RELATION ;; ;; 1 S=M A=18 R=W M=SA #1 ;; 1 S=F A=24 R=W M=SA SPO ;; 2 S=M A=30 R=W M=MA #1 ;; 2 S=F A=36 R=B M=MA SPO ;; 2 S=M A=84 R=B M=MA PAR ;; 2 S=F A=8 R=B M=SC CHI ;; 2 S=F A=66 R=B M=MA PAR ;; But we will report this sorted by age: ;; Problem setup #define USE_2A #define USE_2B #define USE_2C #define USE_2D #define USE_3B #define USE_4A ;;#define USE_SOLUTION // for debugging ;; Sexes (0:female 1:male) ; this does not work with sugar, but it should: ;(int FEMALE 0) ;(int MALE 1) #define FEMALE 0 #define MALE 1 (int S1 FEMALE MALE) (int S2 FEMALE MALE) (int S3 FEMALE MALE) (int S4 FEMALE MALE) (int S5 FEMALE MALE) (int S6 FEMALE MALE) (int S7 FEMALE MALE) ;; Ages (between 0 and 115 years old) #define MIN_AGE 1 #define MAX_AGE 115 (int A1 MIN_AGE MAX_AGE) (int A2 MIN_AGE MAX_AGE) (int A3 MIN_AGE MAX_AGE) (int A4 MIN_AGE MAX_AGE) (int A5 MIN_AGE MAX_AGE) (int A6 MIN_AGE MAX_AGE) (int A7 MIN_AGE MAX_AGE) ;; Races (0:black 1:white) #define BLACK 0 #define WHITE 1 (int R1 BLACK WHITE) (int R2 BLACK WHITE) (int R3 BLACK WHITE) (int R4 BLACK WHITE) (int R5 BLACK WHITE) (int R6 BLACK WHITE) (int R7 BLACK WHITE) ;; Marital Status (0:single 1:married) #define SINGLE 0 #define MARRIED 1 (int M1 SINGLE MARRIED) (int M2 SINGLE MARRIED) (int M3 SINGLE MARRIED) (int M4 SINGLE MARRIED) (int M5 SINGLE MARRIED) (int M6 SINGLE MARRIED) (int M7 SINGLE MARRIED) ;; Structural Zeros: ;;; Married people must be over 14. Set the minimum age based on the marriage flag (< (if (= M1 MARRIED) 14 0) A1) (< (if (= M2 MARRIED) 14 0) A2) (< (if (= M3 MARRIED) 14 0) A3) (< (if (= M4 MARRIED) 14 0) A4) (< (if (= M5 MARRIED) 14 0) A5) (< (if (= M6 MARRIED) 14 0) A6) (< (if (= M7 MARRIED) 14 0) A7) ;; Assure that the output is sorted by age. This does a good job ;; eliminating dupliate answers that simply have swapped records. ;; This is called "breaking symmetry" in the literature. (<= A1 A2) (<= A2 A3) (<= A3 A4) (<= A4 A5) (<= A6 A7) ;; Reported tables ;; Statistic 1A: Total Pop: 7, median=30, mean=38 ;; Median age 30 ;; The ages are sorted, so A4 must be 30. (= A4 30) ; mean age: 38 (= (+ A1 A2 A3 A4 A5 A6 A7) (* 7 38)) ;; Statistic 2A: Female: n=4, median=30, mean=33.5 #ifdef USE_2A (= (+ S1 S2 S3 S4 S5 S6 S7) 3) ;; 4 female (0=female, 1=male) ;; Median age of female is 30 ;; ;; To solve this, we create some temporary variables: ;; FEMALEID1 FEMALEID2 FEMALEID3 FEMALEID4 ;; - the ID number of each female, in order of ages ;; FEMALE_AGE1 FEMALE_AGE2 FEMALE_AGE3 FEMALE_AGE4 ;; - the age of each female, in order of ages ;; ;; So we kow that the average of FEMALE_AGE2 and FEMALEA3 is 30 ;; ;; This is a generic pattern that will be repeated for any cell size of 4 (int FEMALE_ID1 1 4) ; must leave room for 5, 6 and 7 to be female (int FEMALE_ID2 2 5) ; must leave room for 1, 6 and 7 to be female (int FEMALE_ID3 3 6) ; must leave room for 1, 2 and 7 to be female (int FEMALE_ID4 4 7) ; must leave room for 1, 2 and 3 to be female (< FEMALE_ID1 FEMALE_ID2) (< FEMALE_ID2 FEMALE_ID3) (< FEMALE_ID3 FEMALE_ID4) ;; Pigeon hole principle. If the IDs are in order, we only need to assure ;; that each ID maps to a female. We add the final equal and a -1 to force ;; an error if there are not enough females. (= FEMALE_ID1 (if (= S1 FEMALE) 1 (if (= S2 FEMALE) 2 (if (= S3 FEMALE) 3 (if (= S4 FEMALE) 4 -1))))) (= FEMALE_ID2 (if (and (= S2 FEMALE) (< FEMALE_ID1 2)) 2 (if (and (= S3 FEMALE) (< FEMALE_ID1 3)) 3 (if (and (= S4 FEMALE) (< FEMALE_ID1 4)) 4 (if (and (= S5 FEMALE) (< FEMALE_ID1 5)) 5 -1))))) (= FEMALE_ID3 (if (and (= S3 FEMALE) (< FEMALE_ID2 3)) 3 (if (and (= S4 FEMALE) (< FEMALE_ID2 4)) 4 (if (and (= S5 FEMALE) (< FEMALE_ID2 5)) 5 (if (and (= S6 FEMALE) (< FEMALE_ID2 6)) 6 (if (and (= S7 FEMALE) (< FEMALE_ID2 7)) 7 -1)))))) (= FEMALE_ID4 (if (and (= S4 FEMALE) (< FEMALE_ID3 4)) 4 (if (and (= S5 FEMALE) (< FEMALE_ID3 5)) 5 (if (and (= S6 FEMALE) (< FEMALE_ID3 6)) 6 (if (and (= S7 FEMALE) (< FEMALE_ID3 7)) 7 -1))))) ;; Create temporary variables for the ages of these females ;; This uses the Sugar (int FEMALE_AGE1 MIN_AGE MAX_AGE) (int FEMALE_AGE2 MIN_AGE MAX_AGE) (int FEMALE_AGE3 MIN_AGE MAX_AGE) (int FEMALE_AGE4 MIN_AGE MAX_AGE) (< FEMALE_AGE1 FEMALE_AGE2) (< FEMALE_AGE2 FEMALE_AGE3) (< FEMALE_AGE3 FEMALE_AGE4) ;; Fix the female ages to the person ages (element FEMALE_ID1 (A1 A2 A3 A4 A5 A6 A7) FEMALE_AGE1) (element FEMALE_ID2 (A1 A2 A3 A4 A5 A6 A7) FEMALE_AGE2) (element FEMALE_ID3 (A1 A2 A3 A4 A5 A6 A7) FEMALE_AGE3) (element FEMALE_ID4 (A1 A2 A3 A4 A5 A6 A7) FEMALE_AGE4) ;; The average of these is 30, so their sum is 60 (= (+ FEMALE_AGE2 FEMALE_AGE3) 60) ;; end median calculation ;; average female age = 33.5 (= (+ FEMALE_AGE1 FEMALE_AGE2 FEMALE_AGE3 FEMALE_AGE4) 134) ; 33.5 * 4 #endif ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 2B Male: n=3, median=30, average=44 ;; This is a generic pattern that will be repeated for any cell size of 3 ;; #ifdef USE_2B ;; there are three males (= (+ (if (= S1 MALE) 1 0) (if (= S2 MALE) 1 0) (if (= S3 MALE) 1 0) (if (= S4 MALE) 1 0) (if (= S5 MALE) 1 0) (if (= S6 MALE) 1 0) (if (= S7 MALE) 1 0) ) 3) ;; constraints for median. There are only 3 men, so we know that Male #2 is 30 (int MALE_ID1 1 5) ; must leave room for 6 and 7 to be male (int MALE_ID2 2 6) ; must leave room for 1 and 7 to be male (int MALE_ID3 3 7) ; must leave room for 1 and 2 to be male (< MALE_ID1 MALE_ID2) (< MALE_ID2 MALE_ID3) ;; Pigeon hole principle. If the IDs are in order, we only need to assure ;; that each ID maps to a female. We add the final equal and a -1 to force ;; an error if there are not enough females. (= MALE_ID1 (if (= S1 MALE) 1 (if (= S2 MALE) 2 (if (= S3 MALE) 3 (if (= S4 MALE) 4 (if (= S5 MALE) 5 -1)))))) (= MALE_ID2 (if (and (= S2 MALE) (< MALE_ID1 2)) 2 (if (and (= S3 MALE) (< MALE_ID1 3)) 3 (if (and (= S4 MALE) (< MALE_ID1 4)) 4 (if (and (= S5 MALE) (< MALE_ID1 5)) 5 (if (and (= S6 MALE) (< MALE_ID1 6)) 6 -1)))))) (= MALE_ID3 (if (and (= S3 MALE) (< MALE_ID2 3)) 3 (if (and (= S4 MALE) (< MALE_ID2 4)) 4 (if (and (= S5 MALE) (< MALE_ID2 5)) 5 (if (and (= S6 MALE) (< MALE_ID2 6)) 6 (if (and (= S7 MALE) (< MALE_ID2 7)) 7 -1)))))) ;; Create temporary variables for the ages of these males (int MALE_AGE1 MIN_AGE MAX_AGE) (int MALE_AGE2 MIN_AGE MAX_AGE) (int MALE_AGE3 MIN_AGE MAX_AGE) ;; make sure they are ordered (< MALE_AGE1 MALE_AGE2) (< MALE_AGE2 MALE_AGE3) ;; Fix the male ages to the person ages (element MALE_ID1 (A1 A2 A3 A4 A5 A6 A7) MALE_AGE1) (element MALE_ID2 (A1 A2 A3 A4 A5 A6 A7) MALE_AGE2) (element MALE_ID3 (A1 A2 A3 A4 A5 A6 A7) MALE_AGE3) ;; The median is 30 (= MALE_AGE2 30) ; average male age: 44 (= (+ MALE_AGE1 MALE_AGE2 MALE_AGE3) ; average male age = 44 (* 3 44)) #endif ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 2C Black. n=4 median=51 average=48.5 #ifdef USE_2C ;; 4 blacks (= (+ (if (= R1 BLACK) 1 0) (if (= R2 BLACK) 1 0) (if (= R3 BLACK) 1 0) (if (= R4 BLACK) 1 0) (if (= R5 BLACK) 1 0) (if (= R6 BLACK) 1 0) (if (= R7 BLACK) 1 0) ) 4) ;;; Median age of blacks is 51 (int BLACK_ID1 1 4) ; must leave room for 5, 6 and 7 to be female (int BLACK_ID2 2 5) ; must leave room for 1, 6 and 7 to be female (int BLACK_ID3 3 6) ; must leave room for 1, 2 and 7 to be female (int BLACK_ID4 4 7) ; must leave room for 1, 2 and 3 to be female (< BLACK_ID1 BLACK_ID2) (< BLACK_ID2 BLACK_ID3) (< BLACK_ID3 BLACK_ID4) ;; Pigeon hole principle. If the IDs are in order, we only need to assure ;; that each ID maps to a female. We add the final equal and a -1 to force ;; an error if there are not enough females. (= BLACK_ID1 (if (= R1 BLACK) 1 (if (= R2 BLACK) 2 (if (= R3 BLACK) 3 (if (= R4 BLACK) 4 -1))))) (= BLACK_ID2 (if (and (= R2 BLACK) (< BLACK_ID1 2)) 2 (if (and (= R3 BLACK) (< BLACK_ID1 3)) 3 (if (and (= R4 BLACK) (< BLACK_ID1 4)) 4 (if (and (= R5 BLACK) (< BLACK_ID1 5)) 5 -1))))) (= BLACK_ID3 (if (and (= R3 BLACK) (< BLACK_ID2 3)) 3 (if (and (= R4 BLACK) (< BLACK_ID2 4)) 4 (if (and (= R5 BLACK) (< BLACK_ID2 5)) 5 (if (and (= R6 BLACK) (< BLACK_ID2 6)) 6 (if (and (= R7 BLACK) (< BLACK_ID2 7)) 7 -1)))))) (= BLACK_ID4 (if (and (= R4 BLACK) (< BLACK_ID3 4)) 4 (if (and (= R5 BLACK) (< BLACK_ID3 5)) 5 (if (and (= R6 BLACK) (< BLACK_ID3 6)) 6 (if (and (= R7 BLACK) (< BLACK_ID3 7)) 7 -1))))) ;; Create temporary variables for the black ages (int BLACK_AGE1 MIN_AGE MAX_AGE) (int BLACK_AGE2 MIN_AGE MAX_AGE) (int BLACK_AGE3 MIN_AGE MAX_AGE) (int BLACK_AGE4 MIN_AGE MAX_AGE) (< BLACK_AGE1 BLACK_AGE2) (< BLACK_AGE2 BLACK_AGE3) (< BLACK_AGE3 BLACK_AGE4) ;; Fix the black ages to the person ages (element BLACK_ID1 (A1 A2 A3 A4 A5 A6 A7) BLACK_AGE1) (element BLACK_ID2 (A1 A2 A3 A4 A5 A6 A7) BLACK_AGE2) (element BLACK_ID3 (A1 A2 A3 A4 A5 A6 A7) BLACK_AGE3) (element BLACK_ID4 (A1 A2 A3 A4 A5 A6 A7) BLACK_AGE4) ;; The median black age is 51. ;; The average of BLACK_AGE2 and BLACK_AGE3 is 51, so their sum is 51*2 (= (+ BLACK_AGE2 BLACK_AGE3) (* 51 2)) ; average black age = 48.5 (x 4 = 194) (= (+ (if (= R1 BLACK) A1 0) (if (= R2 BLACK) A2 0) (if (= R3 BLACK) A3 0) (if (= R4 BLACK) A4 0) (if (= R5 BLACK) A5 0) (if (= R6 BLACK) A6 0) (if (= R7 BLACK) A7 0) ) 194) #endif ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; 2D. White. n=3 median=24, mean=24 (white=1) #ifdef USE_2D ;; n=3 whites (= (+ (if (= R1 WHITE) 1 0) (if (= R2 WHITE) 1 0) (if (= R3 WHITE) 1 0) (if (= R4 WHITE) 1 0) (if (= R5 WHITE) 1 0) (if (= R6 WHITE) 1 0) (if (= R7 WHITE) 1 0) ) 3) ;; constraints for median. There are only 3 men, so we know that Male #2 is 30 (int WHITE_ID1 1 5) ; must leave room for 6 and 7 to be male (int WHITE_ID2 2 6) ; must leave room for 1 and 7 to be male (int WHITE_ID3 3 7) ; must leave room for 1 and 2 to be male (< WHITE_ID1 WHITE_ID2) (< WHITE_ID2 WHITE_ID3) ;; Pigeon hole principle. If the IDs are in order, we only need to assure ;; that each ID maps to a female. We add the final equal and a -1 to force ;; an error if there are not enough females. (= WHITE_ID1 (if (= R1 WHITE) 1 (if (= R2 WHITE) 2 (if (= R3 WHITE) 3 (if (= R4 WHITE) 4 (if (= R5 WHITE) 5 -1)))))) (= WHITE_ID2 (if (and (= R2 WHITE) (< WHITE_ID1 2)) 2 (if (and (= R3 WHITE) (< WHITE_ID1 3)) 3 (if (and (= R4 WHITE) (< WHITE_ID1 4)) 4 (if (and (= R5 WHITE) (< WHITE_ID1 5)) 5 (if (and (= R6 WHITE) (< WHITE_ID1 6)) 6 -1)))))) (= WHITE_ID3 (if (and (= R3 WHITE) (< WHITE_ID2 3)) 3 (if (and (= R4 WHITE) (< WHITE_ID2 4)) 4 (if (and (= R5 WHITE) (< WHITE_ID2 5)) 5 (if (and (= R6 WHITE) (< WHITE_ID2 6)) 6 (if (and (= R7 WHITE) (< WHITE_ID2 7)) 7 -1)))))) ;; Create temporary variables for the ages of these males (int WHITE_AGE1 MIN_AGE MAX_AGE) (int WHITE_AGE2 MIN_AGE MAX_AGE) (int WHITE_AGE3 MIN_AGE MAX_AGE) ;; make sure they are ordered (< WHITE_AGE1 WHITE_AGE2) (< WHITE_AGE2 WHITE_AGE3) ;; Fix the male ages to the person ages (element WHITE_ID1 (A1 A2 A3 A4 A5 A6 A7) WHITE_AGE1) (element WHITE_ID2 (A1 A2 A3 A4 A5 A6 A7) WHITE_AGE2) (element WHITE_ID3 (A1 A2 A3 A4 A5 A6 A7) WHITE_AGE3) ;; The median white is 24 (= WHITE_AGE2 24) ; average white age: 24 (= (+ WHITE_AGE1 WHITE_AGE2 WHITE_AGE3) ; average white age = 24 (* 3 24)) #endif ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 3A. Single Adults. ;; NOTE: THIS STATISTIC IS SUPPRESSED... ;; ... so we know there are 0, 1 or 2 people in this class: (int SINGLE_ADULT_COUNT 0 2) (= (+ (if (and (= M1 SINGLE) (> A1 17)) 1 0) (if (and (= M2 SINGLE) (> A2 17)) 1 0) (if (and (= M3 SINGLE) (> A3 17)) 1 0) (if (and (= M4 SINGLE) (> A4 17)) 1 0) (if (and (= M5 SINGLE) (> A5 17)) 1 0) (if (and (= M6 SINGLE) (> A6 17)) 1 0) (if (and (= M7 SINGLE) (> A7 17)) 1 0) ) SINGLE_ADULT_COUNT ) (>= SINGLE_ADULT_COUNT 0) (<= SINGLE_ADULT_COUNT 2) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 3B. Married Adults ;; n=4, median=51 mean=54 ;; Count queries #ifdef USE_3B (= (+ (if (= M1 MARRIED) 1 0) ; average age of single adults = (if (= M2 MARRIED) 1 0) (if (= M3 MARRIED) 1 0) (if (= M4 MARRIED) 1 0) (if (= M5 MARRIED) 1 0) (if (= M6 MARRIED) 1 0) (if (= M7 MARRIED) 1 0) ) 4) ;; Median age of married adults is = 51 ;; There are 4, so there are 2 less than 51 and 2 more than 51 (< MARRIED_ADULT_ID1 MARRIED_ADULT_ID2) (< MARRIED_ADULT_ID2 MARRIED_ADULT_ID3) (< MARRIED_ADULT_ID3 MARRIED_ADULT_ID4) ;; Pigeon hole principle. If the IDs are in order, we only need to assure ;; that each ID maps to a female. We add the final equal and a -1 to force ;; an error if there are not enough females. (= MARRIED_ADULT_ID1 (if (= M1 MARRIED) 1 (if (= M2 MARRIED) 2 (if (= M3 MARRIED) 3 (if (= M4 MARRIED) 4 -1))))) (= MARRIED_ADULT_ID2 (if (and (= M2 MARRIED) (< MARRIED_ADULT_ID1 2)) 2 (if (and (= M3 MARRIED) (< MARRIED_ADULT_ID1 3)) 3 (if (and (= M4 MARRIED) (< MARRIED_ADULT_ID1 4)) 4 (if (and (= M5 MARRIED) (< MARRIED_ADULT_ID1 5)) 5 -1))))) (= MARRIED_ADULT_ID3 (if (and (= M3 MARRIED) (< MARRIED_ADULT_ID2 3)) 3 (if (and (= M4 MARRIED) (< MARRIED_ADULT_ID2 4)) 4 (if (and (= M5 MARRIED) (< MARRIED_ADULT_ID2 5)) 5 (if (and (= M6 MARRIED) (< MARRIED_ADULT_ID2 6)) 6 (if (and (= M7 MARRIED) (< MARRIED_ADULT_ID2 7)) 7 -1)))))) (= MARRIED_ADULT_ID4 (if (and (= M4 MARRIED) (< MARRIED_ADULT_ID3 4)) 4 (if (and (= M5 MARRIED) (< MARRIED_ADULT_ID3 5)) 5 (if (and (= M6 MARRIED) (< MARRIED_ADULT_ID3 6)) 6 (if (and (= M7 MARRIED) (< MARRIED_ADULT_ID3 7)) 7 -1))))) ;; Create temporary variables for the ages of these females ;; This uses the Sugar (int MARRIED_ADULT_AGE1 MIN_AGE MAX_AGE) (int MARRIED_ADULT_AGE2 MIN_AGE MAX_AGE) (int MARRIED_ADULT_AGE3 MIN_AGE MAX_AGE) (int MARRIED_ADULT_AGE4 MIN_AGE MAX_AGE) (< MARRIED_ADULT_AGE1 MARRIED_ADULT_AGE2) (< MARRIED_ADULT_AGE2 MARRIED_ADULT_AGE3) (< MARRIED_ADULT_AGE3 MARRIED_ADULT_AGE4) ;; Fix the female ages to the person ages (element MARRIED_ADULT_ID1 (A1 A2 A3 A4 A5 A6 A7) MARRIED_ADULT_AGE1) (element MARRIED_ADULT_ID2 (A1 A2 A3 A4 A5 A6 A7) MARRIED_ADULT_AGE2) (element MARRIED_ADULT_ID3 (A1 A2 A3 A4 A5 A6 A7) MARRIED_ADULT_AGE3) (element MARRIED_ADULT_ID4 (A1 A2 A3 A4 A5 A6 A7) MARRIED_ADULT_AGE4) ;; The median age of the married adults is 51 ;; so the average of these is 51, so their sum is 51*2 (= (+ MARRIED_ADULT_AGE2 MARRIED_ADULT_AGE3) (* 51 2)) ;; end median calculation ;; mean married adult age = 54 (= (+ MARRIED_ADULT_AGE1 MARRIED_ADULT_AGE2 MARRIED_ADULT_AGE3 MARRIED_ADULT_AGE4) (* 4 54)) #endif ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; 4A. Black Females ;; n=3, median=36, mean=36.7 #ifdef USE_4A ;;; Three black females (R=0, S=0) ;; there are three black females (= (+ (if (and (= R1 BLACK) (= S1 FEMALE)) 1 0) (if (and (= R2 BLACK) (= S2 FEMALE)) 1 0) (if (and (= R3 BLACK) (= S3 FEMALE)) 1 0) (if (and (= R4 BLACK) (= S4 FEMALE)) 1 0) (if (and (= R5 BLACK) (= S5 FEMALE)) 1 0) (if (and (= R6 BLACK) (= S6 FEMALE)) 1 0) (if (and (= R7 BLACK) (= S7 FEMALE)) 1 0) ) 3) ;; constraints for median. There are only 3 men, so we know that Male #2 is 30 (int BLACK_FEMALE_ID1 1 5) ; must leave room for 6 and 7 to be male (int BLACK_FEMALE_ID2 2 6) ; must leave room for 1 and 7 to be male (int BLACK_FEMALE_ID3 3 7) ; must leave room for 1 and 2 to be male (< BLACK_FEMALE_ID1 BLACK_FEMALE_ID2) (< BLACK_FEMALE_ID2 BLACK_FEMALE_ID3) ;; Pigeon hole principle. If the IDs are in order, we only need to assure ;; that each ID maps to a female. We add the final equal and a -1 to force ;; an error if there are not enough females. (= BLACK_FEMALE_ID1 (if (and (= R1 BLACK) (= S1 FEMALE)) 1 (if (and (= R2 BLACK) (= S2 FEMALE)) 2 (if (and (= R3 BLACK) (= S3 FEMALE)) 3 (if (and (= R4 BLACK) (= S4 FEMALE)) 4 (if (and (= R5 BLACK) (= S5 FEMALE)) 5 -1)))))) (= BLACK_FEMALE_ID2 (if (and (= R2 BLACK) (= S2 FEMALE) (< BLACK_FEMALE_ID1 2)) 2 (if (and (= R3 BLACK) (= S3 FEMALE) (< BLACK_FEMALE_ID1 3)) 3 (if (and (= R4 BLACK) (= S4 FEMALE) (< BLACK_FEMALE_ID1 4)) 4 (if (and (= R5 BLACK) (= S5 FEMALE) (< BLACK_FEMALE_ID1 5)) 5 (if (and (= R6 BLACK) (= S6 FEMALE) (< BLACK_FEMALE_ID1 6)) 6 -1)))))) (= BLACK_FEMALE_ID3 (if (and (= R3 BLACK) (= S3 FEMALE) (< BLACK_FEMALE_ID2 3)) 3 (if (and (= R4 BLACK) (= S4 FEMALE) (< BLACK_FEMALE_ID2 4)) 4 (if (and (= R5 BLACK) (= S5 FEMALE) (< BLACK_FEMALE_ID2 5)) 5 (if (and (= R6 BLACK) (= S6 FEMALE) (< BLACK_FEMALE_ID2 6)) 6 (if (and (= R7 BLACK) (= S7 FEMALE) (< BLACK_FEMALE_ID2 7)) 7 -1)))))) ;; Create temporary variables for the ages of these males (int BLACK_FEMALE_AGE1 MIN_AGE MAX_AGE) (int BLACK_FEMALE_AGE2 MIN_AGE MAX_AGE) (int BLACK_FEMALE_AGE3 MIN_AGE MAX_AGE) ;; make sure they are ordered (< BLACK_FEMALE_AGE1 BLACK_FEMALE_AGE2) (< BLACK_FEMALE_AGE2 BLACK_FEMALE_AGE3) ;; Fix the male ages to the person ages (element BLACK_FEMALE_ID1 (A1 A2 A3 A4 A5 A6 A7) BLACK_FEMALE_AGE1) (element BLACK_FEMALE_ID2 (A1 A2 A3 A4 A5 A6 A7) BLACK_FEMALE_AGE2) (element BLACK_FEMALE_ID3 (A1 A2 A3 A4 A5 A6 A7) BLACK_FEMALE_AGE3) ;; The median is 36 (= BLACK_FEMALE_AGE2 36) ; media black female age: 36.7 (= (+ BLACK_FEMALE_AGE1 BLACK_FEMALE_AGE2 BLACK_FEMALE_AGE3) ; 110) #endif ;; Statistic 1A. This is a sugar bug; we should not have to put it here. ;(= A4 30) ;; Solution. To verify constraints, uncomment these and everything should satisfy! ;; female=0 black=0 single=0 ;; male =1 white=1 married=1 ;; Note that this is the sorted by age #ifdef USE_SOLUTION (= S1 0) (= A1 8) (= R1 0) (= M1 0) (= S2 1) (= A2 18) (= R2 1) (= M2 0) (= S3 0) (= A3 24) (= R3 1) (= M3 0) (= S4 1) (= A4 30) (= R4 1) (= M4 1) (= S5 0) (= A5 36) (= R5 0) (= M5 1) (= S6 0) (= A6 66) (= R6 0) (= M6 1) (= S7 1) (= A7 84) (= R7 0) (= M7 1) #endif