Closed sharyuwu closed 4 years ago
@sharyuwu, you are correct that || is used for concatenation, but it is an infix operator. That is, you need it to appear between the two operands. If you are concatenating sequence A and B, you would write A || B. In your case, the transition would be:
resultL := resultL || ...
Your state transition would be based on the previous state. This means you would have to initialize resultL to the empty sequence, or it would not be defined on the first occurrence. (I haven't looked at your document to see if you have an initialization.)
Now that I know a bit better what you are trying to do, your conditional expression looks better. However, you haven't defined what to do when neither of the two cases apply. Is that on purpose? It would probably be better to have a "catch all" rule at the end. You can make the final rule True, and then it acts like an "else clause."
Your resultL.e is confusing. Since resultL is a sequence of tuples, not a tuple, this notation does not make sense. You'll have to clarify what entry in the sequence you mean. You have the same problem with resultL.t. Also you are testing to see if the angle is a member of the set resultL.t, but based on the other part of the example, the t field of the tuple is not a set.
I also see that you are only adding to the sequence if the angle is not part of something (I'm not sure what it isn't a part of, but you do have a test for "not membership" of something). Do you really mean a sequence, or could you use a set? The nice thing about a set - if you union with something that is already in the set, the original set remains unchanged.
This means you would have to initialize resultL to the empty sequence, or it would not be defined on the first occurrence.
Yes, I have an init( ) to initialize resultL.
However, you haven't defined what to do when neither of the two cases applies.
Yes, it was designed on purpose. I was planning to omit the angle that did not fit in either of the two cases. This was my reason. After users input the required values, then the software will generate a table like this (I make up the numbers).
Then if the users want to calculate the angle more than one time, the table compares its results.
So this means if I got the same angle, it would be a repetition of the previous results. Therefore, omit it. Also, I always want to compare other results to the first result. Therefore, I designed the data type as a sequence.
But the table I designed might feel weird because it meant I was comparing the results based on different input (different start date and end date). I am thinking to change the design as following. After users input the required values, then the software will generate a table like this. (Again, I make up the numbers)
So this table is comparing different angles under the same input data. I can make sure there will be no repeated angles, so I can change the design as following.
The only reason I decided to use a sequence was that I want to compare the first result to the other results. If I use a set, then I afraid that I can express the comparison process as I plan.
Hello @sharyuwu. I will do my best to reply to your questions by editing comments into a quote of your posting.
This means you would have to initialize resultL to the empty sequence, or it would not be defined on the first occurrence.
Yes, I have an init( ) to initialize resultL.
You have initialized the sequence using the notation for a set. We use angle brackets for a set.
However, you haven't defined what to do when neither of the two cases applies.
Yes, it was designed on purpose. I was planning to omit the angle that did not fit in either of the two cases. This was my reason. After users input the required values, then the software will generate a table like this (I make up the numbers).
Then if the users want to calculate the angle more than one time, the table compares its results.
So this means if I got the same angle, it would be a repetition of the previous results. Therefore, omit it. Also, I always want to compare other results to the first result. Therefore, I designed the data type as a sequence.
I agree that you do not want to repeat calculations, but I feel like you could adopt a simpler approach. Rather than have a function that takes a sequence as input, you can have a simpler function that solves one problem at a time. If you want to build a sequence from the results of calling this function, that would be fine.
I do not fully understand your design, but my impression is that it could be simpler.
Hi Doctor @smiths A big thanks for your answers.
Do you mean we use angle brackets for a set or sequence? In the lecture slides, I believe we use < > for init a sequence.
Yes, I have a better idea of how to build this table. Thanks, again! I will leave this post until I do changes in my document.
You are correct that I meant to say we use angle brackets for a sequence.
Thanks for all the help. This is what the design I end up with. https://github.com/sharyuwu/optimum-tilt-of-solar-panels/blob/master/docs/Design/MIS/MIS.pdf https://github.com/sharyuwu/optimum-tilt-of-solar-panels/blob/master/docs/Design/MIS/MIS.tex#L761 The following picture denotes the process of converting the captured values to a table. the addResult function to collect the information for the output tables. I am using data type, set to avoid the repeat values.
Here is my new table designed. I have one table to show the average energy absorption which corresponding to how much time needed to adjust the solar panel. Another table denotes the time for adjusting the solar panel and its corresponding angle.
Hi Doctor @smiths Can you help me with my mathematic syntax here? There was a bunch of them in my repo and I am just addressing one out now then I will try to fix the rest of them. So here what I was trying to express was that resultL was a sequence that contains tuples ( I thought the mathematic syntax looks like this [< , , >, < , , >,< , , >, ......,< , , >]). Then if resultL is an empty sequence (the length of resultL = 0) then put a tuple of <angle, energy, 100 > in to the sequence. Else if a tuple of <angle, , > was not an element in resultL ( means it is a new result) then put a tuple of <angle, energy, getdiff (resultL.e, energy)> in the sequence. (getdiff (resultL.e, energy) means I want to calculate the difference between the results)
So I thought that two bars ( || ) mean to concatenation two lists which means here to put an element into the sequence.