Bug appearing in at least 12.0.0 and 12.3.1

I'm trying some multidimensional Chebyshev fits. First, define a wrapper to prevent premature symbolic evaluation (I don't want a power series result):

cheb[n_Integer, x_?NumericQ] := ChebyshevT[n, x]

Function to construct list of basis functions for Fit:

chebasis[vars_List, n_Integer] := 
  Flatten@Outer[Times, Sequence @@ 
  Transpose@Table[cheb[i, #] & /@ vars, {i, 0, n}]]

Now, make some test data:

tdata = N[Flatten[Table[{x, y, x y}, {x, -1, 1}, {y, -1, 1}], 1]];

Attempt a fit:

Fit[tdata, chebasis[{x, y}, 1], {x, y}] // Chop

Emits an error message:

Experimental`NumericalFunction::dimsl: {y} given in {x,y} should be a list of dimensions for a particular argument.

It does, however yield a sensible result:

1. cheb[1, x] cheb[1, y]

So, what's going on here? Is it harmless? Can I avoid it?

  • 2
    $\begingroup$ For whatever it's worth the "equivalent" fit with NonlinearModelFit (NonlinearModelFit[tdata, {a1, a2, a3, a4} . chebasis[{x, y}, 1], {a1, a2, a3, a4}, {x, y}] // Chop) gives the same error message and fit. $\endgroup$
    – JimB
    Oct 21 '21 at 15:46
  • 3
    $\begingroup$ Please write an INFORMATIVE (not vague, cutesy, and confusing) title. $\endgroup$ Oct 21 '21 at 19:44
  • 3
    $\begingroup$ @DavidG.Stork If you don't have something constructive to offer, please don't comment. $\endgroup$
    – John Doty
    Oct 21 '21 at 20:25
  • 3
    $\begingroup$ @John Doty: This IS a constructive comment. It points out a weakness. Innumerable other comments are the same, saying a question is (for instance), too vague, or unclear, or needs more work, or should be typeset. I expect you complain about such thousands of comments too, right? Oh... what is "the beast", specifically? And "annoys"? $\endgroup$ Oct 21 '21 at 22:05
  • 5
    $\begingroup$ I have to say I agree with @DavidG.Stork. The purpose of a good title is so that future users searching in stack exchange for a similar question should be able to find this one and therefore not write a duplicate. It also serves the purpose of giving potential answerers a quick idea of what the question is about, which allows them to waste less time clicking through (or wasting your time by not clicking through due to the title not having enough information about the question). $\endgroup$
    – march
    Oct 22 '21 at 15:31

It looks like a bug. Fit tries to create a numerical function with

Experimental`CreateNumericalFunction[{{x, y}},
 {cheb[0, x] cheb[0, y], cheb[0, x] cheb[1, y], cheb[0, y] cheb[1, x], 
  cheb[1, x] cheb[1, y]}, {4}]
(* Experimental`NumericalFunction::dimsl error *)

But it should call it without the extra {} in the first argument:

Experimental`CreateNumericalFunction[{x, y},
 {cheb[0, x] cheb[0, y], cheb[0, x] cheb[1, y], cheb[0, y] cheb[1, x], 
  cheb[1, x] cheb[1, y]}, {4}]

The failure of CreateNumericalFunction just means it falls back on some other method of evaluation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.