## Problem Description and Formulation

The problem requires minimizing the objective function: $4 \times \text{milligrams of potassium} + 5 \times \text{milligrams of magnesium}$, subject to several constraints related to digestive support index and cognitive performance index.

## Constraints

1. **Individual Index Constraints**:
   - Digestive support index of potassium: $23$
   - Cognitive performance index of potassium: $24$
   - Digestive support index of magnesium: $14$
   - Cognitive performance index of magnesium: $28$

2. **Combined Index Constraints**:
   - Total digestive support index $\geq 39$
   - Total cognitive performance index $\geq 125$
   - Total digestive support index $\leq 58$
   - Total cognitive performance index $\leq 219$

3. **Linear Constraint**:
   - $1 \times \text{milligrams of potassium} - 8 \times \text{milligrams of magnesium} \geq 0$

## Gurobi Code Formulation

```python
import gurobi

def optimize_milligrams():
    # Create a new model
    model = gurobi.Model()

    # Define variables
    potassium = model.addVar(name="potassium", lb=0)  # Assuming non-negative
    magnesium = model.addVar(name="magnesium", lb=0)  # Assuming non-negative

    # Objective function: Minimize 4 * potassium + 5 * magnesium
    model.setObjective(4 * potassium + 5 * magnesium, gurobi.GRB.MINIMIZE)

    # Constraints
    model.addConstr(23 * potassium + 14 * magnesium >= 39, name="digestive_support_min")
    model.addConstr(24 * potassium + 28 * magnesium >= 125, name="cognitive_performance_min")
    model.addConstr(23 * potassium + 14 * magnesium <= 58, name="digestive_support_max")
    model.addConstr(24 * potassium + 28 * magnesium <= 219, name="cognitive_performance_max")
    model.addConstr(potassium - 8 * magnesium >= 0, name="linear_constraint")

    # Solve the model
    model.optimize()

    # Print the solution
    if model.status == gurobi.GRB.OPTIMAL:
        print("Optimal Solution:")
        print(f"Milligrams of Potassium: {potassium.varValue}")
        print(f"Milligrams of Magnesium: {magnesium.varValue}")
        print(f"Objective Function Value: {model.objVal}")
    else:
        print("The model is infeasible.")

optimize_milligrams()
```

This code defines the optimization problem using Gurobi, with the specified objective function and constraints. It then solves the model and prints out the optimal values for milligrams of potassium and magnesium, along with the objective function value if an optimal solution exists. If the model is infeasible, it indicates that as well.