Skip to content

Conversation

@mahmudsudo
Copy link
Contributor

closes #43

@dawnandrew100
Copy link
Member

For the display of the polynomials, I was thinking more along the lines of 2x^4 + 3x^3 - 2x +4 rather than (SimplePolynomial{{coefficients: [4, 2, 0, 3, 2] }})

I like the idea of, for example, the simple_derivative function returning a SimplePolynomial struct BUT not the biggest fan of this change

    let dx = simple_derivative(&parsed);
    println!("Derivative coefficients: {dx:?}");
    let dx = simple_derivative(&parsed).coefficients;
    println!("Derivative coefficients: {dx:?}");

I'd prefer that coefficients wouldn't need to be called for functions to work in the case of simple polynomials or terms in the case of extended polynomials

Optimally, the function would look something like this after the display trait is added

    let dx = simple_derivative(&parsed);
    println!("Derivative coefficients: {dx}");

That's also the case for the following functions that I can find (I might miss some)

  • partial_derivative
  • indefinite_integral
  • simple_derivative
  • parse_polynomial_extended
  • parse_simple_polynomial

@mahmudsudo
Copy link
Contributor Author

@dawnandrew100

@dawnandrew100
Copy link
Member

The display trait is now like what I had in mind!

I see that the simple polynomial example was fixed, but what about the others like this in polynomial extended example:

    // Calculative partial derivative
    println!("Partial derivatives of polynomials");
    let dx = partial_derivative(&parsed, "x").terms; <-
    println!("Derivative with respect to x: {dx:?}");

    let dy = partial_derivative(&parsed, "y").terms; <-
    println!("Derivative with respect to y: {dy:?}");

    let dz = partial_derivative(&parsed, "z".to_string()).terms; <-
    println!("Derivative with respect to z: {dz:?}");

And PartialEq might need to be added to the structs so that terms and coefficients don't need to be explicitly called in the tests. So instead of this:

    #[test]
    fn test_derivative_linear() {
        let poly = vec![2.0, 3.0]; // 2 + 3x
        let deriv = simple_derivative(&poly).coefficients;

        assert_eq!(deriv, vec![3.0]); // simple_derivative: 3
    }

it would look like this

    #[test]
    fn test_derivative_linear() {
        let poly = vec![2.0, 3.0]; // 2 + 3x
        let deriv = simple_derivative(&poly);

        assert_eq!(deriv, vec![3.0]); // simple_derivative: 3
    }

With the same being true for the polynomial extended tests.

Also, I just noticed that your commits don't have your username associated with them, so you might need to fix your git settings so that you'll be added as a contributor when these changes are merged

@mahmudsudo
Copy link
Contributor Author

@dawnandrew100

@dawnandrew100
Copy link
Member

@mahmudsudo
The build and clippy checks failed because the PolynomialExtended struct doesn't have the #[derive(Debug)] trait. My guess is it needs this since the polynomial parsing functions now returns the struct instead of the primitive Rust type.

Hopefully you should just be able to add that trait and everything will work as expected, especially because I see that you already added it to the SimplePolynomial struct

@mahmudsudo
Copy link
Contributor Author

Funniest thing was I added it before pushing and edited it away when there was a merge conflict on the branch

@mahmudsudo
Copy link
Contributor Author

@dawnandrew100

@mahmudsudo
Copy link
Contributor Author

Check the other pr, so we can get both merged in time

@dawnandrew100
Copy link
Member

Everything looks good here! I'll merge this a little bit later this afternoon when I'll have time to give it a final once over

@dawnandrew100 dawnandrew100 merged commit 8db5b6e into lignum-vitae:main Jan 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add display trait to functions in spindalis_core

2 participants