operations/operations.rs
1/// This example demonstrates how to perform basic operations on [`Expr`] objects.
2/// The example calculates the squared difference between two [`Expr`] objects.
3/// The [`Expr`] objects are created using the [`Expr::new_leaf`] function.
4/// The squared difference is calculated using the [`Expr::pow`] method.
5/// The result is printed to the console.
6extern crate alpha_micrograd_rust;
7
8use alpha_micrograd_rust::value::Expr;
9
10fn main() {
11 let a = Expr::new_leaf(4.0, "a");
12 let b = Expr::new_leaf(2.0, "b");
13
14 let difference = a - b;
15
16 let square_exponent = Expr::new_leaf(2.0, "square_exponent");
17 let squared_diff = difference.pow(square_exponent, "squared_diff");
18
19 println!("squared difference: {:.2}", squared_diff.result);
20}