
(FPCore (x y z t) :precision binary64 (/ (* x (- y z)) (- t z)))
double code(double x, double y, double z, double t) {
return (x * (y - z)) / (t - z);
}
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)) / (t - z)
end function
public static double code(double x, double y, double z, double t) {
return (x * (y - z)) / (t - z);
}
def code(x, y, z, t): return (x * (y - z)) / (t - z)
function code(x, y, z, t) return Float64(Float64(x * Float64(y - z)) / Float64(t - z)) end
function tmp = code(x, y, z, t) tmp = (x * (y - z)) / (t - z); end
code[x_, y_, z_, t_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / N[(t - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y - z\right)}{t - z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ (* x (- y z)) (- t z)))
double code(double x, double y, double z, double t) {
return (x * (y - z)) / (t - z);
}
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)) / (t - z)
end function
public static double code(double x, double y, double z, double t) {
return (x * (y - z)) / (t - z);
}
def code(x, y, z, t): return (x * (y - z)) / (t - z)
function code(x, y, z, t) return Float64(Float64(x * Float64(y - z)) / Float64(t - z)) end
function tmp = code(x, y, z, t) tmp = (x * (y - z)) / (t - z); end
code[x_, y_, z_, t_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / N[(t - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y - z\right)}{t - z}
\end{array}
(FPCore (x y z t) :precision binary64 (* x (+ (/ y (- t z)) (/ z (- z t)))))
double code(double x, double y, double z, double t) {
return x * ((y / (t - z)) + (z / (z - 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 / (t - z)) + (z / (z - t)))
end function
public static double code(double x, double y, double z, double t) {
return x * ((y / (t - z)) + (z / (z - t)));
}
def code(x, y, z, t): return x * ((y / (t - z)) + (z / (z - t)))
function code(x, y, z, t) return Float64(x * Float64(Float64(y / Float64(t - z)) + Float64(z / Float64(z - t)))) end
function tmp = code(x, y, z, t) tmp = x * ((y / (t - z)) + (z / (z - t))); end
code[x_, y_, z_, t_] := N[(x * N[(N[(y / N[(t - z), $MachinePrecision]), $MachinePrecision] + N[(z / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\frac{y}{t - z} + \frac{z}{z - t}\right)
\end{array}
Initial program 87.2%
associate-/l*97.8%
Simplified97.8%
div-sub97.8%
Applied egg-rr97.8%
Final simplification97.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.5e-18) (not (<= z 1.7e-98))) (* x (/ z (- z t))) (* x (/ y (- t z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.5e-18) || !(z <= 1.7e-98)) {
tmp = x * (z / (z - 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 ((z <= (-2.5d-18)) .or. (.not. (z <= 1.7d-98))) then
tmp = x * (z / (z - 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 ((z <= -2.5e-18) || !(z <= 1.7e-98)) {
tmp = x * (z / (z - t));
} else {
tmp = x * (y / (t - z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.5e-18) or not (z <= 1.7e-98): tmp = x * (z / (z - t)) else: tmp = x * (y / (t - z)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.5e-18) || !(z <= 1.7e-98)) tmp = Float64(x * Float64(z / Float64(z - t))); else tmp = Float64(x * Float64(y / Float64(t - z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.5e-18) || ~((z <= 1.7e-98))) tmp = x * (z / (z - t)); else tmp = x * (y / (t - z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.5e-18], N[Not[LessEqual[z, 1.7e-98]], $MachinePrecision]], N[(x * N[(z / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(y / N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{-18} \lor \neg \left(z \leq 1.7 \cdot 10^{-98}\right):\\
\;\;\;\;x \cdot \frac{z}{z - t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{t - z}\\
\end{array}
\end{array}
if z < -2.50000000000000018e-18 or 1.7000000000000001e-98 < z Initial program 83.0%
remove-double-neg83.0%
distribute-lft-neg-out83.0%
distribute-neg-frac83.0%
distribute-neg-frac283.0%
distribute-lft-neg-out83.0%
distribute-rgt-neg-in83.0%
sub-neg83.0%
distribute-neg-in83.0%
remove-double-neg83.0%
+-commutative83.0%
sub-neg83.0%
sub-neg83.0%
distribute-neg-in83.0%
remove-double-neg83.0%
+-commutative83.0%
sub-neg83.0%
Simplified83.0%
Taylor expanded in y around 0 64.4%
associate-/l*77.5%
Simplified77.5%
if -2.50000000000000018e-18 < z < 1.7000000000000001e-98Initial program 93.7%
remove-double-neg93.7%
distribute-lft-neg-out93.7%
distribute-neg-frac93.7%
distribute-neg-frac293.7%
distribute-lft-neg-out93.7%
distribute-rgt-neg-in93.7%
sub-neg93.7%
distribute-neg-in93.7%
remove-double-neg93.7%
+-commutative93.7%
sub-neg93.7%
sub-neg93.7%
distribute-neg-in93.7%
remove-double-neg93.7%
+-commutative93.7%
sub-neg93.7%
Simplified93.7%
Taylor expanded in y around inf 82.3%
mul-1-neg82.3%
distribute-neg-frac282.3%
sub-neg82.3%
distribute-neg-in82.3%
remove-double-neg82.3%
+-commutative82.3%
sub-neg82.3%
associate-/l*85.1%
Simplified85.1%
Final simplification80.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.55e-20) (not (<= z 4e-94))) (* x (- 1.0 (/ y z))) (* x (/ y (- t z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.55e-20) || !(z <= 4e-94)) {
tmp = x * (1.0 - (y / z));
} 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 ((z <= (-1.55d-20)) .or. (.not. (z <= 4d-94))) then
tmp = x * (1.0d0 - (y / z))
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 ((z <= -1.55e-20) || !(z <= 4e-94)) {
tmp = x * (1.0 - (y / z));
} else {
tmp = x * (y / (t - z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.55e-20) or not (z <= 4e-94): tmp = x * (1.0 - (y / z)) else: tmp = x * (y / (t - z)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.55e-20) || !(z <= 4e-94)) tmp = Float64(x * Float64(1.0 - Float64(y / z))); else tmp = Float64(x * Float64(y / Float64(t - z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.55e-20) || ~((z <= 4e-94))) tmp = x * (1.0 - (y / z)); else tmp = x * (y / (t - z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.55e-20], N[Not[LessEqual[z, 4e-94]], $MachinePrecision]], N[(x * N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(y / N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{-20} \lor \neg \left(z \leq 4 \cdot 10^{-94}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{t - z}\\
\end{array}
\end{array}
if z < -1.55e-20 or 3.9999999999999998e-94 < z Initial program 83.2%
remove-double-neg83.2%
distribute-lft-neg-out83.2%
distribute-neg-frac83.2%
distribute-neg-frac283.2%
distribute-lft-neg-out83.2%
distribute-rgt-neg-in83.2%
sub-neg83.2%
distribute-neg-in83.2%
remove-double-neg83.2%
+-commutative83.2%
sub-neg83.2%
sub-neg83.2%
distribute-neg-in83.2%
remove-double-neg83.2%
+-commutative83.2%
sub-neg83.2%
Simplified83.2%
Taylor expanded in t around 0 59.5%
associate-/l*72.6%
div-sub72.7%
*-inverses72.7%
Simplified72.7%
if -1.55e-20 < z < 3.9999999999999998e-94Initial program 93.5%
remove-double-neg93.5%
distribute-lft-neg-out93.5%
distribute-neg-frac93.5%
distribute-neg-frac293.5%
distribute-lft-neg-out93.5%
distribute-rgt-neg-in93.5%
sub-neg93.5%
distribute-neg-in93.5%
remove-double-neg93.5%
+-commutative93.5%
sub-neg93.5%
sub-neg93.5%
distribute-neg-in93.5%
remove-double-neg93.5%
+-commutative93.5%
sub-neg93.5%
Simplified93.5%
Taylor expanded in y around inf 82.9%
mul-1-neg82.9%
distribute-neg-frac282.9%
sub-neg82.9%
distribute-neg-in82.9%
remove-double-neg82.9%
+-commutative82.9%
sub-neg82.9%
associate-/l*85.8%
Simplified85.8%
Final simplification77.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.6e-22) (not (<= z 4e-94))) (* x (- 1.0 (/ y z))) (* x (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.6e-22) || !(z <= 4e-94)) {
tmp = x * (1.0 - (y / 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 <= (-4.6d-22)) .or. (.not. (z <= 4d-94))) then
tmp = x * (1.0d0 - (y / 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 <= -4.6e-22) || !(z <= 4e-94)) {
tmp = x * (1.0 - (y / z));
} else {
tmp = x * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.6e-22) or not (z <= 4e-94): tmp = x * (1.0 - (y / z)) else: tmp = x * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.6e-22) || !(z <= 4e-94)) tmp = Float64(x * Float64(1.0 - Float64(y / z))); else tmp = Float64(x * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -4.6e-22) || ~((z <= 4e-94))) tmp = x * (1.0 - (y / z)); else tmp = x * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.6e-22], N[Not[LessEqual[z, 4e-94]], $MachinePrecision]], N[(x * N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{-22} \lor \neg \left(z \leq 4 \cdot 10^{-94}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{t}\\
\end{array}
\end{array}
if z < -4.5999999999999996e-22 or 3.9999999999999998e-94 < z Initial program 83.2%
remove-double-neg83.2%
distribute-lft-neg-out83.2%
distribute-neg-frac83.2%
distribute-neg-frac283.2%
distribute-lft-neg-out83.2%
distribute-rgt-neg-in83.2%
sub-neg83.2%
distribute-neg-in83.2%
remove-double-neg83.2%
+-commutative83.2%
sub-neg83.2%
sub-neg83.2%
distribute-neg-in83.2%
remove-double-neg83.2%
+-commutative83.2%
sub-neg83.2%
Simplified83.2%
Taylor expanded in t around 0 59.5%
associate-/l*72.6%
div-sub72.7%
*-inverses72.7%
Simplified72.7%
if -4.5999999999999996e-22 < z < 3.9999999999999998e-94Initial program 93.5%
remove-double-neg93.5%
distribute-lft-neg-out93.5%
distribute-neg-frac93.5%
distribute-neg-frac293.5%
distribute-lft-neg-out93.5%
distribute-rgt-neg-in93.5%
sub-neg93.5%
distribute-neg-in93.5%
remove-double-neg93.5%
+-commutative93.5%
sub-neg93.5%
sub-neg93.5%
distribute-neg-in93.5%
remove-double-neg93.5%
+-commutative93.5%
sub-neg93.5%
Simplified93.5%
Taylor expanded in z around 0 73.6%
associate-/l*77.4%
Simplified77.4%
Final simplification74.5%
(FPCore (x y z t) :precision binary64 (if (<= z -1.3e-20) x (if (<= z 3.35e-40) (* x (/ y t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.3e-20) {
tmp = x;
} else if (z <= 3.35e-40) {
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 (z <= (-1.3d-20)) then
tmp = x
else if (z <= 3.35d-40) 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 (z <= -1.3e-20) {
tmp = x;
} else if (z <= 3.35e-40) {
tmp = x * (y / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.3e-20: tmp = x elif z <= 3.35e-40: tmp = x * (y / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.3e-20) tmp = x; elseif (z <= 3.35e-40) tmp = Float64(x * Float64(y / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.3e-20) tmp = x; elseif (z <= 3.35e-40) tmp = x * (y / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.3e-20], x, If[LessEqual[z, 3.35e-40], N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{-20}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.35 \cdot 10^{-40}:\\
\;\;\;\;x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.29999999999999997e-20 or 3.3499999999999999e-40 < z Initial program 83.2%
remove-double-neg83.2%
distribute-lft-neg-out83.2%
distribute-neg-frac83.2%
distribute-neg-frac283.2%
distribute-lft-neg-out83.2%
distribute-rgt-neg-in83.2%
sub-neg83.2%
distribute-neg-in83.2%
remove-double-neg83.2%
+-commutative83.2%
sub-neg83.2%
sub-neg83.2%
distribute-neg-in83.2%
remove-double-neg83.2%
+-commutative83.2%
sub-neg83.2%
Simplified83.2%
Taylor expanded in z around inf 60.5%
if -1.29999999999999997e-20 < z < 3.3499999999999999e-40Initial program 93.0%
remove-double-neg93.0%
distribute-lft-neg-out93.0%
distribute-neg-frac93.0%
distribute-neg-frac293.0%
distribute-lft-neg-out93.0%
distribute-rgt-neg-in93.0%
sub-neg93.0%
distribute-neg-in93.0%
remove-double-neg93.0%
+-commutative93.0%
sub-neg93.0%
sub-neg93.0%
distribute-neg-in93.0%
remove-double-neg93.0%
+-commutative93.0%
sub-neg93.0%
Simplified93.0%
Taylor expanded in z around 0 70.7%
associate-/l*74.3%
Simplified74.3%
(FPCore (x y z t) :precision binary64 (* x (/ (- z y) (- z t))))
double code(double x, double y, double z, double t) {
return x * ((z - y) / (z - 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) / (z - t))
end function
public static double code(double x, double y, double z, double t) {
return x * ((z - y) / (z - t));
}
def code(x, y, z, t): return x * ((z - y) / (z - t))
function code(x, y, z, t) return Float64(x * Float64(Float64(z - y) / Float64(z - t))) end
function tmp = code(x, y, z, t) tmp = x * ((z - y) / (z - t)); end
code[x_, y_, z_, t_] := N[(x * N[(N[(z - y), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{z - y}{z - t}
\end{array}
Initial program 87.2%
associate-/l*97.8%
Simplified97.8%
Final simplification97.8%
(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 87.2%
remove-double-neg87.2%
distribute-lft-neg-out87.2%
distribute-neg-frac87.2%
distribute-neg-frac287.2%
distribute-lft-neg-out87.2%
distribute-rgt-neg-in87.2%
sub-neg87.2%
distribute-neg-in87.2%
remove-double-neg87.2%
+-commutative87.2%
sub-neg87.2%
sub-neg87.2%
distribute-neg-in87.2%
remove-double-neg87.2%
+-commutative87.2%
sub-neg87.2%
Simplified87.2%
Taylor expanded in z around inf 39.0%
(FPCore (x y z t) :precision binary64 (/ x (/ (- t z) (- y z))))
double code(double x, double y, double z, double t) {
return x / ((t - z) / (y - z));
}
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 / ((t - z) / (y - z))
end function
public static double code(double x, double y, double z, double t) {
return x / ((t - z) / (y - z));
}
def code(x, y, z, t): return x / ((t - z) / (y - z))
function code(x, y, z, t) return Float64(x / Float64(Float64(t - z) / Float64(y - z))) end
function tmp = code(x, y, z, t) tmp = x / ((t - z) / (y - z)); end
code[x_, y_, z_, t_] := N[(x / N[(N[(t - z), $MachinePrecision] / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{t - z}{y - z}}
\end{array}
herbie shell --seed 2024111
(FPCore (x y z t)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderAreaSpots4D from Chart-1.5.3"
:precision binary64
:alt
(/ x (/ (- t z) (- y z)))
(/ (* x (- y z)) (- t z)))