Note that there are some explanatory texts on larger screens.

plurals
  1. POI want to perform summation on a small and fast qualitative data type in Fortran
    primarykey
    data
    text
    <p>This is part of a series of questions about implementing a qualitative data type in Fortran.</p> <p><strong>Background:</strong> The topic relates to something called <em>loop analysis of complex systems</em> which one might read about in, for example, Puccia, C. J. and Levins, R. (1986). <em>Qualitative Modeling of Complex Systems: An Introduction to Loop Analysis and Time Averaging</em>. Harvard University Press, Cambridge, MA, or Levins, R. (1974). The qualitative analysis of partially specified systems. <em>Annals of the New York Academy of Sciences</em>, 231:123–138. While I could implement this technique using numerical matrix algebra (as has been done elsewhere), I am interested in approaching the problem from a different direction. The nature of loop analysis is complex and costly (I am not a CS person, but I think it's something like a #P difficulty calculation), and my long term aims are to create a set of libraries for various and sundry loop analysis problems that employ pruning optimizations based on properties of qualitative arithmetic. If this seems hopelessly misguided, please humor me and consider this an exercise in learning.</p> <p>For my purposes the QUALIT data type can have 4 values: -1, 0, 1, and ? (sometimes represented as -, 0, +, and +/-). More about this data type here: <a href="https://stackoverflow.com/questions/20790427/i-want-to-implement-a-small-and-fast-qualitative-data-type-in-fortran">I want to implement a small and fast qualitative data type in Fortran</a></p> <p>I would like QUALIT type data to reflect arithmetic binary operations SUM() and PROD(). Summation of two QUALIT values, <code>A</code> and <code>B</code> works like this:</p> <pre><code>A B A+B - - - - 0 - - + ? - ? ? 0 - - 0 0 0 0 + + 0 ? ? + - ? + 0 + + + + + ? ? ? - ? ? 0 ? ? + ? ? ? ? </code></pre> <p>In array form summation of two QUALITs looks like:</p> <pre><code> QUALIT 1 - 0 + ? Q - - - ? ? U A 0 - 0 + ? L I + ? + + ? T 2 ? ? ? ? ? </code></pre> <p>And this array with Boolean values:</p> <pre><code> QUALIT 1 00 01 10 11 Q 00 00 00 11 11 U A 01 00 01 10 11 L I 10 11 10 10 11 T 2 11 11 11 11 11 </code></pre> <p>For multiplication such an array would be:</p> <pre><code> QUALIT 1 00 01 10 11 Q 00 10 01 00 11 U A 01 01 01 01 01 L I 10 00 01 10 11 T 2 11 11 01 11 11 </code></pre> <p>I can implement QUALIT summation like this:</p> <pre><code>ELEMENTAL FUNCTION QUALSUM(x,y) IMPLICIT NONE TYPE(QUALIT)::QUALSUM TYPE(QUALIT), INTENT(IN)::x,y TYPE(QUALIT)::summation_array(4,4) LOGICAL::xbit1, xbit2, ybit1, ybit2 INTEGER::index1, index2 summation_array(1,1) = QUALIT(.FALSE.,.FALSE.) summation_array(1,2) = QUALIT(.FALSE.,.FALSE.) summation_array(1,3) = QUALIT(.TRUE., .TRUE.) summation_array(1,4) = QUALIT(.TRUE., .TRUE.) summation_array(2,1) = QUALIT(.FALSE.,.FALSE.) summation_array(2,2) = QUALIT(.FALSE.,.TRUE.) summation_array(2,3) = QUALIT(.TRUE., .FALSE.) summation_array(2,4) = QUALIT(.TRUE., .TRUE.) summation_array(3,1) = QUALIT(.TRUE., .TRUE.) summation_array(3,2) = QUALIT(.TRUE., .FALSE.) summation_array(3,3) = QUALIT(.TRUE., .FALSE.) summation_array(3,4) = QUALIT(.TRUE., .TRUE.) summation_array(4,1) = QUALIT(.TRUE., .TRUE.) summation_array(4,2) = QUALIT(.TRUE., .TRUE.) summation_array(4,3) = QUALIT(.TRUE., .TRUE.) summation_array(4,4) = QUALIT(.TRUE., .TRUE.) xbit1 = x%bit1 xbit2 = x%bit2 ybit1 = y%bit1 ybit2 = y%bit2 index1 = 1 + (2*COUNT([xbit2])) + COUNT([xbit1]) index2 = 1 + (2*COUNT([ybit2])) + COUNT([ybit1]) QUALSUM = summation_array(index1,index2) END FUNCTION QUALSUM </code></pre> <p>My questions (please answer <strong>both</strong>):</p> <ol> <li><p>Is the fastest implementation of SUM going to be to declare a static 4*4 array with elements indexed by the first and second input QUALIT values as in my example above?</p></li> <li><p>Does the answer to question 1 change if I want to perform these operations on sequences? For example given (pseudocode): <code>TYPE (QUALIT) EXAMPLE :: (/-,+,+,0,+,+,?,+,0,0,-/)</code> Any summation operation across an arbitrary number of operands should return <strong>?</strong> as soon as the first <strong>?</strong> is encountered (either in the input, or in the current sum total, so after the second element in <code>EXAMPLE</code> we know that the sum of the whole sequence is <strong>?</strong>) and cease remaining calculations. I am going to want to perform a large number of such summations, and perform them on large vectors of QUALIT data.</p></li> <li><p>Does the answer to this question change when implementing multiplication, rather than summation?</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload