
(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 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= y -5.1e+129)
(/ y (- y z))
(if (or (<= y -9.5e-8) (not (<= y 6.8e+24)))
(- 1.0 (/ x y))
(/ x (- z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.1e+129) {
tmp = y / (y - z);
} else if ((y <= -9.5e-8) || !(y <= 6.8e+24)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
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 <= (-5.1d+129)) then
tmp = y / (y - z)
else if ((y <= (-9.5d-8)) .or. (.not. (y <= 6.8d+24))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.1e+129) {
tmp = y / (y - z);
} else if ((y <= -9.5e-8) || !(y <= 6.8e+24)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.1e+129: tmp = y / (y - z) elif (y <= -9.5e-8) or not (y <= 6.8e+24): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.1e+129) tmp = Float64(y / Float64(y - z)); elseif ((y <= -9.5e-8) || !(y <= 6.8e+24)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.1e+129) tmp = y / (y - z); elseif ((y <= -9.5e-8) || ~((y <= 6.8e+24))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.1e+129], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -9.5e-8], N[Not[LessEqual[y, 6.8e+24]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.1 \cdot 10^{+129}:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{elif}\;y \leq -9.5 \cdot 10^{-8} \lor \neg \left(y \leq 6.8 \cdot 10^{+24}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -5.09999999999999996e129Initial program 99.9%
Taylor expanded in x around 0 91.9%
neg-mul-191.9%
distribute-neg-frac91.9%
Simplified91.9%
frac-2neg91.9%
div-inv91.7%
remove-double-neg91.7%
sub-neg91.7%
distribute-neg-in91.7%
remove-double-neg91.7%
Applied egg-rr91.7%
associate-*r/91.9%
*-rgt-identity91.9%
+-commutative91.9%
unsub-neg91.9%
Simplified91.9%
if -5.09999999999999996e129 < y < -9.50000000000000036e-8 or 6.8000000000000001e24 < y Initial program 100.0%
Taylor expanded in z around 0 81.3%
div-sub81.3%
sub-neg81.3%
*-inverses81.3%
metadata-eval81.3%
distribute-lft-in81.3%
metadata-eval81.3%
+-commutative81.3%
mul-1-neg81.3%
unsub-neg81.3%
Simplified81.3%
if -9.50000000000000036e-8 < y < 6.8000000000000001e24Initial program 99.9%
Taylor expanded in x around inf 78.2%
Final simplification81.3%
(FPCore (x y z)
:precision binary64
(if (<= y -4.8e+129)
(/ 1.0 (- 1.0 (/ z y)))
(if (or (<= y -5.4e-8) (not (<= y 6.2e+25)))
(- 1.0 (/ x y))
(/ x (- z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e+129) {
tmp = 1.0 / (1.0 - (z / y));
} else if ((y <= -5.4e-8) || !(y <= 6.2e+25)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
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 <= (-4.8d+129)) then
tmp = 1.0d0 / (1.0d0 - (z / y))
else if ((y <= (-5.4d-8)) .or. (.not. (y <= 6.2d+25))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e+129) {
tmp = 1.0 / (1.0 - (z / y));
} else if ((y <= -5.4e-8) || !(y <= 6.2e+25)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.8e+129: tmp = 1.0 / (1.0 - (z / y)) elif (y <= -5.4e-8) or not (y <= 6.2e+25): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.8e+129) tmp = Float64(1.0 / Float64(1.0 - Float64(z / y))); elseif ((y <= -5.4e-8) || !(y <= 6.2e+25)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.8e+129) tmp = 1.0 / (1.0 - (z / y)); elseif ((y <= -5.4e-8) || ~((y <= 6.2e+25))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.8e+129], N[(1.0 / N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -5.4e-8], N[Not[LessEqual[y, 6.2e+25]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{+129}:\\
\;\;\;\;\frac{1}{1 - \frac{z}{y}}\\
\mathbf{elif}\;y \leq -5.4 \cdot 10^{-8} \lor \neg \left(y \leq 6.2 \cdot 10^{+25}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -4.7999999999999997e129Initial program 99.9%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
unpow-199.9%
Applied egg-rr99.9%
div-sub99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 91.9%
mul-1-neg91.9%
unsub-neg91.9%
Simplified91.9%
if -4.7999999999999997e129 < y < -5.40000000000000005e-8 or 6.1999999999999996e25 < y Initial program 100.0%
Taylor expanded in z around 0 81.3%
div-sub81.3%
sub-neg81.3%
*-inverses81.3%
metadata-eval81.3%
distribute-lft-in81.3%
metadata-eval81.3%
+-commutative81.3%
mul-1-neg81.3%
unsub-neg81.3%
Simplified81.3%
if -5.40000000000000005e-8 < y < 6.1999999999999996e25Initial program 99.9%
Taylor expanded in x around inf 78.2%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.1e-39) (not (<= y 1.7e-69))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e-39) || !(y <= 1.7e-69)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
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.1d-39)) .or. (.not. (y <= 1.7d-69))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e-39) || !(y <= 1.7e-69)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.1e-39) or not (y <= 1.7e-69): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.1e-39) || !(y <= 1.7e-69)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.1e-39) || ~((y <= 1.7e-69))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.1e-39], N[Not[LessEqual[y, 1.7e-69]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{-39} \lor \neg \left(y \leq 1.7 \cdot 10^{-69}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -2.09999999999999993e-39 or 1.70000000000000004e-69 < y Initial program 99.9%
Taylor expanded in z around 0 74.0%
div-sub74.0%
sub-neg74.0%
*-inverses74.0%
metadata-eval74.0%
distribute-lft-in74.0%
metadata-eval74.0%
+-commutative74.0%
mul-1-neg74.0%
unsub-neg74.0%
Simplified74.0%
if -2.09999999999999993e-39 < y < 1.70000000000000004e-69Initial program 100.0%
Taylor expanded in y around 0 68.3%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.5e-8) (not (<= y 1.9e+24))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e-8) || !(y <= 1.9e+24)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
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 <= (-5.5d-8)) .or. (.not. (y <= 1.9d+24))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e-8) || !(y <= 1.9e+24)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.5e-8) or not (y <= 1.9e+24): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.5e-8) || !(y <= 1.9e+24)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.5e-8) || ~((y <= 1.9e+24))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.5e-8], N[Not[LessEqual[y, 1.9e+24]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{-8} \lor \neg \left(y \leq 1.9 \cdot 10^{+24}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -5.5000000000000003e-8 or 1.90000000000000008e24 < y Initial program 99.9%
Taylor expanded in z around 0 79.9%
div-sub79.9%
sub-neg79.9%
*-inverses79.9%
metadata-eval79.9%
distribute-lft-in79.9%
metadata-eval79.9%
+-commutative79.9%
mul-1-neg79.9%
unsub-neg79.9%
Simplified79.9%
if -5.5000000000000003e-8 < y < 1.90000000000000008e24Initial program 99.9%
Taylor expanded in x around inf 78.2%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (<= y -9.2e-9) 1.0 (if (<= y 5.8e+24) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.2e-9) {
tmp = 1.0;
} else if (y <= 5.8e+24) {
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 <= (-9.2d-9)) then
tmp = 1.0d0
else if (y <= 5.8d+24) 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 <= -9.2e-9) {
tmp = 1.0;
} else if (y <= 5.8e+24) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.2e-9: tmp = 1.0 elif y <= 5.8e+24: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.2e-9) tmp = 1.0; elseif (y <= 5.8e+24) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.2e-9) tmp = 1.0; elseif (y <= 5.8e+24) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.2e-9], 1.0, If[LessEqual[y, 5.8e+24], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.2 \cdot 10^{-9}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{+24}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -9.1999999999999997e-9 or 5.79999999999999958e24 < y Initial program 99.9%
Taylor expanded in y around inf 61.0%
if -9.1999999999999997e-9 < y < 5.79999999999999958e24Initial program 99.9%
Taylor expanded in y around 0 60.6%
Final simplification60.8%
(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 99.9%
Taylor expanded in y around inf 35.6%
Final simplification35.6%
(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 2024066
(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)))