{"action":"created","issue":{"url":"https://api.github.com/repos/modelica/ModelicaSpecification/issues/1499","repository_url":"https://api.github.com/repos/modelica/ModelicaSpecification","labels_url":"https://api.github.com/repos/modelica/ModelicaSpecification/issues/1499/labels{/name}","comments_url":"https://api.github.com/repos/modelica/ModelicaSpecification/issues/1499/comments","events_url":"https://api.github.com/repos/modelica/ModelicaSpecification/issues/1499/events","html_url":"https://github.com/modelica/ModelicaSpecification/issues/1499","id":377133919,"node_id":"MDU6SXNzdWUzNzcxMzM5MTk=","number":1499,"title":"MCP-0010: Reduction Filter","user":{"login":"modelica-trac-importer","id":22202507,"node_id":"MDQ6VXNlcjIyMjAyNTA3","avatar_url":"https://avatars1.githubusercontent.com/u/22202507?v=4","gravatar_id":"","url":"https://api.github.com/users/modelica-trac-importer","html_url":"https://github.com/modelica-trac-importer","followers_url":"https://api.github.com/users/modelica-trac-importer/followers","following_url":"https://api.github.com/users/modelica-trac-importer/following{/other_user}","gists_url":"https://api.github.com/users/modelica-trac-importer/gists{/gist_id}","starred_url":"https://api.github.com/users/modelica-trac-importer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/modelica-trac-importer/subscriptions","organizations_url":"https://api.github.com/users/modelica-trac-importer/orgs","repos_url":"https://api.github.com/users/modelica-trac-importer/repos","events_url":"https://api.github.com/users/modelica-trac-importer/events{/privacy}","received_events_url":"https://api.github.com/users/modelica-trac-importer/received_events","type":"User","site_admin":false},"labels":[{"id":1114701593,"node_id":"MDU6TGFiZWwxMTE0NzAxNTkz","url":"https://api.github.com/repos/modelica/ModelicaSpecification/labels/MCP","name":"MCP","color":"0000aa","default":false},{"id":1114705644,"node_id":"MDU6TGFiZWwxMTE0NzA1NjQ0","url":"https://api.github.com/repos/modelica/ModelicaSpecification/labels/discussion","name":"discussion","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":{"login":"HansOlsson","id":13217430,"node_id":"MDQ6VXNlcjEzMjE3NDMw","avatar_url":"https://avatars0.githubusercontent.com/u/13217430?v=4","gravatar_id":"","url":"https://api.github.com/users/HansOlsson","html_url":"https://github.com/HansOlsson","followers_url":"https://api.github.com/users/HansOlsson/followers","following_url":"https://api.github.com/users/HansOlsson/following{/other_user}","gists_url":"https://api.github.com/users/HansOlsson/gists{/gist_id}","starred_url":"https://api.github.com/users/HansOlsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HansOlsson/subscriptions","organizations_url":"https://api.github.com/users/HansOlsson/orgs","repos_url":"https://api.github.com/users/HansOlsson/repos","events_url":"https://api.github.com/users/HansOlsson/events{/privacy}","received_events_url":"https://api.github.com/users/HansOlsson/received_events","type":"User","site_admin":false},"assignees":[{"login":"mtiller","id":144876,"node_id":"MDQ6VXNlcjE0NDg3Ng==","avatar_url":"https://avatars0.githubusercontent.com/u/144876?v=4","gravatar_id":"","url":"https://api.github.com/users/mtiller","html_url":"https://github.com/mtiller","followers_url":"https://api.github.com/users/mtiller/followers","following_url":"https://api.github.com/users/mtiller/following{/other_user}","gists_url":"https://api.github.com/users/mtiller/gists{/gist_id}","starred_url":"https://api.github.com/users/mtiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtiller/subscriptions","organizations_url":"https://api.github.com/users/mtiller/orgs","repos_url":"https://api.github.com/users/mtiller/repos","events_url":"https://api.github.com/users/mtiller/events{/privacy}","received_events_url":"https://api.github.com/users/mtiller/received_events","type":"User","site_admin":false},{"login":"sjoelund","id":3016460,"node_id":"MDQ6VXNlcjMwMTY0NjA=","avatar_url":"https://avatars0.githubusercontent.com/u/3016460?v=4","gravatar_id":"","url":"https://api.github.com/users/sjoelund","html_url":"https://github.com/sjoelund","followers_url":"https://api.github.com/users/sjoelund/followers","following_url":"https://api.github.com/users/sjoelund/following{/other_user}","gists_url":"https://api.github.com/users/sjoelund/gists{/gist_id}","starred_url":"https://api.github.com/users/sjoelund/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjoelund/subscriptions","organizations_url":"https://api.github.com/users/sjoelund/orgs","repos_url":"https://api.github.com/users/sjoelund/repos","events_url":"https://api.github.com/users/sjoelund/events{/privacy}","received_events_url":"https://api.github.com/users/sjoelund/received_events","type":"User","site_admin":false},{"login":"casella","id":4233148,"node_id":"MDQ6VXNlcjQyMzMxNDg=","avatar_url":"https://avatars1.githubusercontent.com/u/4233148?v=4","gravatar_id":"","url":"https://api.github.com/users/casella","html_url":"https://github.com/casella","followers_url":"https://api.github.com/users/casella/followers","following_url":"https://api.github.com/users/casella/following{/other_user}","gists_url":"https://api.github.com/users/casella/gists{/gist_id}","starred_url":"https://api.github.com/users/casella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/casella/subscriptions","organizations_url":"https://api.github.com/users/casella/orgs","repos_url":"https://api.github.com/users/casella/repos","events_url":"https://api.github.com/users/casella/events{/privacy}","received_events_url":"https://api.github.com/users/casella/received_events","type":"User","site_admin":false},{"login":"MartinOtter","id":7248038,"node_id":"MDQ6VXNlcjcyNDgwMzg=","avatar_url":"https://avatars3.githubusercontent.com/u/7248038?v=4","gravatar_id":"","url":"https://api.github.com/users/MartinOtter","html_url":"https://github.com/MartinOtter","followers_url":"https://api.github.com/users/MartinOtter/followers","following_url":"https://api.github.com/users/MartinOtter/following{/other_user}","gists_url":"https://api.github.com/users/MartinOtter/gists{/gist_id}","starred_url":"https://api.github.com/users/MartinOtter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MartinOtter/subscriptions","organizations_url":"https://api.github.com/users/MartinOtter/orgs","repos_url":"https://api.github.com/users/MartinOtter/repos","events_url":"https://api.github.com/users/MartinOtter/events{/privacy}","received_events_url":"https://api.github.com/users/MartinOtter/received_events","type":"User","site_admin":false},{"login":"christoff-buerger","id":7884278,"node_id":"MDQ6VXNlcjc4ODQyNzg=","avatar_url":"https://avatars2.githubusercontent.com/u/7884278?v=4","gravatar_id":"","url":"https://api.github.com/users/christoff-buerger","html_url":"https://github.com/christoff-buerger","followers_url":"https://api.github.com/users/christoff-buerger/followers","following_url":"https://api.github.com/users/christoff-buerger/following{/other_user}","gists_url":"https://api.github.com/users/christoff-buerger/gists{/gist_id}","starred_url":"https://api.github.com/users/christoff-buerger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christoff-buerger/subscriptions","organizations_url":"https://api.github.com/users/christoff-buerger/orgs","repos_url":"https://api.github.com/users/christoff-buerger/repos","events_url":"https://api.github.com/users/christoff-buerger/events{/privacy}","received_events_url":"https://api.github.com/users/christoff-buerger/received_events","type":"User","site_admin":false},{"login":"HansOlsson","id":13217430,"node_id":"MDQ6VXNlcjEzMjE3NDMw","avatar_url":"https://avatars0.githubusercontent.com/u/13217430?v=4","gravatar_id":"","url":"https://api.github.com/users/HansOlsson","html_url":"https://github.com/HansOlsson","followers_url":"https://api.github.com/users/HansOlsson/followers","following_url":"https://api.github.com/users/HansOlsson/following{/other_user}","gists_url":"https://api.github.com/users/HansOlsson/gists{/gist_id}","starred_url":"https://api.github.com/users/HansOlsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HansOlsson/subscriptions","organizations_url":"https://api.github.com/users/HansOlsson/orgs","repos_url":"https://api.github.com/users/HansOlsson/repos","events_url":"https://api.github.com/users/HansOlsson/events{/privacy}","received_events_url":"https://api.github.com/users/HansOlsson/received_events","type":"User","site_admin":false},{"login":"jespermattsson","id":13779895,"node_id":"MDQ6VXNlcjEzNzc5ODk1","avatar_url":"https://avatars2.githubusercontent.com/u/13779895?v=4","gravatar_id":"","url":"https://api.github.com/users/jespermattsson","html_url":"https://github.com/jespermattsson","followers_url":"https://api.github.com/users/jespermattsson/followers","following_url":"https://api.github.com/users/jespermattsson/following{/other_user}","gists_url":"https://api.github.com/users/jespermattsson/gists{/gist_id}","starred_url":"https://api.github.com/users/jespermattsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jespermattsson/subscriptions","organizations_url":"https://api.github.com/users/jespermattsson/orgs","repos_url":"https://api.github.com/users/jespermattsson/repos","events_url":"https://api.github.com/users/jespermattsson/events{/privacy}","received_events_url":"https://api.github.com/users/jespermattsson/received_events","type":"User","site_admin":false},{"login":"henrikt-ma","id":25294143,"node_id":"MDQ6VXNlcjI1Mjk0MTQz","avatar_url":"https://avatars3.githubusercontent.com/u/25294143?v=4","gravatar_id":"","url":"https://api.github.com/users/henrikt-ma","html_url":"https://github.com/henrikt-ma","followers_url":"https://api.github.com/users/henrikt-ma/followers","following_url":"https://api.github.com/users/henrikt-ma/following{/other_user}","gists_url":"https://api.github.com/users/henrikt-ma/gists{/gist_id}","starred_url":"https://api.github.com/users/henrikt-ma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henrikt-ma/subscriptions","organizations_url":"https://api.github.com/users/henrikt-ma/orgs","repos_url":"https://api.github.com/users/henrikt-ma/repos","events_url":"https://api.github.com/users/henrikt-ma/events{/privacy}","received_events_url":"https://api.github.com/users/henrikt-ma/received_events","type":"User","site_admin":false},{"login":"gkurzbach","id":25528503,"node_id":"MDQ6VXNlcjI1NTI4NTAz","avatar_url":"https://avatars1.githubusercontent.com/u/25528503?v=4","gravatar_id":"","url":"https://api.github.com/users/gkurzbach","html_url":"https://github.com/gkurzbach","followers_url":"https://api.github.com/users/gkurzbach/followers","following_url":"https://api.github.com/users/gkurzbach/following{/other_user}","gists_url":"https://api.github.com/users/gkurzbach/gists{/gist_id}","starred_url":"https://api.github.com/users/gkurzbach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gkurzbach/subscriptions","organizations_url":"https://api.github.com/users/gkurzbach/orgs","repos_url":"https://api.github.com/users/gkurzbach/repos","events_url":"https://api.github.com/users/gkurzbach/events{/privacy}","received_events_url":"https://api.github.com/users/gkurzbach/received_events","type":"User","site_admin":false},{"login":"svorkoetter","id":25961958,"node_id":"MDQ6VXNlcjI1OTYxOTU4","avatar_url":"https://avatars2.githubusercontent.com/u/25961958?v=4","gravatar_id":"","url":"https://api.github.com/users/svorkoetter","html_url":"https://github.com/svorkoetter","followers_url":"https://api.github.com/users/svorkoetter/followers","following_url":"https://api.github.com/users/svorkoetter/following{/other_user}","gists_url":"https://api.github.com/users/svorkoetter/gists{/gist_id}","starred_url":"https://api.github.com/users/svorkoetter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svorkoetter/subscriptions","organizations_url":"https://api.github.com/users/svorkoetter/orgs","repos_url":"https://api.github.com/users/svorkoetter/repos","events_url":"https://api.github.com/users/svorkoetter/events{/privacy}","received_events_url":"https://api.github.com/users/svorkoetter/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/modelica/ModelicaSpecification/milestones/9","html_url":"https://github.com/modelica/ModelicaSpecification/milestone/9","labels_url":"https://api.github.com/repos/modelica/ModelicaSpecification/milestones/9/labels","id":3792655,"node_id":"MDk6TWlsZXN0b25lMzc5MjY1NQ==","number":9,"title":"MCP-1-InDevelopment","description":"","creator":{"login":"modelica-trac-importer","id":22202507,"node_id":"MDQ6VXNlcjIyMjAyNTA3","avatar_url":"https://avatars1.githubusercontent.com/u/22202507?v=4","gravatar_id":"","url":"https://api.github.com/users/modelica-trac-importer","html_url":"https://github.com/modelica-trac-importer","followers_url":"https://api.github.com/users/modelica-trac-importer/followers","following_url":"https://api.github.com/users/modelica-trac-importer/following{/other_user}","gists_url":"https://api.github.com/users/modelica-trac-importer/gists{/gist_id}","starred_url":"https://api.github.com/users/modelica-trac-importer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/modelica-trac-importer/subscriptions","organizations_url":"https://api.github.com/users/modelica-trac-importer/orgs","repos_url":"https://api.github.com/users/modelica-trac-importer/repos","events_url":"https://api.github.com/users/modelica-trac-importer/events{/privacy}","received_events_url":"https://api.github.com/users/modelica-trac-importer/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":0,"state":"open","created_at":"2018-11-03T10:04:15Z","updated_at":"2018-11-04T09:00:33Z","due_on":null,"closed_at":null},"comments":13,"created_at":"2018-11-04T09:58:39Z","updated_at":"2018-11-04T09:02:17Z","closed_at":null,"author_association":"COLLABORATOR","body":"**Modified by dietmarw on 28 Apr 2016 09:24 UTC**\nThis is an MCP regarding implementation of filters (guards) for reduction iterators, in order to for example select only part of an array.\n\nThe document is stored at: ​\n\n * https://svn.modelica.org/projects/MCP/public/MCP-0010_ReductionFilter/\n\nPlease use this ticket to comment on this MCP, in particular if you want to have one guard for each iterator or one for the whole reduction expression. Both have their pros and cons.\n\n----\n\n**Modified by sjoelund&#46;se on 13 Nov 2015 07:58 UTC**\nThis is an MCPI regarding implementation of filters (guards) for reduction iterators, in order to for example select only part of an array.\n\nThe document is stored at: ​https://svn.modelica.org/projects/MCP/MAinternal/MCP-0010_ReductionFilter\n\nPlease use this ticket to comment on this MCPI, in particular if you want to have one guard for each iterator or one for the whole reduction expression. Both have their pros and cons.\n\n----\n\n**Reported by sjoelund&#x2e;se on 22 May 2014 08:07 UTC**\nThis is an MCPI regarding implementation of filters (guards) for reduction iterators, in order to for example select only part of an array.\n\nThe document is stored at: ​https://svn.modelica.org/projects/MCP-Ideas/MAinternal/MCPI-0010_ReductionFilter\n\nPlease use this ticket to comment on this MCPI, in particular if you want to have one guard for each iterator or one for the whole reduction expression. Both have their pros and cons.\n\n----\n\nMigrated-From: https://trac.modelica.org/Modelica/ticket/1499"},"comment":{"url":"https://api.github.com/repos/modelica/ModelicaSpecification/issues/comments/435652931","html_url":"https://github.com/modelica/ModelicaSpecification/issues/1499#issuecomment-435652931","issue_url":"https://api.github.com/repos/modelica/ModelicaSpecification/issues/1499","id":435652931,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTY1MjkzMQ==","user":{"login":"modelica-trac-importer","id":22202507,"node_id":"MDQ6VXNlcjIyMjAyNTA3","avatar_url":"https://avatars1.githubusercontent.com/u/22202507?v=4","gravatar_id":"","url":"https://api.github.com/users/modelica-trac-importer","html_url":"https://github.com/modelica-trac-importer","followers_url":"https://api.github.com/users/modelica-trac-importer/followers","following_url":"https://api.github.com/users/modelica-trac-importer/following{/other_user}","gists_url":"https://api.github.com/users/modelica-trac-importer/gists{/gist_id}","starred_url":"https://api.github.com/users/modelica-trac-importer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/modelica-trac-importer/subscriptions","organizations_url":"https://api.github.com/users/modelica-trac-importer/orgs","repos_url":"https://api.github.com/users/modelica-trac-importer/repos","events_url":"https://api.github.com/users/modelica-trac-importer/events{/privacy}","received_events_url":"https://api.github.com/users/modelica-trac-importer/received_events","type":"User","site_admin":false},"created_at":"2018-11-04T09:02:17Z","updated_at":"2018-11-04T09:02:17Z","author_association":"COLLABORATOR","body":"**Comment by cbuerger on 2 May 2016 12:06 UTC**\nThe proposal can be decomposed in three problems: syntax of reduction filters, static semantics defining the scopes of introduced variables and dynamic semantics defining the order of the elements of the result and when constraints are applied.\n\n**Syntax**\n\nI see two general ideas for _set_ comprehensions (I come to the order of elements, i.e., list comprehension, later when talking about the dynamic semantics).\n\n1. starting from a set of values (seed set), stepwise reduce it by eliminating elements using constrains until finally the content of the new set can be stated\n2. beginning from the computation defining the elements of the new set, stepwise define their domains in terms of restrictions followed by the original seed set\n\nThe first is kind of an algorithmic approach. First define the seed sets; afterwards nested loops iterate their elements. The body of the loops constrains them and constructs the new set. The second is a more mathematical notation. First what is in the new set, then the conditions when it is in the set, except that in mathematics you usually first state the general domain (similar to function definitions in mathematics, where also first the result and then the conditions are stated like in `f(n) = n : n is odd, -n : n is even`).\n\nBoth approaches have a clear reading direction: either from most general to specialised or the other way around.\n\nI propose that any syntax should provide such a deterministic reading direction (no jumping like in C as required to read complex types like function pointers). Thus, I dislike for example:\n```\n          i+j for          i in M, j in N,           if i<10 and j<20\n// content of new set         seed  set                 constraints\n//  most constrained  =======> general  ============> more constrained\n```\nThis form has no straight forward reading direction; neither from most constrained to least nor the other way around.\n\nGiven that the existing Modelica syntax prefers the second form (start with the actual elements of the new set), I would prefer the following syntax:\n```\n{         i+j for        all i<10 and j<20 with       i in M, j in N       }\n// content of new set        constraints             list of seed sets\n//  most constrained  =====> constrained ================> general\n```\nIf there is no restriction the syntax stays as used to, for example:\n```\n{         i+j for                                     i in M, j in N       }\n// content of new set       no constraints           list of seed sets\n//  most constrained  ===================================> general\n```\n\nAbove form introduces two new keywords: `all` and `with`. They start and end _the_ optional reduction constraint of a reduction expression. Each reduction expression has at most one constraint, which must be a boolean expression. Optimisations of this expression, like its splitting, reordering and partially early evaluation to reduce for example the number of iterations of an internal loop implementation is up to the Modelica compiler and should not obfuscate the syntax.\n\nI dislike the keyword `guard` as it sounds like an exception handling construct. What does an reduction expression guard _against_?\n\n**Static semantics (scopes)**\n\nI propose to avoid any kind of _implicit_ nested scoping for the sake of concise and clear meaning. All looping variables should be within the scope of the reduction filter. Thus, I oppose that for example (taking the syntax from the draft)\n```\n{ i+j for  i guard i<10 in N,   j guard j<20 in M }\n```\nimplicitly means\n```\n{ i+j for (i guard i<10 in N), (j guard j<20 in M) }\n```\nwith `(` and `)` opening and closing implicit scopes. There should be no need for developers to consider the nesting of implicit scopes. In particular as inconsistent as in the proposal, where the actual element computation can see inside nested scopes but guards only see their scope (in above example `i+j` can see both local definitions whereas the guards only see their respective). This is hard to understand. It also complicates the refactoring of conditions. For example, if one would like to change the conditions from `guard i<10` and `guard j<20` to `guard i<10 and j<i` both filter conditions must be unified, moved and one guard deleted instead of just changing a single constraint.\n\nTo have a single scope per reduction expression goes well with having exactly a single reduction constraint and pushing responsibility for optimisation to the compiler.\n\nRemember, that developers can always nest reduction expression when they want to compose complex reductions with nested scopes.\n\n**Dynamic semantics (order of elements)**\n\nGiven above proposal (`for all` _single-constraint-expression_ `with`), the order of the elements of result _lists_ is straight forward (let's talk about lists from now on, i.e., seed lists, result list etc.).\n\nA sequence of seed lists `i in N, j in M` is treated like:\n```\nfor i in N\n   for j in M\n      if constraints satisfied\n         compute and add element\n      fi\n   done\ndone\n```\n\nElement-wise reduction could be written as `i in M; j in N`, whereas `M` and `N` must be of the same size. Its meaning is:\n```\nif size(M) != size(N)\n   abort with exception\nfi\nfor index = 1 to size(M)\n   i = M(index)\n   j = N(index)\n   if constraints satisfied\n      compute and add element\n   fi\ndone\n```\n\nReductions of the same type -- only cross-product or only element-wise -- can be chained. The meaning of `i in M, j in N, ..., k in O` is:\n```\nfor i in M\n   for j in N\n      ...\n            for k in O\n               if constraints satisfied\n                  compute and add element\n               fi\n            done\n      ...\n   done\ndone\n```\nSimilarly, the meaning of `i in M; j in N; ...; k in O` is:\n```\nif size(M) != size(N) != ... != size(O)\n   abort with exception\nfi\nfor index = 1 to size(M)\n   i = M(index)\n   j = N(index)\n   ...\n   k = O(index)\n   if constraints satisfied\n      compute and add element\n   fi\ndone\n```\n\nIt should be **prohibited** to mix cross-product and element-wise reductions. The rational is, that semantics for mixed-nested seed lists are hard to define and obscure:\n\n1. Given above proposal, constraints are checked at the innermost loop. Although this is sufficient for sound semantics, it is not obvious for mixed-nested seed lists. For example, consider a reduction `i in M; h in (j in N, k in O)` with `size(M) = 10` and `size(N) + size(O) = 13` and filtered by a constraint `c`. The reduction can be defined or undefined (abort with exception) depending if `c` filters elements of the inner combination `N, O` before element-wise combining them with `M` or not. If 3 elements are filtered before combining element-wise, `M; (N, O)` is well-defined; otherwise not.\n\nInstead, developers can explicitly nest reduction expressions:\n```\n{ outer-new-element for all first-constraint with\n     i in M;\n     h in { inner-new-element for all second-constraint with j in N, k in O } }\n\n{ outer-new-element for all first-constraint and second-constraint with\n     i in M;\n     h in { inner-new-element for j in N, k in O } }\n```\nOf course, the generated code can be optimised; in the above example, the inner reduction could be checked and computed only once, caching the result for the outer reduction.\n\n**n>2-dimensional entities**\n\nI did not consider n>2 dimensional entities yet (matrices etc.). I consider this to be not so straight forward. Maybe a general decomposition concepts is needed for such (composition operators that define in which order to traverse dimensions).\n"}}
{"actor":{"display_login":"modelica-trac-importer"}}