0

I'm making a batch program to solve some equations, I'm hoping that my end result can give me the binary for a QR code. Anyway, I just started with the calculations with exponents. My problem is that I don't know how to do that in batch since I need to use my exponents with a variable x:

x^2 + x^3
x^4 + x^5
x^2 * x^4 + x^3 * x^5 
= x^6 + x^8

Then I thought that I could maybe use couples of numbers since I only need to add one exponent to the other.

(2 , 3) +
(4 , 5)
= (6 , 8)

And I searched the web but didn't find anything about it.
It'd be nice to get help on both methods but (in scratch) I prefer the couples method.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
VVW
  • 13
  • 5

2 Answers2

1

Excuse me. Your question is not clear; perhaps if you explain us what "binary for a QR code" is we may help you in a better way. Anyway, this is my version of a possible solution.

This program:

@echo off
setlocal
for /F "tokens=1,2 delims=(,) " %%a in (file1.txt) do (
   echo (%%a , %%b^) +
   set /A a+=%%a, b+=%%b
)
echo = (%a% , %b%)

... with this data:

(2 , 3)
(4 , 5)

... produce this output:

(2 , 3) +
(4 , 5) +
= (6 , 8)

This program:

@echo off
setlocal EnableDelayedExpansion
rem Do multiplication of all 2-terms equations
for /F "delims=" %%e in (file2.txt) do (
   echo %%e
   set "equation=%%e"
   rem Eliminate "x^ and +" from equation
   for %%a in (x ^^ +) do set equation=!equation:%%a=!
   rem Add exponents
   for /F "tokens=1,2" %%a in ("!equation!") do (
      set /A a+=%%a, b+=%%b
   )
)
echo = x^^%a% + x^^%b%
rem Add similar terms
if %a% equ %b% (
   echo = 2x^^%a%
)

... with this data:

x^2 + x^3
x^4 + x^5

... produce this output:

x^2 + x^3
x^4 + x^5
= x^6 + x^8

..., but with this data:

x^2 + x^3
x^4 + x^3

... produce this output:

x^2 + x^3
x^4 + x^3
= x^6 + x^6
= 2x^6

I hope it helps...

Aacini
  • 65,180
  • 12
  • 72
  • 108
0

There is no operator for exponents in batch arithmetic. However, it's easy enough to do using multiplication:

::x^2
set /a x*=x
::x^3
set /a x*=x*x
::x^4
set /a x*=x*x*x

I don't know what you mean by 'couples of numbers', but if you explain I'll try to help.

As a side note, you could use VBScript to do this. For instance, x = x ^ 2 would square x. For more information on VBScript operators, see here. For information on Batch operators, see here.

BDM
  • 3,760
  • 3
  • 19
  • 27