
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
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)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 97.3%
*-commutative97.3%
sub-neg97.3%
distribute-rgt-in97.3%
metadata-eval97.3%
neg-mul-197.3%
associate-+r+97.3%
unsub-neg97.3%
+-commutative97.3%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.6e+100) (* x z) (if (<= x -6.8e-13) (* x y) (if (<= x 5200.0) (- z) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+100) {
tmp = x * z;
} else if (x <= -6.8e-13) {
tmp = x * y;
} else if (x <= 5200.0) {
tmp = -z;
} 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 (x <= (-1.6d+100)) then
tmp = x * z
else if (x <= (-6.8d-13)) then
tmp = x * y
else if (x <= 5200.0d0) then
tmp = -z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e+100) {
tmp = x * z;
} else if (x <= -6.8e-13) {
tmp = x * y;
} else if (x <= 5200.0) {
tmp = -z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.6e+100: tmp = x * z elif x <= -6.8e-13: tmp = x * y elif x <= 5200.0: tmp = -z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.6e+100) tmp = Float64(x * z); elseif (x <= -6.8e-13) tmp = Float64(x * y); elseif (x <= 5200.0) tmp = Float64(-z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.6e+100) tmp = x * z; elseif (x <= -6.8e-13) tmp = x * y; elseif (x <= 5200.0) tmp = -z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.6e+100], N[(x * z), $MachinePrecision], If[LessEqual[x, -6.8e-13], N[(x * y), $MachinePrecision], If[LessEqual[x, 5200.0], (-z), N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+100}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -6.8 \cdot 10^{-13}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5200:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.5999999999999999e100 or 5200 < x Initial program 92.8%
*-commutative92.8%
sub-neg92.8%
distribute-rgt-in92.8%
metadata-eval92.8%
neg-mul-192.8%
associate-+r+92.8%
unsub-neg92.8%
+-commutative92.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 59.2%
Taylor expanded in x around inf 58.2%
*-commutative58.2%
Simplified58.2%
if -1.5999999999999999e100 < x < -6.80000000000000031e-13Initial program 100.0%
Taylor expanded in y around inf 71.4%
if -6.80000000000000031e-13 < x < 5200Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 99.3%
Taylor expanded in x around 0 72.3%
neg-mul-172.3%
Simplified72.3%
Final simplification66.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.6) (not (<= x 1.35e-14))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6) || !(x <= 1.35e-14)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - 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 ((x <= (-8.6d0)) .or. (.not. (x <= 1.35d-14))) then
tmp = x * (z + y)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.6) || !(x <= 1.35e-14)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.6) or not (x <= 1.35e-14): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.6) || !(x <= 1.35e-14)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.6) || ~((x <= 1.35e-14))) tmp = x * (z + y); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.6], N[Not[LessEqual[x, 1.35e-14]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.6 \lor \neg \left(x \leq 1.35 \cdot 10^{-14}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -8.59999999999999964 or 1.3499999999999999e-14 < x Initial program 94.0%
Taylor expanded in x around inf 98.3%
+-commutative98.3%
Simplified98.3%
if -8.59999999999999964 < x < 1.3499999999999999e-14Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 99.8%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-13) (not (<= x 7.4e-15))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-13) || !(x <= 7.4e-15)) {
tmp = x * (z + y);
} else {
tmp = -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 ((x <= (-5.8d-13)) .or. (.not. (x <= 7.4d-15))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-13) || !(x <= 7.4e-15)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-13) or not (x <= 7.4e-15): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-13) || !(x <= 7.4e-15)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e-13) || ~((x <= 7.4e-15))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-13], N[Not[LessEqual[x, 7.4e-15]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-13} \lor \neg \left(x \leq 7.4 \cdot 10^{-15}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.7999999999999995e-13 or 7.40000000000000034e-15 < x Initial program 94.1%
Taylor expanded in x around inf 98.3%
+-commutative98.3%
Simplified98.3%
if -5.7999999999999995e-13 < x < 7.40000000000000034e-15Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 99.8%
Taylor expanded in x around 0 74.2%
neg-mul-174.2%
Simplified74.2%
Final simplification85.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -8e-13) (not (<= x 8.2e-15))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-13) || !(x <= 8.2e-15)) {
tmp = x * y;
} else {
tmp = -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 ((x <= (-8d-13)) .or. (.not. (x <= 8.2d-15))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-13) || !(x <= 8.2e-15)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e-13) or not (x <= 8.2e-15): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e-13) || !(x <= 8.2e-15)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8e-13) || ~((x <= 8.2e-15))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e-13], N[Not[LessEqual[x, 8.2e-15]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-13} \lor \neg \left(x \leq 8.2 \cdot 10^{-15}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.0000000000000002e-13 or 8.20000000000000072e-15 < x Initial program 94.1%
Taylor expanded in y around inf 49.4%
if -8.0000000000000002e-13 < x < 8.20000000000000072e-15Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 99.8%
Taylor expanded in x around 0 74.2%
neg-mul-174.2%
Simplified74.2%
Final simplification62.8%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 97.3%
*-commutative97.3%
sub-neg97.3%
distribute-rgt-in97.3%
metadata-eval97.3%
neg-mul-197.3%
associate-+r+97.3%
unsub-neg97.3%
+-commutative97.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 76.7%
Taylor expanded in x around 0 41.3%
neg-mul-141.3%
Simplified41.3%
(FPCore (x y z) :precision binary64 0.0)
double code(double x, double y, double z) {
return 0.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.0d0
end function
public static double code(double x, double y, double z) {
return 0.0;
}
def code(x, y, z): return 0.0
function code(x, y, z) return 0.0 end
function tmp = code(x, y, z) tmp = 0.0; end
code[x_, y_, z_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 97.3%
*-commutative97.3%
sub-neg97.3%
distribute-rgt-in97.3%
metadata-eval97.3%
neg-mul-197.3%
associate-+r+97.3%
unsub-neg97.3%
+-commutative97.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 76.7%
Taylor expanded in x around 0 41.3%
neg-mul-141.3%
Simplified41.3%
add-sqr-sqrt25.2%
sqrt-unprod17.9%
sqr-neg17.9%
sqrt-unprod1.2%
add-log-exp4.0%
add-sqr-sqrt8.8%
add-sqr-sqrt8.8%
sqrt-unprod8.8%
*-un-lft-identity8.8%
exp-prod8.8%
add-sqr-sqrt4.0%
sqrt-unprod5.0%
sqr-neg5.0%
sqrt-unprod1.0%
add-sqr-sqrt1.6%
exp-prod1.6%
*-un-lft-identity1.6%
exp-neg1.6%
rgt-mult-inverse2.7%
metadata-eval2.7%
metadata-eval2.7%
Applied egg-rr2.7%
herbie shell --seed 2024147
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))