---
# System prepended metadata

title: Reduction in Field View
tags: [functional cycle 7]

---

# Reduction in Field View

###### tags: `functional cycle 7`

Appetite: 1 week (decide beginning of next week: MCH or Hannes)

## Goal

Implement reductions in the field view from frontend (parsing) to lowering. This is a standalone task, beginner task without dependencies.

## Syntax

```
sum(<field_expr>, axis=<dim>)
```
where `<field_expr>` is required to have dimension `<dim>`.

Notes:
For *normal* fields this requires that the field is *shifted* to be a field that includes the neighbor dimension, e.g.

```python=
v: Field[[Vertex], double]
sum(v(V2V), axis=V2V)
```

*Sparse* fields already have a neighbor dimension, e.g.

```python=
sparse: Field[Vertex, V2V]
sum(sparse, axis=V2V)
```

And for a combination you would have
```python
sum(sparse*vertex(V2V), axis=V2V)
```


## Rabbit holes

We have the following open design task which is explicitly not part of the project. If a field is shifted multiple times there is a ordering problem (which dimension is reduced, does it make sense to reduce an inner dimension, etc.), as e.g. in

```python=
inp: Field[[Vertex], double]
neighs: Field[[Vertex, V2E, E2V, V2E], double] =  inp(V2E)(E2V)(V2E)
```
## No goal

Adding list comprehension syntax-sugar, like

```python
sum(vertex_field(v) for v in V2V)
```