degenerate reductions

If we don't know about 'em, we can't fix 'em.

degenerate reductions

PostPosted by drab » Mon Apr 03, 2017 3:39 pm

Reduction with any function of a scalar should return the scalar unchanged.
But these functions give an error: ⍟○?⊥⊣⊢≡≢⍱⍲⊂⍋⍒⍳∊⍸⍷∩⊆⊇π,⍪⍕
And these functions give the wrong answer: =≠≤<>≥∪∼§

Reduction with any function along an axis of length 1 should return the array reshaped without that axis.
But these functions give an error: ⍟○?⊥⊣⊢≡≢⍱⍲⊂⍋⍒⍳∊⍸⍷∩⊆⊇π,⍪⍕
And these functions give the wrong answer: =≠≤<>≥∪∼§
drab
 
Posts: 295
Joined: Thu Oct 09, 2014 6:23 am

Re: degenerate reductions

PostPosted by forummaster » Mon Apr 03, 2017 8:28 pm

drab wrote:Reduction with any function of a scalar should return the scalar unchanged.
But these functions give an error: ⍟○?⊥⊣⊢≡≢⍱⍲⊂⍋⍒⍳∊⍸⍷∩⊆⊇π,⍪⍕
And these functions give the wrong answer: =≠≤<>≥∪∼§

Reduction with any function along an axis of length 1 should return the array reshaped without that axis.
But these functions give an error: ⍟○?⊥⊣⊢≡≢⍱⍲⊂⍋⍒⍳∊⍸⍷∩⊆⊇π,⍪⍕
And these functions give the wrong answer: =≠≤<>≥∪∼§

This behavior is correct and intended. The definition you cite has various problems I've attempted to address in Reduction of Singletons which lays out the set of rules for that operation in NARS2000.

The idea is to eliminate anomalous results such as +/'A' ←→ 'A' by requiring that the reduction function have an Identity Element and that Reduction follows these rules:

f/V ←→ ⊂(↑V) f ⊃f/1↓V       (for 2<⍴V)  (1-3a)
←→ ⊂(0⊃V) f 1⊃V (for 2=⍴V) (1-3b)
←→ ⊂(↑V) f ⊃f/1↓V (for 1=⍴V) (1-3c)
←→ ⊂IdentityElement (for 0=⍴V) (1-3d)

Combining (1-3c) and (1-3d) yields a definition for Reduction of Singletons of

f/V ←→ ⊂(↑V) f IdentityElement (for 1=⍴V)

For example, this means that

+/'A' ←→ 'A' + 0 ←→ DOMAIN ERROR
⍟/23 ←→ DOMAIN ERROR
=/23 ←→ 23 = 1 ←→ 0

among others. One pleasant effect of these rules is that the result of Reduction is always in the range of the Reduction function, so that (among other things) we can't return 'A' from +/'A' because the Plus function never returns a character, and we can't return 23 from =/23 because the Equal function never returns 23. I appreciate that this differs from the Conventional Wisdom, but it makes a whole lot of sense to me.

Please review the answers you think are wrong and the expressions that signal an error in the light of these rules and let me know if there's anything I've missed..
forummaster
 
Posts: 555
Joined: Wed Jan 23, 2013 1:00 pm

Re: degenerate reductions

PostPosted by drab » Tue Apr 04, 2017 8:00 am

Those are some very sensible ideas. I like them.

But there is still at least 1 problem

+/''
0

Don't your new rules make this an error?
drab
 
Posts: 295
Joined: Thu Oct 09, 2014 6:23 am

Re: degenerate reductions

PostPosted by forummaster » Tue Apr 04, 2017 8:27 pm

drab wrote:Those are some very sensible ideas. I like them.

But there is still at least 1 problem

+/''
0

Don't your new rules make this an error?

Good point! It's fixed in the latest Alpha version:

http://www.nars2000.org/download/binaries/alpha/

Thanks for keeping me honest!
forummaster
 
Posts: 555
Joined: Wed Jan 23, 2013 1:00 pm

Re: degenerate reductions

PostPosted by forummaster » Tue Apr 18, 2017 2:08 pm

Good news! The latest Alpha version now supports System Labels in Anonymous Functions/Operators (AFOs). For example,

      {⍺+∘÷⍵ ⋄ ⎕ID:∞}\7⍴1
1 2 1.5 1.666666667 1.6 1.625 1.615384615

which calculates successive approximations to Phi = (1+√5)÷2.

This feature enables AFOs to be used in Scan whereas, previous to this change, RoS prevented that because there was no way to define the Identity Element for an AFO.

http://www.nars2000.org/download/binaries/alpha/
forummaster
 
Posts: 555
Joined: Wed Jan 23, 2013 1:00 pm

Re: degenerate reductions

PostPosted by drab » Wed Apr 19, 2017 10:18 am

Well, that's interesting , but ...

But we need some detailed guidance about what actually happens inside a multi-line anonymous function.
I couldn't find it.

Obviously, the rules are somewhat different than for regular defined functions.

I'm guessing here, but apparently:

[1] the result is the first unassigned value
[2] all subsequent unassigned value are ignored
[3] no branches are allowed
[4] execution stops at a label
[5] all names are local
[6] ...
drab
 
Posts: 295
Joined: Thu Oct 09, 2014 6:23 am

Re: degenerate reductions

PostPosted by forummaster » Wed Apr 19, 2017 12:49 pm

drab wrote:Well, that's interesting , but ...

But we need some detailed guidance about what actually happens inside a multi-line anonymous function.
I couldn't find it.

Obviously, the rules are somewhat different than for regular defined functions.

I'm guessing here, but apparently:

[1] the result is the first unassigned value
[2] all subsequent unassigned value are ignored
[3] no branches are allowed
[4] execution stops at a label
[5] all names are local
[6] ...

Thanks for the reminder. I haven't gotten around to updating the documentation in the wiki to include examples of System Labels, but otherwise it should explain AFOs as you have, except for your [4] which doesn't hold. The only labels are System Labels which are recognized by a SysLbl name at the start of a stmt followed a colon. Syntax such as ⋄ L1:23 ⋄ is actually a Guard stmt, not a label.
forummaster
 
Posts: 555
Joined: Wed Jan 23, 2013 1:00 pm

Re: degenerate reductions

PostPosted by drab » Wed Apr 19, 2017 2:26 pm

So, is there no longer any fall through to a system label in a regular function, or is that just in an anonymous function?
drab
 
Posts: 295
Joined: Thu Oct 09, 2014 6:23 am

Re: degenerate reductions

PostPosted by forummaster » Wed Apr 19, 2017 3:45 pm

drab wrote:So, is there no longer any fall through to a system label in a regular function, or is that just in an anonymous function?

Execution proceeds line by line, stmt by stmt for both Standard Functions (User-Defined Functions/Operators-- UDFOs) as well as AFOs. The stmts on labeled lines are treated no differently. If execution falls through to a System or Normal Label, so be it.

As you well know, the only difference with System Labels is that execution may begin with that entry point under the usual conditions. After that, execution proceeds as usual. In an AFO, it is good practice to put System Labels at the end of the function, but that is a only a choice, not a requirement. An example of bad coding is {a←⍺+⍵ ⋄ ⎕ID:23 ⋄ a} which returns 23 all the time.
forummaster
 
Posts: 555
Joined: Wed Jan 23, 2013 1:00 pm


Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 1 guest

cron