On Jun 26, 2010, at 4:26 AM, Miles Gould wrote:
> Hi everyone,
>
> I'm writing some code to work with dual numbers (see
> http://en.wikipedia.org/wiki/Dual_number), and, since they can be seen
> as an extension of the reals, it would be nice to implement the number
> protocol and take advantage of the math-combination word. Is this
> possible?
This isn't currently possible without hacking your new types into the custom
math-combination dispatch (not recommended). Usually libraries that define a
new mathematical entity provide their own operators for that entity (v+, v*,
v., etc. for vectors; m+, m., etc. for matrices; q+, q*, etc. for quaternions;
and so on). Another possibility would be to define multimethod versions of +,
-, *, etc. in a different "math.generic" vocabulary using the "multi-methods"
library in extra/, and using your generic math vocab instead of "math" in code
that deals with dual numbers:
---
QUALIFIED: math
FROM: multi-methods => GENERIC: METHOD: ;
IN: math.generic
GENERIC: + ( a b -- c )
METHOD: + { object object } math:+ ;
METHOD: + { dual dual } d+ ;
METHOD: + { dual object } d+ ;
METHOD: + { object dual } d+ ;
---
-Joe
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk