"(Bo's) 1986-article on ordinal fractions may be of interest."
https://www.academia.edu/10031088/ORDINAL_FRACTIONS_-_the_algebra_of_data

Has anyone got an implementation?

Is `=' synonymous with `compatible'? If so, the following seems to work, 
replacing for the literals with a vector.

NB. ordinal fractions, represented by vectors

Dyad=: [: :
Monad=: :[:
Commutes=: adverb def 'assert@:(u -: u~) Dyad'   NB. assertion failure if u 
does not commute

ANY=: , 0
ERROR=: , __
error=: ERROR"_

NB. removes trailing zeros
simplify=: ([: ANY"_^:(0=#) ({.~ (1 i.~([email protected]&=)\.))^:(0={:))"1 Monad

intersect=: dyad define"1
 'X Y'=. x ,:&, y   NB. fill extends the shorter vector
 X=. X + Y * X = 0
 Y=. Y + X * Y = 0
 simplify X error^:(-.@:-:) Y
)

difference=: simplify@:(([ * =)/)@:(,:&,)"1 Dyad


true=: ANY = simplify
eq=: equal=: -:"1 Dyad
incompatible=: (ERROR -: intersect)"1
compatible=: -.@:incompatible
le=: ([ -: intersect)&:,"1
ge=: le~
lt=: subordinate=: le > eq   NB. x subordinate y  proper subset
gt=: superordinate=: ge > eq NB. x superordinate y  proper superset


,.(#~ (1 -.@e.&> ])) <@:(". ::]);._2]0 :0              NB. tests evaluate to 1 
iff pass
 (,3)     -: simplify 3 0 0 0
 ANY      -: simplify ANY
 ANY      -: ANY intersect ANY
 (,1)     -: 1 intersect&:,1
 ERROR    -: 1 intersect&:,2
 ERROR    -: 1 2 3 intersect 1 2 1
 2 3      -: ANY intersect 2 3 0
 0 2 3    -: ANY intersect 0 2 3 0
 2 3      -: 2 3 intersect 2 3 0
 2 3 8    -: 2 3 intersect 2 3 8
             2 3 compatible 2 3 0
             0 2 3 incompatible 2 3 0
             1 [ 2 1 1 1 difference Commutes 2 1 2 1
             1 [ 2 1 0 3 intersect Commutes 0 1 8 3
)


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to