dyval.DAG.math_dag

class promptbench.dyval.DAG.math_dag.ArithmeticDAG(ops, uni_ops, depth, num_children_per_node=2, extra_links_per_node=1, add_cycles=0)

Bases: TreeDAG

A specialized TreeDAG for arithmetic operations.

Extends TreeDAG to represent arithmetic operations with nodes representing numerical values and operations.

Parameters:

opslist

List of arithmetic operations (e.g., ‘+’, ‘-’, ‘*’, ‘/’).

uni_opslist

List of unary operations (e.g., ‘sqrt’, ‘**’).

depthint

Depth of the tree.

num_children_per_nodeint, optional

Number of children per node (default is 2).

extra_links_per_nodeint, optional

Extra links per node (default is 1).

add_cyclesint, optional

Number of cycles to add to the tree (default is 0).

Methods:

generate_tree(depth)

Generates the tree structure with specified depth.

check_link_constraint(father_node, child_node)

Checks if a link between two nodes is valid.

update_values()

Updates the values of the nodes based on arithmetic operations.

generate_tree(depth)
update_values()
class promptbench.dyval.DAG.math_dag.ArithmeticDAGDescriber(dag_obj, ops, uni_ops, add_rand_desc=0, delete_desc=0)

Bases: TreeDAGDescriber

Describer class for ArithmeticDAG.

Provides methods to describe ArithmeticDAG nodes and their arithmetic operations.

Parameters:

dag_objArithmeticDAG

The ArithmeticDAG instance to describe.

opslist

List of binary operations.

uni_opslist

List of unary operations.

add_rand_descint, optional

Number of random descriptions to add.

delete_descint, optional

Number of descriptions to delete.

Methods:

describe_question_node(node)

Describes an ArithmeticDAG node for question formation.

describe_inference_node(node)

Describes an ArithmeticDAG node for inference.

describe_inference_node(node)
describe_question_node(node)
class promptbench.dyval.DAG.math_dag.LinearEq(ops, uni_ops, depth=3, num_dags=1, num_children_per_node=2, extra_links_per_node=1, add_rand_desc=0)

Bases: object

Class for generating and describing linear equations using ArithmeticDAGs.

It creates a set of linear equations and uses ArithmeticDAGs to represent the coefficients.

Parameters:

opslist

List of arithmetic operations.

uni_opslist

List of unary operations.

depthint, optional

Depth of the DAGs (default is 3).

num_dagsint, optional

Number of DAGs to generate (default is 1).

num_children_per_nodeint, optional

Number of children per node in the DAG.

extra_links_per_nodeint, optional

Extra links per node in the DAG.

add_rand_descint, optional

Number of random descriptions to add.

Methods:

describe_question()

Describes the linear equation problem.

describe_inference_steps()

Describes the inference steps to solve the linear equation.

describe_answer()

Provides the answer to the linear equation.

_solve_linear_eq()

Solves the linear equation using numpy’s linear algebra solver.

_has_unique_solution(coeff)

Checks if the equation has a unique solution.

_describe_linear_eq_solution()

Describes the solution of the linear equation.

describe_answer()
describe_inference_steps()
describe_question()