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

  • SEARCH
  • Home
  • 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 8349779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:06:45+00:00 2026-06-09T08:06:45+00:00

When using the vector-space package for derivative towers (see derivative towers ) I come

  • 0

When using the vector-space package for derivative towers (see derivative towers) I come across the need to differentiate integrals.
From math it is quite clear how to achieve this:

f(x) = int g(y) dy from 0 to x

with a function

g : R -> R

for example.

The derivative with respect to x would be:

f'(x) = g(x)

I tried to get this behaviour by first defining a class “Integration”

class Integration a b where
--standard integration function
integrate :: (a -> b) -> a -> a -> b

a basic instance is

instance  Integration Double Double where
  integrate f a b = fst $ integrateQAGS prec 1000 f a b

with integrateQAGS from hmatrix

the problem comes with values b which represent towers of derivatives:

instance Integration Double (Double :> (NC.T Double)) where
  integrate = integrateD

NC.T is from Numeric.Complex (numeric-prelude).
The function integrateD is defined as follows (but wrong):

integrateD ::(Integration a b, HasTrie (Basis a), HasBasis a, AdditiveGroup b) =>  (a -> a :> b) -> a -> a -> (a :> b)
integrateD f l u = D (integrate (powVal . f) l u) (derivative $ f u)

The function does not return what I want, it derives the integrand, but not the integral. The problem is, that I need a linear map which returns f u. The a :> b is defined as follows:

data a :> b = D { powVal :: b, derivative :: a :-* (a :> b) }

I don’t know how to define derivative. Any help will be appreciated, thanks

edit:

I forgot to provide the instance for Integration Double (NC.T Double):

instance  Integration Double (NC.T Double) where
  integrate f a b = bc $ (\g -> integrate g a b) <$> [NC.real . f, NC.imag . f]
      where bc (x:y:[]) = x NC.+: y

and I can give an example of what I mean:
Let’s say I have a function

f(x) = exp(2*x)*sin(x)

>let f = \x -> (Prelude.exp ((pureD 2.0) AR.* (idD x))) * (sin (idD x)) :: Double :> Double 

(AR.*) means multiplication from Algebra.Ring (numeric-prelude)

I can easily integrate this function with the above function integrateD:

>integrateD f 0 1 :: Double :> Double
D 1.888605715258933 ...

When I take a look at the derivative of f:

f'(x) = 2*exp(2*x)*sin(x)+exp(2*x)*cos(x)

and evaluate this at 0 and pi/2 I get 1 and some value:

> derivAtBasis (f 0.0) ()
D 1.0 ...

> derivAtBasis (f (pi AF./ 2)) ()
D 46.281385265558534 ...

Now, when deriving the integral, I get the derivation of the function f not its value at the upper bound

> derivAtBasis (integrate f 0 (pi AF./ 2)) ()
D 46.281385265558534 ...

But I expect:

> f (pi AF./ 2)
D 23.140692632779267 ...
  • 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-09T08:06:46+00:00Added an answer on June 9, 2026 at 8:06 am

    I finally found a solution to my question.
    The key to the solution is the >-< function from the vector-space package, it stands for the chain rule.

    So, I define a function integrateD' like this:

    integrateD' :: (Integration a b, HasTrie (Basis a), HasBasis a, AdditiveGroup b , b ~ Scalar b, VectorSpace b) => (a -> a :> b) -> a -> a -> (a:>b) -> (a :> b)
    integrateD' f l u d_one =  ((\_ -> integrate (powVal . f) l  (u)) >-< (\_ ->  f u)) (d_one)
    

    the d_one means a derivation variable and its derivative must be 1. With this function I can now create some instances like

    instance Integration Double (Double :> Double) where
    integrate f l u = integrateD' f l u (idD 1)
    

    and

    instance Integration ( Double) (Double :> (NC.T Double)) where
    integrate f l u = liftD2 (NC.+:) (integrateD' (\x -> NC.real <$>> f x) l u (idD 1.0 :: Double :> Double)) (integrateD' (\x -> NC.imag <$>> f x) l u (idD 1.0 :: Double :> Double))
    

    unfortunately I can’t use integrateD on complex values out of the box, I have to use liftD2. The reason for this seems to be the idD function, I don’t know if there is a more elegant solution.

    When I look at the example in the question, I now get my desired solution:

    *Main> derivAtBasis (integrateD' f 0 (pi AF./ 2) (idD 1.0 :: Double :> Double )) ()
    D 23.140692632779267 ...
    

    or by using the instance:

    *Main> derivAtBasis (integrate f 0 (pi AF./ 2)) ()
    D 23.140692632779267 ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the support vector machine from the e1071 package to classify my data
I'm using a vector of pointers to objects. These objects are derived from a
I'm using a vector. For my purposes, I generally need it to have (n)
I'm using worldview_inverse * (projection_inverse * vector) to transform screen space coordinates into world
This question is derived from the topic: vector reserve c++ I am using a
When using vector, Out of Memory show. To fix it, I use max_size() to
im using simple vector push_back to object of Type A and getting this error
While using the vector why do we sometime use the operator[] like homework[mid] but
I'm using a vector in my program like this: vector<vector<string> > values; values[0].push_back(test words);
The following is a C++ program using STL vector container. Just wanted to know

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.