How to prevent maxima to rewrite the output of 2*sqrt(2) to 2^(3/2)? - output

Maxima input of
2*sqrt(2)
by default returns the output
2^(3/2)
How can I get Maxima to just return 2*sqrt(2) ?
(I use this in the tex() function.)

To the best of my knowledge, there is no way to prevent Maxima from simplifying 2*sqrt(2) to 2^(3/2), with two probably-hard-to-use exceptions:
(1) Turn off simplification entirely. But that disables all simplifications, e.g. 1 + 1 simplifying to 2. But if you want to try it: just enter simp : false;.
(2) Disable the simplification sqrt(2) to 2^(1/2) via :lisp (setf (get '%sqrt 'operators) nil) But then Maxima for the most part doesn't know what to do with sqrt.
I don't recommend either one of these.

You can try something like
simp: false;
tex(2*sqrt(2));
block code...;
simp: true;
That way you don't have to disable the simplification permanently.

You can do this:
(%i1) matchdeclare(n_, integerp,m_, integerp)$
tellsimp(n_*sqrt(m_), n_*sqrt(box(m_)))$
and afterwards:
(%i3) 2*sqrt(2);
(%o3) 2 √2
(%i4) sqrt(3)*9;
(%o4) 9 √3
You'll notice that the number under the square root sign in the output is colored red, because of box(). But if you select the expression in wxMaxima, and then popup "Copy LaTeX", you'll get exactly what you want, e. g.
\[2\,\sqrt{2}\]
Unfortunately if you try tex(2*sqrt(2)) to get the TeX code, you'll get $$2\,\sqrt{\boxed{2}}$$instead.

Related

Inverted Smoothstep?

I am currently trying to simulate ballistics on an object, that is otherwise not affected by physics. To be precise, I have a rocket-like projectile, that is following an parabolic arc from origin to target with a Lerp. To make it more realistic, I want it not to move at constant speed, but to slow down towards the climax and speed up on its way back down.
I have used the Mathf.Smoothstep function to do the exact opposite of what i need on other objects, i.e. easing in and out of the motion.
So my question is: How do I get an inverted Smoothstep?
I found out that what i would need is actually the inverted formula to smoothstep [ x * x*(3 - 2*x) ], but being not exactly a math genius, I have no idea how to do that. All I got from online calculators was some pretty massive new function, which I'm afraid would not be very efficient.
So maybe there is a function that comes close to an inverted smoothstep, but isn't as complex to compute.
Any help on this would be much appreciated
Thanks in advance,
Tux
Correct formula is available here:
https://www.shadertoy.com/view/MsSBRh
Solution by Inigo Quilez and TinyTexel
Flt SmoothCubeInv(Flt y)
{
if(y<=0)return 0;
if(y>=1)return 1;
return 0.5f-Sin(asinf(1-2*y)/3);
}
I had a similar problem. For me, mirroring the curve in y = x worked:
So an implementation example would be:
float Smooth(float x) {
return x + (x - (x * x * (3.0f - 2.0f * x)));
}
This function has no clamping, so that may have to be added if x can go outside the 0 to 1 interval.
Wolfram Alpha example
If you're moving transforms, it is often a good idea to user iTween or similar animation libraries instead of controlling animation yourself. They have a an easy API and you can set up easing mode too.
But if you need this as a math function, you can use something like this:
y = 0.5 + (x > 0.5 ? 1 : -1) * Mathf.Pow(Mathf.Abs(2x - 1),p)/2
Where p is the measure of steepness that you want. Here's how it looks:
You seem to want a regular parabola. See the graph of this function:
http://www.wolframalpha.com/input/?i=-%28x%2A2-1%29%5E2%2B1
Which is the graph that seems to do what you want: -(x*2-1)^2+1
It goes from y=0 to y=1 and then back again between x=0 and x=1, staying a bit at the top around x=0.5 . It's what you want, if I understood it correctly.
Other ways to write this function, according to wolfram alpha, would be -(4*(x-1)*x) and (4-4*x)*x
Hope it helps.

Switching a logic gate on or off

if I have an "AND gate" with three inputs "A,B and control line C"
can I control switching AND gate on or off .. just like this if C == 1 then AND gates works with input A,B if C==0 then nothing happens
can this be done by any method ??
This is how you would do it in pseudo-code(if I understood correctly):
if((c == 1) && (A || B))
Forgive me if I've got the wrong end of the stick- logic gates are just a way of making a simple concept confusing to me.
Achieve the same output from simpler (2-input) AND gates:
Yeah, hook a switch to the chip to toggle whether it is powered on or not. You don't need any fancy equipment or doubled gates, just turn the thing on to have it function as normal, turn it off and no matter what inputs you apply you'll get 0v on the output pin.

How can I define a abstract odd function in mathematica?

How can I define a abstract odd function, say f[x].
Whenever f[x]+f[-x] appears, mathematica simplifies it to zero.
This can be done easily using upvalues
f[x_] + f[y_] /; x == -y ^:= 0
Normally Mathematica would try to assign the above rule to Plus, which of course does not work since that's protected. By using ^:= instead of := you can assign the rule to f. A quick check yields:
In[2]:= f[3]+f[-3]
Out[2]:= 0
Edit: This, however, only works for Plus. It's probably better to use something more general, like:
f[x_?Negative] := -f[-x]
Now this also works with things like
In[4]:= -f[3] - f[-3]
Out[4]:= 0
If you also want the function to work symbolically, you could add something like:
f[-a_] := -f[a]
I am not good at this, but how about using the TransformationFunctions of Simplify ?
For example, suppose you have the expression 2 Sin[x] + f[x] + 3 + f[-x] + g[x] + g[-x] and you want to simplify it, assuming f[x] is odd function and g[x] is even. Then we want a rule to say f[x]+f[-x]->0 and a rule g[x]+g[-x]->2 g[x].
Hence write
myRules[e_]:=e/.f[x]+f[-x]->0/.g[x]+g[-x]->2 g[x]
Simplify[2 Sin[x]+ f[x]+ 3 +f[-x]+ g[x] + g[-x],
TransformationFunctions->{Automatic,myRules}]
and this gives
3+2 g[x]+2 Sin[x]
Btw, in the above, I am using f[x] where it really should be a pattern f[x_], so that expression such as f[anything]+f[-anything] will also become zero. So, this needs to be improved to make myRules more general. Now it only works for the exact expression f[x]. I am not sure now how to improve this. Might need a delayed rule or so. Will think about it more. But you get the idea I hope.

is line folded? - How to check for folds in VIM

I'm writing some folding functions and I am at a point where I need to check if the current line is actually a fold.
The reason for this is because it is a custom fold method that depends on searching/matching certain lines.
For example, if the current line is folded and looks like:
-FOO------------------------
If you do something like:
getline('.')
You would basically get FOO so there is no way (that I know of) to know if I am at a fold or not.
Is there a helper function for this?
I would think it would have to be something like:
is_folded('.')
I could probably mess with the foldtext to assign a special title for the fold but I want to avoid this.
From :help eval.txt
foldclosed({lnum})
The result is a Number. If the line {lnum} is in a closed
fold, the result is the number of the first line in that fold.
If the line {lnum} is not in a closed fold, -1 is returned.
You can check for a given line if it returns -1 or a line number, you can probably implement your isfolded() function this way.
If you are looking for Vim script function or feature , it is a good idea to start by searching in eval.txt which contains lots of relevant information.

Show tabs with a different character (Emacs)

I'd be happy to have very soft character ">>" instead of white-space, like this:
Mono develop http://primates.ximian.com/~miguel/pictures/Valabinding-classpad.png
How can I achieve that in Emacs?
EDIT: Just realized that blank-mode is superseded by whitespace. Load this and customize whitespace-style to at least contain tabs and tabs-mark. I currently have:
(setq whitespace-style '(trailing tabs newline tab-mark newline-mark))
There is also blank-mode which allows you to achive what you want and it gives you some nice functions to cleanup the whitespace to your likings:
http://www.emacswiki.org/emacs/BlankMode
On my Emacs version (24.3) no additional modules are needed. It's enough to launch
M-x whitespace-mode
To customize go to whitespace-style variable help,
C-h C-h v whitespace-style
This mode has many functionalities. To made it simpler one may choose not to use `Face visualization'.
Use "M-:" (M-x eval-expression) and enter the following expression:
(let ((d (make-display-table)))
(aset d 9 (vector ?> ?>))
(set-window-display-table nil d))
To get back to normal enter:
(set-window-display-table nil nil)
Google search brought up show whitespace-mode. Haven't tried it myself.