How to calculate value of the equation - maxima

I don't know how to calculate my function.
I am trying to assign my output expression to a function, but I can't calculate it in my function with parameters. It always returns an expression.

The ":=" operator quotes (does not evaluate) its arguments. Note that as you defined it, the body of the function is %o6 instead of its value.
There are a couple of ways to achieve what you want. Try this: use the quote-quote '' operator to paste the expression into the function definition like this.
ge(r, t) := ''%o6;

Related

Delphi - Formating a multiple %s string with one argument

When I try to format a string such as '%s%s' using a line of code like so:
format('%s%s', [x]);
I get an exception because you can't have multiple '%s' without using an array with the same amount of arguments such as:
format('%s%s', [x,x]);
However, I don't know how many '%s' I will have to format and therefore I don't know how long the array would have to be. I also only want '%s' assigned to only 1 value.
Is there a way in which you can use multiple '%s' and assign them all to the same index?
As described in the documentation you can use an index specifier to identify the argument by a zero based index. The index specifier is written immediately after the % and is followed by a :.
Your example would be:
Format('%0:s%0:s', [x])
MyStr := StringReplace('%s%s', '%s', x, [rfreplaceALL]);

Infix return if operator in Swift

I have much of validation like this
if (someBoolean) return
Can I create an infix operator with following syntax?
returnif someBoolean
No, you can't write this operator (which would be prefix rather than infix), for two reasons:
operators can't be defined with alphanumeric characters (see the docs for a rundown of what they can be defined with)
you can't write a function (which is what custom operators are) that results in a return in it's calling scope i.e. return within the operator function would just return from the operator function, not from the function you used the operator in

Can't use IF NOT with a set in delphi

I have a set of chars which I define in the TYPE section as:
TAmpls = set of '1'..'9'';
In my function I declare a new variable, in the var section, with type Tampls using:
myAmpls : Tampls;
I then un-assign everything in myAmpls using:
myAMpls := [];
I then find an integer (I'll call it n). If this number is not assigned in my set variable, I want to assign it, for this I have tried using:
if not chr(n) in myAmpls then include(myAmpls,chr(n));
But the compiler throws an error saying:
'Operator not applicable to this operand type'
If I remove the 'not', the code compiles fine, why is this?
I would have thought that whether or not n was already in myAmpls was boolean, so why can't I use 'not'?
Delphi operator precedence is detailed in the documentation. There you will find a table of the operators listing their precedence. I won't reproduce the table here, no least because it's hard to lay out in markdown!
You will also find this text:
An operator with higher precedence is evaluated before an operator with lower precedence, while operators of equal precedence associate to the left.
Your expression is:
not chr(n) in myAmpls
Now, not has higher precedence than in. Which means that not is evaluated first. So the expression is parsed as
(not chr(n)) in myAmpls
And that is a syntax error because not cannot be used with a character operand. You need to apply parens to give the desired meaning to your expression:
not (chr(n) in myAmpls)

Mathematica and Latex

I am constantly using the mathematica software and using TeXForm command to go back and forth between the calculations and the latex document I'm typesetting. However, mathematica won't allow me to define variables with underscore, which I constantly need in my latex document. Does anybody know how to create variables with "smarter" names in mathematica?
In a broader sense, what is the best way to integrate the use of mathematica and latex?
Thanks.
first of all, Mathematica allows you to define variables with underscore.
Subscript[x, 1] = 3
The shortcut for this ist [ctr]+[_]
If you convert a subscript variable with TeXForm, you'll get:
x_1
I prefer to not use the subscript notation for normal variables, because you can not easily see if a variable has allready a value in this notation. So you might just write
x1
We now want to transform these kind of variable names to the subscript notation in TeXForm.
One way to do this is with StringPattern.
1.Transform your expression to a String in TeXForm:
In[360]:= ToString[(-b+y1) ((b-y1)/(b-y2))^(-(w10/(x\[Gamma]1-\[Omega]2))), TeXForm]
Out[360]= (\text{y1}-b) \left(\frac{b-\text{y1}}{b-\text{y2}}\right)^{-\frac{\text{w10}}{\text{x$\gamma $1}-\text{$\omega $2}}}
2.Replace this specific String Pattern to the subscript notation of LaTeX:
In[361]:= StringReplace[%, "\\text{"~~name_?LetterQ~~index_?DigitQ~~"}":> name<>"_"<>index]
Out[361]= (y_1-b) \left(\frac{b-y_1}{b-y_2}\right)^{-\frac{\text{w10}}{\text{x$\gamma $1}-\text{$\omega $2}}}
You might have noticed, that this replacement just worked on the variablenames that consists of just one letter and one digit. Longer variable names will be ignored. This is because the StringPattern "_" stands just for ohne character, for a sequence of characters, use "__", but we have to make shure, that we match with the Shortest possible sequence. To catch the longer variable names we apply another string replacement:
In[362]:= StringReplace[%,
"\\text{"~~Shortest[name__]~~Shortest[index__?DigitQ]~~"}":> "\\text{"<>name<>"}_{"<>index<>"}"]
Out[362]= (y_1-b) \left(\frac{b-y_1}{b-y_2}\right)^{-\frac{\text{w}_{10}}{\text{x$\gamma $}_{1}-\text{$\omega $}_{2}}}
Now all variables appear to be in the correct LaTeX-notation for subscript variables. But some of the "\text{}"s and "{}"s are obsolet now, due to single letters or digits, inside.
To optimize the LaTeX code, we can add further repacements:
In[371]:= StringReplace[%, "{" ~~ i_?DigitQ ~~ "}" :> i];
StringReplace[%, "\\text{" ~~ name_?LetterQ ~~ "}" :> name]
Out[372]= (y_1-b) \left(\frac{b-y_1}{b-y_2}\right)^{-\frac{w_{10}}{\text{x$\gamma $}_1-\text{$\omega $}_2}}
Now i think the TeX looks good enough, so we can define a function that does all the replacements in one step:
In[506]:=
ClearAll[myTeXForm]
SetAttributes[myTeXForm, HoldFirst]
myTeXForm[expr_] := Fold[StringReplace, ToString[HoldPattern[expr], TeXForm],
{"\\text{HoldPattern}\\left[" ~~ str__ ~~ "\\right]" ~~ EndOfString :> str,
"\\text{" ~~ Shortest[str__] ~~ Shortest[i__?DigitQ] ~~ "}" :>
"\\text{" <> str <> "}_{" <> i <> "}",
{"{" ~~ i_?DigitQ ~~ "}" :> i, "\\text{" ~~ s_?LetterQ ~~ "}" :> s}}]
Testing the function:
b=134;
myTeXForm[(-b+y1) ((b-y1)/(b-y2))^(-(w10/(x\[Gamma]13-\[Omega]2)))]
Out[510]= (y_1-b) \left(\frac{b-y_1}{b-y_2}\right)^{-\frac{w_{10}}{\text{x$\gamma $}_{13}-\text{$\omega $}_2}}
Note that i used a little trick to protect the function agains its argument values. In this example the variable b has allready the value 134, but in the TeX Output it should still apear as "b". To do so i added the Attribut HoldFirst to our function and used HoldPattern inside. Maybe one can do this easier, but it works fine.
Hope this might inspire you.
Best regards.

Lua throwaway result

I have a situation where I perform some operations on tables, call them T and V. I have set the metatable up correctly and everything works as expected. The issue is that I usually don't need the result of the calculation. So instead of writing
for i=1,5 do
_=T+V
end
is there a way to just have
for i=1,5 do
T+V
end
?
I am not using the Lua commandline so I cannot just write =T+V.
Make a function that does nothing and pass it to it:
function NOP() end
for i=1,5 do
NOP(T+V)
end
This additionally serves to document your intentions, and that the side-effect is what you're after.
Looking at syntax of Lua in extended BNF I don't see an way to construct an expression (exp) without a equal sign or something else.
There are only 4 cases where an expression (exp) can be used:
Assigning a value e.g. p = exp
As condition e.g. while exp then
In a function call i.e. f(exp)
for indexing i.e. t[exp]

Resources