# How many arguments does a function require, and how to use that in Manipulate

The goal is to vary the order parameters in wavelet transforms in the Manipulate environment. The various transformations have arguments of different rank. For example,

HaarWavelet[] has no order argument.

DaubechiesWavelet[m] has a single order argument $m$ and the desire is to present choices for $m$.

BiorthogonalSplineWavelet[m,n] has an order parameter $m$ and a dual order parameter $n$ and the desire is to let the user control $m$ and $n$.

The current state of my effort is this:

data = DiskMatrix; Manipulate[ dwt = DiscreteWaveletTransform[dat32, wavelet]; gdwd = WaveletMatrixPlot[dwt] , {wavelet, {HaarWavelet[], DaubechiesWavelet[], MeyerWavelet[]}}] The different transforms can be selected, but there is no capability to change the order parameters. How can order parameters be introduced?

• Related: (7040), (56665) – Mr.Wizard Jun 13 '15 at 2:23
• MrW: valuable insights. Thank you. – dantopa Jun 15 '15 at 14:42

I'm pretty sure there ought to be something cleaner. While we wait for a better answer, you may use this to return the minimum and maximum number of arguments allowed for each wavelet:

nArgs[fun_] :=
StringCases[ToString@DownValues@fun,
Shortest["ArgumentCountQ"~~__~~(n1:NumberString)~~__~~ (n2:NumberString)] :>
ToExpression[{n1, n2}]]

{#, nArgs@#} & /@ ToExpression /@ Names["*Wavelet"]

(*
{{BattleLemarieWavelet, {{2, 2}}},
{BiorthogonalSplineWavelet, {{2, 2}}},
{CDFWavelet, {{1, 1}}},
{CoifletWavelet, {{1, 1}}},
{DaubechiesWavelet, {{1, 1}}},
{DGaussianWavelet, {{1, 1}}},
{GaborWavelet, {{1, 1}}},
{HaarWavelet, {{0, 0}}},
{MexicanHatWavelet, {{1, 1}}},
{MeyerWavelet, {{2, 2}}},
{MorletWavelet, {{0, 0}}},
{PaulWavelet, {{1, 1}}},
{ReverseBiorthogonalSplineWavelet, {{2, 2}}},
{ShannonWavelet, {{1, 1}}},
{SymletWavelet, {{1, 1}}}}
*)


So:

m[fun_] := nArgs[fun][[1, 2]]
d = DiskMatrix;
Manipulate[
WaveletMatrixPlot@DiscreteWaveletTransform[d, wv[Sequence @@ x[[;; m@wv]]]],
{{x, {1, 1}}, ControlType -> None},
{wv, {HaarWavelet, DaubechiesWavelet, MeyerWavelet}},
Dynamic@Panel@Grid[{Slider[Dynamic@x[[#]], {0, 10, 1}], x[[#]]} & /@ Range@m@wv]] • Cleaner is better. Nice idea. – dantopa Jun 15 '15 at 14:39