Skip to content

Experiment with differentiation via typeclasses - #10

Open
neclitoris wants to merge 1 commit into
mainfrom
neclitoris/differentiation
Open

Experiment with differentiation via typeclasses#10
neclitoris wants to merge 1 commit into
mainfrom
neclitoris/differentiation

Conversation

@neclitoris

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/MLambda/TypeLits.hs
Map f (x ': xs) = f x ': Map f xs

-- | Creates a list of indices into a type-level list.
type Fins :: forall {k} (l :: [k]) . [k] -> [Fin l]

@TurtlePU TurtlePU Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, тут лучше

type Fins :: forall {k}. forall (l :: [k]) -> [Fin l]

если такое компилируется

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Или просто forall l -> [Fin l], как в сигнатуре для (!)

type family Args (i :: [[Natural]]) e :: Type where
Args i e = Rec At (Fins @(ArgsL i e) (ArgsL i e))

type family Fun (i :: [[Natural]]) (o :: [Natural]) e :: Type where

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно просто type Fun i o e = ... вместо тайпфэмили

Comment thread src/MLambda/Differentiable.hs

data (:.:) f1 f2 = f1 :.: f2

instance (Functional f1 i1 o1 e, Functional f2 (o1 : i2) o2 e, i ~ i1 ++ i2) => Functional (f1 :.: f2) i o2 e where

@TurtlePU TurtlePU Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не просто

(Functional f i j e, Functional g j k e) => Functional (f :.: g) i k e

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В текущей постановке тебе нужно как-то прокинуть в этот инстанс свидетель разделения i ~ i1 ++ i2, по которому в рантайме рекорд можно будет разбить на две части

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Потому что кайнды не сходятся. В конце концов, хочется иметь отображение из многих тензоров в один (таковым является, например, матмул), а тут j одновременно и как параметр, и как результат.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тогда, видимо, в качестве первого шага в композиции нужно класть список "функций", а не одну функцию. Либо сорить вспомогательной штукой которая переставляет входные аргументы

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Либо делать так, чтобы "функция" могла возвращать много тензоров, а не один, но это без гетерогенных индексов не выражается

ArgsL '[] e = '[]
ArgsL (x ': xs) e = NDArr x e : ArgsL xs e

type family Args (i :: [[Natural]]) e :: Type where

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут бтв тоже просто type вместо type family можно

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants