2017-09-14 5 views
1

Tenir compte les énoncés suivants:maxima - MATCHDECLARE ne le premier argument comme une variable

(%i1) matchdeclare([a,b], constantp); 
(%o1)        done 
(%i2) defmatch(match, a*x+b); 
(%o2)        match 
(%i3) match(2*x+3); 
(%o3)       [b = 3, a = 2] 

Je veux généraliser ce modèle dans une fonction. Mais il ne semble pas fonctionner plus:

(%i1) matchForm(test, form, constants) := block(
    matchdeclare(constants, constantp), 
    defmatch(match, form), 
    match(test) 
); 
(%o1) matchForm(test, form, constants) := 
    block(matchdeclare(constants, constantp), defmatch(match, form), match(test)) 
(%i2) test: 2*x+3; 
(%o2)        2 x + 3 
(%i3) form: a*x+b; 
(%o3)        a x + b 
(%i4) constants: [a,b]; 
(%o4)        [a, b] 
(%i5) matchForm(test, form, constants); 
defmatch: evaluation of atomic pattern yields: a x + b 
(%o5)        false 

Débogage un peu, un peu, il semble que la question est que MATCHDECLARE n'accepte pas l'argument comme une variable. Y a-t-il un moyen de faire une fonction comme j'essaye de faire en maxima?

Répondre

1

Je ne l'ai pas essayé, mais: peut-être vous pouvez obtenir l'effet que vous voulez via

apply (matchdeclare, [constants, 'constantp]), 

qui évaluera constants avant d'appeler matchdeclare.

+0

J'ai essayé ceci mais n'ai pas semblé fonctionner. – Kasper

+0

Mais cela fonctionne 'matchForm (test, formulaire, constantes): = bloc ( appliquer (matchdeclare, [constantes, constantep]), appliquer (defmatch, [match, form]), match (2 * x + 3) ) ' – Kasper

+0

Je suis heureux de vous entendre dire que vous avez réussi. –