
(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 8 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 (/ (- 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 93.6%
associate-*l/97.1%
Simplified97.1%
*-commutative97.1%
clear-num96.9%
un-div-inv97.3%
Applied egg-rr97.3%
Final simplification97.3%
(FPCore (x y z t)
:precision binary64
(if (<= t -5.4e-113)
x
(if (or (<= t 8.4e-156) (and (not (<= t 1e-112)) (<= t 2.8e-11)))
(* y (/ x (- t)))
x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -5.4e-113) {
tmp = x;
} else if ((t <= 8.4e-156) || (!(t <= 1e-112) && (t <= 2.8e-11))) {
tmp = y * (x / -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 <= (-5.4d-113)) then
tmp = x
else if ((t <= 8.4d-156) .or. (.not. (t <= 1d-112)) .and. (t <= 2.8d-11)) then
tmp = y * (x / -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 <= -5.4e-113) {
tmp = x;
} else if ((t <= 8.4e-156) || (!(t <= 1e-112) && (t <= 2.8e-11))) {
tmp = y * (x / -t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -5.4e-113: tmp = x elif (t <= 8.4e-156) or (not (t <= 1e-112) and (t <= 2.8e-11)): tmp = y * (x / -t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -5.4e-113) tmp = x; elseif ((t <= 8.4e-156) || (!(t <= 1e-112) && (t <= 2.8e-11))) tmp = Float64(y * Float64(x / Float64(-t))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -5.4e-113) tmp = x; elseif ((t <= 8.4e-156) || (~((t <= 1e-112)) && (t <= 2.8e-11))) tmp = y * (x / -t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -5.4e-113], x, If[Or[LessEqual[t, 8.4e-156], And[N[Not[LessEqual[t, 1e-112]], $MachinePrecision], LessEqual[t, 2.8e-11]]], N[(y * N[(x / (-t)), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.4 \cdot 10^{-113}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 8.4 \cdot 10^{-156} \lor \neg \left(t \leq 10^{-112}\right) \land t \leq 2.8 \cdot 10^{-11}:\\
\;\;\;\;y \cdot \frac{x}{-t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -5.39999999999999991e-113 or 8.40000000000000049e-156 < t < 9.9999999999999995e-113 or 2.8e-11 < t Initial program 90.7%
associate-*l/97.3%
Simplified97.3%
Taylor expanded in y around 0 53.6%
if -5.39999999999999991e-113 < t < 8.40000000000000049e-156 or 9.9999999999999995e-113 < t < 2.8e-11Initial program 98.9%
associate-*l/96.8%
Simplified96.8%
Taylor expanded in x around inf 63.4%
*-commutative63.4%
distribute-lft-in63.4%
*-rgt-identity63.4%
mul-1-neg63.4%
distribute-rgt-neg-in63.4%
unsub-neg63.4%
Simplified63.4%
clear-num63.4%
un-div-inv64.3%
Applied egg-rr64.3%
Taylor expanded in t around 0 51.7%
associate-*r/51.7%
associate-*l/51.6%
metadata-eval51.6%
distribute-neg-frac51.6%
associate-*r*51.7%
distribute-neg-frac51.7%
metadata-eval51.7%
metadata-eval51.7%
associate-/r*51.7%
neg-mul-151.7%
associate-/r/51.7%
*-commutative51.7%
associate-*r/52.6%
*-rgt-identity52.6%
associate-/r/47.7%
*-commutative47.7%
Simplified47.7%
Final simplification51.5%
(FPCore (x y z t)
:precision binary64
(if (<= t -2.7e-105)
x
(if (or (<= t 8.8e-156) (and (not (<= t 8.5e-113)) (<= t 2.3e-12)))
(* (/ y t) (- x))
x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.7e-105) {
tmp = x;
} else if ((t <= 8.8e-156) || (!(t <= 8.5e-113) && (t <= 2.3e-12))) {
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 (t <= (-2.7d-105)) then
tmp = x
else if ((t <= 8.8d-156) .or. (.not. (t <= 8.5d-113)) .and. (t <= 2.3d-12)) 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 (t <= -2.7e-105) {
tmp = x;
} else if ((t <= 8.8e-156) || (!(t <= 8.5e-113) && (t <= 2.3e-12))) {
tmp = (y / t) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -2.7e-105: tmp = x elif (t <= 8.8e-156) or (not (t <= 8.5e-113) and (t <= 2.3e-12)): tmp = (y / t) * -x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -2.7e-105) tmp = x; elseif ((t <= 8.8e-156) || (!(t <= 8.5e-113) && (t <= 2.3e-12))) 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 (t <= -2.7e-105) tmp = x; elseif ((t <= 8.8e-156) || (~((t <= 8.5e-113)) && (t <= 2.3e-12))) tmp = (y / t) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -2.7e-105], x, If[Or[LessEqual[t, 8.8e-156], And[N[Not[LessEqual[t, 8.5e-113]], $MachinePrecision], LessEqual[t, 2.3e-12]]], N[(N[(y / t), $MachinePrecision] * (-x)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.7 \cdot 10^{-105}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 8.8 \cdot 10^{-156} \lor \neg \left(t \leq 8.5 \cdot 10^{-113}\right) \land t \leq 2.3 \cdot 10^{-12}:\\
\;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -2.69999999999999993e-105 or 8.7999999999999996e-156 < t < 8.4999999999999995e-113 or 2.29999999999999989e-12 < t Initial program 90.7%
associate-*l/97.3%
Simplified97.3%
Taylor expanded in y around 0 53.6%
if -2.69999999999999993e-105 < t < 8.7999999999999996e-156 or 8.4999999999999995e-113 < t < 2.29999999999999989e-12Initial program 98.9%
associate-*l/96.8%
Simplified96.8%
Taylor expanded in x around inf 63.4%
*-commutative63.4%
distribute-lft-in63.4%
*-rgt-identity63.4%
mul-1-neg63.4%
distribute-rgt-neg-in63.4%
unsub-neg63.4%
Simplified63.4%
clear-num63.4%
un-div-inv64.3%
Applied egg-rr64.3%
Taylor expanded in t around 0 51.7%
mul-1-neg51.7%
associate-*l/51.7%
distribute-rgt-neg-in51.7%
Simplified51.7%
Final simplification52.9%
(FPCore (x y z t) :precision binary64 (if (<= z -1.45e-103) (+ x (* z (/ y t))) (if (<= z 1.9e-82) (- x (* x (/ y t))) (+ x (/ z (/ t y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.45e-103) {
tmp = x + (z * (y / t));
} else if (z <= 1.9e-82) {
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.45d-103)) then
tmp = x + (z * (y / t))
else if (z <= 1.9d-82) 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.45e-103) {
tmp = x + (z * (y / t));
} else if (z <= 1.9e-82) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.45e-103: tmp = x + (z * (y / t)) elif z <= 1.9e-82: 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.45e-103) tmp = Float64(x + Float64(z * Float64(y / t))); elseif (z <= 1.9e-82) 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.45e-103) tmp = x + (z * (y / t)); elseif (z <= 1.9e-82) 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.45e-103], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.9e-82], 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.45 \cdot 10^{-103}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-82}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if z < -1.4499999999999999e-103Initial program 96.5%
associate-*l/96.8%
Simplified96.8%
Taylor expanded in z around inf 86.6%
associate-*l/88.1%
*-commutative88.1%
Simplified88.1%
if -1.4499999999999999e-103 < z < 1.9000000000000001e-82Initial program 94.7%
associate-*l/96.7%
Simplified96.7%
Taylor expanded in x around inf 91.3%
*-commutative91.3%
distribute-lft-in91.3%
*-rgt-identity91.3%
mul-1-neg91.3%
distribute-rgt-neg-in91.3%
unsub-neg91.3%
Simplified91.3%
if 1.9000000000000001e-82 < z Initial program 89.9%
associate-*l/97.7%
Simplified97.7%
*-commutative97.7%
clear-num97.7%
un-div-inv97.8%
Applied egg-rr97.8%
Taylor expanded in z around inf 82.0%
*-commutative82.0%
associate-/l*87.6%
Simplified87.6%
Final simplification89.1%
(FPCore (x y z t) :precision binary64 (if (<= z -5.3e-103) (+ x (* z (/ y t))) (if (<= z 1.6e-82) (- x (/ x (/ t y))) (+ x (/ z (/ t y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -5.3e-103) {
tmp = x + (z * (y / t));
} else if (z <= 1.6e-82) {
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 <= (-5.3d-103)) then
tmp = x + (z * (y / t))
else if (z <= 1.6d-82) 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 <= -5.3e-103) {
tmp = x + (z * (y / t));
} else if (z <= 1.6e-82) {
tmp = x - (x / (t / y));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -5.3e-103: tmp = x + (z * (y / t)) elif z <= 1.6e-82: tmp = x - (x / (t / y)) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -5.3e-103) tmp = Float64(x + Float64(z * Float64(y / t))); elseif (z <= 1.6e-82) 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 <= -5.3e-103) tmp = x + (z * (y / t)); elseif (z <= 1.6e-82) tmp = x - (x / (t / y)); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -5.3e-103], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.6e-82], 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 -5.3 \cdot 10^{-103}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-82}:\\
\;\;\;\;x - \frac{x}{\frac{t}{y}}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if z < -5.30000000000000006e-103Initial program 96.5%
associate-*l/96.8%
Simplified96.8%
Taylor expanded in z around inf 86.6%
associate-*l/88.1%
*-commutative88.1%
Simplified88.1%
if -5.30000000000000006e-103 < z < 1.6000000000000001e-82Initial program 94.7%
associate-*l/96.7%
Simplified96.7%
Taylor expanded in x around inf 91.3%
*-commutative91.3%
distribute-lft-in91.3%
*-rgt-identity91.3%
mul-1-neg91.3%
distribute-rgt-neg-in91.3%
unsub-neg91.3%
Simplified91.3%
clear-num91.3%
un-div-inv92.2%
Applied egg-rr92.2%
if 1.6000000000000001e-82 < z Initial program 89.9%
associate-*l/97.7%
Simplified97.7%
*-commutative97.7%
clear-num97.7%
un-div-inv97.8%
Applied egg-rr97.8%
Taylor expanded in z around inf 82.0%
*-commutative82.0%
associate-/l*87.6%
Simplified87.6%
Final simplification89.4%
(FPCore (x y z t) :precision binary64 (+ x (* (- z x) (/ y t))))
double code(double x, double y, double z, double t) {
return x + ((z - x) * (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 + ((z - x) * (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x + ((z - x) * (y / t));
}
def code(x, y, z, t): return x + ((z - x) * (y / t))
function code(x, y, z, t) return Float64(x + Float64(Float64(z - x) * Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x + ((z - x) * (y / t)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(z - x\right) \cdot \frac{y}{t}
\end{array}
Initial program 93.6%
associate-*l/97.1%
Simplified97.1%
Final simplification97.1%
(FPCore (x y z t) :precision binary64 (+ x (* z (/ y t))))
double code(double x, double y, double z, double t) {
return x + (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 + (z * (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x + (z * (y / t));
}
def code(x, y, z, t): return x + (z * (y / t))
function code(x, y, z, t) return Float64(x + Float64(z * Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x + (z * (y / t)); end
code[x_, y_, z_, t_] := N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \frac{y}{t}
\end{array}
Initial program 93.6%
associate-*l/97.1%
Simplified97.1%
Taylor expanded in z around inf 74.7%
associate-*l/77.6%
*-commutative77.6%
Simplified77.6%
Final simplification77.6%
(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 93.6%
associate-*l/97.1%
Simplified97.1%
Taylor expanded in y around 0 39.5%
Final simplification39.5%
(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 2023221
(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)))