# HP Forums

You're currently viewing a stripped down version of our content. View the full version with proper formatting.
From the recent public beta announcement,

(04-14-2021 06:32 AM)Tim Wessman Wrote: [ -> ][*]Able to have multiple functions of same name with different number of arguments (no default arguments though)

I thought someone might benefit from seeing the syntax for this. And while technically correct that PPL does not support default arguments, you can still get the equivalent of default arguments as shown below.

Here's an example of multiple arguments using the same function name defined with different number of arguments.

Code:
``` // quadratic formula demonstration of default parameters // QF(a, b, c) // QF(b, c)  assumes a=1 // QF(c)  assumes a=1, b=0 EXPORT QF(a,b,c) BEGIN  LOCAL d;  d:=b^2-4*a*c;  RETURN (−b+{1,−1}*√(d))/(2*a); END; EXPORT QF(b,c) BEGIN   QF(1,b,c); END; EXPORT QF(c) BEGIN   QF(1,0,c) END;```

And here's a simple example of the variable argument syntax.

Code:
``` // Parallel Resistors: Adds resistors in parallel. // Requires at least two parameters, a and b. // The rest of the parameters are put in list c. // If only two parameters are given, then c is {}. // PPL allows up to 16 parameters total, // so a and b plus 14 more in list c EXPORT ParallelResistors(a,b,...c) BEGIN   c:=CONCAT(a,b,c);   RETURN 1/ΣLIST(1/c); END;```

IMHO, these are nice additions to PPL.
Testing the code in the simulator

QF(1,2,3) [enter] returns "Error: Invalid input"

PHP Code:
`export parallelResistors_home( a, b, ... c )begin  c := concat( a, b, c );  return 1 / Σlist(1/c);end; `
parallelResistors_home( 2, 4, 3 ) [enter] returns
0.92307692308 > 1 / ( ½ + ¼ + 1/3) // ok

parallelResistors_home( 2, 4 ) [enter] returns
1.33333333333...∞ > 1 / ( ½ +¼ )
exact(Ans) [enter] 4/3

parallelResistors_home( 1, 2, 4, 3, 5 ) [enter] returns
0.43795620438 > 1 / ( 1 + ½ + ¼ + 1/3 + 1/5 ) // ok

PHP Code:
`#casparallelResistors_cas( a, b, ... c ):=begin  c := concat( a, b, c );  return 1 / Σlist(1/c);end;#end `
[Check] returns "Error: Syntax Error in program line 2"

parallelResistors_cas(R_1, R_2, R_3) > 1 / ( (1/R_1) +(1/R_2)+1/R_3) ) > R_1*R_2*R_3 / (R_1*R_2 + R_1*R_3 + R_2*R_3)
(04-17-2021 04:32 PM)compsystems Wrote: [ -> ]QF(1,2,3) [enter] returns "Error: Invalid input"

x^2+2x+3 has imaginary roots. Go to Home Settings and turn on Complex mode to see the results.

Quote:[php]#cas
parallelResistors_cas( a, b, ... c ):=

I think the new syntax for multiple and variable arguments is only for PPL, not CAS programming.

Also, note that there is no space between the dots and the variable name: ...c not ... c
Hello,

Thanks, nice example and good test programs to make sure the system works.

indeed, these are PPL improvements, not CAS ones...

Cyrille
> ... turn on Complex mode to see the results.

change flag externally

HComplex:=00; [enter] 00 // a+b*i format and complex solutions off
QF(1,2,3) [enter] returns "Error: Invalid input" > "Unreral"

HComplex:=01; [enter] 01 // a+b*i format and complex solutions on
QF(1,2,3) [enter] {−1+1.41421356238*i, −1-1.41421356238*i } [ab/c] {−1+√2*i,−1-√2*i}

HComplex:=11; [enter] 11 // a+b*i> (a,b) format and complex solutions on
QF(1,2,3) [enter] { (−1, 1.41421356238),(−1, −1.41421356238 )}

change the flag internally within a code
PHP Code:
`EXPORT QF(a,b,c)BEGIN LOCAL d; HComplex:=01; d:=b^2-4*a*c; RETURN (−b+{1,−1}*√(d))/(2*a);END; `
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :