WolframFormatter

Trait WolframFormatter 

Source
pub trait WolframFormatter {
    // Required methods
    fn to_wolfram_with_depth(
        &self,
        context: &WolframContext,
        depth: usize,
    ) -> Result<String, FormattingError>;
    fn format_function_with_depth(
        &self,
        name: &str,
        args: &[Expression],
        context: &WolframContext,
        depth: usize,
    ) -> Result<String, FormattingError>;

    // Provided method
    fn to_wolfram(
        &self,
        context: &WolframContext,
    ) -> Result<String, FormattingError> { ... }
}
Expand description

Format the expression to Wolfram Language

Required Methods§

Source

fn to_wolfram_with_depth( &self, context: &WolframContext, depth: usize, ) -> Result<String, FormattingError>

Format with explicit recursion depth tracking

Internal method that provides stack overflow protection by tracking recursion depth. This method returns a Result to allow proper error propagation during recursive formatting.

§Arguments
  • context - Wolfram formatting configuration
  • depth - Current recursion depth (starts at 0)
§Returns
  • Ok(String) - Successfully formatted Wolfram expression
  • Err(String) - Error message if limits exceeded
§Safety Limits
  • Maximum recursion depth: 1000 levels
  • Maximum terms per operation: 10000 terms/factors/arguments
Source

fn format_function_with_depth( &self, name: &str, args: &[Expression], context: &WolframContext, depth: usize, ) -> Result<String, FormattingError>

Convert function to Wolfram Language with depth tracking

Provided Methods§

Source

fn to_wolfram( &self, context: &WolframContext, ) -> Result<String, FormattingError>

Format an Expression as Wolfram Language notation

Converts mathematical expressions into Wolfram Language format suitable for use in Mathematica and other Wolfram products.

§Arguments
  • context - Wolfram formatting configuration
§Context Options
  • needs_parentheses - Whether to wrap the entire expression in parentheses
§Examples
use mathhook_core::{Expression, expr};
use mathhook_core::formatter::wolfram::{WolframFormatter, WolframContext};

let expression = expr!(x ^ 2);
let context = WolframContext::default();
let result = expression.to_wolfram(&context).unwrap();
assert!(result.contains("Power"));
assert!(result.contains("x"));
§Error Handling

Returns error messages for expressions that exceed safety limits:

  • Maximum recursion depth (1000 levels)
  • Maximum terms per operation (10000 terms)

Implementors§