Skip to main content

GenConfig

Struct GenConfig 

Source
pub struct GenConfig {
Show 18 fields pub max_lhs_complexity: u32, pub max_rhs_complexity: u32, pub max_length: usize, pub constants: Vec<Symbol>, pub unary_ops: Vec<Symbol>, pub binary_ops: Vec<Symbol>, pub rhs_constants: Option<Vec<Symbol>>, pub rhs_unary_ops: Option<Vec<Symbol>>, pub rhs_binary_ops: Option<Vec<Symbol>>, pub symbol_max_counts: HashMap<Symbol, u32>, pub rhs_symbol_max_counts: Option<HashMap<Symbol, u32>>, pub min_num_type: NumType, pub generate_lhs: bool, pub generate_rhs: bool, pub user_constants: Vec<UserConstant>, pub user_functions: Vec<UserFunction>, pub show_pruned_arith: bool, pub symbol_table: Arc<SymbolTable>,
}
Expand description

Configuration for expression generation

Controls which symbols are available, complexity limits, and various generation options for creating candidate expressions that may solve a given equation.

§Architecture

Expressions are generated in two categories:

  • LHS (Left-Hand Side): Expressions containing x, representing functions like f(x)
  • RHS (Right-Hand Side): Constant expressions not containing x, like π² or sqrt(2)

The generator creates all valid expressions up to the configured complexity limits, then the solver finds pairs where LHS(target) ≈ RHS.

§Example

use ries_rs::gen::GenConfig;
use ries_rs::symbol::Symbol;
use std::collections::HashMap;

let config = GenConfig {
    max_lhs_complexity: 50,
    max_rhs_complexity: 30,
    max_length: 12,
    constants: vec![Symbol::One, Symbol::Two, Symbol::Pi, Symbol::E],
    unary_ops: vec![Symbol::Neg, Symbol::Sqrt, Symbol::Square],
    binary_ops: vec![Symbol::Add, Symbol::Sub, Symbol::Mul, Symbol::Div],
    ..GenConfig::default()
};

Fields§

§max_lhs_complexity: u32

Maximum complexity score for left-hand-side expressions.

LHS expressions contain x and represent the function side of equations. Higher values allow more complex expressions (e.g., sin(x) + x²), but exponentially increase search time and memory usage.

Default: 128 (allows fairly complex expressions)

§max_rhs_complexity: u32

Maximum complexity score for right-hand-side expressions.

RHS expressions are constants not containing x. Since they don’t need to be solved for, they can typically use lower complexity limits than LHS.

Default: 128

§max_length: usize

Maximum number of symbols in a single expression.

This is a hard limit on expression length regardless of complexity score. Prevents pathological cases with many low-complexity symbols.

Default: MAX_EXPR_LEN (255)

§constants: Vec<Symbol>

Symbols available for constants and variables (Seft::A type).

These push a value onto the expression stack. Typically includes:

  • One, Two, Three, etc. (numeric constants)
  • Pi, E (mathematical constants)
  • X (the variable to solve for)

Default: All built-in constants from Symbol::constants()

§unary_ops: Vec<Symbol>

Symbols available for unary operations (Seft::B type).

These transform a single value: f(a). Includes operations like:

  • Neg (negation: -a)
  • Sqrt, Square (powers and roots)
  • SinPi, CosPi (trigonometric functions)
  • Ln, Exp (logarithmic and exponential)
  • Recip (reciprocal: 1/a)

Default: All built-in unary operators from Symbol::unary_ops()

§binary_ops: Vec<Symbol>

Symbols available for binary operations (Seft::C type).

These combine two values: f(a, b). Includes operations like:

  • Add, Sub, Mul, Div (arithmetic)
  • Pow, Root, Log (power functions and logarithms)

Default: All built-in binary operators from Symbol::binary_ops()

§rhs_constants: Option<Vec<Symbol>>

Optional override for RHS-only constant symbols.

When set, RHS expressions use these symbols instead of constants. Useful for generating LHS with more symbols but keeping RHS simple.

Default: None (use constants for both LHS and RHS)

§rhs_unary_ops: Option<Vec<Symbol>>

Optional override for RHS-only unary operators.

When set, RHS expressions use these operators instead of unary_ops. Example: allow Lambert W in LHS only, exclude from RHS constants.

Default: None (use unary_ops for both LHS and RHS)

§rhs_binary_ops: Option<Vec<Symbol>>

Optional override for RHS-only binary operators.

When set, RHS expressions use these operators instead of binary_ops.

Default: None (use binary_ops for both LHS and RHS)

§symbol_max_counts: HashMap<Symbol, u32>

Maximum usage count per symbol within a single expression.

Maps each symbol to the maximum number of times it can appear. Useful for limiting redundancy (e.g., max 2 uses of Pi). Corresponds to the -O command-line option.

Default: Empty (no limits)

§rhs_symbol_max_counts: Option<HashMap<Symbol, u32>>

Optional RHS-only symbol count limits.

When set, applies different symbol count limits to RHS expressions. Corresponds to the --O-RHS command-line option.

Default: None (use symbol_max_counts for both)

§min_num_type: NumType

Minimum numeric type required for generated expressions.

Filters expressions by the “sophistication” of numbers they produce:

  • Integer: Only integer results
  • Rational: Rational numbers (fractions)
  • Algebraic: Algebraic numbers (roots of polynomials)
  • Transcendental: Any real number (including π, e, trig)

Lower values restrict output to simpler mathematical constructs.

Default: NumType::Transcendental (accept all)

§generate_lhs: bool

Whether to generate LHS expressions containing x.

Set to false if you only need constant RHS expressions. Can significantly reduce generation time when LHS is not needed.

Default: true

§generate_rhs: bool

Whether to generate RHS constant expressions.

Set to false if you only need LHS expressions. Useful for specific analysis tasks.

Default: true

§user_constants: Vec<UserConstant>

User-defined constants for custom searches.

These constants are available during expression evaluation, allowing searches involving domain-specific values. Defined via -N command-line option.

Default: Empty

§user_functions: Vec<UserFunction>

User-defined functions for custom searches.

Custom functions that can appear in generated expressions, extending the available operations beyond built-in symbols. Defined via -F command-line option.

Default: Empty

§show_pruned_arith: bool

Enable diagnostic output for arithmetic pruning.

When true, prints information about expressions that were discarded due to arithmetic errors (overflow, domain errors, etc.). Useful for debugging generation behavior.

Default: false

§symbol_table: Arc<SymbolTable>

Symbol table with weights and display names.

Provides complexity weights for each symbol and custom display names. Weights control how “expensive” each symbol is toward the complexity limit.

Default: Empty table (uses built-in default weights)

Trait Implementations§

Source§

impl Clone for GenConfig

Source§

fn clone(&self) -> GenConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for GenConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.