Early exposure of economics students to symbolic computation in Python

Andrew Adrian Pua

2025-12-12

… is a mixed bag.

Background

  1. Context:

    • 1st year economics majors
    • Optimization: 3 unit lecture, 1 unit lab
    • Integrated version, students with advance notification
  2. Minimal setup: No Python background, cloud computing via SymPy Live Shell and Google Colab

My intended goals

  1. Every student should be able to open their textbook (or references) and then work on examples and answer the exercises using SymPy.
  2. Even better if they could write a full solution with text, explanations, and mathematical reasoning.
  3. Best case: All of the above, giving value to setting up a computational representation of a problem rather than “dump everything into computer and cross your fingers”

Choices

  1. Meet only one hour once a week
  2. Meet only 12 times, but 3 of those times are exams
  3. Introduce every basic thing early vs introduce things just-in-time
  4. Work individually vs work with groups
  5. Topics in “maths” course should be in sync vs relegate some “symbolically overwhelming” topics to lab: A mix happened.

Example: Finding extrema and doing some comparative statics

From Essential Mathematics for Economic Analysis:

Thinking in terms of SymPy when developing a solution

  1. Obtain the stationary points of \(f\).

    • Declare variables.
    • Define a function.
    • Know how to calculate derivatives.
    • Know how to solve a system of equations.

Thinking in terms of SymPy when developing a solution

  1. Determine whether each stationary point is a local maximum, local minimum, saddle point, or “cannot tell”.

    • Enter an expression.
    • Make substitutions.
    • Check whether conditions are satisfied.

Thinking in terms of SymPy when developing a solution

  1. Produce an expression of the maximized value of \(f\).

    • Make substitutions.
  2. Produce an expression of how the maximized value of \(f\) going to be affected by changes in \(a\).

    • Make substitutions.
    • Know how to calculate derivatives.
    • Do this mechanically or use Envelope Theorem.

Code

  1. Setup the function to be optimized.
from sympy import *
f, x, y, a, D = symbols('f x y a D', real = True)
f = (x**2-a*x*y)*exp(y)
  1. Find stationary points.
eq1 = Derivative(f, x).doit() 
eq2 = Derivative(f, y).doit()
soln = solve([eq1, eq2], [x, y], dict = True)
soln
[{x: 0, y: 0}, {x: -a, y: -2}]

Code, continued

  1. Determine if you have a local max, local min, or saddle point.
D = Derivative(f, x, x).doit()*Derivative(f, y, y).doit()-(Derivative(f, x, y).doit())**2
soln[0]
{x: 0, y: 0}
soln[1]
{x: -a, y: -2}
D.subs(soln[0]), D.subs(soln[1])
(-a**2, a**2*exp(-4))

Code, continued

  1. Effect of changing \(a\) on \(f\)
f.subs(soln[1])

\(\displaystyle - \frac{a^{2}}{e^{2}}\)

Derivative(f.subs(soln[1]), a).doit()

\(\displaystyle - \frac{2 a}{e^{2}}\)

Derivative(f, a).doit().subs(soln[1])

\(\displaystyle - \frac{2 a}{e^{2}}\)

Advantages

  1. Chance to see theory in a different form
  2. Teach programming (in a narrow sense) indirectly
  3. Be comfortable with the “command line”
  4. Create dynamic documents and weave Python calculations into documents – Learn LaTeX, HTML, Markdown indirectly
  5. Taking notes in line with the current generation
  6. “Dumping everything on a computer” mentality can somehow be corrected.

Double-edged swords

  1. AI is literally built in to Google Colab
  2. Can be frustrating to move around the lab troubleshooting every little thing
  3. 1 hour goes by so fast
  4. Unclear whether skills get transferred to major courses
  5. Not very natural to learn syntax and write code: Why? It requires thinking and a suspension of disbelief.

Student evaluation

Based on 3 evaluations during the first 4 to 5 meetings:

  1. Roughly 50%-60% were distracted by other open tabs.
  2. Roughly 80%-90% of students can see tangible evidence that the lectures are connected to the lab.
  3. Roughly 60% of students forgotten commands from past labs.
  4. Not everyone can finish all exercises

Exam styles

  1. Write code by hand for first half and then answer the same exercise with a computer
  2. A report with a full solution and explanation could be required.
  3. Students have a hard time writing self-contained code on paper which will run without error.
  4. Some students failed the course.

Should you do it? Yes, if you …

  1. Want to pick up something new under pressure (dignity as an instructor at stake!)
  2. Want to write a paper, create new materials, and present ay some other conference
  3. Want to really understand how the courses at your institution mesh together
  4. Reduce the tedious calculations and make room for other material

Should you do it? No, if you …

  1. Do not have enough patience: troubleshooting can be taxing
  2. Have grander plans than what could be achievable given the constraints
  3. Feel that it is highly unlikely that students will use these skills in their major or even in the “real world”

Final advertisements

  1. Questions, proposals, collaboration?

  2. Email me at andrew.pua@dlsu.edu.ph or approach me.

  3. Drop in https://ecoxlabmath.neocities.org if you want to know more.