Changes between Version 18 and Version 19 of ReplacingGMPNotes/TheCurrentGMPImplementation


Ignore:
Timestamp:
Jan 17, 2007 2:25:33 AM (7 years ago)
Author:
p_tanski
Comment:

add clarification

Legend:

Unmodified
Added
Removed
Modified
  • ReplacingGMPNotes/TheCurrentGMPImplementation

    v18 v19  
    109109=== GMP Library Implementation === 
    110110 
    111 [general notes, not finished] The GMP library, like most multi-precision libraries has a fundamental limitation that might seem odd if you are only familiar with Haskell--not likely, but it bears mention anyway!  GMP functions require that their operands be separate entities.  (Remember: an operation such as `a + b` has three entities: the two operands and the result.)  That is, if you want to add `mpz_t a` to `mpz_t b`, and place the result in `mpz_t c`, you are fine but if you try to add `a` to `a` you will run into trouble.  (The problem is, the multi-precision integer library functions are designed so the operands cannot alias; this is more of a problem for complex operations such as multiplication than simple operations like addition.)  This limitation might be overcome by designing the API differently, for example: 
     111The GMP library, like most multi-precision libraries has a fundamental limitation that might seem odd if you are only familiar with Haskell--not likely, but it bears mention anyway!  GMP functions require that their operands be separate entities.  (Remember: an operation such as `a + b` has three entities: the two operands and the result.)  That is, if you want to add `mpz_t a` to `mpz_t b`, and place the result in `mpz_t c`, you are fine but if you try to add `a` to `a` you will run into trouble.  (The problem is, the multi-precision integer library functions are designed so the operands cannot alias; this is more of a problem for complex operations such as multiplication than simple operations like addition.)  This limitation might be overcome by designing the API differently, for example: 
    112112 1. compare the operands in Haskell, Cmm or whatever before you pass them to the _add function;  
    113113 2. if the operands are the same, create a separate copy of the operand 
    114114 3. -- you are o.k. for the case where two operands cannot be the same.   
    115115 
    116 For the case where one of the operands and the result is the same you would have to check outside the general Haskell, Cmm or whatever function wrapping the _add function--you would seem to need a higher level construct.  This is also a problem with Ints in GHCi.  Here is an example: 
     116For the case where one of the operands and the result is the same you would have to check outside the general Haskell, Cmm or whatever function wrapping the _add function--you would seem to need a higher level construct.  This is already handled by the Haskell language, since `Integer`s are subject to the same functional properties as other non-mutable variables.  There does seem to be a problem with `Int`s and `Integer`s in GHCi--I (PDT) am not sure whether this is a naming problem (the name after `let` is a binding-name) or an evaluation problem.  Here is an example: 
    117117{{{ 
    118118#!html 
     
    127127  <font color=Red>-- a = a + a</font> 
    128128  <font color=DarkOrchid>></font> <font color=Blue>let</font> <font color=Black>m_integer</font> <font color=Blue>=</font> <font color=Black>m_integer</font> <font color=Blue>+</font> <font color=Black>m_integer</font> 
     129  <font color=Red>--"m_integer" after "let" here is a new binding</font> 
    129130  <font color=DarkOrchid>></font> <font color=Blue>let</font> <font color=Black>n_integer</font> <font color=Blue>=</font> <font color=Black>m_integer</font> <font color=Blue>+</font> <font color=Black>m_integer</font> 
    130131