Skip to content

mathy.problems

Problem Generation

Utility functions for helping generate input problems.

gen_binomial_times_binomial

gen_binomial_times_binomial(
    op = '+',
    min_vars = 1,
    max_vars = 2,
    simple_variables = True,
    powers_probability = 0.33,
    like_variables_probability = 1.0,
) -> Tuple[str, int]
Generate a binomial multiplied by another binomial.

Example

(2e + 12p)(16 + 7e)

2 e * 12 p * + 16 7 e * + *

gen_binomial_times_monomial

gen_binomial_times_monomial(
    op = '+',
    min_vars = 1,
    max_vars = 2,
    simple_variables = True,
    powers_probability = 0.33,
    like_variables_probability = 1.0,
) -> Tuple[str, int]
Generate a binomial multiplied by a monomial.

Example

(4x^3 + y) * 2x

4 x 3 ^ * y + 2 x * *

gen_combine_terms_in_place

gen_combine_terms_in_place(
    min_terms = 16,
    max_terms = 26,
    easy = True,
    powers = False,
) -> Tuple[str, int]
Generate a problem that puts one pair of like terms next to each other somewhere inside a large tree of unlike terms.

The problem is intended to be solved in a very small number of moves, making training across many episodes relatively quick, and reducing the combinatorial explosion of branches that need to be searched to solve the task.

The hope is that by focusing the agent on selecting the right moves inside of a ridiculously large expression it will learn to select actions to combine like terms invariant of the sequence length.

Example

4y + 12j + 73q + 19k + 13z + 56l + (24x + 12x) + 43n + 17j

4 y * 12 j * + 73 q * + 19 k * + 13 z * + 56 l * + 24 x * 12 x * + + 43 n * + 17 j * +

gen_commute_haystack

gen_commute_haystack(
    min_terms = 5,
    max_terms = 8,
    commute_blockers = 1,
    easy = True,
    powers = False,
)
A problem with a bunch of terms that have no matches, and a single set of two terms that do match, but are separated by one other term. The challenge is to commute the terms to each other in one move.

Example

4y + 12j + 73q + 19k + 13z + 24x + 56l + 12x  + 43n + 17j"
                              ^-----------^

4 y * 12 j * + 73 q * + 19 k * + 13 z * + 24 x * + 56 l * + 12 x * + 43 n * + 17 j * +

gen_move_around_blockers_one

gen_move_around_blockers_one(number_blockers:int, powers_probability:float=0.5)
Two like terms separated by (n) blocker terms.

Example

4x + (y + f) + x

4 x * y f + + x +

gen_move_around_blockers_two

gen_move_around_blockers_two(number_blockers:int, powers_probability:float=0.5)
Two like terms with three blockers.

Example

7a + 4x + (2f + j) + x + 3d

7 a * 4 x * + 2 f * j + + x + 3 d * +

gen_simplify_multiple_terms

gen_simplify_multiple_terms(
    num_terms: int,
    optional_var: bool = False,
    op: Union[List[str], str] = '+',
    common_variables: bool = True,
    inner_terms_scaling: float = 0.3,
    powers_probability: float = 0.33,
    optional_var_probability: float = 0.8,
    noise_probability: float = 0.8,
    shuffle_probability: float = 0.66,
    noise_terms: int = None,
) -> Tuple[str, int]
Generate a polynomial problem with like terms that need to be combined and simplified.

Example

2a + 3j - 7b + 17.2a + j

2 a * 3 j * + 7 b * - 17.2 a * + j +

get_blocker

get_blocker(num_blockers=1, exclude_vars=[])
Get a string of terms to place between target simplification terms in order to challenge the agent's ability to use commutative/associative rules to move terms around.

get_rand_vars

get_rand_vars(num_vars, exclude_vars=[], common_variables=False)
Get a list of random variables, excluding the given list of hold-out variables

split_in_two_random

split_in_two_random(value:int)
Split a given number into two smaller numbers that sum to it. Returns: a tuple of (lower, higher) numbers that sum to the input

use_pretty_numbers

use_pretty_numbers(enabled:bool=True)
Determine if problems should include only pretty numbers or a whole range of integers and floats. Using pretty numbers will restrict the numbers that are generated to integers between 1 and 12. When not using pretty numbers, floats and large integers will be included in the output from rand_number


Last update: April 19, 2020