# How to define the product of n functions

**URL:** https://discourse.julialang.org/t/how-to-define-the-product-of-n-functions/115615
**Category:** General Usage
**Created:** [June 13, 2024, 6:52pm UTC](https://discourse.julialang.org/t/how-to-define-the-product-of-n-functions/115615 "2024-06-13T18:52:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)
#### Post date: [June 13, 2024, 6:52pm UTC](https://discourse.julialang.org/t/how-to-define-the-product-of-n-functions/115615/1 "2024-06-13T18:52:40Z")

</div>

I want to define the product of n complex functions:  
B(z)=\displaystyle\prod\_{k=1}^n\frac{z-p\_k}{1-\overline{p}\_kz}, where p\_k are n complex numbers of modulus \<1.  
I calculated a vector of partial products, and the function B is the last one in the respective vector.  
Is there a simpler way to get the definition of this product?

```julia
function fproduct(f, g) 
    z -> f(z) * g(z)
end
BlaschkeF(z::Complex; p=0.5+0*im) = (z-p)/(1-conj(p)*z)
unitf(z::Complex) = 1.0+0*im    
n=5   
params = [0.95*cis(k*2pi/n) for k in 0:n-1]    
prodf = Function[]
for p in params
    g = z->BlaschkeF(z;p=p)
    if !isempty(prodf)
        ppr = fproduct(last(prodf), g) #ppr -partial product  
    else 
        ppr = fproduct(unitf, g)  
    end
    push!(prodf, ppr) 
end
B(z)=last(prodf)(z)

```

---

<div class="post-metadata">

### Author: ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)
#### Post date: [June 13, 2024, 7:04pm UTC](https://discourse.julialang.org/t/how-to-define-the-product-of-n-functions/115615/2 "2024-06-13T19:04:34Z")

</div>

> Is there a simpler way to get the definition of this product?

How about this?

```julia
BlaschkeF(z; p=0.5+0*im) = (z-p)/(1-conj(p)*z)
n=5   
params = [0.95*cis(k*2pi/n) for k in 0:n-1]    
B(z) = prod(BlaschkeF(z, p=p) for p in params)

```

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [June 13, 2024, 7:09pm UTC](https://discourse.julialang.org/t/how-to-define-the-product-of-n-functions/115615/3 "2024-06-13T19:09:54Z")

</div>

I think `params` should be an input argument to `B`, instead of a global variable.
