Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 1 characters in body
Source Link
lurker
  • 58.5k
  • 9
  • 74
  • 108

Assuming your diff_term is good (which you can test modularly at the Prolog prompt), let's look at diff_poly:

diff_poly([Term | Rest], DiffVar, DiffedPoly) :- diff_term(Term, DiffVar, DiffedTerm), % DiffedPoly = DiffedTerm. diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]). 

This clause says that DiffedPoly is the polynomial [Term|Rest] differentiated with respect to DiffVar. Sounds good so far.

Your first expression within the clause says, *DiffedTerm is Term differentiated with respect to DiffVar. That sounds good, too.

The next commented line says to unify DiffedPoly with DiffedTerm. This would no longer make sense since the fully differentiated polynomial would, in general not be just the differentiated term (unless, of course, the polynomial only had one term). Let's leave that commented out.

Finally, youwe have:

diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]) 

This says, The result of differentiating the rest of the polynomial (without the first term) with respect to DiffVar is the first term differentiated with respect to DiffVar (i.e.i.e., DiffTerm) followed by the fully differentiated polynomial (DiffedPoly). If you think about that, it doesn't make sense. It's written as if you changed what DiffedPoly really means. This query should be expressing, *The fully differentiated polynomial (DiffedPoly) is the differentiation of the initial term (DiffedTerm) followed by the differentiation of the rest of the polynomial (differentiation of Rest with respect to DiffVar)The fully differentiated polynomial (DiffedPoly) is the differentiation of the initial term (DiffedTerm) followed by the differentiation of the rest of the polynomial (differentiation of Rest with respect to DiffVar). Translate this last description into Prolog, then you'll be almost there.

Almost... that's because there needs to be a base case to the recursion. What happens on an empty polynomial? You would need also to add a diff_poly([], <something>, <something>) for that case.

Assuming your diff_term is good (which you can test modularly at the Prolog prompt), let's look at diff_poly:

diff_poly([Term | Rest], DiffVar, DiffedPoly) :- diff_term(Term, DiffVar, DiffedTerm), % DiffedPoly = DiffedTerm. diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]). 

This clause says that DiffedPoly is the polynomial [Term|Rest] differentiated with respect to DiffVar. Sounds good so far.

Your first expression within the clause says, *DiffedTerm is Term differentiated with respect to DiffVar. That sounds good, too.

The next commented line says to unify DiffedPoly with DiffedTerm. This would no longer make sense since the fully differentiated polynomial would, in general not be just the differentiated term (unless, of course, the polynomial only had one term). Let's leave that commented out.

Finally, you have:

diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]) 

This says, The result of differentiating the rest of the polynomial (without the first term) with respect to DiffVar is the first term differentiated with respect to DiffVar (i.e. DiffTerm) followed by the fully differentiated polynomial (DiffedPoly). If you think about that, it doesn't make sense. It's written as if you changed what DiffedPoly really means. This query should be expressing, *The fully differentiated polynomial (DiffedPoly) is the differentiation of the initial term (DiffedTerm) followed by the differentiation of the rest of the polynomial (differentiation of Rest with respect to DiffVar). Translate this last description into Prolog, then you'll be almost there.

Almost... that's because there needs to be a base case to the recursion. What happens on an empty polynomial? You would need also to add a diff_poly([], <something>, <something>) for that case.

Assuming your diff_term is good (which you can test modularly at the Prolog prompt), let's look at diff_poly:

diff_poly([Term | Rest], DiffVar, DiffedPoly) :- diff_term(Term, DiffVar, DiffedTerm), % DiffedPoly = DiffedTerm. diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]). 

This clause says that DiffedPoly is the polynomial [Term|Rest] differentiated with respect to DiffVar. Sounds good so far.

Your first expression within the clause says, *DiffedTerm is Term differentiated with respect to DiffVar. That sounds good, too.

The next commented line says to unify DiffedPoly with DiffedTerm. This would no longer make sense since the fully differentiated polynomial would, in general not be just the differentiated term (unless, of course, the polynomial only had one term). Let's leave that commented out.

Finally, we have:

diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]) 

This says, The result of differentiating the rest of the polynomial (without the first term) with respect to DiffVar is the first term differentiated with respect to DiffVar (i.e., DiffTerm) followed by the fully differentiated polynomial (DiffedPoly). If you think about that, it doesn't make sense. It's written as if you changed what DiffedPoly really means. This query should be expressing, The fully differentiated polynomial (DiffedPoly) is the differentiation of the initial term (DiffedTerm) followed by the differentiation of the rest of the polynomial (differentiation of Rest with respect to DiffVar). Translate this last description into Prolog, then you'll be almost there.

Almost... that's because there needs to be a base case to the recursion. What happens on an empty polynomial? You would need also to add a diff_poly([], <something>, <something>) for that case.

added 82 characters in body
Source Link
lurker
  • 58.5k
  • 9
  • 74
  • 108

Let'sAssuming your diff_term is good (which you can test modularly at the Prolog prompt), let's look at your diff_poly:

diff_poly([Term | Rest], DiffVar, DiffedPoly) :- diff_term(Term, DiffVar, DiffedTerm), % DiffedPoly = DiffedTerm. diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]). 

This clause says that DiffedPoly is the polynomial [Term|Rest] differentiated with respect to DiffVar. Sounds good so far.

Your first expression within the clause says, *DiffedTerm is Term differentiated with respect to DiffVar. That sounds good, too.

The next commented line says to unify DiffedPoly with DiffedTerm. This would no longer make sense since the fully differentiated polynomial would, in general not be just the differentiated term (unless, of course, the polynomial only had one term). Let's leave that commented out.

Finally, you have:

diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]) 

This says, The result of differentiating the rest of the polynomial (without the first term) with respect to DiffVar is the first term differentiated with respect to DiffVar (i.e. DiffTerm) followed by the fully differentiated polynomial (DiffedPoly). If you think about that, it doesn't make sense. It's written as if you changed what DiffedPoly really means. This query should be expressing that, *The fully differentiated polynomial (DiffedPoly) is the differentiation of the initial term (DiffedTerm) followed by the differentiation of the rest of the polynomial (differentiation of Rest with respect to DiffVar). Translate this last description into Prolog, then you'll be almost there.

Almost... that's because there needs to be a base case to the recursion. What happens on an empty polynomial? You would need also to add a diff_poly([], <something>, <something>) for that case.

Let's look at your diff_poly:

diff_poly([Term | Rest], DiffVar, DiffedPoly) :- diff_term(Term, DiffVar, DiffedTerm), % DiffedPoly = DiffedTerm. diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]). 

This clause says that DiffedPoly is the polynomial [Term|Rest] differentiated with respect to DiffVar. Sounds good.

Your first expression within the clause says, *DiffedTerm is Term differentiated with respect to DiffVar. That sounds good, too.

The next commented line says to unify DiffedPoly with DiffedTerm. This would no longer make sense since the fully differentiated polynomial would, in general not be just the differentiated term (unless, of course, the polynomial only had one term). Let's leave that commented out.

Finally, you have:

diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]) 

This says, The result of differentiating the rest of the polynomial (without the first term) with respect to DiffVar is the first term differentiated with respect to DiffVar (i.e. DiffTerm) followed by the fully differentiated polynomial (DiffedPoly). If you think about that, it doesn't make sense. This should be expressing that *The fully differentiated polynomial (DiffedPoly) is the differentiation of the initial term (DiffedTerm) followed by the differentiation of the rest of the polynomial (differentiation of Rest with respect to DiffVar). Translate this last description into Prolog, then you'll be almost there.

Almost... that's because there needs to be a base case to the recursion. What happens on an empty polynomial? You would need also to add a diff_poly([], <something>, <something>) for that case.

Assuming your diff_term is good (which you can test modularly at the Prolog prompt), let's look at diff_poly:

diff_poly([Term | Rest], DiffVar, DiffedPoly) :- diff_term(Term, DiffVar, DiffedTerm), % DiffedPoly = DiffedTerm. diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]). 

This clause says that DiffedPoly is the polynomial [Term|Rest] differentiated with respect to DiffVar. Sounds good so far.

Your first expression within the clause says, *DiffedTerm is Term differentiated with respect to DiffVar. That sounds good, too.

The next commented line says to unify DiffedPoly with DiffedTerm. This would no longer make sense since the fully differentiated polynomial would, in general not be just the differentiated term (unless, of course, the polynomial only had one term). Let's leave that commented out.

Finally, you have:

diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]) 

This says, The result of differentiating the rest of the polynomial (without the first term) with respect to DiffVar is the first term differentiated with respect to DiffVar (i.e. DiffTerm) followed by the fully differentiated polynomial (DiffedPoly). If you think about that, it doesn't make sense. It's written as if you changed what DiffedPoly really means. This query should be expressing, *The fully differentiated polynomial (DiffedPoly) is the differentiation of the initial term (DiffedTerm) followed by the differentiation of the rest of the polynomial (differentiation of Rest with respect to DiffVar). Translate this last description into Prolog, then you'll be almost there.

Almost... that's because there needs to be a base case to the recursion. What happens on an empty polynomial? You would need also to add a diff_poly([], <something>, <something>) for that case.

Source Link
lurker
  • 58.5k
  • 9
  • 74
  • 108

Let's look at your diff_poly:

diff_poly([Term | Rest], DiffVar, DiffedPoly) :- diff_term(Term, DiffVar, DiffedTerm), % DiffedPoly = DiffedTerm. diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]). 

This clause says that DiffedPoly is the polynomial [Term|Rest] differentiated with respect to DiffVar. Sounds good.

Your first expression within the clause says, *DiffedTerm is Term differentiated with respect to DiffVar. That sounds good, too.

The next commented line says to unify DiffedPoly with DiffedTerm. This would no longer make sense since the fully differentiated polynomial would, in general not be just the differentiated term (unless, of course, the polynomial only had one term). Let's leave that commented out.

Finally, you have:

diff_poly(Rest, DiffVar, [DiffedTerm | DiffedPoly]) 

This says, The result of differentiating the rest of the polynomial (without the first term) with respect to DiffVar is the first term differentiated with respect to DiffVar (i.e. DiffTerm) followed by the fully differentiated polynomial (DiffedPoly). If you think about that, it doesn't make sense. This should be expressing that *The fully differentiated polynomial (DiffedPoly) is the differentiation of the initial term (DiffedTerm) followed by the differentiation of the rest of the polynomial (differentiation of Rest with respect to DiffVar). Translate this last description into Prolog, then you'll be almost there.

Almost... that's because there needs to be a base case to the recursion. What happens on an empty polynomial? You would need also to add a diff_poly([], <something>, <something>) for that case.