Guest User

Untitled

a guest
Oct 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. Clear[H]
  2.  
  3. H[s_][x_, y_] :=
  4. f[x] + Piecewise[{{-1, s === "-"}}, 1]*g[y] /; s === "+" || s === "-"
  5.  
  6. {H["+"][x, y], H["-"][x, y]}
  7.  
  8. (* {f[x] + g[y], f[x] - g[y]} *)
  9.  
  10. Clear[H]
  11.  
  12. H[s_][x_, y_] := f[x] + Sign[s]*g[y] /; Abs[s] === 1
  13.  
  14. {H[1][x, y], H[-1][x, y]}
  15.  
  16. (* {f[x] + g[y], f[x] - g[y]} *)
  17.  
  18. Needs["Notation´"]
  19.  
  20. Symbolize[H±] (* Be careful to use the Writing Assistant palette or other formatting guides s.t. the definition actually displays like you want it to and not Subscript or similar means *)
  21.  
  22. H±[x_, y_] := f[x] ± g[y] (* Same caveat about typesetting applies here as well *)
  23.  
  24. In[1] := H±[1,2]
  25. Out[1]:= f[1]±g[2]
  26.  
  27. h[op_Symbol][x_, y_] := op[f[x], g[y]]
  28.  
  29. {h[Plus][m, n], h[Subtract][m, n], h[Times][m, n]}
  30. (* {f[m] + g[n], f[m] - g[n], f[m] g[n]} *)
  31.  
  32. k[op_Symbol /; MemberQ[{Plus, Subtract}, op]][x_, y_] := op[f[x], g[y]]
  33.  
  34. {k[Plus][m, n], k[Subtract][m, n], k[Times][m, n]}
  35. (* {f[m] + g[n], f[m] - g[n], k[Times][m, n]} *)
  36.  
  37. (h:SubPlus|SubMinus)[H] ^:= With[
  38. {hh=Replace[h, {SubPlus->Plus, SubMinus->Subtract}]},
  39. hh[f[#1], g[#2]]&
  40. ]
  41.  
  42. SubPlus[H][x, y]
  43. SubMinus[H][2, 3]
Add Comment
Please, Sign In to add comment