Henrywood and Agarwal, Equation (3)

?

Percentage Accurate: 74.1% → 90.6%
Time: 12.9s
Precision: binary64
Cost: 14288

?

\[c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]
\[\begin{array}{l} [V, l] = \mathsf{sort}([V, l])\\ \end{array} \begin{array}{l} t_0 := c0 \cdot \frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}\\ \mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{+304}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;V \cdot \ell \leq -4 \cdot 10^{-314}:\\ \;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{V \cdot \left(-\ell\right)}}\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{-281}:\\ \;\;\;\;\frac{c0}{\sqrt{\ell \cdot \frac{V}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 4 \cdot 10^{+304}:\\ \;\;\;\;\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (c0 A V l) :precision binary64 (* c0 (sqrt (/ A (* V l)))))
;; Ensure these are sorted, for example in Racket, do
(match-define (list V l) (sort (V l) <))

(FPCore (c0 A V l)
 :precision binary64
 (let* ((t_0 (* c0 (/ (sqrt (/ A V)) (sqrt l)))))
   (if (<= (* V l) -5e+304)
     t_0
     (if (<= (* V l) -4e-314)
       (* c0 (/ (sqrt (- A)) (sqrt (* V (- l)))))
       (if (<= (* V l) 2e-281)
         (/ c0 (sqrt (* l (/ V A))))
         (if (<= (* V l) 4e+304) (/ c0 (/ (sqrt (* V l)) (sqrt A))) t_0))))))
double code(double c0, double A, double V, double l) {
	return c0 * sqrt((A / (V * l)));
}
// Ensure these are sorted
assert(V < l);

double code(double c0, double A, double V, double l) {
	double t_0 = c0 * (sqrt((A / V)) / sqrt(l));
	double tmp;
	if ((V * l) <= -5e+304) {
		tmp = t_0;
	} else if ((V * l) <= -4e-314) {
		tmp = c0 * (sqrt(-A) / sqrt((V * -l)));
	} else if ((V * l) <= 2e-281) {
		tmp = c0 / sqrt((l * (V / A)));
	} else if ((V * l) <= 4e+304) {
		tmp = c0 / (sqrt((V * l)) / sqrt(A));
	} else {
		tmp = t_0;
	}
	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
NOTE: V and l should be sorted in increasing order before calling this 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) :: t_0
    real(8) :: tmp
    t_0 = c0 * (sqrt((a / v)) / sqrt(l))
    if ((v * l) <= (-5d+304)) then
        tmp = t_0
    else if ((v * l) <= (-4d-314)) then
        tmp = c0 * (sqrt(-a) / sqrt((v * -l)))
    else if ((v * l) <= 2d-281) then
        tmp = c0 / sqrt((l * (v / a)))
    else if ((v * l) <= 4d+304) then
        tmp = c0 / (sqrt((v * l)) / sqrt(a))
    else
        tmp = t_0
    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)));
}
// Ensure these are sorted
assert V < l;

public static double code(double c0, double A, double V, double l) {
	double t_0 = c0 * (Math.sqrt((A / V)) / Math.sqrt(l));
	double tmp;
	if ((V * l) <= -5e+304) {
		tmp = t_0;
	} else if ((V * l) <= -4e-314) {
		tmp = c0 * (Math.sqrt(-A) / Math.sqrt((V * -l)));
	} else if ((V * l) <= 2e-281) {
		tmp = c0 / Math.sqrt((l * (V / A)));
	} else if ((V * l) <= 4e+304) {
		tmp = c0 / (Math.sqrt((V * l)) / Math.sqrt(A));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(c0, A, V, l):
	return c0 * math.sqrt((A / (V * l)))
[V, l] = sort([V, l])

def code(c0, A, V, l):
	t_0 = c0 * (math.sqrt((A / V)) / math.sqrt(l))
	tmp = 0
	if (V * l) <= -5e+304:
		tmp = t_0
	elif (V * l) <= -4e-314:
		tmp = c0 * (math.sqrt(-A) / math.sqrt((V * -l)))
	elif (V * l) <= 2e-281:
		tmp = c0 / math.sqrt((l * (V / A)))
	elif (V * l) <= 4e+304:
		tmp = c0 / (math.sqrt((V * l)) / math.sqrt(A))
	else:
		tmp = t_0
	return tmp
function code(c0, A, V, l)
	return Float64(c0 * sqrt(Float64(A / Float64(V * l))))
end
V, l = sort([V, l])

function code(c0, A, V, l)
	t_0 = Float64(c0 * Float64(sqrt(Float64(A / V)) / sqrt(l)))
	tmp = 0.0
	if (Float64(V * l) <= -5e+304)
		tmp = t_0;
	elseif (Float64(V * l) <= -4e-314)
		tmp = Float64(c0 * Float64(sqrt(Float64(-A)) / sqrt(Float64(V * Float64(-l)))));
	elseif (Float64(V * l) <= 2e-281)
		tmp = Float64(c0 / sqrt(Float64(l * Float64(V / A))));
	elseif (Float64(V * l) <= 4e+304)
		tmp = Float64(c0 / Float64(sqrt(Float64(V * l)) / sqrt(A)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(c0, A, V, l)
	tmp = c0 * sqrt((A / (V * l)));
end
V, l = num2cell(sort([V, l])){:}

function tmp_2 = code(c0, A, V, l)
	t_0 = c0 * (sqrt((A / V)) / sqrt(l));
	tmp = 0.0;
	if ((V * l) <= -5e+304)
		tmp = t_0;
	elseif ((V * l) <= -4e-314)
		tmp = c0 * (sqrt(-A) / sqrt((V * -l)));
	elseif ((V * l) <= 2e-281)
		tmp = c0 / sqrt((l * (V / A)));
	elseif ((V * l) <= 4e+304)
		tmp = c0 / (sqrt((V * l)) / sqrt(A));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[c0_, A_, V_, l_] := N[(c0 * N[Sqrt[N[(A / N[(V * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
NOTE: V and l should be sorted in increasing order before calling this function.

code[c0_, A_, V_, l_] := Block[{t$95$0 = N[(c0 * N[(N[Sqrt[N[(A / V), $MachinePrecision]], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(V * l), $MachinePrecision], -5e+304], t$95$0, If[LessEqual[N[(V * l), $MachinePrecision], -4e-314], N[(c0 * N[(N[Sqrt[(-A)], $MachinePrecision] / N[Sqrt[N[(V * (-l)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], 2e-281], N[(c0 / N[Sqrt[N[(l * N[(V / A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(V * l), $MachinePrecision], 4e+304], N[(c0 / N[(N[Sqrt[N[(V * l), $MachinePrecision]], $MachinePrecision] / N[Sqrt[A], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}
\begin{array}{l}
[V, l] = \mathsf{sort}([V, l])\\
\end{array}
\begin{array}{l}
t_0 := c0 \cdot \frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}\\
\mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{+304}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;V \cdot \ell \leq -4 \cdot 10^{-314}:\\
\;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{V \cdot \left(-\ell\right)}}\\

\mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{-281}:\\
\;\;\;\;\frac{c0}{\sqrt{\ell \cdot \frac{V}{A}}}\\

\mathbf{elif}\;V \cdot \ell \leq 4 \cdot 10^{+304}:\\
\;\;\;\;\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

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) < -4.9999999999999997e304 or 3.9999999999999998e304 < (*.f64 V l)

    1. Initial program 30.9%

      \[c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]
    2. Applied egg-rr62.0%

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

      [Start]30.9

      \[ c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]

      associate-/r* [=>]59.2

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

      sqrt-div [=>]62.0

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

    if -4.9999999999999997e304 < (*.f64 V l) < -3.9999999999e-314

    1. Initial program 81.9%

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

      \[\leadsto c0 \cdot \color{blue}{\frac{\sqrt{-A}}{\sqrt{\ell \cdot \left(-V\right)}}} \]
      Step-by-step derivation

      [Start]81.9

      \[ c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]

      frac-2neg [=>]81.9

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

      sqrt-div [=>]99.2

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

      *-commutative [=>]99.2

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

      distribute-rgt-neg-in [=>]99.2

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

    if -3.9999999999e-314 < (*.f64 V l) < 2e-281

    1. Initial program 63.0%

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

      \[\leadsto c0 \cdot \color{blue}{\frac{1}{\sqrt{\frac{V}{\frac{A}{\ell}}}}} \]
      Step-by-step derivation

      [Start]63.0

      \[ c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]

      clear-num [=>]63.0

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

      sqrt-div [=>]63.0

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

      metadata-eval [=>]63.0

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

      associate-/l* [=>]80.2

      \[ c0 \cdot \frac{1}{\sqrt{\color{blue}{\frac{V}{\frac{A}{\ell}}}}} \]
    3. Simplified63.0%

      \[\leadsto c0 \cdot \color{blue}{\frac{1}{\sqrt{\frac{V \cdot \ell}{A}}}} \]
      Step-by-step derivation

      [Start]80.2

      \[ c0 \cdot \frac{1}{\sqrt{\frac{V}{\frac{A}{\ell}}}} \]

      associate-/l* [<=]63.0

      \[ c0 \cdot \frac{1}{\sqrt{\color{blue}{\frac{V \cdot \ell}{A}}}} \]
    4. Applied egg-rr80.4%

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

      [Start]63.0

      \[ c0 \cdot \frac{1}{\sqrt{\frac{V \cdot \ell}{A}}} \]

      un-div-inv [=>]63.0

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

      associate-/l* [=>]80.4

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

      associate-/r/ [=>]80.4

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

    if 2e-281 < (*.f64 V l) < 3.9999999999999998e304

    1. Initial program 83.4%

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

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

      [Start]83.4

      \[ c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]

      sqrt-div [=>]99.4

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

      associate-*r/ [=>]96.2

      \[ \color{blue}{\frac{c0 \cdot \sqrt{A}}{\sqrt{V \cdot \ell}}} \]
    3. Simplified99.5%

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

      [Start]96.2

      \[ \frac{c0 \cdot \sqrt{A}}{\sqrt{V \cdot \ell}} \]

      associate-/l* [=>]99.5

      \[ \color{blue}{\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification92.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{+304}:\\ \;\;\;\;c0 \cdot \frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}\\ \mathbf{elif}\;V \cdot \ell \leq -4 \cdot 10^{-314}:\\ \;\;\;\;c0 \cdot \frac{\sqrt{-A}}{\sqrt{V \cdot \left(-\ell\right)}}\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{-281}:\\ \;\;\;\;\frac{c0}{\sqrt{\ell \cdot \frac{V}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 4 \cdot 10^{+304}:\\ \;\;\;\;\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy79.9%
Cost34640
\[\begin{array}{l} t_0 := \sqrt{\frac{c0}{V} \cdot \left(A \cdot \frac{c0}{\ell}\right)}\\ t_1 := c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-318}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-186}:\\ \;\;\;\;\frac{c0}{{\left(\frac{\frac{A}{\ell}}{V}\right)}^{-0.5}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+304}:\\ \;\;\;\;c0 \cdot {\left(\frac{V \cdot \ell}{A}\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy81.1%
Cost27724
\[\begin{array}{l} t_0 := c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-317}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;c0 \cdot \frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+304}:\\ \;\;\;\;c0 \cdot {\left(\frac{V \cdot \ell}{A}\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{c0}{V} \cdot \left(A \cdot \frac{c0}{\ell}\right)}\\ \end{array} \]
Alternative 3
Accuracy78.2%
Cost20808
\[\begin{array}{l} t_0 := c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{-186}:\\ \;\;\;\;\frac{c0}{{\left(\frac{\frac{A}{\ell}}{V}\right)}^{-0.5}}\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+304}:\\ \;\;\;\;c0 \cdot {\left(\frac{V \cdot \ell}{A}\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{A \cdot \left(\frac{c0}{V} \cdot \frac{c0}{\ell}\right)}\\ \end{array} \]
Alternative 4
Accuracy86.0%
Cost14288
\[\begin{array}{l} t_0 := c0 \cdot \frac{\sqrt{\frac{A}{V}}}{\sqrt{\ell}}\\ \mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{+137}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;V \cdot \ell \leq -4 \cdot 10^{-196}:\\ \;\;\;\;c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{-281}:\\ \;\;\;\;\frac{c0}{\sqrt{\ell \cdot \frac{V}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 4 \cdot 10^{+304}:\\ \;\;\;\;\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Accuracy85.7%
Cost14288
\[\begin{array}{l} t_0 := \sqrt{\frac{A}{V}}\\ \mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{+137}:\\ \;\;\;\;\frac{c0 \cdot t_0}{\sqrt{\ell}}\\ \mathbf{elif}\;V \cdot \ell \leq -4 \cdot 10^{-196}:\\ \;\;\;\;c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}\\ \mathbf{elif}\;V \cdot \ell \leq 2 \cdot 10^{-281}:\\ \;\;\;\;\frac{c0}{\sqrt{\ell \cdot \frac{V}{A}}}\\ \mathbf{elif}\;V \cdot \ell \leq 4 \cdot 10^{+304}:\\ \;\;\;\;\frac{c0}{\frac{\sqrt{V \cdot \ell}}{\sqrt{A}}}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \frac{t_0}{\sqrt{\ell}}\\ \end{array} \]
Alternative 6
Accuracy80.0%
Cost7890
\[\begin{array}{l} \mathbf{if}\;V \cdot \ell \leq -5 \cdot 10^{+137} \lor \neg \left(V \cdot \ell \leq -2 \cdot 10^{-170} \lor \neg \left(V \cdot \ell \leq 2 \cdot 10^{-251}\right) \land V \cdot \ell \leq 2 \cdot 10^{+154}\right):\\ \;\;\;\;c0 \cdot \sqrt{\frac{\frac{A}{\ell}}{V}}\\ \mathbf{else}:\\ \;\;\;\;c0 \cdot \sqrt{\frac{A}{V \cdot \ell}}\\ \end{array} \]
Alternative 7
Accuracy80.7%
Cost7688
\[\begin{array}{l} t_0 := \frac{A}{V \cdot \ell}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-310}:\\ \;\;\;\;c0 \cdot \sqrt{\frac{\frac{A}{\ell}}{V}}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+303}:\\ \;\;\;\;c0 \cdot {\left(\frac{V \cdot \ell}{A}\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{\sqrt{\ell \cdot \frac{V}{A}}}\\ \end{array} \]
Alternative 8
Accuracy80.7%
Cost7624
\[\begin{array}{l} t_0 := \frac{A}{V \cdot \ell}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-310}:\\ \;\;\;\;c0 \cdot \sqrt{\frac{\frac{A}{\ell}}{V}}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+303}:\\ \;\;\;\;c0 \cdot \sqrt{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{c0}{\sqrt{\ell \cdot \frac{V}{A}}}\\ \end{array} \]
Alternative 9
Accuracy74.1%
Cost6848
\[c0 \cdot \sqrt{\frac{A}{V \cdot \ell}} \]

Error

Reproduce?

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