Message Boards Message Boards

0
|
4015 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Is it possible to hide slots in a function?

I'm writing some utility functions for manipulating equations. The algebraic manipulation palette doesn't have cross multiplication, for example, which I find a handy manipulation. It it easily implemented as:

crossMultiply[a_==b_]:=Numerator[a] Denominator[b]==Numerator[b] Denominator[a]

and can be put at the end of an equation using double slashes.

In[209]:= x+y==((-2+y) y)/x^2//crossMultiply
Out[209]= x^2 (x+y)==(-2+y) y

If I want to divide both sides of an equation by some expression, I can use

divideBy[a_ == b_, divisor_: 1] := a/divisor == b/divisor

I can do this:

In[210]:= x^2 == (-2+y)y //divideBy[#,s]&
Out[210]= x^2/s == ((-2+y)y)/s

but I'd like to avoid using the slot and ampersand, so that it would look like this;

 In[210]:= x^2 == (-2+y)y //divideBy[s]
 Out[210]= x^2/s == ((-2+y)y)/s

Any ideas?

POSTED BY: Eric Johnstone
2 Replies

How about:

divideByBy[divisor_: 1][a_ == b_] := a/divisor == b/divisor

 x^2 == (-2 + y) y // divideByBy[s]

 (*  Out[5]= x^2/s == ((-2 + y) y)/s  *)

 x^2 == (-2 + y) y // divideByBy[]

(*  Out[8]= x^2 == (-2 + y) y  *)

Regards Henrik

POSTED BY: Henrik Schachner

Thanks Henrik,

That is a new notation for me. So the [a_==b_] automatically takes the stuff to the left of the double slashes just like crossMultiply did. This opens a whole new area to explore.

Eric

POSTED BY: Eric Johnstone
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract