Changes between Version 18 and Version 19 of ReplacingGMPNotes/TheCurrentGMPImplementation
- Timestamp:
- Jan 17, 2007 2:25:33 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ReplacingGMPNotes/TheCurrentGMPImplementation
v18 v19 109 109 === GMP Library Implementation === 110 110 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:111 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: 112 112 1. compare the operands in Haskell, Cmm or whatever before you pass them to the _add function; 113 113 2. if the operands are the same, create a separate copy of the operand 114 114 3. -- you are o.k. for the case where two operands cannot be the same. 115 115 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 al so a problem with Ints in GHCi. Here is an example: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 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: 117 117 {{{ 118 118 #!html … … 127 127 <font color=Red>-- a = a + a</font> 128 128 <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> 129 130 <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> 130 131