
(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 7 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
(let* ((t_1 (- x (/ (* y (- x z)) t))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 1e+303)))
(+ x (* y (/ (- z x) t)))
t_1)))
double code(double x, double y, double z, double t) {
double t_1 = x - ((y * (x - z)) / t);
double tmp;
if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 1e+303)) {
tmp = x + (y * ((z - x) / t));
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = x - ((y * (x - z)) / t);
double tmp;
if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 1e+303)) {
tmp = x + (y * ((z - x) / t));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x - ((y * (x - z)) / t) tmp = 0 if (t_1 <= -math.inf) or not (t_1 <= 1e+303): tmp = x + (y * ((z - x) / t)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x - Float64(Float64(y * Float64(x - z)) / t)) tmp = 0.0 if ((t_1 <= Float64(-Inf)) || !(t_1 <= 1e+303)) tmp = Float64(x + Float64(y * Float64(Float64(z - x) / t))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x - ((y * (x - z)) / t); tmp = 0.0; if ((t_1 <= -Inf) || ~((t_1 <= 1e+303))) tmp = x + (y * ((z - x) / t)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 1e+303]], $MachinePrecision]], N[(x + N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y \cdot \left(x - z\right)}{t}\\
\mathbf{if}\;t\_1 \leq -\infty \lor \neg \left(t\_1 \leq 10^{+303}\right):\\
\;\;\;\;x + y \cdot \frac{z - x}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < -inf.0 or 1e303 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) Initial program 82.6%
associate-/l*100.0%
Simplified100.0%
if -inf.0 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 1e303Initial program 99.5%
Final simplification99.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.8e-114) (not (<= y 5.6e-126))) (+ x (* y (/ (- z x) t))) (+ x (/ (* z y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.8e-114) || !(y <= 5.6e-126)) {
tmp = x + (y * ((z - x) / t));
} else {
tmp = x + ((z * 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 ((y <= (-3.8d-114)) .or. (.not. (y <= 5.6d-126))) then
tmp = x + (y * ((z - x) / t))
else
tmp = x + ((z * y) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.8e-114) || !(y <= 5.6e-126)) {
tmp = x + (y * ((z - x) / t));
} else {
tmp = x + ((z * y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.8e-114) or not (y <= 5.6e-126): tmp = x + (y * ((z - x) / t)) else: tmp = x + ((z * y) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.8e-114) || !(y <= 5.6e-126)) tmp = Float64(x + Float64(y * Float64(Float64(z - x) / t))); else tmp = Float64(x + Float64(Float64(z * y) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -3.8e-114) || ~((y <= 5.6e-126))) tmp = x + (y * ((z - x) / t)); else tmp = x + ((z * y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.8e-114], N[Not[LessEqual[y, 5.6e-126]], $MachinePrecision]], N[(x + N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-114} \lor \neg \left(y \leq 5.6 \cdot 10^{-126}\right):\\
\;\;\;\;x + y \cdot \frac{z - x}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\end{array}
\end{array}
if y < -3.7999999999999998e-114 or 5.59999999999999983e-126 < y Initial program 91.6%
associate-/l*97.6%
Simplified97.6%
if -3.7999999999999998e-114 < y < 5.59999999999999983e-126Initial program 99.2%
associate-/l*80.1%
Simplified80.1%
Taylor expanded in z around inf 94.5%
Final simplification96.4%
(FPCore (x y z t) :precision binary64 (if (or (<= z -8.9e-45) (not (<= z 3e+14))) (+ x (* y (/ z t))) (* x (- 1.0 (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8.9e-45) || !(z <= 3e+14)) {
tmp = x + (y * (z / t));
} else {
tmp = x * (1.0 - (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 <= (-8.9d-45)) .or. (.not. (z <= 3d+14))) then
tmp = x + (y * (z / t))
else
tmp = x * (1.0d0 - (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8.9e-45) || !(z <= 3e+14)) {
tmp = x + (y * (z / t));
} else {
tmp = x * (1.0 - (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8.9e-45) or not (z <= 3e+14): tmp = x + (y * (z / t)) else: tmp = x * (1.0 - (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8.9e-45) || !(z <= 3e+14)) tmp = Float64(x + Float64(y * Float64(z / t))); else tmp = Float64(x * Float64(1.0 - Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -8.9e-45) || ~((z <= 3e+14))) tmp = x + (y * (z / t)); else tmp = x * (1.0 - (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8.9e-45], N[Not[LessEqual[z, 3e+14]], $MachinePrecision]], N[(x + N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.9 \cdot 10^{-45} \lor \neg \left(z \leq 3 \cdot 10^{+14}\right):\\
\;\;\;\;x + y \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\end{array}
\end{array}
if z < -8.90000000000000034e-45 or 3e14 < z Initial program 93.1%
associate-/l*90.3%
Simplified90.3%
Taylor expanded in z around inf 85.4%
associate-/l*84.2%
Simplified84.2%
if -8.90000000000000034e-45 < z < 3e14Initial program 96.1%
+-commutative96.1%
*-commutative96.1%
associate-/l*94.3%
fma-define94.3%
Simplified94.3%
Taylor expanded in z around 0 86.8%
mul-1-neg86.8%
*-rgt-identity86.8%
associate-/l*89.9%
distribute-rgt-neg-in89.9%
mul-1-neg89.9%
distribute-lft-in89.9%
mul-1-neg89.9%
unsub-neg89.9%
Simplified89.9%
Final simplification86.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9.6e-44) (not (<= z 4.4e+15))) (+ x (/ z (/ t y))) (* x (- 1.0 (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.6e-44) || !(z <= 4.4e+15)) {
tmp = x + (z / (t / y));
} else {
tmp = x * (1.0 - (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 <= (-9.6d-44)) .or. (.not. (z <= 4.4d+15))) then
tmp = x + (z / (t / y))
else
tmp = x * (1.0d0 - (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9.6e-44) || !(z <= 4.4e+15)) {
tmp = x + (z / (t / y));
} else {
tmp = x * (1.0 - (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -9.6e-44) or not (z <= 4.4e+15): tmp = x + (z / (t / y)) else: tmp = x * (1.0 - (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -9.6e-44) || !(z <= 4.4e+15)) tmp = Float64(x + Float64(z / Float64(t / y))); else tmp = Float64(x * Float64(1.0 - Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -9.6e-44) || ~((z <= 4.4e+15))) tmp = x + (z / (t / y)); else tmp = x * (1.0 - (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9.6e-44], N[Not[LessEqual[z, 4.4e+15]], $MachinePrecision]], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.6 \cdot 10^{-44} \lor \neg \left(z \leq 4.4 \cdot 10^{+15}\right):\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\end{array}
\end{array}
if z < -9.60000000000000035e-44 or 4.4e15 < z Initial program 93.1%
associate-/l*90.3%
Simplified90.3%
Taylor expanded in z around inf 85.4%
associate-/l*84.2%
Simplified84.2%
*-commutative84.2%
associate-/r/90.4%
Applied egg-rr90.4%
if -9.60000000000000035e-44 < z < 4.4e15Initial program 96.1%
+-commutative96.1%
*-commutative96.1%
associate-/l*94.3%
fma-define94.3%
Simplified94.3%
Taylor expanded in z around 0 86.8%
mul-1-neg86.8%
*-rgt-identity86.8%
associate-/l*89.9%
distribute-rgt-neg-in89.9%
mul-1-neg89.9%
distribute-lft-in89.9%
mul-1-neg89.9%
unsub-neg89.9%
Simplified89.9%
Final simplification90.1%
(FPCore (x y z t) :precision binary64 (+ x (/ (- z x) (/ t y))))
double code(double x, double y, double z, double t) {
return x + ((z - x) / (t / y));
}
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 + ((z - x) / (t / y))
end function
public static double code(double x, double y, double z, double t) {
return x + ((z - x) / (t / y));
}
def code(x, y, z, t): return x + ((z - x) / (t / y))
function code(x, y, z, t) return Float64(x + Float64(Float64(z - x) / Float64(t / y))) end
function tmp = code(x, y, z, t) tmp = x + ((z - x) / (t / y)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{z - x}{\frac{t}{y}}
\end{array}
Initial program 94.5%
associate-/l*91.0%
Simplified91.0%
associate-*r/94.5%
*-commutative94.5%
associate-*r/97.1%
clear-num97.1%
un-div-inv97.9%
Applied egg-rr97.9%
Final simplification97.9%
(FPCore (x y z t) :precision binary64 (* x (- 1.0 (/ y t))))
double code(double x, double y, double z, double t) {
return x * (1.0 - (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 * (1.0d0 - (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x * (1.0 - (y / t));
}
def code(x, y, z, t): return x * (1.0 - (y / t))
function code(x, y, z, t) return Float64(x * Float64(1.0 - Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x * (1.0 - (y / t)); end
code[x_, y_, z_, t_] := N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \frac{y}{t}\right)
\end{array}
Initial program 94.5%
+-commutative94.5%
*-commutative94.5%
associate-/l*97.1%
fma-define97.1%
Simplified97.1%
Taylor expanded in z around 0 65.0%
mul-1-neg65.0%
*-rgt-identity65.0%
associate-/l*69.0%
distribute-rgt-neg-in69.0%
mul-1-neg69.0%
distribute-lft-in69.0%
mul-1-neg69.0%
unsub-neg69.0%
Simplified69.0%
Final simplification69.0%
(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.5%
+-commutative94.5%
*-commutative94.5%
associate-/l*97.1%
fma-define97.1%
Simplified97.1%
Taylor expanded in y around 0 40.4%
Final simplification40.4%
(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 2024046
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:alt
(- x (+ (* x (/ y t)) (* (- z) (/ y t))))
(+ x (/ (* y (- z x)) t)))