Average Error: 19.3 → 5.9
Time: 13.1s
Precision: binary64
Cost: 26952
\[ \begin{array}{c}[V, l] = \mathsf{sort}([V, l])\\ \end{array} \]
\[c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]
\[\begin{array}{l} \mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{-316}:\\ \;\;\;\;\frac{\frac{\sqrt{-A}}{\sqrt{-V}}}{\sqrt{\ell}} \cdot c0\\ \mathbf{elif}\;V \cdot \ell \leq 0:\\ \;\;\;\;c0 \cdot {\left(e^{0.25 \cdot \left(\log \left(\frac{-1}{V}\right) + \log \left(\frac{-A}{\ell}\right)\right)}\right)}^{2}\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\ \;\;\;\;c0 \cdot \left(\sqrt{A} \cdot \frac{1}{\sqrt{V \cdot \ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \end{array} \]
(FPCore (c0 A V l) :precision binary64 (* c0 (sqrt (/ A (* V l)))))
(FPCore (c0 A V l)
 :precision binary64
 (if (<= (* V l) -5e-316)
   (* (/ (/ (sqrt (- A)) (sqrt (- V))) (sqrt l)) c0)
   (if (<= (* V l) 0.0)
     (* c0 (pow (exp (* 0.25 (+ (log (/ -1.0 V)) (log (/ (- A) l))))) 2.0))
     (if (<= (* V l) 2e+303)
       (* c0 (* (sqrt A) (/ 1.0 (sqrt (* V l)))))
       (sqrt (* (/ c0 l) (/ (* A c0) V)))))))
double code(double c0, double A, double V, double l) {
	return c0 * sqrt((A / (V * l)));
}
double code(double c0, double A, double V, double l) {
	double tmp;
	if ((V * l) <= -5e-316) {
		tmp = ((sqrt(-A) / sqrt(-V)) / sqrt(l)) * c0;
	} else if ((V * l) <= 0.0) {
		tmp = c0 * pow(exp((0.25 * (log((-1.0 / V)) + log((-A / l))))), 2.0);
	} else if ((V * l) <= 2e+303) {
		tmp = c0 * (sqrt(A) * (1.0 / sqrt((V * l))));
	} else {
		tmp = sqrt(((c0 / l) * ((A * c0) / V)));
	}
	return tmp;
}
real(8) function code(c0, a, v, l)
    real(8), intent (in) :: c0
    real(8), intent (in) :: a
    real(8), intent (in) :: v
    real(8), intent (in) :: l
    code = c0 * sqrt((a / (v * l)))
end function
real(8) function code(c0, a, v, l)
    real(8), intent (in) :: c0
    real(8), intent (in) :: a
    real(8), intent (in) :: v
    real(8), intent (in) :: l
    real(8) :: tmp
    if ((v * l) <= (-5d-316)) then
        tmp = ((sqrt(-a) / sqrt(-v)) / sqrt(l)) * c0
    else if ((v * l) <= 0.0d0) then
        tmp = c0 * (exp((0.25d0 * (log(((-1.0d0) / v)) + log((-a / l))))) ** 2.0d0)
    else if ((v * l) <= 2d+303) then
        tmp = c0 * (sqrt(a) * (1.0d0 / sqrt((v * l))))
    else
        tmp = sqrt(((c0 / l) * ((a * c0) / v)))
    end if
    code = tmp
end function
public static double code(double c0, double A, double V, double l) {
	return c0 * Math.sqrt((A / (V * l)));
}
public static double code(double c0, double A, double V, double l) {
	double tmp;
	if ((V * l) <= -5e-316) {
		tmp = ((Math.sqrt(-A) / Math.sqrt(-V)) / Math.sqrt(l)) * c0;
	} else if ((V * l) <= 0.0) {
		tmp = c0 * Math.pow(Math.exp((0.25 * (Math.log((-1.0 / V)) + Math.log((-A / l))))), 2.0);
	} else if ((V * l) <= 2e+303) {
		tmp = c0 * (Math.sqrt(A) * (1.0 / Math.sqrt((V * l))));
	} else {
		tmp = Math.sqrt(((c0 / l) * ((A * c0) / V)));
	}
	return tmp;
}
def code(c0, A, V, l):
	return c0 * math.sqrt((A / (V * l)))
def code(c0, A, V, l):
	tmp = 0
	if (V * l) <= -5e-316:
		tmp = ((math.sqrt(-A) / math.sqrt(-V)) / math.sqrt(l)) * c0
	elif (V * l) <= 0.0:
		tmp = c0 * math.pow(math.exp((0.25 * (math.log((-1.0 / V)) + math.log((-A / l))))), 2.0)
	elif (V * l) <= 2e+303:
		tmp = c0 * (math.sqrt(A) * (1.0 / math.sqrt((V * l))))
	else:
		tmp = math.sqrt(((c0 / l) * ((A * c0) / V)))
	return tmp
function code(c0, A, V, l)
	return Float64(c0 * sqrt(Float64(A / Float64(V * l))))
end
function code(c0, A, V, l)
	tmp = 0.0
	if (Float64(V * l) <= -5e-316)
		tmp = Float64(Float64(Float64(sqrt(Float64(-A)) / sqrt(Float64(-V))) / sqrt(l)) * c0);
	elseif (Float64(V * l) <= 0.0)
		tmp = Float64(c0 * (exp(Float64(0.25 * Float64(log(Float64(-1.0 / V)) + log(Float64(Float64(-A) / l))))) ^ 2.0));
	elseif (Float64(V * l) <= 2e+303)
		tmp = Float64(c0 * Float64(sqrt(A) * Float64(1.0 / sqrt(Float64(V * l)))));
	else
		tmp = sqrt(Float64(Float64(c0 / l) * Float64(Float64(A * c0) / V)));
	end
	return tmp
end
function tmp = code(c0, A, V, l)
	tmp = c0 * sqrt((A / (V * l)));
end
function tmp_2 = code(c0, A, V, l)
	tmp = 0.0;
	if ((V * l) <= -5e-316)
		tmp = ((sqrt(-A) / sqrt(-V)) / sqrt(l)) * c0;
	elseif ((V * l) <= 0.0)
		tmp = c0 * (exp((0.25 * (log((-1.0 / V)) + log((-A / l))))) ^ 2.0);
	elseif ((V * l) <= 2e+303)
		tmp = c0 * (sqrt(A) * (1.0 / sqrt((V * l))));
	else
		tmp = sqrt(((c0 / l) * ((A * c0) / V)));
	end
	tmp_2 = tmp;
end
code[c0_, A_, V_, l_] := N[(c0 * N[Sqrt[N[(A / N[(V * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[c0_, A_, V_, l_] := If[LessEqual[N[(V * l), $MachinePrecision], -5e-316], N[(N[(N[(N[Sqrt[(-A)], $MachinePrecision] / N[Sqrt[(-V)], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision] * c0), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], 0.0], N[(c0 * N[Power[N[Exp[N[(0.25 * N[(N[Log[N[(-1.0 / V), $MachinePrecision]], $MachinePrecision] + N[Log[N[((-A) / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], 2e+303], N[(c0 * N[(N[Sqrt[A], $MachinePrecision] * N[(1.0 / N[Sqrt[N[(V * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[(c0 / l), $MachinePrecision] * N[(N[(A * c0), $MachinePrecision] / V), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}
\begin{array}{l}
\mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{-316}:\\
\;\;\;\;\frac{\frac{\sqrt{-A}}{\sqrt{-V}}}{\sqrt{\ell}} \cdot c0\\

\mathbf{elif}\;V \cdot \ell \leq 0:\\
\;\;\;\;c0 \cdot {\left(e^{0.25 \cdot \left(\log \left(\frac{-1}{V}\right) + \log \left(\frac{-A}{\ell}\right)\right)}\right)}^{2}\\

\mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\
\;\;\;\;c0 \cdot \left(\sqrt{A} \cdot \frac{1}{\sqrt{V \cdot \ell}}\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 regimes
  2. if (*.f64 V l) < -5.000000017e-316

    1. Initial program 15.1

      \[c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]
    2. Applied egg-rr25.6

      \[\leadsto c0 \cdot \color{blue}{\sqrt[3]{{\left(\frac{\frac{A}{V}}{\ell}\right)}^{1.5}}} \]
    3. Taylor expanded in c0 around 0 15.1

      \[\leadsto \color{blue}{\sqrt{\frac{A}{V \cdot \ell}} \cdot c0} \]
    4. Simplified17.5

      \[\leadsto \color{blue}{\sqrt{\frac{\frac{A}{V}}{\ell}} \cdot c0} \]
      Proof
      (*.f64 (sqrt.f64 (/.f64 (/.f64 A V) l)) c0): 0 points increase in error, 0 points decrease in error
      (*.f64 (sqrt.f64 (Rewrite<= associate-/r*_binary64 (/.f64 A (*.f64 V l)))) c0): 18 points increase in error, 32 points decrease in error
    5. Applied egg-rr11.4

      \[\leadsto \color{blue}{\frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}} \cdot c0 \]
    6. Applied egg-rr1.0

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{-A}}{\sqrt{-V}}}}{\sqrt{\ell}} \cdot c0 \]

    if -5.000000017e-316 < (*.f64 V l) < -0.0

    1. Initial program 63.5

      \[c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]
    2. Applied egg-rr35.8

      \[\leadsto c0 \cdot \color{blue}{{\left({\left(\frac{\frac{A}{V}}{\ell}\right)}^{0.25}\right)}^{2}} \]
    3. Taylor expanded in V around -inf 33.7

      \[\leadsto c0 \cdot {\color{blue}{\left(e^{0.25 \cdot \left(\log \left(\frac{-1}{V}\right) + \log \left(-1 \cdot \frac{A}{\ell}\right)\right)}\right)}}^{2} \]

    if -0.0 < (*.f64 V l) < 2e303

    1. Initial program 10.5

      \[c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]
    2. Applied egg-rr0.8

      \[\leadsto c0 \cdot \color{blue}{\left(\sqrt{A} \cdot \frac{1}{\sqrt{V \cdot \ell}}\right)} \]

    if 2e303 < (*.f64 V l)

    1. Initial program 39.0

      \[c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]
    2. Applied egg-rr36.7

      \[\leadsto \color{blue}{\sqrt{\frac{\frac{A}{V}}{\ell} \cdot \left(c0 \cdot c0\right)}} \]
    3. Taylor expanded in A around 0 40.3

      \[\leadsto \sqrt{\color{blue}{\frac{A \cdot {c0}^{2}}{V \cdot \ell}}} \]
    4. Simplified31.0

      \[\leadsto \sqrt{\color{blue}{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}} \]
      Proof
      (*.f64 (/.f64 c0 l) (/.f64 (*.f64 A c0) V)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 c0 l) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 c0 A)) V)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 c0 (*.f64 c0 A)) (*.f64 l V))): 51 points increase in error, 33 points decrease in error
      (/.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 c0 c0) A)) (*.f64 l V)): 21 points increase in error, 14 points decrease in error
      (/.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 c0 2)) A) (*.f64 l V)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 A (pow.f64 c0 2))) (*.f64 l V)): 0 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 A (pow.f64 c0 2)) (Rewrite<= *-commutative_binary64 (*.f64 V l))): 0 points increase in error, 0 points decrease in error
  3. Recombined 4 regimes into one program.
  4. Final simplification5.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{-316}:\\ \;\;\;\;\frac{\frac{\sqrt{-A}}{\sqrt{-V}}}{\sqrt{\ell}} \cdot c0\\ \mathbf{elif}\;V \cdot \ell \leq 0:\\ \;\;\;\;c0 \cdot {\left(e^{0.25 \cdot \left(\log \left(\frac{-1}{V}\right) + \log \left(\frac{-A}{\ell}\right)\right)}\right)}^{2}\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\ \;\;\;\;c0 \cdot \left(\sqrt{A} \cdot \frac{1}{\sqrt{V \cdot \ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \end{array} \]

Alternatives

Alternative 1
Error6.2
Cost20036
\[\begin{array}{l} \mathbf{if}\;V \cdot \ell \leq 0:\\ \;\;\;\;\frac{\frac{\sqrt{-A}}{\sqrt{-V}}}{\sqrt{\ell}} \cdot c0\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\ \;\;\;\;c0 \cdot \left(\sqrt{A} \cdot \frac{1}{\sqrt{V \cdot \ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \end{array} \]
Alternative 2
Error6.2
Cost14416
\[\begin{array}{l} \mathbf{if}\;V \cdot \ell \leq -\infty:\\ \;\;\;\;c0 \cdot \frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}\\ \mathbf{elif}\;V \cdot \ell \leq -2 \cdot 10^{-225}:\\ \;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{\ell \cdot \left(-V\right)}}\\ \mathbf{elif}\;V \cdot \ell \leq 5 \cdot 10^{-315}:\\ \;\;\;\;\frac{c0}{\sqrt{\ell} \cdot \sqrt{\frac{V}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\ \;\;\;\;c0 \cdot \left(\sqrt{A} \cdot \frac{1}{\sqrt{V \cdot \ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \end{array} \]
Alternative 3
Error9.3
Cost14288
\[\begin{array}{l} t_0 := \sqrt{\frac{A}{V}} \cdot \frac{c0}{\sqrt{\ell}}\\ \mathbf{if}\;V \cdot \ell \leq -2 \cdot 10^{+136}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;V \cdot \ell \leq -2 \cdot 10^{-84}:\\ \;\;\;\;\frac{c0}{\sqrt{\frac{V \cdot \ell}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 5 \cdot 10^{-315}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\ \;\;\;\;\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \end{array} \]
Alternative 4
Error8.8
Cost14288
\[\begin{array}{l} t_0 := \frac{c0}{\sqrt{\ell} \cdot \sqrt{\frac{V}{A}}}\\ \mathbf{if}\;V \cdot \ell \leq -2 \cdot 10^{+136}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;V \cdot \ell \leq -5 \cdot 10^{-70}:\\ \;\;\;\;\frac{c0}{\sqrt{\frac{V \cdot \ell}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 5 \cdot 10^{-315}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\ \;\;\;\;\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \end{array} \]
Alternative 5
Error8.8
Cost14288
\[\begin{array}{l} t_0 := \frac{c0}{\sqrt{\ell} \cdot \sqrt{\frac{V}{A}}}\\ \mathbf{if}\;V \cdot \ell \leq -2 \cdot 10^{+136}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;V \cdot \ell \leq -5 \cdot 10^{-70}:\\ \;\;\;\;\frac{c0}{\sqrt{\frac{V \cdot \ell}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 5 \cdot 10^{-315}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\ \;\;\;\;c0 \cdot \frac{\sqrt{A}}{\sqrt{V \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \end{array} \]
Alternative 6
Error6.2
Cost14288
\[\begin{array}{l} \mathbf{if}\;V \cdot \ell \leq -\infty:\\ \;\;\;\;c0 \cdot \frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}\\ \mathbf{elif}\;V \cdot \ell \leq -2 \cdot 10^{-225}:\\ \;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{\ell \cdot \left(-V\right)}}\\ \mathbf{elif}\;V \cdot \ell \leq 5 \cdot 10^{-315}:\\ \;\;\;\;\frac{c0}{\sqrt{\ell} \cdot \sqrt{\frac{V}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\ \;\;\;\;c0 \cdot \frac{\sqrt{A}}{\sqrt{V \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \end{array} \]
Alternative 7
Error12.5
Cost14028
\[\begin{array}{l} \mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{-132}:\\ \;\;\;\;\frac{c0}{\sqrt{\frac{V \cdot \ell}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 0:\\ \;\;\;\;\frac{c0}{\sqrt{\frac{\ell}{\frac{A}{V}}}}\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{+303}:\\ \;\;\;\;\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \end{array} \]
Alternative 8
Error14.5
Cost7624
\[\begin{array}{l} t_0 := \frac{A}{V \cdot \ell}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-315}:\\ \;\;\;\;c0 \cdot \sqrt{\frac{\frac{A}{V}}{\ell}}\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+296}:\\ \;\;\;\;\frac{c0}{\sqrt{\frac{V \cdot \ell}{A}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{\sqrt{\frac{\ell}{\frac{A}{V}}}}\\ \end{array} \]
Alternative 9
Error14.6
Cost7624
\[\begin{array}{l} t_0 := \frac{A}{V \cdot \ell}\\ \mathbf{if}\;t_0 \leq 0:\\ \;\;\;\;\sqrt{\frac{c0}{\ell} \cdot \frac{A \cdot c0}{V}}\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+296}:\\ \;\;\;\;c0 \cdot \sqrt{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{\sqrt{\frac{\ell}{\frac{A}{V}}}}\\ \end{array} \]
Alternative 10
Error18.8
Cost7112
\[\begin{array}{l} t_0 := \frac{c0}{\sqrt{\frac{V \cdot \ell}{A}}}\\ \mathbf{if}\;V \leq -1 \cdot 10^{-120}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;V \leq -1 \cdot 10^{-219}:\\ \;\;\;\;\frac{c0}{\sqrt{\frac{\ell}{\frac{A}{V}}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error19.2
Cost6848
\[\frac{c0}{\sqrt{\frac{V \cdot \ell}{A}}} \]

Error

Reproduce

herbie shell --seed 2022295 
(FPCore (c0 A V l)
  :name "Henrywood and Agarwal, Equation (3)"
  :precision binary64
  (* c0 (sqrt (/ A (* V l)))))