
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
Initial program 100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (- x y) z)))
(if (<= z -9.5e-8)
t_0
(if (<= z -4.1e-100)
(/ y (- y z))
(if (<= z -7.6e-126)
(/ x (- z y))
(if (<= z 2.1e+29) (- 1.0 (/ x y)) t_0))))))
double code(double x, double y, double z) {
double t_0 = (x - y) / z;
double tmp;
if (z <= -9.5e-8) {
tmp = t_0;
} else if (z <= -4.1e-100) {
tmp = y / (y - z);
} else if (z <= -7.6e-126) {
tmp = x / (z - y);
} else if (z <= 2.1e+29) {
tmp = 1.0 - (x / y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x - y) / z
if (z <= (-9.5d-8)) then
tmp = t_0
else if (z <= (-4.1d-100)) then
tmp = y / (y - z)
else if (z <= (-7.6d-126)) then
tmp = x / (z - y)
else if (z <= 2.1d+29) then
tmp = 1.0d0 - (x / y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x - y) / z;
double tmp;
if (z <= -9.5e-8) {
tmp = t_0;
} else if (z <= -4.1e-100) {
tmp = y / (y - z);
} else if (z <= -7.6e-126) {
tmp = x / (z - y);
} else if (z <= 2.1e+29) {
tmp = 1.0 - (x / y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x - y) / z tmp = 0 if z <= -9.5e-8: tmp = t_0 elif z <= -4.1e-100: tmp = y / (y - z) elif z <= -7.6e-126: tmp = x / (z - y) elif z <= 2.1e+29: tmp = 1.0 - (x / y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x - y) / z) tmp = 0.0 if (z <= -9.5e-8) tmp = t_0; elseif (z <= -4.1e-100) tmp = Float64(y / Float64(y - z)); elseif (z <= -7.6e-126) tmp = Float64(x / Float64(z - y)); elseif (z <= 2.1e+29) tmp = Float64(1.0 - Float64(x / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x - y) / z; tmp = 0.0; if (z <= -9.5e-8) tmp = t_0; elseif (z <= -4.1e-100) tmp = y / (y - z); elseif (z <= -7.6e-126) tmp = x / (z - y); elseif (z <= 2.1e+29) tmp = 1.0 - (x / y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[z, -9.5e-8], t$95$0, If[LessEqual[z, -4.1e-100], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -7.6e-126], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.1e+29], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{z}\\
\mathbf{if}\;z \leq -9.5 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -4.1 \cdot 10^{-100}:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{elif}\;z \leq -7.6 \cdot 10^{-126}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{+29}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -9.50000000000000036e-8 or 2.1000000000000002e29 < z Initial program 100.0%
Simplified0
Taylor expanded in z around inf 0
Simplified0
if -9.50000000000000036e-8 < z < -4.0999999999999999e-100Initial program 99.9%
Simplified0
Taylor expanded in x around 0 0
Simplified0
if -4.0999999999999999e-100 < z < -7.5999999999999997e-126Initial program 100.0%
Simplified0
Taylor expanded in x around inf 0
Simplified0
if -7.5999999999999997e-126 < z < 2.1000000000000002e29Initial program 100.0%
Simplified0
Taylor expanded in z around 0 0
Simplified0
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ x (- z y))))
(if (<= x -2.4e+53)
t_0
(if (<= x 490000.0)
(/ y (- y z))
(if (<= x 6.1e+71) t_0 (if (<= x 9.4e+104) (- 1.0 (/ x y)) t_0))))))
double code(double x, double y, double z) {
double t_0 = x / (z - y);
double tmp;
if (x <= -2.4e+53) {
tmp = t_0;
} else if (x <= 490000.0) {
tmp = y / (y - z);
} else if (x <= 6.1e+71) {
tmp = t_0;
} else if (x <= 9.4e+104) {
tmp = 1.0 - (x / y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x / (z - y)
if (x <= (-2.4d+53)) then
tmp = t_0
else if (x <= 490000.0d0) then
tmp = y / (y - z)
else if (x <= 6.1d+71) then
tmp = t_0
else if (x <= 9.4d+104) then
tmp = 1.0d0 - (x / y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x / (z - y);
double tmp;
if (x <= -2.4e+53) {
tmp = t_0;
} else if (x <= 490000.0) {
tmp = y / (y - z);
} else if (x <= 6.1e+71) {
tmp = t_0;
} else if (x <= 9.4e+104) {
tmp = 1.0 - (x / y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x / (z - y) tmp = 0 if x <= -2.4e+53: tmp = t_0 elif x <= 490000.0: tmp = y / (y - z) elif x <= 6.1e+71: tmp = t_0 elif x <= 9.4e+104: tmp = 1.0 - (x / y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x / Float64(z - y)) tmp = 0.0 if (x <= -2.4e+53) tmp = t_0; elseif (x <= 490000.0) tmp = Float64(y / Float64(y - z)); elseif (x <= 6.1e+71) tmp = t_0; elseif (x <= 9.4e+104) tmp = Float64(1.0 - Float64(x / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / (z - y); tmp = 0.0; if (x <= -2.4e+53) tmp = t_0; elseif (x <= 490000.0) tmp = y / (y - z); elseif (x <= 6.1e+71) tmp = t_0; elseif (x <= 9.4e+104) tmp = 1.0 - (x / y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.4e+53], t$95$0, If[LessEqual[x, 490000.0], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.1e+71], t$95$0, If[LessEqual[x, 9.4e+104], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{z - y}\\
\mathbf{if}\;x \leq -2.4 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 490000:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{elif}\;x \leq 6.1 \cdot 10^{+71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 9.4 \cdot 10^{+104}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.4e53 or 4.9e5 < x < 6.1000000000000003e71 or 9.40000000000000034e104 < x Initial program 99.9%
Simplified0
Taylor expanded in x around inf 0
Simplified0
if -2.4e53 < x < 4.9e5Initial program 100.0%
Simplified0
Taylor expanded in x around 0 0
Simplified0
if 6.1000000000000003e71 < x < 9.40000000000000034e104Initial program 99.8%
Simplified0
Taylor expanded in z around 0 0
Simplified0
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (/ x y)))) (if (<= y -5e-82) t_0 (if (<= y 0.000116) (/ x (- z y)) t_0))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -5e-82) {
tmp = t_0;
} else if (y <= 0.000116) {
tmp = x / (z - y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (x / y)
if (y <= (-5d-82)) then
tmp = t_0
else if (y <= 0.000116d0) then
tmp = x / (z - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -5e-82) {
tmp = t_0;
} else if (y <= 0.000116) {
tmp = x / (z - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (x / y) tmp = 0 if y <= -5e-82: tmp = t_0 elif y <= 0.000116: tmp = x / (z - y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -5e-82) tmp = t_0; elseif (y <= 0.000116) tmp = Float64(x / Float64(z - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (x / y); tmp = 0.0; if (y <= -5e-82) tmp = t_0; elseif (y <= 0.000116) tmp = x / (z - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5e-82], t$95$0, If[LessEqual[y, 0.000116], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -5 \cdot 10^{-82}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.000116:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.9999999999999998e-82 or 1.16e-4 < y Initial program 100.0%
Simplified0
Taylor expanded in z around 0 0
Simplified0
if -4.9999999999999998e-82 < y < 1.16e-4Initial program 100.0%
Simplified0
Taylor expanded in x around inf 0
Simplified0
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (/ x y)))) (if (<= y -1.2e-124) t_0 (if (<= y 2.6e-92) (/ x z) t_0))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -1.2e-124) {
tmp = t_0;
} else if (y <= 2.6e-92) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (x / y)
if (y <= (-1.2d-124)) then
tmp = t_0
else if (y <= 2.6d-92) then
tmp = x / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -1.2e-124) {
tmp = t_0;
} else if (y <= 2.6e-92) {
tmp = x / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (x / y) tmp = 0 if y <= -1.2e-124: tmp = t_0 elif y <= 2.6e-92: tmp = x / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -1.2e-124) tmp = t_0; elseif (y <= 2.6e-92) tmp = Float64(x / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (x / y); tmp = 0.0; if (y <= -1.2e-124) tmp = t_0; elseif (y <= 2.6e-92) tmp = x / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.2e-124], t$95$0, If[LessEqual[y, 2.6e-92], N[(x / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -1.2 \cdot 10^{-124}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-92}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.19999999999999996e-124 or 2.6e-92 < y Initial program 100.0%
Simplified0
Taylor expanded in z around 0 0
Simplified0
if -1.19999999999999996e-124 < y < 2.6e-92Initial program 100.0%
Simplified0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y z) :precision binary64 (if (<= y -2.55e-74) 1.0 (if (<= y 6.8e-10) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.55e-74) {
tmp = 1.0;
} else if (y <= 6.8e-10) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-2.55d-74)) then
tmp = 1.0d0
else if (y <= 6.8d-10) then
tmp = x / z
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.55e-74) {
tmp = 1.0;
} else if (y <= 6.8e-10) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.55e-74: tmp = 1.0 elif y <= 6.8e-10: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.55e-74) tmp = 1.0; elseif (y <= 6.8e-10) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.55e-74) tmp = 1.0; elseif (y <= 6.8e-10) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.55e-74], 1.0, If[LessEqual[y, 6.8e-10], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.55 \cdot 10^{-74}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-10}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.5499999999999998e-74 or 6.8000000000000003e-10 < y Initial program 100.0%
Simplified0
Taylor expanded in y around inf 0
Simplified0
if -2.5499999999999998e-74 < y < 6.8000000000000003e-10Initial program 100.0%
Simplified0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Simplified0
Taylor expanded in y around inf 0
Simplified0
(FPCore (x y z) :precision binary64 (- (/ x (- z y)) (/ y (- z y))))
double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x / (z - y)) - (y / (z - y))
end function
public static double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
def code(x, y, z): return (x / (z - y)) - (y / (z - y))
function code(x, y, z) return Float64(Float64(x / Float64(z - y)) - Float64(y / Float64(z - y))) end
function tmp = code(x, y, z) tmp = (x / (z - y)) - (y / (z - y)); end
code[x_, y_, z_] := N[(N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z - y} - \frac{y}{z - y}
\end{array}
herbie shell --seed 2024110
(FPCore (x y z)
:name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
:precision binary64
:alt
(- (/ x (- z y)) (/ y (- z y)))
(/ (- x y) (- z y)))