Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //:TODO: Get more help from girlfriend for
- //: mul2, mul3, mul4, mul5 functions.
- //:To solve an algebra equation, you must always do the
- //:same thing to both sides of the equation to keep it
- //:balanced.
- //:Solving equations involving a power of 2 are easy because ://
- //:it has a natural inverse function, the square root: ://
- //: ://
- //: 6^2 = 36 ://
- //: sqrt( 6^2 ) = sqrt( 36 ) ://
- //: ://
- //: sqrt cancels out power ( ^ ) ://
- //: ://
- //: 6 = sqrt( 36 ) ://
- //: ://
- //: I find doing something similiar with log to be ://
- //: really hard to remember. So I created some inverse ://
- //: functions to help solve them. ://
- //: ://
- //: EXAMPLE: The inverse of log2 is bow2. ://
- //: ://
- //: SO: ://
- //: log2( 512 ) = 9 ://
- //: bow2( log2( 512) ) = bow2( 9 ) ://
- //: ://
- //: bow2 cancels out log2 leaving 512 ://
- //: ://
- //: 512 = bow2( 9 ) ://
- //: ://
- //: bow2( 9 ) to source code instructions is: pow(2,9) ://
- //: ://
- //: 512 = pow( 2 , 9 ) ://
- //: 512 = 2 ^ 9 ://
- //: ://
- //:----------------------------------------------------------://
- //:Another thing I need to solve: ://
- //: 512 / 2 / 2 / 2 / 2 / 2 / 2 / 2 / 2 / 2 === 1 ://
- //: 1 2 3 4 5 6 7 8 9 ://
- //: ://
- //: Because: 2^9 === 512 ://
- //: ://
- //: Dividing in a loop like this is stupid though. ://
- //: So how do we express: ://
- //: DivideBy_2_Ntimes( 512 , 9 ) === 1 ://
- //: ://
- //: 512 / ( pow(2,9) ) === 1 ://
- //: ://
- //: In function call terms: ://
- //: ://
- //: div2(512,9) === 1 ://
- //: ://
- //: So... logically the inverse function of "div2" ://
- //: would be "mul2" ://
- //: ://
- //: mul2(1,9) === 512 ://
- //: ://
- //: The source code? ://
- //: mul2(1,9) === ? ? ? ? ? ://
- //: ://
- //: pow: Power Function
- //: log: Natural logarithm function
- var pow = Math.pow; //:Shorthand function reference.
- var log = Math.log; //:Shorthand function reference.
- //://////////////////////////////////////////////////////////://
- //: mul2 and div2 are inverses of each other: ://
- //: mul2( div2( whatever ) ) === whatever ://
- //: div2( mul2( whatever ) ) === whatever ://
- //://////////////////////////////////////////////////////////://
- //: ://
- //: Credit for Math Logic in div* and mul* functions: ://
- //: Frankie Lampson ://
- //: ://
- //://////////////////////////////////////////////////////////://
- //:B: Base
- //:N: N number of times.
- function div2( B, N ){ return( B / (pow(2,N) ) ); }
- function div3( B, N ){ return( B / (pow(3,N) ) ); }
- function div4( B, N ){ return( B / (pow(4,N) ) ); }
- function div5( B, N ){ return( B / (pow(5,N) ) ); }
- //:B: Base
- //:N: N number of times.
- function mul2( B, N ){ return( 0 /** TODO:FIGURE_OUT **/ ); };
- function mul3( B, N ){ return( 0 /** TODO:FIGURE_OUT **/ ); };
- function mul4( B, N ){ return( 0 /** TODO:FIGURE_OUT **/ ); };
- function mul5( B, N ){ return( 0 /** TODO:FIGURE_OUT **/ ); };
- //://////////////////////////////////////////////////////////://
- //:log functions with different bases:
- function log2( x ){ return( log(x) / log(2) ); };
- function log3( x ){ return( log(x) / log(3) ); };
- function log4( x ){ return( log(x) / log(4) ); };
- function log5( x ){ return( log(x) / log(5) ); };
- //:corresponding inverse log functions:
- //: "bow2" is the inverse of "log2"
- //: "bow3" is the inverse of "log3"
- //: "bow4" is the inverse of "log4"
- //: "bow5" is the inverse of "log5"
- function bow2( y ){ return pow(2,y); /**( 2^y )**/ };
- function bow3( y ){ return pow(3,y); /**( 3^y )**/ };
- function bow4( y ){ return pow(4,y); /**( 4^y )**/ };
- function bow5( y ){ return pow(5,y); /**( 5^y )**/ };
- //: SOLVE: log2( x ) = 7
- //:
- //:--------------------------------------------://
- //:
- //: 1:
- //: We have an inverse of log2, it is bow2.
- //: We can use bow2 to cancel out log2.
- //: Apply bow2 to both sides:
- //:
- //:
- //: bow2( log2( x ) ) = bow2( 7 )
- //:
- //:
- //: 2:
- //: x is now isolated, because "bow2"
- //: undid the effects of "log2"
- //:
- //: x = bow2( 7 )
- //:
- //:
- //: 3:
- //: Remove "bow2" token by substituting the
- //: function call with the function body:
- //:
- //: Function With Formal Parameter "y"
- //:
- //: bow2( y ){ return pow(2,y); }
- //:
- //: Function With ACTUAL Parameter "7"
- //:
- //: bow2( 7 ){ return pow(2,7); }
- //:
- //: THUS:
- //: bow2( 7 ) === pow(2,7) === 2^7
- //:
- //: x=bow2( 7 )
- //: x=2^7
- //: x=128
- //:
- //: 4:
- //: Check Work:
- //: log2( 128 ) = 7
- //:
- //:If our input is {y:7}
- //:We are saying:
- //:
- //:Solve For x: log2( x ) = 7
- function solve_for_x_log2_x_equals_y( arg ){
- y = arg.y; //:Extract argument from object.
- x = bow2( y );
- y_check = log2( x );
- if( y != y_check ){
- alert("[Checking_Work_Failed]");
- throw("[Checking_Work_Failed]");
- };;
- return( x );
- };;
Add Comment
Please, Sign In to add comment