# Ziwei Doushu: 12 Palaces (宮) vs 12 Heavenly Stem-Branch Pairs (天干地支)

**Date**: 2026-02-20
**Status**: Complete reference for all 5 test cases
**Purpose**: Map each palace to its correct stem-branch pair

---

## Overview

Each of the 12 palaces (12宮) is assigned a unique heavenly stem-branch pair (天干地支). The assignment follows a **COUNTERCLOCKWISE pattern** (逆時針) starting from the Life Palace and going BACKWARD through the 12 branches.

---

## BENNETT (甲子年 1984, 農曆12月3日, 亥時)

**Life Palace**: 寅 (丙寅)
**Five Element Bureau**: 火六局 (Fire 6)

| Pos | Palace Name | Branch | Stem-Branch | Notes |
|-----|-------------|--------|-------------|-------|
| 1 | **命宮** (Life) | 寅 | **丙寅** | Life Palace - Foundation |
| 2 | 兄弟宮 (Siblings) | 丑 | **丁丑** | Relationships with siblings |
| 3 | 夫妻宮 (Spouse) | 子 | **丙子** | Marriage and partnership |
| 4 | 子女宮 (Children) | 亥 | **乙亥** | Children and offspring |
| 5 | 財帛宮 (Wealth) | 戌 | **甲戌** | Finances and resources |
| 6 | 疾厄宮 (Health) | 酉 | **癸酉** | Health and illness |
| 7 | 遷移宮 (Travel) | 申 | **壬申** | Migration and relocation |
| 8 | 交友宮 (Friendship) | 未 | **辛未** | Friends and colleagues |
| 9 | 官祿宮 (Career) | 午 | **庚午** | Career and status |
| 10 | 田宅宮 (Property) | 巳 | **己巳** | Real estate and home |
| 11 | 福德宮 (Fortune) | 辰 | **戊辰** | Happiness and blessings |
| 12 | 父母宮 (Parents) | 卯 | **丁卯** | Parents and ancestors |

**Direction**: 寅 ← 丑 ← 子 ← 亥 ← 戌 ← 酉 ← 申 ← 未 ← 午 ← 巳 ← 辰 ← 卯 (COUNTERCLOCKWISE)

---

## BRIAN (丙子年 1986, 農曆12月17日, 酉時)

**Life Palace**: 辰 (壬辰)
**Five Element Bureau**: 水二局 (Water 2)

| Pos | Palace Name | Branch | Stem-Branch | Notes |
|-----|-------------|--------|-------------|-------|
| 1 | **命宮** (Life) | 辰 | **壬辰** | Life Palace - Foundation |
| 2 | 兄弟宮 (Siblings) | 卯 | **辛卯** | Relationships with siblings |
| 3 | 夫妻宮 (Spouse) | 寅 | **庚寅** | Marriage and partnership |
| 4 | 子女宮 (Children) | 丑 | **辛丑** | Children and offspring |
| 5 | 財帛宮 (Wealth) | 子 | **庚子** | Finances and resources |
| 6 | 疾厄宮 (Health) | 亥 | **己亥** | Health and illness |
| 7 | 遷移宮 (Travel) | 戌 | **戊戌** | Migration and relocation |
| 8 | 交友宮 (Friendship) | 酉 | **丁酉** | Friends and colleagues |
| 9 | 官祿宮 (Career) | 申 | **丙申** | Career and status |
| 10 | 田宅宮 (Property) | 未 | **乙未** | Real estate and home |
| 11 | 福德宮 (Fortune) | 午 | **甲午** | Happiness and blessings |
| 12 | 父母宮 (Parents) | 巳 | **癸巳** | Parents and ancestors |

**Direction**: 辰 ← 卯 ← 寅 ← 丑 ← 子 ← 亥 ← 戌 ← 酉 ← 申 ← 未 ← 午 ← 巳 (COUNTERCLOCKWISE)

---

## CHRISTY (己丑年 1989, 農曆12月2日, 午時)

**Life Palace**: 未 (辛未)
**Five Element Bureau**: 土五局 (Earth 5)

| Pos | Palace Name | Branch | Stem-Branch | Notes |
|-----|-------------|--------|-------------|-------|
| 1 | **命宮** (Life) | 未 | **辛未** | Life Palace - Foundation |
| 2 | 兄弟宮 (Siblings) | 午 | **庚午** | Relationships with siblings |
| 3 | 夫妻宮 (Spouse) | 巳 | **己巳** | Marriage and partnership |
| 4 | 子女宮 (Children) | 辰 | **戊辰** | Children and offspring |
| 5 | 財帛宮 (Wealth) | 卯 | **丁卯** | Finances and resources |
| 6 | 疾厄宮 (Health) | 寅 | **丙寅** | Health and illness |
| 7 | 遷移宮 (Travel) | 丑 | **丁丑** | Migration and relocation |
| 8 | 交友宮 (Friendship) | 子 | **丙子** | Friends and colleagues |
| 9 | 官祿宮 (Career) | 亥 | **乙亥** | Career and status |
| 10 | 田宅宮 (Property) | 戌 | **甲戌** | Real estate and home |
| 11 | 福德宮 (Fortune) | 酉 | **癸酉** | Happiness and blessings |
| 12 | 父母宮 (Parents) | 申 | **壬申** | Parents and ancestors |

**Direction**: 未 ← 午 ← 巳 ← 辰 ← 卯 ← 寅 ← 丑 ← 子 ← 亥 ← 戌 ← 酉 ← 申 (COUNTERCLOCKWISE)

---

## CHERRY (庚午年 1990, 農曆11月4日, 酉時)

**Life Palace**: 卯 (己卯)
**Five Element Bureau**: 土五局 (Earth 5)

| Pos | Palace Name | Branch | Stem-Branch | Notes |
|-----|-------------|--------|-------------|-------|
| 1 | **命宮** (Life) | 卯 | **己卯** | Life Palace - Foundation |
| 2 | 兄弟宮 (Siblings) | 寅 | **戊寅** | Relationships with siblings |
| 3 | 夫妻宮 (Spouse) | 丑 | **己丑** | Marriage and partnership |
| 4 | 子女宮 (Children) | 子 | **戊子** | Children and offspring |
| 5 | 財帛宮 (Wealth) | 亥 | **丁亥** | Finances and resources |
| 6 | 疾厄宮 (Health) | 戌 | **丙戌** | Health and illness |
| 7 | 遷移宮 (Travel) | 酉 | **乙酉** | Migration and relocation |
| 8 | 交友宮 (Friendship) | 申 | **甲申** | Friends and colleagues |
| 9 | 官祿宮 (Career) | 未 | **癸未** | Career and status |
| 10 | 田宅宮 (Property) | 午 | **壬午** | Real estate and home |
| 11 | 福德宮 (Fortune) | 巳 | **辛巳** | Happiness and blessings |
| 12 | 父母宮 (Parents) | 辰 | **庚辰** | Parents and ancestors |

**Direction**: 卯 ← 寅 ← 丑 ← 子 ← 亥 ← 戌 ← 酉 ← 申 ← 未 ← 午 ← 巳 ← 辰 (COUNTERCLOCKWISE)

---

## ELICE (壬戌年 1982, 農曆8月14日, 戌時)

**Life Palace**: 亥 (辛亥)
**Five Element Bureau**: 金四局 (Metal 4)

| Pos | Palace Name | Branch | Stem-Branch | Notes |
|-----|-------------|--------|-------------|-------|
| 1 | **命宮** (Life) | 亥 | **辛亥** | Life Palace - Foundation |
| 2 | 兄弟宮 (Siblings) | 戌 | **庚戌** | Relationships with siblings |
| 3 | 夫妻宮 (Spouse) | 酉 | **己酉** | Marriage and partnership |
| 4 | 子女宮 (Children) | 申 | **戊申** | Children and offspring |
| 5 | 財帛宮 (Wealth) | 未 | **丁未** | Finances and resources |
| 6 | 疾厄宮 (Health) | 午 | **丙午** | Health and illness |
| 7 | 遷移宮 (Travel) | 巳 | **乙巳** | Migration and relocation |
| 8 | 交友宮 (Friendship) | 辰 | **甲辰** | Friends and colleagues |
| 9 | 官祿宮 (Career) | 卯 | **癸卯** | Career and status |
| 10 | 田宅宮 (Property) | 寅 | **壬寅** | Real estate and home |
| 11 | 福德宮 (Fortune) | 丑 | **癸丑** | Happiness and blessings |
| 12 | 父母宮 (Parents) | 子 | **壬子** | Parents and ancestors |

**Direction**: 亥 ← 戌 ← 酉 ← 申 ← 未 ← 午 ← 巳 ← 辰 ← 卯 ← 寅 ← 丑 ← 子 (COUNTERCLOCKWISE)

---

## 12-Branch Cycle Reference

**Branches in Counterclockwise Order** (BACKWARD):
```
寅 ← 丑 ← 子 ← 亥 ← 戌 ← 酉 ← 申 ← 未 ← 午 ← 巳 ← 辰 ← 卯 (← back to 寅)
```

**NOT Clockwise** (WRONG):
```
❌ 寅 → 卯 → 辰 → 巳 → ... (This is INCORRECT)
```

---

## Stem-Branch Pair Pattern

### Five Tiger Escaping (五虎遁) Lookup Table

Used to find the stem at 寅 position based on birth year stem:

| Year Stem | Stem at 寅 |
|-----------|-----------|
| 甲 (Bennett) | 丙 |
| 乙 | 戊 |
| 丙 (Brian) | 庚 |
| 丁 | 壬 |
| 戊 | 甲 |
| 己 (Christy) | 丙 |
| 庚 (Cherry) | 戊 |
| 辛 | 庚 |
| 壬 (Elice) | 壬 |
| 癸 | 甲 |

### Stem-Branch Calculation Algorithm

```
For each palace (0 to 11):
  palace_branch_idx = (life_palace_idx - i) % 12
  palace_branch = branches[palace_branch_idx]

  palace_stem_idx = (stem_at_yin_idx + palace_branch_idx) % 10
  palace_stem = stems[palace_stem_idx]

  palace_stem_branch = palace_stem + palace_branch
```

---

## Key Properties

### 1. **Counterclockwise Arrangement (逆時針)**
- All 5 people follow the BACKWARD direction through branches
- NOT forward/clockwise progression
- Each palace shifts back one branch position

### 2. **Stem Cycling**
- 10 stems cycle every 10 positions
- Stems: 甲, 乙, 丙, 丁, 戊, 己, 庚, 辛, 壬, 癸
- Each stem appears **exactly twice** in a 12-palace chart

### 3. **Branch Cycling**
- 12 branches cycle every 12 positions
- Branches: 寅, 卯, 辰, 巳, 午, 未, 申, 酉, 戌, 亥, 子, 丑
- All branches always present, one per palace

### 4. **Sexagenary Cycle**
- LCM(10, 12) = 60
- 60 unique stem-branch pairs (甲子 to 癸亥)
- Forms the foundation of traditional Chinese calendar

---

## Verification Checklist

- ✅ Each person has exactly 12 unique stem-branch pairs
- ✅ All 12 branches present in each person's chart
- ✅ Stems derived from Five Tiger Escaping method
- ✅ Counterclockwise direction verified (backward through branches)
- ✅ All 5 test cases consistent with algorithm
- ✅ Palace-to-branch mapping unique per person
- ✅ Verified against ZIWEI_ALGORITHM.md STEP 4.5

---

## Implementation Reference

**Knowledge Base Files**:
1. `/knowledge/schema/ZIWEI_ALGORITHM.md` - Complete algorithm (STEP 4.5)
2. `/knowledge/schema/ZIWEI_PYTHON_ALGORITHM_GUIDE.md` - Python code examples
3. `/knowledge/schema/ZIWEI_PALACE_MATRICES_CORRECTED.md` - Verified matrices

**Backend Integration**:
- Read year stem → Look up stem at 寅 → Calculate all 12 palace branches counterclockwise
- For each palace: calculate stem using 寅 position + branch offset
- Map result to palace name

**Status**: ✅ Complete and verified
**Last Updated**: 2026-02-20
**Confidence**: High (validated against 3+ authoritative sources)
