/*
* Copyright (C) 2011 Alasdair C. Hamilton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package ket.math.purpose.symbolicFunctions;
import java.awt.*;
import java.util.*;
import ket.math.*;
import ket.display.*;
import ket.display.box.Box;
import ket.display.box.BoxFactory;
import ket.display.box.BoxFactory;
import ket.display.box.BoxGraphic;
import ket.display.box.BoxTools;
import ket.display.box.BoxWord;
import ket.math.purpose.IntegerValue;
import ket.math.purpose.SymbolicState;
/**
* A specific mathematical operation that acts on arguments in a case-specific
* way.
*/
public class SymbolicFunctionPartialDerivative extends SymbolicFunctionForm {
@Override
public String toLatex(Vector<Argument> args) {
int lowestDerivativeIndex = (args.size()<2) ? 0 : 1;
Argument orderArgument = ArgumentFactory.getOrderArgument(lowestDerivativeIndex, args);
String orderLatex = orderArgument!=null ? "^"+orderArgument.toLatex()+" " : " ";
switch (args.size()) {
case 0:
return "\\frac{\\mathrm{\\partial}}{\\mathrm{\\partial}}";
case 1:
return "\\frac{\\mathrm{\\partial}"+orderLatex+"}{\\mathrm{\\partial}"+args.get(0).toLatex()+"}";
case 2:
return "\\frac{\\mathrm{\\partial}"+orderLatex+args.get(0).toLatex()+"}{\\mathrm{\\partial}"+args.get(1).toLatex()+"}";
default:
String numerator = "\\mathrm{\\partial}"+orderLatex+args.get(0).toLatex();
String denomonator = "\\mathrm{\\partial}"+args.get(1).toLatex();
for (int i=2; i<args.size(); i++) {
denomonator += "\\, \\mathrm{\\partial}" + args.get(i).toLatex();
}
return "\\frac{"+numerator+"}{"+denomonator+"}";
}
}
/*-
@Override
public String toHTML(Vector<Argument> args) {
int lowestDerivativeIndex = (args.size()<2) ? 0 : 1;
Argument orderArgument = ArgumentFactory.getOrderArgument(lowestDerivativeIndex, args);
String orderHTML = orderArgument!=null ? " <SUP>"+orderArgument.toHTML()+"</SUP> " : " ";
String partial = Symbol.PARTIAL.toHTML();
switch (args.size()) {
case 0:
return partial + "/" + partial;
case 1:
return partial + orderHTML + "/" +
partial +
args.firstElement().toHTML();
case 2:
return partial + orderHTML +
args.firstElement().toHTML()+
"/"+partial+
args.lastElement().toHTML();
default:
String html = partial+
orderHTML+
args.firstElement().toHTML()+"/";
html += partial+args.get(1).toHTML();
for (int i=2; i<=args.size()-1; i++) {
html += " "+partial+args.get(i).toHTML();
}
return html;
}
}
*/
@Override
public String toHTML(Vector<Argument> args) {
int lowestDerivativeIndex = (args.size()<2) ? 0 : 1;
Argument orderArgument = ArgumentFactory.getOrderArgument(lowestDerivativeIndex, args);
String orderHTML = orderArgument!=null ? "<SUP>"+orderArgument.toHTML()+"</SUP>" : "";
String partial = Symbol.PARTIAL.toHTML();
String numerator, denomonator;
switch (args.size()) {
case 0:
return HTMLTools.toFraction(partial, partial);
case 1:
numerator = partial + orderHTML;
denomonator = partial + args.firstElement().toHTML();
return HTMLTools.toFraction(numerator, denomonator);
case 2:
numerator = partial+orderHTML+ args.firstElement().toHTML();
denomonator = partial + args.lastElement().toHTML();
return HTMLTools.toFraction(numerator, denomonator);
default:
numerator = partial + orderHTML + args.firstElement().toHTML();
denomonator = partial + args.get(1).toHTML();
for (int i=2; i<=args.size()-1; i++) {
denomonator += partial + args.get(i).toHTML();
}
return HTMLTools.toFraction(numerator, denomonator);
}
}
@Override
public Box toBox(Argument argument, long settings, ColourScheme colourScheme, Vector<Argument> args) {
if (args.size()>0) {
BoxWord dBox = new BoxWord(null, Symbol.PARTIAL.toUnicode(), 0L);
return BoxFactory.derivative(argument, dBox, getArgUpperLimit(), args, settings, colourScheme);
} else {
return super.toBox(argument, settings, colourScheme, args);
}
}
}