
(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 5 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.7%
associate-*l/97.6%
Simplified97.6%
Final simplification97.6%
(FPCore (x y z t) :precision binary64 (if (or (<= x -4e+127) (not (<= x 3.1e+20))) (- x (* x (/ y t))) (+ x (/ z (/ t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4e+127) || !(x <= 3.1e+20)) {
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 ((x <= (-4d+127)) .or. (.not. (x <= 3.1d+20))) 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 ((x <= -4e+127) || !(x <= 3.1e+20)) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -4e+127) or not (x <= 3.1e+20): tmp = x - (x * (y / t)) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -4e+127) || !(x <= 3.1e+20)) 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 ((x <= -4e+127) || ~((x <= 3.1e+20))) tmp = x - (x * (y / t)); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -4e+127], N[Not[LessEqual[x, 3.1e+20]], $MachinePrecision]], 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}\;x \leq -4 \cdot 10^{+127} \lor \neg \left(x \leq 3.1 \cdot 10^{+20}\right):\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if x < -3.99999999999999982e127 or 3.1e20 < x Initial program 91.9%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 93.6%
*-commutative93.6%
distribute-rgt-in93.6%
*-lft-identity93.6%
mul-1-neg93.6%
distribute-lft-neg-in93.6%
associate-*l/85.7%
unsub-neg85.7%
*-commutative85.7%
associate-*r/93.6%
Simplified93.6%
if -3.99999999999999982e127 < x < 3.1e20Initial program 93.2%
associate-*l/96.3%
Simplified96.3%
Taylor expanded in z around inf 84.4%
associate-*l/88.1%
*-commutative88.1%
Simplified88.1%
clear-num88.0%
div-inv88.1%
Applied egg-rr88.1%
Final simplification90.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -5.4e+128) (not (<= y 1e+89))) (* x (/ (- y) t)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.4e+128) || !(y <= 1e+89)) {
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 ((y <= (-5.4d+128)) .or. (.not. (y <= 1d+89))) 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 ((y <= -5.4e+128) || !(y <= 1e+89)) {
tmp = x * (-y / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -5.4e+128) or not (y <= 1e+89): tmp = x * (-y / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -5.4e+128) || !(y <= 1e+89)) tmp = Float64(x * Float64(Float64(-y) / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -5.4e+128) || ~((y <= 1e+89))) tmp = x * (-y / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -5.4e+128], N[Not[LessEqual[y, 1e+89]], $MachinePrecision]], N[(x * N[((-y) / t), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{+128} \lor \neg \left(y \leq 10^{+89}\right):\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.40000000000000002e128 or 9.99999999999999995e88 < y Initial program 82.1%
associate-*l/98.8%
Simplified98.8%
Taylor expanded in x around inf 60.5%
*-commutative60.5%
distribute-rgt-in60.5%
*-lft-identity60.5%
mul-1-neg60.5%
distribute-lft-neg-in60.5%
associate-*l/47.9%
unsub-neg47.9%
*-commutative47.9%
associate-*r/60.5%
Simplified60.5%
clear-num60.5%
div-inv60.5%
Applied egg-rr60.5%
Taylor expanded in t around 0 44.0%
mul-1-neg44.0%
associate-*l/55.5%
*-commutative55.5%
distribute-rgt-neg-in55.5%
distribute-neg-frac55.5%
neg-mul-155.5%
associate-/l*55.5%
metadata-eval55.5%
associate-/r*55.5%
neg-mul-155.5%
associate-*r/55.5%
*-rgt-identity55.5%
distribute-neg-frac55.5%
associate-/r/51.4%
*-commutative51.4%
Simplified51.4%
Taylor expanded in y around 0 44.0%
mul-1-neg44.0%
associate-/l*51.4%
associate-/r/55.5%
*-commutative55.5%
distribute-rgt-neg-in55.5%
distribute-neg-frac55.5%
Simplified55.5%
if -5.40000000000000002e128 < y < 9.99999999999999995e88Initial program 98.4%
associate-*l/97.0%
Simplified97.0%
Taylor expanded in y around 0 54.6%
Final simplification54.9%
(FPCore (x y z t) :precision binary64 (if (<= y 6e+170) (+ x (* (/ y t) z)) (* x (/ (- y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6e+170) {
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 (y <= 6d+170) 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 (y <= 6e+170) {
tmp = x + ((y / t) * z);
} else {
tmp = x * (-y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 6e+170: tmp = x + ((y / t) * z) else: tmp = x * (-y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 6e+170) tmp = Float64(x + Float64(Float64(y / t) * z)); else tmp = Float64(x * Float64(Float64(-y) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 6e+170) tmp = x + ((y / t) * z); else tmp = x * (-y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 6e+170], 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}\;y \leq 6 \cdot 10^{+170}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\end{array}
\end{array}
if y < 5.99999999999999994e170Initial program 93.8%
associate-*l/97.3%
Simplified97.3%
Taylor expanded in z around inf 79.0%
associate-*l/81.6%
*-commutative81.6%
Simplified81.6%
if 5.99999999999999994e170 < y Initial program 84.5%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in x around inf 73.3%
*-commutative73.3%
distribute-rgt-in73.3%
*-lft-identity73.3%
mul-1-neg73.3%
distribute-lft-neg-in73.3%
associate-*l/61.1%
unsub-neg61.1%
*-commutative61.1%
associate-*r/73.3%
Simplified73.3%
clear-num73.2%
div-inv73.3%
Applied egg-rr73.3%
Taylor expanded in t around 0 61.3%
mul-1-neg61.3%
associate-*l/73.5%
*-commutative73.5%
distribute-rgt-neg-in73.5%
distribute-neg-frac73.5%
neg-mul-173.5%
associate-/l*73.4%
metadata-eval73.4%
associate-/r*73.4%
neg-mul-173.4%
associate-*r/73.5%
*-rgt-identity73.5%
distribute-neg-frac73.5%
associate-/r/67.7%
*-commutative67.7%
Simplified67.7%
Taylor expanded in y around 0 61.3%
mul-1-neg61.3%
associate-/l*67.6%
associate-/r/73.5%
*-commutative73.5%
distribute-rgt-neg-in73.5%
distribute-neg-frac73.5%
Simplified73.5%
Final simplification80.7%
(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.7%
associate-*l/97.6%
Simplified97.6%
Taylor expanded in y around 0 38.2%
Final simplification38.2%
(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 2023195
(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)))