
(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 (+ 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 92.3%
associate-*l/97.7%
Simplified97.7%
Final simplification97.7%
(FPCore (x y z t) :precision binary64 (if (or (<= x -9e-61) (not (<= x 1.55e+45))) (* x (- 1.0 (/ y t))) (+ x (* (/ y t) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -9e-61) || !(x <= 1.55e+45)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + ((y / t) * z);
}
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 ((x <= (-9d-61)) .or. (.not. (x <= 1.55d+45))) then
tmp = x * (1.0d0 - (y / t))
else
tmp = x + ((y / t) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -9e-61) || !(x <= 1.55e+45)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + ((y / t) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -9e-61) or not (x <= 1.55e+45): tmp = x * (1.0 - (y / t)) else: tmp = x + ((y / t) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -9e-61) || !(x <= 1.55e+45)) tmp = Float64(x * Float64(1.0 - Float64(y / t))); else tmp = Float64(x + Float64(Float64(y / t) * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -9e-61) || ~((x <= 1.55e+45))) tmp = x * (1.0 - (y / t)); else tmp = x + ((y / t) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -9e-61], N[Not[LessEqual[x, 1.55e+45]], $MachinePrecision]], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-61} \lor \neg \left(x \leq 1.55 \cdot 10^{+45}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\end{array}
\end{array}
if x < -9e-61 or 1.54999999999999994e45 < x Initial program 89.8%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 95.7%
*-commutative95.7%
distribute-lft-in95.8%
*-rgt-identity95.8%
mul-1-neg95.8%
distribute-rgt-neg-in95.8%
unsub-neg95.8%
Simplified95.8%
Taylor expanded in x around 0 95.7%
if -9e-61 < x < 1.54999999999999994e45Initial program 95.3%
associate-*l/95.2%
Simplified95.2%
Taylor expanded in z around inf 85.1%
associate-*l/86.5%
*-commutative86.5%
Simplified86.5%
Final simplification91.5%
(FPCore (x y z t) :precision binary64 (if (<= x -1.25e-60) (- x (* x (/ y t))) (if (<= x 4.5e+43) (+ x (* (/ y t) z)) (* x (- 1.0 (/ y t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.25e-60) {
tmp = x - (x * (y / t));
} else if (x <= 4.5e+43) {
tmp = x + ((y / t) * z);
} 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 (x <= (-1.25d-60)) then
tmp = x - (x * (y / t))
else if (x <= 4.5d+43) then
tmp = x + ((y / t) * z)
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 (x <= -1.25e-60) {
tmp = x - (x * (y / t));
} else if (x <= 4.5e+43) {
tmp = x + ((y / t) * z);
} else {
tmp = x * (1.0 - (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1.25e-60: tmp = x - (x * (y / t)) elif x <= 4.5e+43: tmp = x + ((y / t) * z) else: tmp = x * (1.0 - (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1.25e-60) tmp = Float64(x - Float64(x * Float64(y / t))); elseif (x <= 4.5e+43) tmp = Float64(x + Float64(Float64(y / t) * z)); 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 (x <= -1.25e-60) tmp = x - (x * (y / t)); elseif (x <= 4.5e+43) tmp = x + ((y / t) * z); else tmp = x * (1.0 - (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.25e-60], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.5e+43], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-60}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{+43}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\end{array}
\end{array}
if x < -1.25e-60Initial program 91.2%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 96.1%
*-commutative96.1%
distribute-lft-in96.1%
*-rgt-identity96.1%
mul-1-neg96.1%
distribute-rgt-neg-in96.1%
unsub-neg96.1%
Simplified96.1%
if -1.25e-60 < x < 4.5e43Initial program 95.3%
associate-*l/95.2%
Simplified95.2%
Taylor expanded in z around inf 85.1%
associate-*l/86.5%
*-commutative86.5%
Simplified86.5%
if 4.5e43 < x Initial program 88.1%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 95.4%
*-commutative95.4%
distribute-lft-in95.4%
*-rgt-identity95.4%
mul-1-neg95.4%
distribute-rgt-neg-in95.4%
unsub-neg95.4%
Simplified95.4%
Taylor expanded in x around 0 95.4%
Final simplification91.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.9e-46) (not (<= y 6.2e-79))) (* (/ y t) (- x)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.9e-46) || !(y <= 6.2e-79)) {
tmp = (y / t) * -x;
} 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 ((y <= (-3.9d-46)) .or. (.not. (y <= 6.2d-79))) then
tmp = (y / t) * -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.9e-46) || !(y <= 6.2e-79)) {
tmp = (y / t) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.9e-46) or not (y <= 6.2e-79): tmp = (y / t) * -x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.9e-46) || !(y <= 6.2e-79)) tmp = Float64(Float64(y / t) * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -3.9e-46) || ~((y <= 6.2e-79))) tmp = (y / t) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.9e-46], N[Not[LessEqual[y, 6.2e-79]], $MachinePrecision]], N[(N[(y / t), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{-46} \lor \neg \left(y \leq 6.2 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.9000000000000003e-46 or 6.1999999999999999e-79 < y Initial program 88.8%
associate-*l/97.5%
Simplified97.5%
Taylor expanded in x around inf 64.9%
*-commutative64.9%
distribute-lft-in64.9%
*-rgt-identity64.9%
mul-1-neg64.9%
distribute-rgt-neg-in64.9%
unsub-neg64.9%
Simplified64.9%
Taylor expanded in y around inf 47.8%
associate-*l/52.3%
neg-mul-152.3%
distribute-rgt-neg-in52.3%
Simplified52.3%
if -3.9000000000000003e-46 < y < 6.1999999999999999e-79Initial program 98.1%
associate-*l/98.1%
Simplified98.1%
Taylor expanded in y around 0 58.7%
Final simplification54.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -6.8e-44) (not (<= y 5.2e-77))) (/ x (/ t (- y))) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.8e-44) || !(y <= 5.2e-77)) {
tmp = x / (t / -y);
} 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 ((y <= (-6.8d-44)) .or. (.not. (y <= 5.2d-77))) then
tmp = x / (t / -y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.8e-44) || !(y <= 5.2e-77)) {
tmp = x / (t / -y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -6.8e-44) or not (y <= 5.2e-77): tmp = x / (t / -y) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -6.8e-44) || !(y <= 5.2e-77)) tmp = Float64(x / Float64(t / Float64(-y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -6.8e-44) || ~((y <= 5.2e-77))) tmp = x / (t / -y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6.8e-44], N[Not[LessEqual[y, 5.2e-77]], $MachinePrecision]], N[(x / N[(t / (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-44} \lor \neg \left(y \leq 5.2 \cdot 10^{-77}\right):\\
\;\;\;\;\frac{x}{\frac{t}{-y}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.80000000000000033e-44 or 5.2000000000000002e-77 < y Initial program 88.8%
associate-*l/97.5%
Simplified97.5%
Taylor expanded in x around inf 64.9%
*-commutative64.9%
distribute-lft-in64.9%
*-rgt-identity64.9%
mul-1-neg64.9%
distribute-rgt-neg-in64.9%
unsub-neg64.9%
Simplified64.9%
Taylor expanded in y around inf 47.8%
associate-*r/47.8%
*-commutative47.8%
neg-mul-147.8%
distribute-rgt-neg-in47.8%
associate-/l*53.0%
Simplified53.0%
if -6.80000000000000033e-44 < y < 5.2000000000000002e-77Initial program 98.1%
associate-*l/98.1%
Simplified98.1%
Taylor expanded in y around 0 58.7%
Final simplification55.2%
(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 92.3%
associate-*l/97.7%
Simplified97.7%
Taylor expanded in x around inf 66.1%
*-commutative66.1%
distribute-lft-in66.2%
*-rgt-identity66.2%
mul-1-neg66.2%
distribute-rgt-neg-in66.2%
unsub-neg66.2%
Simplified66.2%
Taylor expanded in x around 0 66.1%
Final simplification66.1%
(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 92.3%
associate-*l/97.7%
Simplified97.7%
Taylor expanded in y around 0 31.1%
Final simplification31.1%
(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 2023224
(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)))