small refactoring

This commit is contained in:
Gregory Bednov 2025-12-26 11:58:00 +03:00
commit f393c583b8

View file

@ -1,13 +1,15 @@
// src/main.rs
mod ast;
mod dsl;
use std::sync::Arc;
use ast::{
ExprAst, ExprAst::Atom, ExprAst::Composition as C, ExprAst::Junction as J, Prim::AddPair,
Prim::Cos, Prim::Input, Prim::Sin, Prim::Triple, ast_input, hash_ast,
ExprAst,
ExprAst::{Atom, Composition as C, Junction as J},
Prim::{AddPair, Cos, Input, Sin, Triple},
ast_input, hash_ast,
};
use dsl::{Composition, Expr, Function, Junction};
// ========= тестовые функции =========
@ -22,46 +24,25 @@ fn triple(x: f64) -> f64 {
3.0 * x
}
// (a,b) -> a + b
/// (a,b) -> a + b
fn add_pair(p: (f64, f64)) -> f64 {
p.0 + p.1
}
// ========= демонстрация =========
// AST для sin(cos(x) + 3*x)
fn pupa() -> ExprAst {
// cos(x)
let cos_x = C(Box::new(ast_input()), Box::new(Atom(Cos)));
// 3 * x
let triple_x = C(Box::new(ast_input()), Box::new(Atom(Triple)));
// (cos(x), 3*x)
let j = J(Box::new(cos_x), Box::new(triple_x));
// AddPair ∘ Junction => cos(x) + 3*x
let add = C(Box::new(j), Box::new(Atom(AddPair)));
// Sin ∘ (AddPair ∘ Junction)
C(Box::new(add), Box::new(Atom(Sin)))
}
fn lupa() -> ExprAst {
use ast::*;
// cos(x)
let cos_x = C(Box::new(ast::ast_input()), Box::new(Atom(Cos)));
// 3 * x
let triple_x = C(Box::new(ast_input()), Box::new(Atom(Triple)));
// (cos(x), 3*x)
let j = J(Box::new(triple_x), Box::new(cos_x));
// AddPair ∘ Junction => cos(x) + 3*x
let add = C(Box::new(j), Box::new(Atom(AddPair)));
// Sin ∘ (AddPair ∘ Junction)
C(Box::new(add), Box::new(Atom(Sin)))
}