MathematicalReasoner<T>

Models & Types · AiDotNet.Reasoning.DomainSpecific

Specialized reasoner for mathematical problems using verified reasoning and external verification.

Implements: IDomainReasoner<T>

For Beginners

MathematicalReasoner is like a math tutor that not only solves problems but also checks its work with a calculator and verifies each step makes sense.

What makes it special for math:

  • Uses Chain-of-Thought to show work step-by-step
  • Verifies calculations with CalculatorVerifier
  • Can use Self-Consistency for important problems
  • Critic model checks mathematical reasoning
  • Self-refinement fixes calculation errors

Example workflow: Problem: “If John has 15 apples and gives away 40%, how many does he have left?”

  1. Generate reasoning steps
  2. Step 1: “Calculate 40% of 15 = 6”

→ CalculatorVerifier: ✓ Correct

  1. Step 2: “Subtract: 15 - 6 = 9”

→ CalculatorVerifier: ✓ Correct

  1. Step 3: “John has 9 apples left”
  2. All steps verified → High confidence answer

Used for benchmarks:

  • GSM8K (grade school math)
  • MATH (competition mathematics)
  • Any mathematical reasoning tasks

Constructors

Constructor Summary
MathematicalReasoner(IChatClient<T> chatModel, IEnumerable<IAgentTool> tools) Initializes a new instance of the MathematicalReasoner class.

Methods

Method Summary
Task<ReasoningResult<T>> SolveAsync(string problem, ReasoningConfig config, bool useVerification, bool useSelfConsistency, CancellationToken cancellationToken) Solves a mathematical problem using verified reasoning.
string ExtractNumericalAnswer(ReasoningResult<T> result) Extracts numerical answer from reasoning result for benchmark evaluation.