Closed GoogleCodeExporter closed 8 years ago
I don't consider this a real bug report, rather some questions about Pure to be
discussed, and I'd be happy to do so. But it would be much easier to do this on
the Pure mailing list (or if you prefer to not subscribe to the mailing list,
then in private mail). The GoogleCode issue tracker isn't really well-suited
for this kind of thing.
I have a few remarks, however. First, note that Pure is *not* a computer
algebra system, it's a general-purpose programming language which calls for
different design choices than would be made in a CAS. Nevertheless, if some
Pure function doesn't work the way that you want, you can easily replace it
with your own version (maybe in its own namespace, to avoid name clashes).
Concerning the issue with commutativity, that's not a rule you can use in plain
term rewriting, any term rewriting interpreter will loop on it. There are ways
to deal with this by adding a guard which will order the operands of
commutative operations in certain ways. But maybe what you want is really
rewriting modulo equational theories? Pure doesn't do this, so you might wish
to take a look at other systems like Maude or theorem provers instead, which
provide that kind of functionality.
"Also, Pure manual assert that during a computation with integers, the
interpreter automatically convert integers to bigints whenever the result
cannot fit into a machine integer."
No, that's not true. There are certain operations which will return bigint
results, and mixed operations generally promote an int to a bigint if the other
operand is bigint already. But int results are never promoted to bigint in
order to avoid wrap-around.
If you can point me to a place where the manual says otherwise, I'd appreciate
that, because that would be an error in the manual.
Original comment by aggraef@gmail.com
on 13 Jul 2012 at 11:50
Thanks you so much. I understand that Pure is not CAS (but my first impression
was that it shlould be much easier/more efficient to write a CAS in Pure,
relying on already existing symbolic facilities provided by Pure, e.g, without
reinventing "symbolic computations" as it should be the case if one uses an
imperative language. Perhaps, as a dreamer, I'm wrong!!).
Going through Prelude, I can see that addition and multiplication (+, *) are
not exact on integers, whereas (less basic) operators as div and % are
exact!! I am a little bit surprised by this choice by the authors of Pure. Of
course, as you suggested, a type guard can solve(!!) the problem.
e.g: the greatest machine integer being 2^31 -1, consider the value
m=(2^30)/2=1073741824; and define a new type bigaddint as follows:
> type bigaddint x::integer = x>=1073741824;
Then one gets an exact addition, plus, as follows;
> infixl 2000 plus;
x::bigaddint plus y::bigaddint = (x+0L)+ y;
x plus y = x+y otherwise;
The computation is now exact:
> 4000 + 1073741824; 4000 plus 1073741824;
1073745824
1073745824
> 1073741824 + 1073741824; 1073741824 plus 1073741824;
-2147483648
2147483648L
However, it seems not easy to directly extend the + operator to an exact
addition (by adding a tag rule as done for plus!!). Also, the choice
m=(2^30)/2=1073741824 appearing in the declaration of the type bigaddint seems
not canonical/or may not be efficient with rrespect to memory space in various
situations.
Original comment by Ngc.Bert...@gmail.com
on 16 Jul 2012 at 7:59
Interesting comments, but as I said I'd really suggest to take this discussion
to the mailing list where other Pure users can chime in. :)
Original comment by aggraef@gmail.com
on 16 Jul 2012 at 10:09
Original issue reported on code.google.com by
Ngc.Bert...@gmail.com
on 13 Jul 2012 at 4:09