| Alternative 1 | |
|---|---|
| Accuracy | 91.2% |
| Cost | 7760 |

(FPCore (x y z t a) :precision binary64 (/ (* (* x y) z) (sqrt (- (* z z) (* t a)))))
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (* x (* y (/ z (sqrt (- (* z z) (* t a))))))))
(if (<= z -3e+147)
(* y (- x))
(if (<= z -6e-151)
t_1
(if (<= z 2.1e-207)
(* (pow (* t (- a)) -0.5) (* z (* y x)))
(if (<= z 6.1e+97)
t_1
(/ (* y x) (/ (+ z (* -0.5 (/ a (/ z t)))) z))))))))double code(double x, double y, double z, double t, double a) {
return ((x * y) * z) / sqrt(((z * z) - (t * a)));
}
double code(double x, double y, double z, double t, double a) {
double t_1 = x * (y * (z / sqrt(((z * z) - (t * a)))));
double tmp;
if (z <= -3e+147) {
tmp = y * -x;
} else if (z <= -6e-151) {
tmp = t_1;
} else if (z <= 2.1e-207) {
tmp = pow((t * -a), -0.5) * (z * (y * x));
} else if (z <= 6.1e+97) {
tmp = t_1;
} else {
tmp = (y * x) / ((z + (-0.5 * (a / (z / t)))) / z);
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = ((x * y) * z) / sqrt(((z * z) - (t * a)))
end function
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: t_1
real(8) :: tmp
t_1 = x * (y * (z / sqrt(((z * z) - (t * a)))))
if (z <= (-3d+147)) then
tmp = y * -x
else if (z <= (-6d-151)) then
tmp = t_1
else if (z <= 2.1d-207) then
tmp = ((t * -a) ** (-0.5d0)) * (z * (y * x))
else if (z <= 6.1d+97) then
tmp = t_1
else
tmp = (y * x) / ((z + ((-0.5d0) * (a / (z / t)))) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) * z) / Math.sqrt(((z * z) - (t * a)));
}
public static double code(double x, double y, double z, double t, double a) {
double t_1 = x * (y * (z / Math.sqrt(((z * z) - (t * a)))));
double tmp;
if (z <= -3e+147) {
tmp = y * -x;
} else if (z <= -6e-151) {
tmp = t_1;
} else if (z <= 2.1e-207) {
tmp = Math.pow((t * -a), -0.5) * (z * (y * x));
} else if (z <= 6.1e+97) {
tmp = t_1;
} else {
tmp = (y * x) / ((z + (-0.5 * (a / (z / t)))) / z);
}
return tmp;
}
def code(x, y, z, t, a): return ((x * y) * z) / math.sqrt(((z * z) - (t * a)))
def code(x, y, z, t, a): t_1 = x * (y * (z / math.sqrt(((z * z) - (t * a))))) tmp = 0 if z <= -3e+147: tmp = y * -x elif z <= -6e-151: tmp = t_1 elif z <= 2.1e-207: tmp = math.pow((t * -a), -0.5) * (z * (y * x)) elif z <= 6.1e+97: tmp = t_1 else: tmp = (y * x) / ((z + (-0.5 * (a / (z / t)))) / z) return tmp
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) * z) / sqrt(Float64(Float64(z * z) - Float64(t * a)))) end
function code(x, y, z, t, a) t_1 = Float64(x * Float64(y * Float64(z / sqrt(Float64(Float64(z * z) - Float64(t * a)))))) tmp = 0.0 if (z <= -3e+147) tmp = Float64(y * Float64(-x)); elseif (z <= -6e-151) tmp = t_1; elseif (z <= 2.1e-207) tmp = Float64((Float64(t * Float64(-a)) ^ -0.5) * Float64(z * Float64(y * x))); elseif (z <= 6.1e+97) tmp = t_1; else tmp = Float64(Float64(y * x) / Float64(Float64(z + Float64(-0.5 * Float64(a / Float64(z / t)))) / z)); end return tmp end
function tmp = code(x, y, z, t, a) tmp = ((x * y) * z) / sqrt(((z * z) - (t * a))); end
function tmp_2 = code(x, y, z, t, a) t_1 = x * (y * (z / sqrt(((z * z) - (t * a))))); tmp = 0.0; if (z <= -3e+147) tmp = y * -x; elseif (z <= -6e-151) tmp = t_1; elseif (z <= 2.1e-207) tmp = ((t * -a) ^ -0.5) * (z * (y * x)); elseif (z <= 6.1e+97) tmp = t_1; else tmp = (y * x) / ((z + (-0.5 * (a / (z / t)))) / z); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] / N[Sqrt[N[(N[(z * z), $MachinePrecision] - N[(t * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(x * N[(y * N[(z / N[Sqrt[N[(N[(z * z), $MachinePrecision] - N[(t * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3e+147], N[(y * (-x)), $MachinePrecision], If[LessEqual[z, -6e-151], t$95$1, If[LessEqual[z, 2.1e-207], N[(N[Power[N[(t * (-a)), $MachinePrecision], -0.5], $MachinePrecision] * N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.1e+97], t$95$1, N[(N[(y * x), $MachinePrecision] / N[(N[(z + N[(-0.5 * N[(a / N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}
\begin{array}{l}
t_1 := x \cdot \left(y \cdot \frac{z}{\sqrt{z \cdot z - t \cdot a}}\right)\\
\mathbf{if}\;z \leq -3 \cdot 10^{+147}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;z \leq -6 \cdot 10^{-151}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-207}:\\
\;\;\;\;{\left(t \cdot \left(-a\right)\right)}^{-0.5} \cdot \left(z \cdot \left(y \cdot x\right)\right)\\
\mathbf{elif}\;z \leq 6.1 \cdot 10^{+97}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x}{\frac{z + -0.5 \cdot \frac{a}{\frac{z}{t}}}{z}}\\
\end{array}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 61.7% |
|---|---|
| Target | 88.9% |
| Herbie | 91.2% |
if z < -2.99999999999999993e147Initial program 6.9%
Simplified6.6%
[Start]6.9% | \[ \frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}
\] |
|---|---|
*-commutative [=>]6.9% | \[ \frac{\color{blue}{\left(y \cdot x\right)} \cdot z}{\sqrt{z \cdot z - t \cdot a}}
\] |
associate-*l* [=>]6.5% | \[ \frac{\color{blue}{y \cdot \left(x \cdot z\right)}}{\sqrt{z \cdot z - t \cdot a}}
\] |
associate-*r/ [<=]6.6% | \[ \color{blue}{y \cdot \frac{x \cdot z}{\sqrt{z \cdot z - t \cdot a}}}
\] |
Taylor expanded in z around -inf 100.0%
Simplified100.0%
[Start]100.0% | \[ y \cdot \left(-1 \cdot x\right)
\] |
|---|---|
neg-mul-1 [<=]100.0% | \[ y \cdot \color{blue}{\left(-x\right)}
\] |
if -2.99999999999999993e147 < z < -6e-151 or 2.10000000000000003e-207 < z < 6.1e97Initial program 85.9%
Simplified90.4%
[Start]85.9% | \[ \frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}
\] |
|---|---|
associate-/l* [=>]90.4% | \[ \color{blue}{\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}}
\] |
Applied egg-rr92.1%
[Start]90.4% | \[ \frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}
\] |
|---|---|
div-inv [=>]90.4% | \[ \color{blue}{\left(x \cdot y\right) \cdot \frac{1}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}}
\] |
clear-num [<=]90.4% | \[ \left(x \cdot y\right) \cdot \color{blue}{\frac{z}{\sqrt{z \cdot z - t \cdot a}}}
\] |
associate-*l* [=>]92.1% | \[ \color{blue}{x \cdot \left(y \cdot \frac{z}{\sqrt{z \cdot z - t \cdot a}}\right)}
\] |
if -6e-151 < z < 2.10000000000000003e-207Initial program 79.1%
Simplified67.9%
[Start]79.1% | \[ \frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}
\] |
|---|---|
associate-/l* [=>]67.9% | \[ \color{blue}{\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}}
\] |
Applied egg-rr79.2%
[Start]67.9% | \[ \frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}
\] |
|---|---|
associate-/l* [<=]79.1% | \[ \color{blue}{\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}}
\] |
clear-num [=>]79.2% | \[ \color{blue}{\frac{1}{\frac{\sqrt{z \cdot z - t \cdot a}}{\left(x \cdot y\right) \cdot z}}}
\] |
associate-/r/ [=>]79.1% | \[ \color{blue}{\frac{1}{\sqrt{z \cdot z - t \cdot a}} \cdot \left(\left(x \cdot y\right) \cdot z\right)}
\] |
pow1/2 [=>]79.1% | \[ \frac{1}{\color{blue}{{\left(z \cdot z - t \cdot a\right)}^{0.5}}} \cdot \left(\left(x \cdot y\right) \cdot z\right)
\] |
pow-flip [=>]79.2% | \[ \color{blue}{{\left(z \cdot z - t \cdot a\right)}^{\left(-0.5\right)}} \cdot \left(\left(x \cdot y\right) \cdot z\right)
\] |
metadata-eval [=>]79.2% | \[ {\left(z \cdot z - t \cdot a\right)}^{\color{blue}{-0.5}} \cdot \left(\left(x \cdot y\right) \cdot z\right)
\] |
*-commutative [=>]79.2% | \[ {\left(z \cdot z - t \cdot a\right)}^{-0.5} \cdot \color{blue}{\left(z \cdot \left(x \cdot y\right)\right)}
\] |
Taylor expanded in z around 0 79.2%
Simplified79.2%
[Start]79.2% | \[ {\left(-1 \cdot \left(a \cdot t\right)\right)}^{-0.5} \cdot \left(z \cdot \left(x \cdot y\right)\right)
\] |
|---|---|
associate-*r* [=>]79.2% | \[ {\color{blue}{\left(\left(-1 \cdot a\right) \cdot t\right)}}^{-0.5} \cdot \left(z \cdot \left(x \cdot y\right)\right)
\] |
neg-mul-1 [<=]79.2% | \[ {\left(\color{blue}{\left(-a\right)} \cdot t\right)}^{-0.5} \cdot \left(z \cdot \left(x \cdot y\right)\right)
\] |
if 6.1e97 < z Initial program 37.2%
Simplified39.1%
[Start]37.2% | \[ \frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}
\] |
|---|---|
associate-/l* [=>]39.1% | \[ \color{blue}{\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}}
\] |
Taylor expanded in z around inf 92.4%
Applied egg-rr84.1%
[Start]92.4% | \[ \frac{x \cdot y}{\frac{z + -0.5 \cdot \frac{a \cdot t}{z}}{z}}
\] |
|---|---|
expm1-log1p-u [=>]82.6% | \[ \frac{x \cdot y}{\frac{z + -0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{a \cdot t}{z}\right)\right)}}{z}}
\] |
expm1-udef [=>]82.6% | \[ \frac{x \cdot y}{\frac{z + -0.5 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{a \cdot t}{z}\right)} - 1\right)}}{z}}
\] |
associate-/l* [=>]84.1% | \[ \frac{x \cdot y}{\frac{z + -0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{a}{\frac{z}{t}}}\right)} - 1\right)}{z}}
\] |
Simplified98.6%
[Start]84.1% | \[ \frac{x \cdot y}{\frac{z + -0.5 \cdot \left(e^{\mathsf{log1p}\left(\frac{a}{\frac{z}{t}}\right)} - 1\right)}{z}}
\] |
|---|---|
expm1-def [=>]84.1% | \[ \frac{x \cdot y}{\frac{z + -0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{a}{\frac{z}{t}}\right)\right)}}{z}}
\] |
expm1-log1p [=>]98.6% | \[ \frac{x \cdot y}{\frac{z + -0.5 \cdot \color{blue}{\frac{a}{\frac{z}{t}}}}{z}}
\] |
Final simplification93.4%
| Alternative 1 | |
|---|---|
| Accuracy | 91.2% |
| Cost | 7760 |
| Alternative 2 | |
|---|---|
| Accuracy | 90.0% |
| Cost | 7496 |
| Alternative 3 | |
|---|---|
| Accuracy | 83.0% |
| Cost | 7304 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.2% |
| Cost | 7304 |
| Alternative 5 | |
|---|---|
| Accuracy | 75.4% |
| Cost | 1096 |
| Alternative 6 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 1096 |
| Alternative 7 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 1096 |
| Alternative 8 | |
|---|---|
| Accuracy | 76.0% |
| Cost | 1092 |
| Alternative 9 | |
|---|---|
| Accuracy | 77.2% |
| Cost | 1092 |
| Alternative 10 | |
|---|---|
| Accuracy | 73.9% |
| Cost | 840 |
| Alternative 11 | |
|---|---|
| Accuracy | 74.7% |
| Cost | 776 |
| Alternative 12 | |
|---|---|
| Accuracy | 72.7% |
| Cost | 388 |
| Alternative 13 | |
|---|---|
| Accuracy | 42.4% |
| Cost | 192 |
herbie shell --seed 2023165
(FPCore (x y z t a)
:name "Statistics.Math.RootFinding:ridders from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(if (< z -3.1921305903852764e+46) (- (* y x)) (if (< z 5.976268120920894e+90) (/ (* x z) (/ (sqrt (- (* z z) (* a t))) y)) (* y x)))
(/ (* (* x y) z) (sqrt (- (* z z) (* t a)))))