Skip to content

Swarm

Mathy can solve problems using a swarm-planning algorithm from the fragile library that does not require a pre-trained model.

The basic idea behind fragile's swarm planning is to simulate many different possible actions simultaneously, then select the most rewarding one to take.

In practice, the swarm planning algorithm can solve almost all of the mathy environments with little effort.

Solve Many Tasks

Because the swarm planning algorithm doesn't require training, we can apply it to any task that Mathy exposes and expect to see a decent result.

Open Example In Colab

#!pip install gymnasium

import random

import gymnasium as gym
from mathy.solver import SwarmConfig, swarm_solve
from mathy_envs.gym import MathyGymEnv

config = SwarmConfig(max_iters=10)
task = random.choice(["poly", "binomial", "complex"])
env: MathyGymEnv = gym.make(f"mathy-{task}-easy-v0")
_, problem = env.mathy.get_initial_state(env.env_problem_args)
swarm_solve(problem.text, config)