1
\$\begingroup\$

I am looking for help for two things.

  1. proof of correctness (the tests have passed, but I do not now how to prove it correct)
  2. Improvements on the Algorithm Efficiency.

The algorithm goes through 2 arrays arrays through permutations. The ordering is set up based on the array index, NOT the number inside the index. Noteably, if both parallel arrrays are set up diffrent, the algorithm should run fine.The algorithm then adds the function to the sum, which estimates computes the series.

Code is below.


def f(x:float, y:float, a:float)->float:
    """
    param x:float, x coordinate 
    param y:flaot, y coordinate 
    param a:float, paramter of the curve 
    """
    return x + (y * a)

def main():
    """
    algorithm: 
    Suppouse arrays are orderd by thier index and NOT the element inside 
    Go through an ordering which meets that (one ordering is enough) 
    add on the function at that point to the sequence 
    """
    x = [1.0, 2.0, 3.0]
    y = [2.0, 3.0, 4.0]
    a = 2.0 
    seq = [0.0] * len(x)
    for row in range(0, len(x) + 1):
        for col in range(0, len(x) + 1):
            for at in range(row, col):
                seq[at] = seq[at] + f(x[at], y[at], a)
    print(seq)
    
if __name__ == "__main__":
    main() 

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Where is the task description? Where is the example? Where are those tests? How are we supposed to tell whether it's correct when we don't even know what it shall do? \$\endgroup\$ Nov 13, 2020 at 22:25

1 Answer 1

0
\$\begingroup\$

Disclaimer: Not a Code Reviewer

Just some comments:

  • Looks not bad at all;

  • First thing first, read through PEP8 if you like – I should also do that myself ( ˆ_ˆ )

  • Name things just a bit more descriptive, I understand that math people code like that and use single variable naming a lot;

  • Comment concise (one perfect scenario – which does not exist – would be the understandability of the code without any comment);

  • Use unittest if you like;

  • Turn on your IDE's spell checking;

  • Not sure about what we are doing overall, but my guess is that we might be able to start the second loop from the row + 1:

def get_linear_calc(x: float, y: float, coeff: float) -> float:
    """
    param x:float, x coordinate
    param y:flaot, y coordinate
    param coeff:float, parameter of the curve
    """
    return x + (y * coeff)


def get_ordered_sequence(x, y, coeff):
    """
    algorithm:
    Suppose arrays are ordered by their index and NOT the element inside
    Go through an ordering which meets that (one ordering is enough)
    add on the function curr that point to the sequence
    """
    seq = [0.0] * len(x)
    for row in range(len(x) + 1):
        for col in range(row + 1, len(x) + 1):
            for curr in range(row, col):
                seq[curr] += get_linear_calc(x[curr], y[curr], coeff)
    return seq


if __name__ == "__main__":
    x = (1.0, 2.0, 3.0, 2.0)
    y = (2.0, 3.0, 4.0, 1.0)
    coeff = 2.0
    print(get_ordered_sequence(x, y, coeff))

PS: I don't name things well, ignore my naming.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.