sallam-ahmed / Polynomial-Calculator

Data Structure 2015 Course Project
Apache License 2.0
0 stars 3 forks source link

Dfs redundancy #38

Closed khaledkee closed 8 years ago

khaledkee commented 8 years ago

When we started the polynomial calculator, it was intended for two polynomials operations with the only exception for finding roots at the time. More one polynomial operations has been introduced. If you opened the dfs functions, you'll find that dfs and dfsSecond are very similar but the small difference they have doesn't allow merging them. Basically the difference is that dfsSecond doesn't contain one polynomial operations. What's more, is that each one polynomial operations are treated differently (each one has difference loop), however, any two polynomial operation is considered the same. The reasons and details is omitted. I'm thinking of refactoring the dfs functions to be more generic and elegant.

sallam-ahmed commented 8 years ago

How would you manage to do that ? by eliminating one of the functions and using only one for bot ?! Both are treated differently, the one way would be considering the one polynomial operation is virtually two operations , would it be like that ?! P.S : I support redundancy fixing, the lesser the better [considering same performance and reliability]

khaledkee commented 8 years ago

Both are treated differently, the one way would be considering the one polynomial operation is virtually two operations , would it be like that ?!

No.

How would you manage to do that ?

First to successfully merge the two functions, we should change the character for root finding. The result of two polynomials operation is stored with link '=' the same as root finding. Then, there is essentially two types of one polynomial operations those with parameters and those without. The biggest difference is that with parameters you can have different results for different parameters, and these results are stored in dictionary along with the parameters (as Key). That's what makes storing derivative differs from storing substitution for example. The problem here is that dictionary doesn't contain ToString(), or precisely it doesn't behave as we want. So we wrote a small loop to convert it. But as you can see, there is a condition for each special link to determine if it's dictionary or not. On the bright side, we can just write a function that takes the specially linked objects and determine how to convert them to String or XML Element. Then call it for any special link in the dfs including the result of two polynomial operations which is a polynomial and it DOES contain ToString() that behaves as we want.