
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * (z - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * (z - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
(FPCore (x y z t) :precision binary64 (+ x (* (/ y t) (- z x))))
double code(double x, double y, double z, double t) {
return x + ((y / t) * (z - x));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y / t) * (z - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y / t) * (z - x));
}
def code(x, y, z, t): return x + ((y / t) * (z - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y / t) * Float64(z - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y / t) * (z - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{t} \cdot \left(z - x\right)
\end{array}
Initial program 94.0%
associate-*l/98.3%
Simplified98.3%
Final simplification98.3%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.1e-280) (not (<= z 7.5e-142))) (+ x (* (/ y t) z)) (* x (/ y (- t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.1e-280) || !(z <= 7.5e-142)) {
tmp = x + ((y / t) * z);
} else {
tmp = x * (y / -t);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-3.1d-280)) .or. (.not. (z <= 7.5d-142))) then
tmp = x + ((y / t) * z)
else
tmp = x * (y / -t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.1e-280) || !(z <= 7.5e-142)) {
tmp = x + ((y / t) * z);
} else {
tmp = x * (y / -t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.1e-280) or not (z <= 7.5e-142): tmp = x + ((y / t) * z) else: tmp = x * (y / -t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.1e-280) || !(z <= 7.5e-142)) tmp = Float64(x + Float64(Float64(y / t) * z)); else tmp = Float64(x * Float64(y / Float64(-t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.1e-280) || ~((z <= 7.5e-142))) tmp = x + ((y / t) * z); else tmp = x * (y / -t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.1e-280], N[Not[LessEqual[z, 7.5e-142]], $MachinePrecision]], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y / (-t)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-280} \lor \neg \left(z \leq 7.5 \cdot 10^{-142}\right):\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{-t}\\
\end{array}
\end{array}
if z < -3.10000000000000021e-280 or 7.49999999999999958e-142 < z Initial program 93.5%
associate-*l/98.0%
Simplified98.0%
Taylor expanded in z around inf 77.2%
associate-*l/82.1%
*-commutative82.1%
Simplified82.1%
if -3.10000000000000021e-280 < z < 7.49999999999999958e-142Initial program 96.0%
associate-*l/99.7%
Simplified99.7%
Taylor expanded in x around inf 97.9%
distribute-lft-in97.9%
*-rgt-identity97.9%
mul-1-neg97.9%
distribute-rgt-neg-in97.9%
distribute-lft-neg-out97.9%
neg-mul-197.9%
associate-*r*97.9%
associate-*r/94.2%
mul-1-neg94.2%
unsub-neg94.2%
associate-*r/97.9%
Simplified97.9%
clear-num97.8%
div-inv97.9%
clear-num97.9%
Applied egg-rr97.9%
Taylor expanded in t around 0 63.0%
mul-1-neg63.0%
associate-*l/58.4%
distribute-rgt-neg-in58.4%
*-commutative58.4%
Simplified58.4%
Taylor expanded in y around 0 63.0%
associate-*r/63.0%
*-commutative63.0%
associate-/l*62.8%
associate-/r/63.0%
metadata-eval63.0%
associate-/r*63.0%
neg-mul-163.0%
associate-*l/63.0%
*-lft-identity63.0%
associate-/l*58.4%
associate-/r/65.2%
*-commutative65.2%
Simplified65.2%
Final simplification78.9%
(FPCore (x y z t) :precision binary64 (if (<= z -1.1e+18) (+ x (* (/ y t) z)) (if (<= z 2.2e+46) (- x (* x (/ y t))) (+ x (/ z (/ t y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.1e+18) {
tmp = x + ((y / t) * z);
} else if (z <= 2.2e+46) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= (-1.1d+18)) then
tmp = x + ((y / t) * z)
else if (z <= 2.2d+46) then
tmp = x - (x * (y / t))
else
tmp = x + (z / (t / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.1e+18) {
tmp = x + ((y / t) * z);
} else if (z <= 2.2e+46) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.1e+18: tmp = x + ((y / t) * z) elif z <= 2.2e+46: tmp = x - (x * (y / t)) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.1e+18) tmp = Float64(x + Float64(Float64(y / t) * z)); elseif (z <= 2.2e+46) tmp = Float64(x - Float64(x * Float64(y / t))); else tmp = Float64(x + Float64(z / Float64(t / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.1e+18) tmp = x + ((y / t) * z); elseif (z <= 2.2e+46) tmp = x - (x * (y / t)); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.1e+18], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.2e+46], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{+18}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{+46}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if z < -1.1e18Initial program 85.1%
associate-*l/98.1%
Simplified98.1%
Taylor expanded in z around inf 78.2%
associate-*l/89.9%
*-commutative89.9%
Simplified89.9%
if -1.1e18 < z < 2.2e46Initial program 97.8%
associate-*l/97.9%
Simplified97.9%
Taylor expanded in x around inf 86.7%
distribute-lft-in86.7%
*-rgt-identity86.7%
mul-1-neg86.7%
distribute-rgt-neg-in86.7%
distribute-lft-neg-out86.7%
neg-mul-186.7%
associate-*r*86.7%
associate-*r/86.0%
mul-1-neg86.0%
unsub-neg86.0%
associate-*r/86.7%
Simplified86.7%
if 2.2e46 < z Initial program 95.8%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in z around inf 91.4%
associate-*l/95.6%
*-commutative95.6%
Simplified95.6%
clear-num95.5%
div-inv95.6%
Applied egg-rr95.6%
Final simplification89.2%
(FPCore (x y z t) :precision binary64 (if (<= z -2.4e+18) (+ x (* (/ y t) z)) (if (<= z 2.22e+46) (- x (/ x (/ t y))) (+ x (/ z (/ t y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.4e+18) {
tmp = x + ((y / t) * z);
} else if (z <= 2.22e+46) {
tmp = x - (x / (t / y));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= (-2.4d+18)) then
tmp = x + ((y / t) * z)
else if (z <= 2.22d+46) then
tmp = x - (x / (t / y))
else
tmp = x + (z / (t / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.4e+18) {
tmp = x + ((y / t) * z);
} else if (z <= 2.22e+46) {
tmp = x - (x / (t / y));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.4e+18: tmp = x + ((y / t) * z) elif z <= 2.22e+46: tmp = x - (x / (t / y)) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.4e+18) tmp = Float64(x + Float64(Float64(y / t) * z)); elseif (z <= 2.22e+46) tmp = Float64(x - Float64(x / Float64(t / y))); else tmp = Float64(x + Float64(z / Float64(t / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -2.4e+18) tmp = x + ((y / t) * z); elseif (z <= 2.22e+46) tmp = x - (x / (t / y)); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.4e+18], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.22e+46], N[(x - N[(x / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+18}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{elif}\;z \leq 2.22 \cdot 10^{+46}:\\
\;\;\;\;x - \frac{x}{\frac{t}{y}}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if z < -2.4e18Initial program 85.1%
associate-*l/98.1%
Simplified98.1%
Taylor expanded in z around inf 78.2%
associate-*l/89.9%
*-commutative89.9%
Simplified89.9%
if -2.4e18 < z < 2.21999999999999999e46Initial program 97.8%
associate-*l/97.9%
Simplified97.9%
Taylor expanded in x around inf 86.7%
distribute-lft-in86.7%
*-rgt-identity86.7%
mul-1-neg86.7%
distribute-rgt-neg-in86.7%
distribute-lft-neg-out86.7%
neg-mul-186.7%
associate-*r*86.7%
associate-*r/86.0%
mul-1-neg86.0%
unsub-neg86.0%
associate-*r/86.7%
Simplified86.7%
clear-num86.7%
div-inv87.0%
Applied egg-rr87.0%
if 2.21999999999999999e46 < z Initial program 95.8%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in z around inf 91.4%
associate-*l/95.6%
*-commutative95.6%
Simplified95.6%
clear-num95.5%
div-inv95.6%
Applied egg-rr95.6%
Final simplification89.4%
(FPCore (x y z t) :precision binary64 (if (<= t -580000000000.0) x (if (<= t 1.45e+23) (* x (/ y (- t))) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -580000000000.0) {
tmp = x;
} else if (t <= 1.45e+23) {
tmp = x * (y / -t);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-580000000000.0d0)) then
tmp = x
else if (t <= 1.45d+23) then
tmp = x * (y / -t)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -580000000000.0) {
tmp = x;
} else if (t <= 1.45e+23) {
tmp = x * (y / -t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -580000000000.0: tmp = x elif t <= 1.45e+23: tmp = x * (y / -t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -580000000000.0) tmp = x; elseif (t <= 1.45e+23) tmp = Float64(x * Float64(y / Float64(-t))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -580000000000.0) tmp = x; elseif (t <= 1.45e+23) tmp = x * (y / -t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -580000000000.0], x, If[LessEqual[t, 1.45e+23], N[(x * N[(y / (-t)), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -580000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 1.45 \cdot 10^{+23}:\\
\;\;\;\;x \cdot \frac{y}{-t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -5.8e11 or 1.45000000000000006e23 < t Initial program 87.7%
associate-*l/98.8%
Simplified98.8%
Taylor expanded in y around 0 57.9%
if -5.8e11 < t < 1.45000000000000006e23Initial program 99.1%
associate-*l/97.9%
Simplified97.9%
Taylor expanded in x around inf 59.5%
distribute-lft-in59.5%
*-rgt-identity59.5%
mul-1-neg59.5%
distribute-rgt-neg-in59.5%
distribute-lft-neg-out59.5%
neg-mul-159.5%
associate-*r*59.5%
associate-*r/58.8%
mul-1-neg58.8%
unsub-neg58.8%
associate-*r/59.5%
Simplified59.5%
clear-num59.4%
div-inv59.8%
clear-num59.8%
Applied egg-rr59.8%
Taylor expanded in t around 0 46.3%
mul-1-neg46.3%
associate-*l/43.1%
distribute-rgt-neg-in43.1%
*-commutative43.1%
Simplified43.1%
Taylor expanded in y around 0 46.3%
associate-*r/46.3%
*-commutative46.3%
associate-/l*46.2%
associate-/r/46.3%
metadata-eval46.3%
associate-/r*46.3%
neg-mul-146.3%
associate-*l/46.3%
*-lft-identity46.3%
associate-/l*43.1%
associate-/r/47.0%
*-commutative47.0%
Simplified47.0%
Final simplification51.9%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 94.0%
associate-*l/98.3%
Simplified98.3%
Taylor expanded in y around 0 34.0%
Final simplification34.0%
(FPCore (x y z t) :precision binary64 (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - ((x * (y / t)) + (-z * (y / t)))
end function
public static double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
def code(x, y, z, t): return x - ((x * (y / t)) + (-z * (y / t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(x * Float64(y / t)) + Float64(Float64(-z) * Float64(y / t)))) end
function tmp = code(x, y, z, t) tmp = x - ((x * (y / t)) + (-z * (y / t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision] + N[((-z) * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)
\end{array}
herbie shell --seed 2023279
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:herbie-target
(- x (+ (* x (/ y t)) (* (- z) (/ y t))))
(+ x (/ (* y (- z x)) t)))