Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:08:09+00:00 2026-06-17T10:08:09+00:00

I am interested in learning an elegant way to use currying in a functional

  • 0

I am interested in learning an elegant way to use currying in a functional programming language to numerically evaluate multiple integrals. My language of choice is F#.

If I want to integrate f(x,y,z)=8xyz on the region [0,1]x[0,1]x[0,1] I start by writing down a triple integral of the differential form 8xyz dx dy dz. In some sense, this is a function of three ordered arguments: a (float -> float -> float -> float).

I take the first integral and the problem reduces to the double integral of 4xy dx dy on [0,1]x[0,1]. Conceptually, we have curried the function to become a (float -> float -> float).

After the second integral I am left to take the integral of 2x dx, a (float -> float), on the unit interval.

After three integrals I am left with the result, the number 1.0.

Ignoring optimizations of the numeric integration, how could I succinctly execute this? I would like to write something like:

let diffForm = (fun x y z -> 8 * x * y * z)

let result =
    diffForm
    |> Integrate 0.0 1.0
    |> Integrate 0.0 1.0
    |> Integrate 0.0 1.0

Is this doable, if perhaps impractical? I like the idea of how closely this would capture what is going on mathematically.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:08:10+00:00Added an answer on June 17, 2026 at 10:08 am

    I like the idea of how closely this would capture what is going on mathematically.

    I’m afraid your premise is false: The pipe operator threads a value through a chain of functions and is closely related to function composition. Integrating over an n-dimensional domain however is analogous to n nested loops, i.e. in your case something like

    for x in x_grid_nodes do
        for y in y_grid_nodes do
            for z in z_grid_nodes do
                integral <- integral + ... // details depend on integration scheme
    

    You cannot easily map that to a chain of three independet calls to some Integrate function and thus the composition integrate x1 x2 >> integrate y1 y2 >> integrate z1 z2 is actually not what you do when you integrate f. That is why Tomas’ solution—if I understood it correctly (and I am not sure about that…)—essentially evaluates your function on an implicitly defined 3D grid and passes that to the integration function. I suspect that is as close as you can get to your original question.

    You did not ask for it, but if you do want to evaluate a n-dimensional integral in practice, look into Monte Carlo integration, which avoids another problem commonly known as the “curse of dimensionality”, i.e. that fact that the number of required sample points grows exponentially with n with classic integration schemes.

    Update

    You can implement iterated integration, but not with a single integrate function, because the type of the function to be integrated is different for each step of the integration (i.e. each step turns an n-ary function to an (n – 1)-ary one):

    let f = fun x y z -> 8.0 * x * y * z
    
    // numerically integrate f on [x1, x2]
    let trapRule f x1 x2 = (x2 - x1) * (f x1 + f x2) / 2.0 
    
    // uniform step size for simplicity
    let h = 0.1
    
    // integrate an unary function f on a given discrete grid
    let integrate grid f =
        let mutable integral = 0.0
        for x1, x2 in Seq.zip grid (Seq.skip 1 grid) do
            integral <- integral + trapRule f x1 x2
        integral
    
    // integrate a 3-ary function f with respect to its last argument
    let integrate3 lower upper f =
        let grid = seq { lower .. h .. upper }
        fun x y -> integrate grid (f x y)
    
    // integrate a 2-ary function f with respect to its last argument
    let integrate2 lower upper f =
        let grid = seq { lower .. h .. upper }
        fun x -> integrate grid (f x)
    
    // integrate an unary function f on [lower, upper]
    let integrate1 lower upper f =
        integrate (seq { lower .. h .. upper }) f
    

    With your example function f

    f |> integrate3 0.0 1.0 |> integrate2 0.0 1.0 |> integrate1 0.0 1.0
    

    yields 1.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know much about functional programming but am interested in learning Clojure. Are
I am interested learning more about the D programming programming language, and especially using
I'm interested in learning a programming language with support for GUI, multithreading and easy
I'm interested in learning the smart, elegant way to build navigation items throughout a
I'm interested in learning to use OpenGL and I had the idea of writing
I'm interested in learning python to have access to a more agile language for
I am very interested in learning windows shell programming. So...I searched for books on
I’m interested in learning which technique developers prefer to use to enforce uniqueness in
I'm interested in learning how to design/plan for web application development, in a multiple
Description I'm interested in learning if there is any way to control sort order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.